User bans, emoji and other bug fixes, age limiter, etc #26

Merged
profitroll merged 31 commits from dev into master 2023-01-31 15:26:56 +02:00
17 changed files with 50 additions and 17 deletions
Showing only changes of commit 23b2925ffa - Show all commits

View File

@ -29,6 +29,7 @@ from modules.commands.start import *
from modules.commands.warn import *
from modules.commands.warnings import *
from modules.callbacks.ban import *
from modules.callbacks.nothing import *
from modules.callbacks.reapply import *
from modules.callbacks.rules import *

View File

@ -125,6 +125,7 @@
"youtube_video": "На каналі [{0}]({1}) нове відео!\n\n**[{2}]({3})**",
"not_member": "❌ **Дія неможлива**\nУ тебе немає заповненої та схваленої анкети. Заповни таку за допомогою /reapply та спробуй ще раз після її підтвердження.",
"issue": "**Допоможіть боту**\nЗнайшли баг або помилку? Маєте файну ідею для нової функції? Повідомте нас, створивши нову задачу на гіті.\n\nЗа можливості, опишіть свій запит максимально детально. Якщо є змога, також додайте скріншоти або додаткову відому інформацію.",
"you_are_banned": "⚠️ **Вас було заблоковано**\nТепер не можна відправити анкету або користуватись командами бота.",
"yes": "Так",
"no": "Ні",
"voice_message": [
@ -236,7 +237,9 @@
"spoiler_preview": "Попередній перегляд",
"spoiler_send_chat": "Надіслати в холо-чат",
"spoiler_send_other": "Надіслати в інший чат",
"issue": "🪄 Створити задачу"
"issue": "🪄 Створити задачу",
"ban": "💀 Заблокувати",
"banned": "☠️ Заблоковано"
},
"callback": {
"sub_accepted": "✅ Анкету {0} схвалено",
@ -244,6 +247,7 @@
"sub_russian": "🇷🇺 Анкету {0} відхилено",
"sus_allowed": "✅ Доступ {0} дозволено",
"sus_rejected": "❌ Доступ {0} заборонено",
"sub_banned": "☠️ Користувача заблоковано",
"nothing": "🔔 Дія вже виконана",
"rules_page": " Показано правило {0}",
"rules_home": " Показано головну правил",

27
modules/callbacks/ban.py Normal file
View File

@ -0,0 +1,27 @@
from app import app, isAnAdmin
from pyrogram.types import InlineKeyboardMarkup, InlineKeyboardButton, CallbackQuery
from pyrogram import filters
from pyrogram.client import Client
from modules.utils import locale
from modules.database import col_bans
from modules.logging import logWrite
@app.on_callback_query(filters.regex("ban_[\s\S]*"))
async def callback_query_reject(app: Client, clb: CallbackQuery):
fullclb = clb.data.split("_")
if not await isAnAdmin(int(fullclb[1])):
col_bans.insert_one( {"user": int(fullclb[1])} )
edited_markup = [[InlineKeyboardButton(text=str(locale("banned", "button")), callback_data="nothing")]]
await clb.message.edit(text=clb.message.text, reply_markup=InlineKeyboardMarkup(edited_markup))
await clb.answer(text=locale("sub_banned", "callback", locale=clb.from_user))
logWrite(f"User {fullclb[1]} has been banned by {clb.from_user.id}")
try:
await app.send_message(int(fullclb[1]), locale("you_are_banned", "message"))
except Exception as exp:
logWrite(f"Could send ban message to {fullclb[1]} due to {exp}")

View File

@ -75,7 +75,7 @@ async def callback_query_reapply_reject(app: Client, clb: CallbackQuery):
col_tmp.update_one({"user": {"$eq": holo_user.id}, "type": {"$eq": "application"}}, {"$set": {"state": "rejected", "sent": False}})
edited_markup = [[InlineKeyboardButton(text=str(locale("declined", "button")), callback_data="nothing")]]
edited_markup = [[InlineKeyboardButton(text=str(locale("declined", "button")), callback_data="nothing")], [InlineKeyboardButton(text=str(locale("ban", "button")), callback_data=f"ban_{fullclb[2]}")]]
await clb.message.edit(text=clb.message.text, reply_markup=InlineKeyboardMarkup(edited_markup))
await clb.answer(text=locale("sub_rejected", "callback", locale=clb.from_user).format(fullclb[2]), show_alert=True)

View File

@ -63,7 +63,7 @@ async def callback_query_reject(app: Client, clb: CallbackQuery):
col_tmp.update_one({"user": {"$eq": holo_user.id}, "type": {"$eq": "application"}}, {"$set": {"state": "rejected", "sent": False}})
edited_markup = [[InlineKeyboardButton(text=str(locale("declined", "button")), callback_data="nothing")]]
edited_markup = [[InlineKeyboardButton(text=str(locale("declined", "button")), callback_data="nothing")], [InlineKeyboardButton(text=str(locale("ban", "button")), callback_data=f"ban_{fullclb[2]}")]]
await clb.message.edit(text=clb.message.text, reply_markup=InlineKeyboardMarkup(edited_markup))
await clb.answer(text=locale("sub_rejected", "callback", locale=clb.from_user).format(holo_user.id), show_alert=True)

View File

@ -7,7 +7,7 @@ from modules.database import col_tmp, col_spoilers, col_applications
from modules import custom_filters
# Cancel command ===============================================================================================================
@app.on_message((custom_filters.enabled_applications | custom_filters.enabled_sponsorships) & ~filters.scheduled & filters.command("cancel", prefixes=["/"]))
@app.on_message((custom_filters.enabled_applications | custom_filters.enabled_sponsorships) & ~filters.scheduled & filters.command("cancel", prefixes=["/"]) & ~custom_filters.banned)
async def command_cancel(app: Client, msg: Message):
col_tmp.delete_many( {"user": msg.from_user.id, "sent": False} )
col_spoilers.delete_many( {"user": msg.from_user.id, "completed": False} )

View File

@ -9,7 +9,7 @@ from classes.holo_user import HoloUser
# Issue command ================================================================================================================
@app.on_message(custom_filters.enabled_general & ~filters.scheduled & filters.private & filters.command(["issue"], prefixes=["/"]))
@app.on_message(custom_filters.enabled_general & ~filters.scheduled & filters.private & filters.command(["issue"], prefixes=["/"]) & ~custom_filters.banned)
async def cmd_issue(app: Client, msg: Message):
await msg.reply_text(locale("issue", "message", locale=msg.from_user), disable_web_page_preview=True, reply_markup=InlineKeyboardMarkup(
[

View File

@ -11,7 +11,7 @@ from modules.database import col_applications, col_users
from classes.errors.geo import PlaceNotFoundError
# Nearby command ===============================================================================================================
@app.on_message(custom_filters.enabled_applications & ~filters.scheduled & (filters.private | (filters.chat(configGet("admin", "groups")) | filters.chat(configGet("users", "groups")))) & filters.command(["nearby"], prefixes=["/"]) & (custom_filters.allowed | custom_filters.admin))
@app.on_message(custom_filters.enabled_applications & ~filters.scheduled & (filters.private | (filters.chat(configGet("admin", "groups")) | filters.chat(configGet("users", "groups")))) & filters.command(["nearby"], prefixes=["/"]) & (custom_filters.allowed | custom_filters.admin) & ~custom_filters.banned)
async def cmd_nearby(app: Client, msg: Message):
holo_user = HoloUser(msg.from_user)

View File

@ -10,7 +10,7 @@ from modules.database import col_tmp, col_applications
from modules import custom_filters
# Reapply command ==============================================================================================================
@app.on_message(custom_filters.enabled_applications & ~filters.scheduled & filters.private & filters.command(["reapply"], prefixes=["/"]))
@app.on_message(custom_filters.enabled_applications & ~filters.scheduled & filters.private & filters.command(["reapply"], prefixes=["/"]) & ~custom_filters.banned)
async def cmd_reapply(app: Client, msg: Message):
holo_user = HoloUser(msg.from_user)

View File

@ -36,7 +36,7 @@ class DefaultRulesMarkup(list):
# Rules command =============================================================================================================
@app.on_message(custom_filters.enabled_general & ~filters.scheduled & filters.private & filters.command(["rules"], prefixes=["/"]))
@app.on_message(custom_filters.enabled_general & ~filters.scheduled & filters.private & ~custom_filters.banned & filters.command(["rules"], prefixes=["/"]))
async def cmd_rules(app: Client, msg: Message):
await msg.reply_text(locale("rules_msg", locale=msg.from_user), disable_web_page_preview=True, reply_markup=DefaultRulesMarkup(msg.from_user).keyboard)
# ==============================================================================================================================

View File

@ -10,7 +10,7 @@ from modules.database import col_spoilers, col_applications
from modules import custom_filters
# Spoiler command ==============================================================================================================
@app.on_message(custom_filters.enabled_spoilers & ~filters.scheduled & filters.private & filters.command(["spoiler"], prefixes=["/"]))
@app.on_message(custom_filters.enabled_spoilers & ~filters.scheduled & filters.private & ~custom_filters.banned & filters.command(["spoiler"], prefixes=["/"]))
async def cmd_spoiler(app: Client, msg: Message):
try:

View File

@ -8,7 +8,7 @@ from modules.utils import locale, should_quote
from modules.database import col_applications
# Sponsorship command ==========================================================================================================
@app.on_message(custom_filters.enabled_sponsorships & ~filters.scheduled & filters.command(["sponsorship"], prefixes=["/"]) & (custom_filters.allowed | custom_filters.admin))
@app.on_message(custom_filters.enabled_sponsorships & ~filters.scheduled & filters.command(["sponsorship"], prefixes=["/"]) & ~custom_filters.banned & (custom_filters.allowed | custom_filters.admin))
async def cmd_sponsorship(app: Client, msg: Message):
holo_user = HoloUser(msg.from_user)
if holo_user.application_state()[0] == "fill":

View File

@ -9,7 +9,7 @@ from bson.objectid import ObjectId
from bson.errors import InvalidId
# Start command ================================================================================================================
@app.on_message(custom_filters.enabled_applications & ~filters.scheduled & filters.private & filters.command(["start"], prefixes=["/"]))
@app.on_message(custom_filters.enabled_applications & ~filters.scheduled & filters.private & filters.command(["start"], prefixes=["/"]) & ~custom_filters.banned)
async def cmd_start(app: Client, msg: Message):
user = col_users.find_one({"user": msg.from_user.id})

View File

@ -16,7 +16,7 @@ from modules import custom_filters
confirmation_1 = []
for pattern in all_locales("confirm", "keyboard"):
confirmation_1.append(pattern[0][0])
@app.on_message((custom_filters.enabled_applications | custom_filters.enabled_sponsorships) & ~filters.scheduled & filters.private & filters.command(confirmation_1, prefixes=[""]))
@app.on_message((custom_filters.enabled_applications | custom_filters.enabled_sponsorships) & ~filters.scheduled & filters.private & filters.command(confirmation_1, prefixes=[""]) & ~custom_filters.banned)
async def confirm_yes(app: Client, msg: Message, kind: Literal["application", "sponsorship", "unknown"] = "unknown"):
holo_user = HoloUser(msg.from_user)
@ -145,7 +145,7 @@ async def confirm_yes(app: Client, msg: Message, kind: Literal["application", "s
confirmation_2 = []
for pattern in all_locales("confirm", "keyboard"):
confirmation_2.append(pattern[1][0])
@app.on_message((custom_filters.enabled_applications | custom_filters.enabled_sponsorships) & ~filters.scheduled & filters.private & filters.command(confirmation_2, prefixes=[""]))
@app.on_message((custom_filters.enabled_applications | custom_filters.enabled_sponsorships) & ~filters.scheduled & filters.private & filters.command(confirmation_2, prefixes=[""]) & ~custom_filters.banned)
async def confirm_no(app: Client, msg: Message, kind: Literal["application", "sponsorship", "unknown"] = "unknown"):
holo_user = HoloUser(msg.from_user)

View File

@ -10,7 +10,7 @@ from classes.holo_user import HoloUser
from modules import custom_filters
# Contact getting ==============================================================================================================
@app.on_message(custom_filters.enabled_applications & ~filters.scheduled & filters.contact & filters.private & (custom_filters.allowed | custom_filters.admin))
@app.on_message(custom_filters.enabled_applications & ~filters.scheduled & filters.contact & filters.private & (custom_filters.allowed | custom_filters.admin) & ~custom_filters.banned)
async def get_contact(app: Client, msg: Message):
holo_user = HoloUser(msg.from_user)

View File

@ -8,6 +8,7 @@ from pyrogram.client import Client
from classes.holo_user import HoloUser
from modules.utils import configGet, logWrite, locale, all_locales
from modules.database import col_messages, col_spoilers
from modules import custom_filters
async def message_involved(msg: Message) -> bool:
message = col_messages.find_one({"destination.id": msg.reply_to_message.id, "destination.chat": msg.reply_to_message.chat.id})
@ -22,7 +23,7 @@ async def message_context(msg: Message) -> tuple:
return 0, 0
# Any other input ==============================================================================================================
@app.on_message(~ filters.scheduled & (filters.private | filters.chat(configGet("admin", "groups"))))
@app.on_message(~ filters.scheduled & (filters.private | filters.chat(configGet("admin", "groups"))) & ~custom_filters.banned)
async def any_stage(app: Client, msg: Message):
if msg.via_bot is None:

View File

@ -12,7 +12,7 @@ for pattern in all_locales("welcome", "keyboard"):
welcome_1.append(pattern[0][0])
for pattern in all_locales("return", "keyboard"):
welcome_1.append(pattern[0][0])
@app.on_message(custom_filters.enabled_applications & ~filters.scheduled & filters.private & filters.command(welcome_1, prefixes=[""]))
@app.on_message(custom_filters.enabled_applications & ~filters.scheduled & filters.private & filters.command(welcome_1, prefixes=[""]) & ~custom_filters.banned)
async def welcome_pass(app: Client, msg: Message, once_again: bool = False) -> None:
"""Set user's stage to 1 and start a fresh application
@ -39,7 +39,7 @@ async def welcome_pass(app: Client, msg: Message, once_again: bool = False) -> N
welcome_2 = []
for pattern in all_locales("welcome", "keyboard"):
welcome_2.append(pattern[1][0])
@app.on_message(custom_filters.enabled_applications & ~filters.scheduled & filters.private & filters.command(welcome_2, prefixes=[""]))
@app.on_message(custom_filters.enabled_applications & ~filters.scheduled & filters.private & filters.command(welcome_2, prefixes=[""]) & ~custom_filters.banned)
async def welcome_reject(app: Client, msg: Message):
logWrite(f"User {msg.from_user.id} rejected to start the application")