from os import path, sep from app import app, isAnAdmin from pyrogram import filters from pyrogram.enums.chat_members_filter import ChatMembersFilter from modules.utils import configGet, jsonLoad, locale, should_quote # Warnings command ============================================================================================================= @app.on_message(~ filters.scheduled & filters.command(["warnings"], prefixes=["/"])) async def cmd_warnings(app, msg): if msg.chat.id == configGet("admin_group") or await isAnAdmin(msg.from_user.id): warnings = jsonLoad(f"{configGet('data', 'locations')}{sep}warnings.json") if len(msg.command) <= 1: await msg.reply_text(locale("syntax_warnings", "message"), quote=should_quote(msg)) if path.exists(f"{configGet('data', 'locations')}{sep}users{sep}{msg.command[1]}.json"): target_id = str(int(msg.command[1])) target_name = "N/A" else: list_of_users = [] async for m in app.get_chat_members(configGet("destination_group"), filter=ChatMembersFilter.SEARCH, query=msg.command[1]): list_of_users.append(m) if len(list_of_users) != 0: target = list_of_users[0].user target_name = target.first_name target_id = str(target.id) else: await msg.reply_text(locale("no_user_warnings", "message").format(msg.command[1])) return if target_id not in warnings: await msg.reply_text(locale("no_warnings", "message").format(target_name, target_id), quote=should_quote(msg)) else: if warnings[target_id] <= 5: await msg.reply_text(locale("warnings_1", "message").format(target_name, target_id, warnings[target_id]), quote=should_quote(msg)) else: await msg.reply_text(locale("warnings_2", "message").format(target_name, target_id, warnings[target_id]), quote=should_quote(msg)) # ==============================================================================================================================