from app import app, isAnAdmin from pyrogram import filters from pyrogram.enums.chat_members_filter import ChatMembersFilter from modules.utils import configGet, locale, should_quote from modules.database import col_users, col_warnings # Warnings command ============================================================================================================= @app.on_message(~ filters.scheduled & filters.command(["warnings"], prefixes=["/"])) async def cmd_warnings(app, msg): 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)) try: user_db = col_users.find_one({"user": int(msg.command[1])}) target_id = user_db["user"] target_name = user_db["tg_name"] except: 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 warns = len(list(col_warnings.find({"user": target_id}))) if warns == 0: await msg.reply_text(locale("no_warnings", "message").format(target_name, target_id), quote=should_quote(msg)) else: if warns <= 5: await msg.reply_text(locale("warnings_1", "message").format(target_name, target_id, warns), quote=should_quote(msg)) else: await msg.reply_text(locale("warnings_2", "message").format(target_name, target_id, warns), quote=should_quote(msg)) # ==============================================================================================================================