From 49bed307ad50835d75f740043d2e709068c14e97 Mon Sep 17 00:00:00 2001 From: profitroll Date: Thu, 15 Dec 2022 14:31:42 +0100 Subject: [PATCH] Improved isAnAdmin() usage --- modules/commands/applications.py | 2 +- modules/commands/label.py | 2 +- modules/commands/message.py | 2 +- modules/commands/reboot.py | 2 +- modules/commands/warn.py | 2 +- modules/commands/warnings.py | 2 +- modules/handlers/contact.py | 2 +- modules/handlers/group_join.py | 2 +- modules/inline.py | 2 +- 9 files changed, 9 insertions(+), 9 deletions(-) diff --git a/modules/commands/applications.py b/modules/commands/applications.py index 4b7578c..2749739 100644 --- a/modules/commands/applications.py +++ b/modules/commands/applications.py @@ -10,7 +10,7 @@ from modules.database import col_applications @app.on_message(~ filters.scheduled & filters.command(["applications"], prefixes=["/"])) async def cmd_applications(app, msg): - if (await isAnAdmin(msg.from_user.id)) or (msg.chat.id == configGet("admin_group")): + if await isAnAdmin(msg.from_user.id) is True: await app.send_chat_action(msg.chat.id, ChatAction.UPLOAD_DOCUMENT) filename = uuid1() output = [] diff --git a/modules/commands/label.py b/modules/commands/label.py index f474fe0..02e2c1d 100644 --- a/modules/commands/label.py +++ b/modules/commands/label.py @@ -6,7 +6,7 @@ from classes.holo_user import HoloUser @app.on_message(~ filters.scheduled & filters.private & filters.command(["label"], prefixes=["/"])) async def cmd_label(app, msg): - if msg.chat.id == configGet("admin_group") or await isAnAdmin(msg.from_user.id): + if await isAnAdmin(msg.from_user.id) is True: if len(msg.command) < 3: await msg.reply_text("Invalid syntax:\n`/label USER LABEL`") diff --git a/modules/commands/message.py b/modules/commands/message.py index 1aa377d..1952898 100644 --- a/modules/commands/message.py +++ b/modules/commands/message.py @@ -7,7 +7,7 @@ from modules.utils import logWrite, locale, configGet, should_quote @app.on_message(~ filters.scheduled & filters.command(["message"], prefixes=["/"])) async def cmd_message(app, msg): - if msg.chat.id == configGet("admin_group") or await isAnAdmin(msg.from_user.id): + if await isAnAdmin(msg.from_user.id) is True: try: diff --git a/modules/commands/reboot.py b/modules/commands/reboot.py index 1397f41..8ff59cf 100644 --- a/modules/commands/reboot.py +++ b/modules/commands/reboot.py @@ -11,7 +11,7 @@ pid = getpid() @app.on_message(~ filters.scheduled & filters.private & filters.command(["kill", "die", "reboot"], prefixes=["/"])) async def cmd_kill(app, msg): - if msg.chat.id == configGet("admin_group") or await isAnAdmin(msg.from_user.id): + if await isAnAdmin(msg.from_user.id) is True: logWrite(f"Shutting down bot with pid {pid}") await msg.reply_text(f"Вимкнення бота з підом `{pid}`", quote=should_quote(msg)) scheduler.shutdown() diff --git a/modules/commands/warn.py b/modules/commands/warn.py index 9d56e63..50f948c 100644 --- a/modules/commands/warn.py +++ b/modules/commands/warn.py @@ -10,7 +10,7 @@ async def cmd_warn(app, msg): if msg.chat.id == configGet("destination_group"): if msg.reply_to_message_id != None: - if await isAnAdmin(msg.from_user.id): + if await isAnAdmin(msg.from_user.id) is True: message = " ".join(msg.command[1:]) if len(msg.command) > 1 else "" col_warnings.insert_one({"user": msg.reply_to_message.from_user.id, "admin": msg.from_user.id, "date": datetime.now(), "reason": message}) if message == "": diff --git a/modules/commands/warnings.py b/modules/commands/warnings.py index 4a6ecda..843817e 100644 --- a/modules/commands/warnings.py +++ b/modules/commands/warnings.py @@ -8,7 +8,7 @@ from modules.database import col_users, col_warnings @app.on_message(~ filters.scheduled & filters.command(["warnings"], prefixes=["/"])) async def cmd_warnings(app, msg): - if await isAnAdmin(msg.from_user.id): + if await isAnAdmin(msg.from_user.id) is True: if len(msg.command) <= 1: await msg.reply_text(locale("syntax_warnings", "message"), quote=should_quote(msg)) diff --git a/modules/handlers/contact.py b/modules/handlers/contact.py index 10c4f6f..462a13a 100644 --- a/modules/handlers/contact.py +++ b/modules/handlers/contact.py @@ -8,7 +8,7 @@ from modules.utils import configGet, jsonLoad, locale, logWrite # Contact getting ============================================================================================================== @app.on_message(~ filters.scheduled & filters.contact & filters.private) async def get_contact(app, msg): - if (path.exists(f"{configGet('data', 'locations')}{sep}users{sep}{msg.from_user.id}.json") and jsonLoad(f"{configGet('data', 'locations')}{sep}users{sep}{msg.from_user.id}.json")["approved"]) or (await isAnAdmin(msg.from_user.id)): + if (path.exists(f"{configGet('data', 'locations')}{sep}users{sep}{msg.from_user.id}.json") and jsonLoad(f"{configGet('data', 'locations')}{sep}users{sep}{msg.from_user.id}.json")["approved"]) or (await isAnAdmin(msg.from_user.id) is True): if msg.contact.user_id != None: try: user_data = jsonLoad(f"{configGet('data', 'locations')}{sep}users{sep}{msg.contact.user_id}.json") diff --git a/modules/handlers/group_join.py b/modules/handlers/group_join.py index f4c53a8..6012d9d 100644 --- a/modules/handlers/group_join.py +++ b/modules/handlers/group_join.py @@ -8,7 +8,7 @@ from modules.utils import configGet, jsonLoad, locale #@app.on_message(filters.new_chat_members, group=configGet("destination_group")) async def filter_join(app, member): if member.invite_link != None: - if (path.exists(f"{configGet('data', 'locations')}{sep}users{sep}{member.from_user.id}.json") and jsonLoad(f"{configGet('data', 'locations')}{sep}users{sep}{member.from_user.id}.json")["approved"]) or (await isAnAdmin(member.from_user.id)): + if (path.exists(f"{configGet('data', 'locations')}{sep}users{sep}{member.from_user.id}.json") and jsonLoad(f"{configGet('data', 'locations')}{sep}users{sep}{member.from_user.id}.json")["approved"]) or (await isAnAdmin(member.from_user.id) is True): if configGet("link", file=str(member.from_user.id)) == member.invite_link.invite_link: return if await isAnAdmin(member.invite_link.creator.id): diff --git a/modules/inline.py b/modules/inline.py index 4b8c6f9..d9866ff 100644 --- a/modules/inline.py +++ b/modules/inline.py @@ -25,7 +25,7 @@ async def inline_answer(client, inline_query): ) return - if (path.exists(f"{configGet('data', 'locations')}{sep}users{sep}{inline_query.from_user.id}.json") and jsonLoad(f"{configGet('data', 'locations')}{sep}users{sep}{inline_query.from_user.id}.json")["approved"]) or (await isAnAdmin(inline_query.from_user.id)): + if (path.exists(f"{configGet('data', 'locations')}{sep}users{sep}{inline_query.from_user.id}.json") and jsonLoad(f"{configGet('data', 'locations')}{sep}users{sep}{inline_query.from_user.id}.json")["approved"]) or (await isAnAdmin(inline_query.from_user.id) is True): list_of_users = [] async for m in app.get_chat_members(configGet("destination_group"), limit=configGet("inline_preview_count"), filter=ChatMembersFilter.SEARCH, query=inline_query.query):