From 23b2925ffaf0ed6bbd3f53248076f438f72eabe6 Mon Sep 17 00:00:00 2001 From: profitroll Date: Mon, 30 Jan 2023 11:28:23 +0100 Subject: [PATCH] This commit closes #17 --- holochecker.py | 1 + locale/uk.json | 6 +++++- modules/callbacks/ban.py | 27 +++++++++++++++++++++++++++ modules/callbacks/reapply.py | 2 +- modules/callbacks/sub.py | 2 +- modules/commands/cancel.py | 2 +- modules/commands/issue.py | 2 +- modules/commands/nearby.py | 2 +- modules/commands/reapply.py | 2 +- modules/commands/rules.py | 2 +- modules/commands/spoiler.py | 2 +- modules/commands/sponsorship.py | 2 +- modules/commands/start.py | 2 +- modules/handlers/confirmation.py | 4 ++-- modules/handlers/contact.py | 2 +- modules/handlers/everything.py | 3 ++- modules/handlers/welcome.py | 4 ++-- 17 files changed, 50 insertions(+), 17 deletions(-) create mode 100644 modules/callbacks/ban.py diff --git a/holochecker.py b/holochecker.py index be4de80..50d434d 100644 --- a/holochecker.py +++ b/holochecker.py @@ -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 * diff --git a/locale/uk.json b/locale/uk.json index f7997c5..440becb 100644 --- a/locale/uk.json +++ b/locale/uk.json @@ -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": "ℹ️ Показано головну правил", diff --git a/modules/callbacks/ban.py b/modules/callbacks/ban.py new file mode 100644 index 0000000..b34ad76 --- /dev/null +++ b/modules/callbacks/ban.py @@ -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}") \ No newline at end of file diff --git a/modules/callbacks/reapply.py b/modules/callbacks/reapply.py index 121a7d3..13671f2 100644 --- a/modules/callbacks/reapply.py +++ b/modules/callbacks/reapply.py @@ -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) diff --git a/modules/callbacks/sub.py b/modules/callbacks/sub.py index f806f50..e9ba485 100644 --- a/modules/callbacks/sub.py +++ b/modules/callbacks/sub.py @@ -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) diff --git a/modules/commands/cancel.py b/modules/commands/cancel.py index 8721dc8..d46fa6f 100644 --- a/modules/commands/cancel.py +++ b/modules/commands/cancel.py @@ -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} ) diff --git a/modules/commands/issue.py b/modules/commands/issue.py index f300455..b6dd9bb 100644 --- a/modules/commands/issue.py +++ b/modules/commands/issue.py @@ -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( [ diff --git a/modules/commands/nearby.py b/modules/commands/nearby.py index f0a80a4..993322b 100644 --- a/modules/commands/nearby.py +++ b/modules/commands/nearby.py @@ -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) diff --git a/modules/commands/reapply.py b/modules/commands/reapply.py index c2722fc..70e5105 100644 --- a/modules/commands/reapply.py +++ b/modules/commands/reapply.py @@ -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) diff --git a/modules/commands/rules.py b/modules/commands/rules.py index f81a701..3ddc3b5 100644 --- a/modules/commands/rules.py +++ b/modules/commands/rules.py @@ -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) # ============================================================================================================================== \ No newline at end of file diff --git a/modules/commands/spoiler.py b/modules/commands/spoiler.py index 8b0f150..b28429c 100644 --- a/modules/commands/spoiler.py +++ b/modules/commands/spoiler.py @@ -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: diff --git a/modules/commands/sponsorship.py b/modules/commands/sponsorship.py index 4896b2a..46cc05a 100644 --- a/modules/commands/sponsorship.py +++ b/modules/commands/sponsorship.py @@ -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": diff --git a/modules/commands/start.py b/modules/commands/start.py index 85b8e0c..0452507 100644 --- a/modules/commands/start.py +++ b/modules/commands/start.py @@ -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}) diff --git a/modules/handlers/confirmation.py b/modules/handlers/confirmation.py index 9dc8a79..51e82da 100644 --- a/modules/handlers/confirmation.py +++ b/modules/handlers/confirmation.py @@ -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) diff --git a/modules/handlers/contact.py b/modules/handlers/contact.py index 83f3122..1a75fef 100644 --- a/modules/handlers/contact.py +++ b/modules/handlers/contact.py @@ -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) diff --git a/modules/handlers/everything.py b/modules/handlers/everything.py index b8e1547..9cc5f0c 100644 --- a/modules/handlers/everything.py +++ b/modules/handlers/everything.py @@ -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: diff --git a/modules/handlers/welcome.py b/modules/handlers/welcome.py index 2450178..5b139d2 100644 --- a/modules/handlers/welcome.py +++ b/modules/handlers/welcome.py @@ -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")