diff --git a/userge/plugins/admin/gban.py b/userge/plugins/admin/gban.py index 2a603050c..d151dc6ec 100644 --- a/userge/plugins/admin/gban.py +++ b/userge/plugins/admin/gban.py @@ -12,6 +12,7 @@ import requests import spamwatch +from pyrogram.errors.exceptions.bad_request_400 import ChatAdminRequired from userge import userge, Message, Config, get_collection, Filters @@ -32,14 +33,6 @@ async def me_can_restrict_members(chat_id: int): return False -async def user_is_admin(chat_id: int, user_id: int) -> bool: - check_status = await userge.get_chat_member(chat_id, user_id) - admin_strings = ["creator", "administrator"] - if check_status.status not in admin_strings: - return False - return True - - @userge.on_cmd("gban", about={ 'header': "Globally Ban A User", 'description': "Adds User to your GBan List. " @@ -49,7 +42,7 @@ async def user_is_admin(chat_id: int, user_id: int) -> bool: allow_channels=False, allow_bots=False) async def gban_user(message: Message): """ ban a user globally """ - chat_id = message.chat.id + await message.edit("`GBanning...`") if message.reply_to_message: user_id = message.reply_to_message.from_user.id reason = message.input_str @@ -85,31 +78,27 @@ async def gban_user(message: Message): "**#Already_GBanned**\n\nUser Already Exists in My Gban List.\n" f"**Reason For GBan:** `{found['reason']}`", del_in=5) return - async for chat in userge.get_common_chats(user_id): - await chat.kick_member(user_id) - sent = await message.edit( - r"\\**#GBanned_User**//" - f"\n\n**First Name:** [{firstname}](tg://user?id={user_id})\n" - f"**User ID:** `{user_id}`\n**Reason:** `{reason}`") + await asyncio.gather( + GBAN_USER_BASE.insert_one( + {'firstname': firstname, 'user_id': user_id, 'reason': reason}), + message.edit( + r"\\**#GBanned_User**//" + f"\n\n**First Name:** [{firstname}](tg://user?id={user_id})\n" + f"**User ID:** `{user_id}`\n**Reason:** `{reason}`")) # TODO: can we add something like "GBanned by {any_sudo_user_fname}" - await GBAN_USER_BASE.insert_one( - {'firstname': firstname, 'user_id': user_id, 'reason': reason}) - if message.chat.type not in ('private', 'bot') and await me_can_restrict_members(chat_id): - if await user_is_admin(chat_id, user_id): - await sent.reply( - f"**#GBanned_user** is admin of {message.chat.title}\n\n" - "**Failed to Ban** but still they are GBanned") - else: - await userge.kick_chat_member(chat_id, user_id) + for chat in await userge.get_common_chats(user_id): + try: + await chat.kick_member(user_id) + await CHANNEL.log( + r"\\**#Antispam_Log**//" + f"\n**User:** [{firstname}](tg://user?id={user_id})\n" + f"**User ID:** `{user_id}`\n" + f"**Chat:** {chat.title}\n" + f"**Chat ID:** `{chat.id}`\n" + f"**Reason:** `{reason}`\n\n$GBAN #id{user_id}") + except ChatAdminRequired: + pass LOG.info("G-Banned %s", str(user_id)) - await CHANNEL.log( - r"\\**#Antispam_Log**//" - f"\n**User:** [{firstname}](tg://user?id={user_id})\n" - f"**User ID:** `{user_id}`\n" - f"**Chat:** {message.chat.title}\n" - f"**Chat ID:** `{chat_id}`\n" - f"**Reason:** `{reason}`\n\n$GBAN #id{user_id}" - ) try: if message.reply_to_message: await CHANNEL.fwd_msg(message.reply_to_message) @@ -126,7 +115,7 @@ async def gban_user(message: Message): allow_channels=False, allow_bots=False) async def ungban_user(message: Message): """ unban a user globally """ - chat_id = message.chat.id + await message.edit("`UnGBanning...`") if message.reply_to_message: user_id = message.reply_to_message.from_user.id else: @@ -141,21 +130,23 @@ async def ungban_user(message: Message): if not found: await message.err("User Not Found in My Gban List") return - async for chat in userge.get_common_chats(user_id): - await chat.unban_member(user_id) await asyncio.gather( GBAN_USER_BASE.delete_one({'firstname': firstname, 'user_id': user_id}), message.edit( r"\\**#UnGbanned_User**//" f"\n\n**First Name:** [{firstname}](tg://user?id={user_id})\n" - f"**User ID:** `{user_id}`"), - CHANNEL.log( - r"\\**#Antispam_Log**//" - f"\n**User:** [{firstname}](tg://user?id={user_id})\n" - f"**User ID:** `{user_id}`\n" - f"**Chat:** {message.chat.title}\n" - f"**Chat ID:** `{chat_id}`\n\n$UNGBAN #id{user_id}") - ) + f"**User ID:** `{user_id}`")) + for chat in await userge.get_common_chats(user_id): + try: + await chat.unban_member(user_id) + await CHANNEL.log( + r"\\**#Antispam_Log**//" + f"\n**User:** [{firstname}](tg://user?id={user_id})\n" + f"**User ID:** `{user_id}`\n" + f"**Chat:** {chat.title}\n" + f"**Chat ID:** `{chat.id}`\n\n$UNGBAN #id{user_id}") + except ChatAdminRequired: + pass LOG.info("UnGbanned %s", str(user_id)) diff --git a/userge/plugins/utils/filters.py b/userge/plugins/utils/filters.py index 386fd9cec..83465f6dc 100644 --- a/userge/plugins/utils/filters.py +++ b/userge/plugins/utils/filters.py @@ -73,7 +73,7 @@ async def delete_filters(message: Message) -> None: await message.edit(text=out, del_in=3) -@userge.on_cmd(r"addfilter (\w[^\|]*)(?:\s?\|\s?([\s\S]+))?", +@userge.on_cmd(r"addfilter ([^\s\|][^\|]*)(?:\s?\|\s?([\s\S]+))?", about={ 'header': "Adds a filter by name", 'options': { diff --git a/userge/plugins/utils/notes.py b/userge/plugins/utils/notes.py index 411985eed..a58652f8f 100644 --- a/userge/plugins/utils/notes.py +++ b/userge/plugins/utils/notes.py @@ -83,7 +83,7 @@ async def mv_to_global_note(message: Message) -> None: await message.edit(text=out, del_in=3) -@userge.on_cmd(r"(?:#|get\s)(\w[\w_]*)", +@userge.on_cmd(r"(?:#|get\s)(\S+)", about={'header': "Gets a note by name", 'usage': "#[notename]\nget notename"}, group=-1, @@ -113,7 +113,7 @@ async def get_note(message: Message) -> None: reply_to_message_id=reply_to_message_id) -@userge.on_cmd(r"addnote (\w[\w_]*)(?:\s([\s\S]+))?", +@userge.on_cmd(r"addnote (\S+)(?:\s([\s\S]+))?", about={ 'header': "Adds a note by name", 'options': { @@ -134,7 +134,7 @@ async def add_note(message: Message) -> None: if replied and replied.text: content = replied.text.html if content: - content = "🗒 **--{}--** 🗒\n\n{}".format(notename, content) + content = "📝 **--{}--** 📝\n\n{}".format(notename, content) if not (content or (replied and replied.media)): await message.err(text="No Content Found!") return