From b3669df4db6878b97d6b0d1b2afd64f2f1c3aecb Mon Sep 17 00:00:00 2001 From: rking32 Date: Thu, 23 Jul 2020 01:47:27 +0530 Subject: [PATCH] fix notes bug in channels, bots and some cleanups --- userge/core/methods/decorators/on_cmd.py | 5 +- userge/core/methods/decorators/on_filters.py | 4 +- .../core/methods/decorators/on_left_member.py | 2 +- .../core/methods/decorators/on_new_member.py | 2 +- userge/plugins/admin/gadmin.py | 975 +++++++----------- userge/plugins/admin/gban.py | 3 +- userge/plugins/admin/locks.py | 56 +- userge/plugins/misc/utube.py | 3 +- userge/plugins/utils/filters.py | 2 +- userge/plugins/utils/notes.py | 2 - userge/plugins/utils/welcome.py | 4 +- 11 files changed, 425 insertions(+), 633 deletions(-) diff --git a/userge/core/methods/decorators/on_cmd.py b/userge/core/methods/decorators/on_cmd.py index 6b70f4639..484275343 100644 --- a/userge/core/methods/decorators/on_cmd.py +++ b/userge/core/methods/decorators/on_cmd.py @@ -91,7 +91,7 @@ def on_cmd(self, If ``True``, allow this via your bot, defaults to True. check_client (``bool``, *optional*): - If ``True``, check client is bot or not before execute, defaults to True. + If ``True``, check client is bot or not before execute, defaults to False. kwargs: prefix (``str``, *optional*): @@ -143,4 +143,5 @@ def on_cmd(self, and (m.text.startswith(Config.SUDO_TRIGGER) if trigger else True)) filters_ = filters_ & (outgoing_flt | incoming_flt) return self._build_decorator(log=f"On {pattern}", filters=filters_, flt=cmd, - check_client=check_client, scope=scope, **kwargs) + check_client=check_client and allow_via_bot, + scope=scope, **kwargs) diff --git a/userge/core/methods/decorators/on_filters.py b/userge/core/methods/decorators/on_filters.py index 980b06d9a..b92896ff6 100644 --- a/userge/core/methods/decorators/on_filters.py +++ b/userge/core/methods/decorators/on_filters.py @@ -21,7 +21,7 @@ def on_filters(self, filters: Filters, group: int = 0, allow_via_bot: bool = True, - check_client: bool = False) -> RawDecorator._PYRORETTYPE: + check_client: bool = True) -> RawDecorator._PYRORETTYPE: """\nDecorator for handling filters Parameters: @@ -41,4 +41,4 @@ def on_filters(self, flt = types.raw.Filter(self, group, allow_via_bot) filters = Filters.create(lambda _, __: flt.is_enabled) & filters return self._build_decorator(log=f"On Filters {filters}", filters=filters, - flt=flt, check_client=check_client) + flt=flt, check_client=check_client and allow_via_bot) diff --git a/userge/core/methods/decorators/on_left_member.py b/userge/core/methods/decorators/on_left_member.py index f577df791..34d5fd690 100644 --- a/userge/core/methods/decorators/on_left_member.py +++ b/userge/core/methods/decorators/on_left_member.py @@ -20,7 +20,7 @@ def on_left_member(self, leaving_chats: Filters.chat, group: int = -2, allow_via_bot: bool = True, - check_client: bool = False) -> RawDecorator._PYRORETTYPE: + check_client: bool = True) -> RawDecorator._PYRORETTYPE: """\nDecorator for handling left members Parameters: diff --git a/userge/core/methods/decorators/on_new_member.py b/userge/core/methods/decorators/on_new_member.py index d45e83a7f..157692f46 100644 --- a/userge/core/methods/decorators/on_new_member.py +++ b/userge/core/methods/decorators/on_new_member.py @@ -20,7 +20,7 @@ def on_new_member(self, welcome_chats: Filters.chat, group: int = -2, allow_via_bot: bool = True, - check_client: bool = False) -> RawDecorator._PYRORETTYPE: + check_client: bool = True) -> RawDecorator._PYRORETTYPE: """\nDecorator for handling new members Parameters: diff --git a/userge/plugins/admin/gadmin.py b/userge/plugins/admin/gadmin.py index 9a3e423b0..828b07c69 100644 --- a/userge/plugins/admin/gadmin.py +++ b/userge/plugins/admin/gadmin.py @@ -17,7 +17,6 @@ from pyrogram.errors import (FloodWait, UserAdminInvalid, UsernameInvalid, - ChatAdminRequired, PeerIdInvalid, UserIdInvalid) @@ -26,32 +25,6 @@ CHANNEL = userge.getCLogger(__name__) -async def is_admin(message: Message): - check_user = await message.client.get_chat_member(message.chat.id, message.from_user.id) - user_type = check_user.status - if user_type == "member": - return False - if user_type == "administrator": - rm_perm = check_user.can_restrict_members - if rm_perm: - return True - return False - return True - - -async def is_sudoadmin(message: Message): - check_user = await message.client.get_chat_member(message.chat.id, message.from_user.id) - user_type = check_user.status - if user_type == "member": - return False - if user_type == "administrator": - add_adminperm = check_user.can_promote_members - if add_adminperm: - return True - return False - return True - - @userge.on_cmd("promote", about={ 'header': "use this to promote group members", 'description': "Provides admin rights to the person in the supergroup.\n" @@ -60,7 +33,7 @@ async def is_sudoadmin(message: Message): 'examples': [ "{tr}promote [username | userid] or [reply to user] :custom title (optional)", "{tr}promote @someusername/userid/replytouser Staff (custom title)"]}, - allow_channels=False, allow_bots=False, allow_private=False) + allow_channels=False, allow_bots=False, allow_private=False, only_admins=True) async def promote_usr(message: Message): """ promote members in tg group @@ -68,9 +41,9 @@ async def promote_usr(message: Message): custom_rank = "" chat_id = message.chat.id get_group = await message.client.get_chat(chat_id) - can_promo = await is_sudoadmin(message) + check_user = await message.client.get_chat_member(message.chat.id, message.from_user.id) - if can_promo: + if check_user.can_promote_members: await message.edit("`Trying to Promote User.. Hang on!! ⏳`") @@ -97,7 +70,7 @@ async def promote_usr(message: Message): else: await message.edit( text="`no valid user_id or message specified,`" - "`do .help promote for more info`", del_in=0) + "`do .help promote for more info`", del_in=5) return if user_id: @@ -115,7 +88,7 @@ async def promote_usr(message: Message): await message.client.set_administrator_title(chat_id, user_id, custom_rank) - await message.edit("`👑 Promoted Successfully..`", del_in=0) + await message.edit("`👑 Promoted Successfully..`", del_in=5) await CHANNEL.log( f"#PROMOTE\n\n" @@ -126,38 +99,28 @@ async def promote_usr(message: Message): except UsernameInvalid: await message.edit( - text="`invalid username, try again with valid info ⚠`", del_in=0 + text="`invalid username, try again with valid info ⚠`", del_in=5 ) - return except PeerIdInvalid: await message.edit( - text="`invalid username or userid, try again with valid info ⚠`", del_in=0 + text="`invalid username or userid, try again with valid info ⚠`", del_in=5 ) - return except UserIdInvalid: await message.edit( - text="`invalid userid, try again with valid info ⚠`", del_in=0 + text="`invalid userid, try again with valid info ⚠`", del_in=5 ) - return - - except ChatAdminRequired: - await message.edit( - text=r"`i don't have permission to do that >︿<`", del_in=0 - ) - return except Exception as e_f: await message.edit( text="`something went wrong! 🤔`\n\n" f"**ERROR:** `{e_f}`" ) - return else: await message.edit( - text=r"`i don't have proper permission to do that! (*  ̄︿ ̄)`", del_in=0) + text=r"`i don't have proper permission to do that! (*  ̄︿ ̄)`", del_in=5) @userge.on_cmd("demote", about={ @@ -165,16 +128,16 @@ async def promote_usr(message: Message): 'description': "Remove admin rights from admin in the supergroup.\n" "[NOTE: Requires proper admin rights in the chat!!!]", 'examples': "{tr}demote [username | userid] or [reply to user]"}, - allow_channels=False, allow_bots=False, allow_private=False) + allow_channels=False, allow_bots=False, allow_private=False, only_admins=True) async def demote_usr(message: Message): """ demote members in tg group """ chat_id = message.chat.id get_group = await message.client.get_chat(chat_id) - can_demote = await is_sudoadmin(message) + check_user = await message.client.get_chat_member(message.chat.id, message.from_user.id) - if can_demote: + if check_user.can_promote_members: await message.edit("`Trying to Demote User.. Hang on!! ⏳`") @@ -191,7 +154,7 @@ async def demote_usr(message: Message): can_invite_users=False, can_pin_messages=False) - await message.edit("`🛡 Demoted Successfully..`", del_in=0) + await message.edit("`🛡 Demoted Successfully..`", del_in=5) await CHANNEL.log( f"#DEMOTE\n\n" f"USER: [{get_mem.user.first_name}](tg://user?id={get_mem.user.id}) " @@ -200,34 +163,24 @@ async def demote_usr(message: Message): except UsernameInvalid: await message.edit( - text="`invalid username, try again with valid info ⚠`", del_in=0 + text="`invalid username, try again with valid info ⚠`", del_in=5 ) - return except PeerIdInvalid: await message.edit( - text="`invalid username or userid, try again with valid info ⚠`", del_in=0 + text="`invalid username or userid, try again with valid info ⚠`", del_in=5 ) - return except UserIdInvalid: await message.edit( - text="`invalid userid, try again with valid info ⚠`", del_in=0 + text="`invalid userid, try again with valid info ⚠`", del_in=5 ) - return - - except ChatAdminRequired: - await message.edit( - text=r"`i don't have permission to do that >︿<`", del_in=0 - ) - return except Exception as e_f: await message.edit( text="`something went wrong! 🤔`\n\n" - f"**ERROR:** `{e_f}`", del_in=0 + f"**ERROR:** `{e_f}`", del_in=5 ) - return elif message.reply_to_message: @@ -243,36 +196,27 @@ async def demote_usr(message: Message): can_invite_users=False, can_pin_messages=False) - await message.edit("`🛡 Demoted Successfully..`", del_in=0) + await message.edit("`🛡 Demoted Successfully..`", del_in=5) await CHANNEL.log( f"#DEMOTE\n\n" f"USER: [{get_mem.user.first_name}](tg://user?id={get_mem.user.id}) " f"(`{get_mem.user.id}`)\n" f"CHAT: `{get_group.title}` (`{chat_id}`)") - except ChatAdminRequired: - await message.edit( - text=r"`i don't have permission to do that >︿<`", del_in=0 - ) - return - except Exception as e_f: await message.edit( text="`something went wrong! 🤔`\n\n" - f"**ERROR:** `{e_f}`", del_in=0 + f"**ERROR:** `{e_f}`", del_in=5 ) - return else: await message.edit( text="`no valid user_id or message specified,`" - "`do .help demote for more info` ⚠", del_in=0) - - return + "`do .help demote for more info` ⚠", del_in=5) else: await message.edit( - text=r"`i don't have proper permission to do that! (*  ̄︿ ̄)`", del_in=0) + text=r"`i don't have proper permission to do that! (*  ̄︿ ̄)`", del_in=5) @userge.on_cmd("ban", about={ @@ -280,7 +224,7 @@ async def demote_usr(message: Message): 'description': "Ban member from supergroup.\n" "[NOTE: Requires proper admin rights in the chat!!!]", 'examples': "{tr}ban [username | userid] or [reply to user] :reason (optional)"}, - allow_channels=False, allow_bots=False, allow_private=False) + allow_channels=False, allow_bots=False, allow_private=False, only_admins=True) async def ban_usr(message: Message): """ ban user from tg group @@ -288,73 +232,56 @@ async def ban_usr(message: Message): reason = "" chat_id = message.chat.id get_group = await message.client.get_chat(chat_id) - can_ban = await is_admin(message) - - if can_ban: - await message.edit("`Trying to Ban User.. Hang on!! ⏳`") + await message.edit("`Trying to Ban User.. Hang on!! ⏳`") - if message.reply_to_message: - user_id = message.reply_to_message.from_user.id - reason = message.input_str + if message.reply_to_message: + user_id = message.reply_to_message.from_user.id + reason = message.input_str + else: + args = message.input_str.split(maxsplit=1) + if len(args) == 2: + user_id, reason = args + elif len(args) == 1: + user_id = args[0] else: - args = message.input_str.split(maxsplit=1) - if len(args) == 2: - user_id, reason = args - elif len(args) == 1: - user_id = args[0] - else: - await message.edit( - text="`no valid user_id or message specified,`" - "`do .help ban for more info` ⚠", del_in=0) - return - - if user_id: - - try: - get_mem = await message.client.get_chat_member(chat_id, user_id) - await message.client.kick_chat_member(chat_id, user_id) - await message.edit( - f"#BAN\n\n" - f"USER: [{get_mem.user.first_name}](tg://user?id={get_mem.user.id}) " - f"(`{get_mem.user.id}`)\n" - f"CHAT: `{get_group.title}` (`{chat_id}`)\n" - f"REASON: `{reason}`", log=True) + await message.edit( + text="`no valid user_id or message specified,`" + "`do .help ban for more info` ⚠", del_in=5) + return - except UsernameInvalid: - await message.edit( - text="`invalid username, try again with valid info ⚠`", del_in=0 - ) - return + if user_id: - except PeerIdInvalid: - await message.edit( - text="`invalid username or userid, try again with valid info ⚠`", del_in=0 - ) - return + try: + get_mem = await message.client.get_chat_member(chat_id, user_id) + await message.client.kick_chat_member(chat_id, user_id) + await message.edit( + f"#BAN\n\n" + f"USER: [{get_mem.user.first_name}](tg://user?id={get_mem.user.id}) " + f"(`{get_mem.user.id}`)\n" + f"CHAT: `{get_group.title}` (`{chat_id}`)\n" + f"REASON: `{reason}`", log=True) - except UserIdInvalid: - await message.edit( - text="`invalid userid, try again with valid info ⚠`", del_in=0 - ) - return + except UsernameInvalid: + await message.edit( + text="`invalid username, try again with valid info ⚠`", del_in=5 + ) - except ChatAdminRequired: - await message.edit( - text=r"`i don't have permission to do that >︿<`", del_in=0 - ) - return + except PeerIdInvalid: + await message.edit( + text="`invalid username or userid, try again with valid info ⚠`", del_in=5 + ) - except Exception as e_f: - await message.edit( - text="`something went wrong! 🤔`\n\n" - f"**ERROR:** `{e_f}`", del_in=0 + except UserIdInvalid: + await message.edit( + text="`invalid userid, try again with valid info ⚠`", del_in=5 ) - return - else: - await message.edit( - text=r"`i don't have proper permission to do that! (*  ̄︿ ̄)`", del_in=0) + except Exception as e_f: + await message.edit( + text="`something went wrong! 🤔`\n\n" + f"**ERROR:** `{e_f}`", del_in=5 + ) @userge.on_cmd("unban", about={ @@ -362,90 +289,76 @@ async def ban_usr(message: Message): 'description': "Unban member from supergroup.\n" "[NOTE: Requires proper admin rights in the chat!!!]", 'examples': "{tr}unban [username | userid] or [reply to user]"}, - allow_channels=False, allow_bots=False, allow_private=False) + allow_channels=False, allow_bots=False, allow_private=False, only_admins=True) async def unban_usr(message: Message): """ unban user from tg group """ chat_id = message.chat.id get_group = await message.client.get_chat(chat_id) - can_unban = await is_admin(message) - if can_unban: + await message.edit("`Trying to Unban User.. Hang on!! ⏳`") - await message.edit("`Trying to Unban User.. Hang on!! ⏳`") + user_id = message.input_str - user_id = message.input_str + if user_id: - if user_id: - - try: - get_mem = await message.client.get_chat_member(chat_id, user_id) - await message.client.unban_chat_member(chat_id, user_id) - await message.edit("`🛡 Successfully Unbanned..`", del_in=0) - await CHANNEL.log( - f"#UNBAN\n\n" - f"USER: [{get_mem.user.first_name}](tg://user?id={get_mem.user.id}) " - f"(`{get_mem.user.id}`)\n" - f"CHAT: `{get_group.title}` (`{chat_id}`)") - - except UsernameInvalid: - await message.edit( - text="`invalid username, try again with valid info ⚠`", del_in=0 - ) - return + try: + get_mem = await message.client.get_chat_member(chat_id, user_id) + await message.client.unban_chat_member(chat_id, user_id) + await message.edit("`🛡 Successfully Unbanned..`", del_in=5) + await CHANNEL.log( + f"#UNBAN\n\n" + f"USER: [{get_mem.user.first_name}](tg://user?id={get_mem.user.id}) " + f"(`{get_mem.user.id}`)\n" + f"CHAT: `{get_group.title}` (`{chat_id}`)") - except PeerIdInvalid: - await message.edit( - text="`invalid username or userid, try again with valid info ⚠`", del_in=0 - ) - return + except UsernameInvalid: + await message.edit( + text="`invalid username, try again with valid info ⚠`", del_in=5 + ) - except UserIdInvalid: - await message.edit( - text="`invalid userid, try again with valid info ⚠`", del_in=0 - ) - return + except PeerIdInvalid: + await message.edit( + text="`invalid username or userid, try again with valid info ⚠`", del_in=5 + ) - except Exception as e_f: - await message.edit( - text="`something went wrong! 🤔`\n\n" - f"**ERROR:** `{e_f}`", del_in=0 + except UserIdInvalid: + await message.edit( + text="`invalid userid, try again with valid info ⚠`", del_in=5 ) - return - elif message.reply_to_message: + except Exception as e_f: + await message.edit( + text="`something went wrong! 🤔`\n\n" + f"**ERROR:** `{e_f}`", del_in=5 + ) - try: - get_mem = await message.client.get_chat_member( - chat_id, - message.reply_to_message.from_user.id - ) - await message.client.unban_chat_member(chat_id, get_mem.user.id) - await message.edit("`🛡 Successfully Unbanned..`", del_in=0) - await CHANNEL.log( - f"#UNBAN\n\n" - f"USER: [{get_mem.user.first_name}](tg://user?id={get_mem.user.id}) " - f"(`{get_mem.user.id}`)\n" - f"CHAT: `{get_group.title}` (`{chat_id}`)") + elif message.reply_to_message: - except Exception as e_f: - await message.edit( - text="`something went wrong 🤔,`\n\n" - f"**ERROR:** `{e_f}`", del_in=0 - ) - return + try: + get_mem = await message.client.get_chat_member( + chat_id, + message.reply_to_message.from_user.id + ) + await message.client.unban_chat_member(chat_id, get_mem.user.id) + await message.edit("`🛡 Successfully Unbanned..`", del_in=5) + await CHANNEL.log( + f"#UNBAN\n\n" + f"USER: [{get_mem.user.first_name}](tg://user?id={get_mem.user.id}) " + f"(`{get_mem.user.id}`)\n" + f"CHAT: `{get_group.title}` (`{chat_id}`)") - else: + except Exception as e_f: await message.edit( - text="`no valid user_id or message specified,`" - "`do .help unban for more info` ⚠", del_in=0) - - return + text="`something went wrong 🤔,`\n\n" + f"**ERROR:** `{e_f}`", del_in=5 + ) else: await message.edit( - text=r"`i don't have proper permission to do that! (*  ̄︿ ̄)`", del_in=0) + text="`no valid user_id or message specified,`" + "`do .help unban for more info` ⚠", del_in=5) @userge.on_cmd("kick", about={ @@ -453,101 +366,75 @@ async def unban_usr(message: Message): 'description': "Kick member from supergroup. member can rejoin the group again if they want.\n" "[NOTE: Requires proper admin rights in the chat!!!]", 'examples': "{tr}kick [username | userid] or [reply to user]"}, - allow_channels=False, allow_bots=False, allow_private=False) + allow_channels=False, allow_bots=False, allow_private=False, only_admins=True) async def kick_usr(message: Message): """ kick user from tg group """ chat_id = message.chat.id get_group = await message.client.get_chat(chat_id) - can_kick = await is_admin(message) - if can_kick: + await message.edit("`Trying to Kick User.. Hang on!! ⏳`") - await message.edit("`Trying to Kick User.. Hang on!! ⏳`") + user_id = message.input_str - user_id = message.input_str - - if user_id: + if user_id: - try: - get_mem = await message.client.get_chat_member(chat_id, user_id) - await message.client.kick_chat_member(chat_id, user_id, int(time.time() + 60)) - await message.edit( - f"#KICK\n\n" - f"USER: [{get_mem.user.first_name}](tg://user?id={get_mem.user.id}) " - f"(`{get_mem.user.id}`)\n" - f"CHAT: `{get_group.title}` (`{chat_id}`)", log=True) - - except UsernameInvalid: - await message.edit( - text="`invalid username, try again with valid info ⚠`", del_in=0 - ) - return - - except PeerIdInvalid: - await message.edit( - text="`invalid username or userid, try again with valid info ⚠`", del_in=0 - ) - return - - except UserIdInvalid: - await message.edit( - text="`invalid userid, try again with valid info ⚠`", del_in=0 - ) - return + try: + get_mem = await message.client.get_chat_member(chat_id, user_id) + await message.client.kick_chat_member(chat_id, user_id, int(time.time() + 60)) + await message.edit( + f"#KICK\n\n" + f"USER: [{get_mem.user.first_name}](tg://user?id={get_mem.user.id}) " + f"(`{get_mem.user.id}`)\n" + f"CHAT: `{get_group.title}` (`{chat_id}`)", log=True) - except ChatAdminRequired: - await message.edit( - text=r"`i don't have permission to do that >︿<`", del_in=0 - ) - return + except UsernameInvalid: + await message.edit( + text="`invalid username, try again with valid info ⚠`", del_in=5 + ) - except Exception as e_f: - await message.edit( - text="`something went wrong! 🤔`\n\n" - f"**ERROR:** `{e_f}`", del_in=0 + except PeerIdInvalid: + await message.edit( + text="`invalid username or userid, try again with valid info ⚠`", del_in=5 ) - return - elif message.reply_to_message: + except UserIdInvalid: + await message.edit( + text="`invalid userid, try again with valid info ⚠`", del_in=5 + ) - try: - get_mem = await message.client.get_chat_member( - chat_id, - message.reply_to_message.from_user.id - ) - await message.client.kick_chat_member( - chat_id, get_mem.user.id, int(time.time() + 45)) - await message.edit( - f"#KICK\n\n" - f"USER: [{get_mem.user.first_name}](tg://user?id={get_mem.user.id}) " - f"(`{get_mem.user.id}`)\n" - f"CHAT: `{get_group.title}` (`{chat_id}`)", log=True) + except Exception as e_f: + await message.edit( + text="`something went wrong! 🤔`\n\n" + f"**ERROR:** `{e_f}`", del_in=5 + ) - except ChatAdminRequired: - await message.edit( - text=r"`i don't have permission to do that >︿<`", del_in=0 - ) - return + elif message.reply_to_message: - except Exception as e_f: - await message.edit( - text="`something went wrong! 🤔`\n\n" - f"**ERROR:** `{e_f}`", del_in=0 + try: + get_mem = await message.client.get_chat_member( + chat_id, + message.reply_to_message.from_user.id ) - return - - else: + await message.client.kick_chat_member( + chat_id, get_mem.user.id, int(time.time() + 45)) await message.edit( - text="`no valid user_id or message specified,`" - "`do .help kick for more info` ⚠", del_in=0) + f"#KICK\n\n" + f"USER: [{get_mem.user.first_name}](tg://user?id={get_mem.user.id}) " + f"(`{get_mem.user.id}`)\n" + f"CHAT: `{get_group.title}` (`{chat_id}`)", log=True) - return + except Exception as e_f: + await message.edit( + text="`something went wrong! 🤔`\n\n" + f"**ERROR:** `{e_f}`", del_in=5 + ) else: await message.edit( - text=r"`i don't have proper permission to do that! (*  ̄︿ ̄)`", del_in=0) + text="`no valid user_id or message specified,`" + "`do .help kick for more info` ⚠", del_in=5) @userge.on_cmd("mute", about={ @@ -561,7 +448,7 @@ async def kick_usr(message: Message): 'examples': [ "{tr}mute -flag [username | userid] or [reply to user] :reason (optional)", "{tr}mute -d1 @someusername/userid/replytouser SPAM (mute for one day:reason SPAM)"]}, - allow_channels=False, allow_bots=False, allow_private=False) + allow_channels=False, allow_bots=False, allow_private=False, only_admins=True) async def mute_usr(message: Message): """ mute user from tg group @@ -570,223 +457,175 @@ async def mute_usr(message: Message): chat_id = message.chat.id flags = message.flags get_group = await message.client.get_chat(chat_id) - can_mute = await is_admin(message) minutes = flags.get('-m', 0) hours = flags.get('-h', 0) days = flags.get('-d', 0) - if can_mute: + await message.edit("`Trying to Mute User.. Hang on!! ⏳`") - await message.edit("`Trying to Mute User.. Hang on!! ⏳`") - - if message.reply_to_message: - user_id = message.reply_to_message.from_user.id - reason = message.filtered_input_str + if message.reply_to_message: + user_id = message.reply_to_message.from_user.id + reason = message.filtered_input_str + else: + args = message.filtered_input_str.split(maxsplit=1) + if len(args) == 2: + user_id, reason = args + elif len(args) == 1: + user_id = args[0] else: - args = message.filtered_input_str.split(maxsplit=1) - if len(args) == 2: - user_id, reason = args - elif len(args) == 1: - user_id = args[0] - else: - await message.edit( - text="`no valid user_id or message specified,`" - "`do .help mute for more info`", del_in=0) - return - - if minutes: - - try: - get_mem = await message.client.get_chat_member(chat_id, user_id) - mute_period = int(minutes) * 60 - await message.client.restrict_chat_member( - chat_id, user_id, - ChatPermissions(), - int(time.time() + mute_period)) - await message.edit( - f"#MUTE\n\n" - f"USER: [{get_mem.user.first_name}](tg://user?id={get_mem.user.id}) " - f"(`{get_mem.user.id}`)\n" - f"CHAT: `{get_group.title}` (`{chat_id}`)\n" - f"MUTE UNTIL: `{minutes} minutes`\n" - f"REASON: `{reason}`", log=True) - - except UsernameInvalid: - await message.edit( - text="`invalid username, try again with valid info ⚠`", del_in=0 - ) - return - - except PeerIdInvalid: - await message.edit( - text="`invalid username or userid, try again with valid info ⚠`", del_in=0 - ) - return - - except UserIdInvalid: - await message.edit( - text="`invalid userid, try again with valid info ⚠`", del_in=0 - ) - return - - except ChatAdminRequired: - await message.edit( - text=r"`i don't have permission to do that >︿<`", del_in=0 - ) - return - - except Exception as e_f: - await message.edit( - text=f"`something went wrong 🤔,`" - f"`do .help mute for more info`\n\n" - f"**ERROR**: `{e_f}`", del_in=0) - return - - elif hours: - - try: - get_mem = await message.client.get_chat_member(chat_id, user_id) - mute_period = int(hours) * 3600 - await message.client.restrict_chat_member( - chat_id, user_id, - ChatPermissions(), - int(time.time() + mute_period)) - await message.edit( - f"#MUTE\n\n" - f"USER: [{get_mem.user.first_name}](tg://user?id={get_mem.user.id}) " - f"(`{get_mem.user.id}`)\n" - f"CHAT: `{get_group.title}` (`{chat_id}`)\n" - f"MUTE UNTIL: `{hours} hours`\n" - f"REASON: `{reason}`", log=True) - - except UsernameInvalid: - await message.edit( - text="`invalid username, try again with valid info ⚠`", del_in=0 - ) - return + await message.edit( + text="`no valid user_id or message specified,`" + "`do .help mute for more info`", del_in=5) + return - except PeerIdInvalid: - await message.edit( - text="`invalid username or userid, try again with valid info ⚠`", del_in=0 - ) - return + if minutes: - except UserIdInvalid: - await message.edit( - text="`invalid userid, try again with valid info ⚠`", del_in=0 - ) - return + try: + get_mem = await message.client.get_chat_member(chat_id, user_id) + mute_period = int(minutes) * 60 + await message.client.restrict_chat_member( + chat_id, user_id, + ChatPermissions(), + int(time.time() + mute_period)) + await message.edit( + f"#MUTE\n\n" + f"USER: [{get_mem.user.first_name}](tg://user?id={get_mem.user.id}) " + f"(`{get_mem.user.id}`)\n" + f"CHAT: `{get_group.title}` (`{chat_id}`)\n" + f"MUTE UNTIL: `{minutes} minutes`\n" + f"REASON: `{reason}`", log=True) - except ChatAdminRequired: - await message.edit( - text=r"`i don't have permission to do that >︿<`", del_in=0 - ) - return + except UsernameInvalid: + await message.edit( + text="`invalid username, try again with valid info ⚠`", del_in=5 + ) - except Exception as e_f: - await message.edit( - text=f"`something went wrong 🤔,`" - f"`do .help mute for more info`\n\n" - f"**ERROR**: `{e_f}`", del_in=0) - return + except PeerIdInvalid: + await message.edit( + text="`invalid username or userid, try again with valid info ⚠`", del_in=5 + ) - elif days: + except UserIdInvalid: + await message.edit( + text="`invalid userid, try again with valid info ⚠`", del_in=5 + ) - try: - get_mem = await message.client.get_chat_member(chat_id, user_id) - mute_period = int(days) * 86400 - await message.client.restrict_chat_member( - chat_id, user_id, - ChatPermissions(), - int(time.time() + mute_period)) - await message.edit( - f"#MUTE\n\n" - f"USER: [{get_mem.user.first_name}](tg://user?id={get_mem.user.id}) " - f"(`{get_mem.user.id}`)\n" - f"CHAT: `{get_group.title}` (`{chat_id}`)\n" - f"MUTE UNTIL: `{days} days`\n" - f"REASON: `{reason}`", log=True) + except Exception as e_f: + await message.edit( + text=f"`something went wrong 🤔,`" + f"`do .help mute for more info`\n\n" + f"**ERROR**: `{e_f}`", del_in=5) + + elif hours: + + try: + get_mem = await message.client.get_chat_member(chat_id, user_id) + mute_period = int(hours) * 3600 + await message.client.restrict_chat_member( + chat_id, user_id, + ChatPermissions(), + int(time.time() + mute_period)) + await message.edit( + f"#MUTE\n\n" + f"USER: [{get_mem.user.first_name}](tg://user?id={get_mem.user.id}) " + f"(`{get_mem.user.id}`)\n" + f"CHAT: `{get_group.title}` (`{chat_id}`)\n" + f"MUTE UNTIL: `{hours} hours`\n" + f"REASON: `{reason}`", log=True) - except UsernameInvalid: - await message.edit( - text="`invalid username, try again with valid info ⚠`", del_in=0 - ) - return + except UsernameInvalid: + await message.edit( + text="`invalid username, try again with valid info ⚠`", del_in=5 + ) - except PeerIdInvalid: - await message.edit( - text="`invalid username or userid, try again with valid info ⚠`", del_in=0 - ) - return + except PeerIdInvalid: + await message.edit( + text="`invalid username or userid, try again with valid info ⚠`", del_in=5 + ) - except UserIdInvalid: - await message.edit( - text="`invalid userid, try again with valid info ⚠`", del_in=0 - ) - return + except UserIdInvalid: + await message.edit( + text="`invalid userid, try again with valid info ⚠`", del_in=5 + ) - except ChatAdminRequired: - await message.edit( - text=r"`i don't have permission to do that >︿<`", del_in=0 - ) - return + except Exception as e_f: + await message.edit( + text=f"`something went wrong 🤔,`" + f"`do .help mute for more info`\n\n" + f"**ERROR**: `{e_f}`", del_in=5) + + elif days: + + try: + get_mem = await message.client.get_chat_member(chat_id, user_id) + mute_period = int(days) * 86400 + await message.client.restrict_chat_member( + chat_id, user_id, + ChatPermissions(), + int(time.time() + mute_period)) + await message.edit( + f"#MUTE\n\n" + f"USER: [{get_mem.user.first_name}](tg://user?id={get_mem.user.id}) " + f"(`{get_mem.user.id}`)\n" + f"CHAT: `{get_group.title}` (`{chat_id}`)\n" + f"MUTE UNTIL: `{days} days`\n" + f"REASON: `{reason}`", log=True) - except Exception as e_f: - await message.edit( - text=f"`something went wrong 🤔,`" - f"`do .help mute for more info`\n\n" - f"**ERROR**: {e_f}", del_in=0) - return + except UsernameInvalid: + await message.edit( + text="`invalid username, try again with valid info ⚠`", del_in=5 + ) - else: + except PeerIdInvalid: + await message.edit( + text="`invalid username or userid, try again with valid info ⚠`", del_in=5 + ) - try: - get_mem = await message.client.get_chat_member(chat_id, user_id) - await message.client.restrict_chat_member(chat_id, user_id, ChatPermissions()) - await message.edit( - f"#MUTE\n\n" - f"USER: [{get_mem.user.first_name}](tg://user?id={get_mem.user.id}) " - f"(`{get_mem.user.id}`)\n" - f"CHAT: `{get_group.title}` (`{chat_id}`)\n" - f"MUTE UNTIL: `forever`\n" - f"REASON: `{reason}`", log=True) + except UserIdInvalid: + await message.edit( + text="`invalid userid, try again with valid info ⚠`", del_in=5 + ) - except UsernameInvalid: - await message.edit( - text="`invalid username, try again with valid info ⚠`", del_in=0 - ) - return + except Exception as e_f: + await message.edit( + text=f"`something went wrong 🤔,`" + f"`do .help mute for more info`\n\n" + f"**ERROR**: {e_f}", del_in=5) - except PeerIdInvalid: - await message.edit( - text="`invalid username or userid, try again with valid info ⚠`", del_in=0 - ) - return + else: - except UserIdInvalid: - await message.edit( - text="`invalid userid, try again with valid info ⚠`", del_in=0 - ) - return + try: + get_mem = await message.client.get_chat_member(chat_id, user_id) + await message.client.restrict_chat_member(chat_id, user_id, ChatPermissions()) + await message.edit( + f"#MUTE\n\n" + f"USER: [{get_mem.user.first_name}](tg://user?id={get_mem.user.id}) " + f"(`{get_mem.user.id}`)\n" + f"CHAT: `{get_group.title}` (`{chat_id}`)\n" + f"MUTE UNTIL: `forever`\n" + f"REASON: `{reason}`", log=True) - except ChatAdminRequired: - await message.edit( - text=r"`i don't have permission to do that >︿<`", del_in=0 - ) - return + except UsernameInvalid: + await message.edit( + text="`invalid username, try again with valid info ⚠`", del_in=5 + ) - except Exception as e_f: - await message.edit( - text=f"`something went wrong 🤔,`" - f"`do .help mute for more info`\n\n" - f"**ERROR**: {e_f}", del_in=0) + except PeerIdInvalid: + await message.edit( + text="`invalid username or userid, try again with valid info ⚠`", del_in=5 + ) - return + except UserIdInvalid: + await message.edit( + text="`invalid userid, try again with valid info ⚠`", del_in=5 + ) - else: - await message.edit( - text=r"`i don't have proper permission to do that! (*  ̄︿ ̄)`", del_in=0) + except Exception as e_f: + await message.edit( + text=f"`something went wrong 🤔,`" + f"`do .help mute for more info`\n\n" + f"**ERROR**: {e_f}", del_in=5) @userge.on_cmd("unmute", about={ @@ -794,14 +633,13 @@ async def mute_usr(message: Message): 'description': "Unmute member from supergroup.\n" "[NOTE: Requires proper admin rights in the chat!!!]", 'examples': "{tr}unmute [username | userid] or [reply to user]"}, - allow_channels=False, allow_bots=False, allow_private=False) + allow_channels=False, allow_bots=False, allow_private=False, only_admins=True) async def unmute_usr(message: Message): """ unmute user from tg group """ chat_id = message.chat.id get_group = await message.client.get_chat(chat_id) - can_unmute = await is_admin(message) amsg = get_group.permissions.can_send_messages amedia = get_group.permissions.can_send_media_messages @@ -815,109 +653,96 @@ async def unmute_usr(message: Message): ainvite = get_group.permissions.can_invite_users apin = get_group.permissions.can_pin_messages - if can_unmute: - - await message.edit("`Trying to Unmute User.. Hang on!! ⏳`") - - user_id = message.input_str - - if user_id: - - try: - get_mem = await message.client.get_chat_member(chat_id, user_id) - await message.client.restrict_chat_member( - chat_id, user_id, - ChatPermissions( - can_send_messages=amsg, - can_send_media_messages=amedia, - can_send_stickers=astickers, - can_send_animations=aanimations, - can_send_games=agames, - can_use_inline_bots=ainlinebots, - can_add_web_page_previews=awebprev, - can_send_polls=apolls, - can_change_info=ainfo, - can_invite_users=ainvite, - can_pin_messages=apin)) - - await message.edit("`🛡 Successfully Unmuted..`", del_in=0) - await CHANNEL.log( - f"#UNMUTE\n\n" - f"USER: [{get_mem.user.first_name}](tg://user?id={get_mem.user.id}) " - f"(`{get_mem.user.id}`)\n" - f"CHAT: `{get_group.title}` (`{chat_id}`)") - - except UsernameInvalid: - await message.edit( - text="`invalid username, try again with valid info ⚠`", del_in=0 - ) - return + await message.edit("`Trying to Unmute User.. Hang on!! ⏳`") + + user_id = message.input_str + + if user_id: + + try: + get_mem = await message.client.get_chat_member(chat_id, user_id) + await message.client.restrict_chat_member( + chat_id, user_id, + ChatPermissions( + can_send_messages=amsg, + can_send_media_messages=amedia, + can_send_stickers=astickers, + can_send_animations=aanimations, + can_send_games=agames, + can_use_inline_bots=ainlinebots, + can_add_web_page_previews=awebprev, + can_send_polls=apolls, + can_change_info=ainfo, + can_invite_users=ainvite, + can_pin_messages=apin)) + + await message.edit("`🛡 Successfully Unmuted..`", del_in=5) + await CHANNEL.log( + f"#UNMUTE\n\n" + f"USER: [{get_mem.user.first_name}](tg://user?id={get_mem.user.id}) " + f"(`{get_mem.user.id}`)\n" + f"CHAT: `{get_group.title}` (`{chat_id}`)") - except PeerIdInvalid: - await message.edit( - text="`invalid username or userid, try again with valid info ⚠`", del_in=0 - ) - return + except UsernameInvalid: + await message.edit( + text="`invalid username, try again with valid info ⚠`", del_in=5 + ) - except UserIdInvalid: - await message.edit( - text="`invalid userid, try again with valid info ⚠`", del_in=0 - ) - return + except PeerIdInvalid: + await message.edit( + text="`invalid username or userid, try again with valid info ⚠`", del_in=5 + ) - except Exception as e_f: - await message.edit( - text="`something went wrong!` 🤔\n\n" - f"**ERROR:** `{e_f}`", del_in=0 + except UserIdInvalid: + await message.edit( + text="`invalid userid, try again with valid info ⚠`", del_in=5 ) - return - elif message.reply_to_message: + except Exception as e_f: + await message.edit( + text="`something went wrong!` 🤔\n\n" + f"**ERROR:** `{e_f}`", del_in=5 + ) - try: - get_mem = await message.client.get_chat_member( - chat_id, - message.reply_to_message.from_user.id - ) - await message.client.restrict_chat_member( - chat_id, get_mem.user.id, - ChatPermissions( - can_send_messages=amsg, - can_send_media_messages=amedia, - can_send_stickers=astickers, - can_send_animations=aanimations, - can_send_games=agames, - can_use_inline_bots=ainlinebots, - can_add_web_page_previews=awebprev, - can_send_polls=apolls, - can_change_info=ainfo, - can_invite_users=ainvite, - can_pin_messages=apin)) - - await message.edit("`🛡 Successfully Unmuted..`", del_in=0) - await CHANNEL.log( - f"#UNMUTE\n\n" - f"USER: [{get_mem.user.first_name}](tg://user?id={get_mem.user.id}) " - f"(`{get_mem.user.id}`)\n" - f"CHAT: `{get_group.title}` (`{chat_id}`)") + elif message.reply_to_message: - except Exception as e_f: - await message.edit( - text="`something went wrong! 🤔`\n\n" - f"**ERROR:** `{e_f}`", del_in=0 + try: + get_mem = await message.client.get_chat_member( + chat_id, + message.reply_to_message.from_user.id ) - return + await message.client.restrict_chat_member( + chat_id, get_mem.user.id, + ChatPermissions( + can_send_messages=amsg, + can_send_media_messages=amedia, + can_send_stickers=astickers, + can_send_animations=aanimations, + can_send_games=agames, + can_use_inline_bots=ainlinebots, + can_add_web_page_previews=awebprev, + can_send_polls=apolls, + can_change_info=ainfo, + can_invite_users=ainvite, + can_pin_messages=apin)) + + await message.edit("`🛡 Successfully Unmuted..`", del_in=5) + await CHANNEL.log( + f"#UNMUTE\n\n" + f"USER: [{get_mem.user.first_name}](tg://user?id={get_mem.user.id}) " + f"(`{get_mem.user.id}`)\n" + f"CHAT: `{get_group.title}` (`{chat_id}`)") - else: + except Exception as e_f: await message.edit( - text="`no valid user_id or message specified,`" - "`do .help unmute for more info`", del_in=0) - - return + text="`something went wrong! 🤔`\n\n" + f"**ERROR:** `{e_f}`", del_in=5 + ) else: await message.edit( - text=r"`i don't have proper permission to do that! (*  ̄︿ ̄)`", del_in=0) + text="`no valid user_id or message specified,`" + "`do .help unmute for more info`", del_in=5) @userge.on_cmd("zombies", about={ @@ -935,11 +760,12 @@ async def zombie_clean(message: Message): """ chat_id = message.chat.id get_group = await message.client.get_chat(chat_id) + check_user = await message.client.get_chat_member(message.chat.id, message.from_user.id) flags = message.flags rm_delaccs = '-c' in flags - can_clean = await is_admin(message) + can_clean = check_user.status in ("administrator", "creator") if rm_delaccs: @@ -978,7 +804,7 @@ async def zombie_clean(message: Message): del_stats = f"`👻 Found` **{del_total}** `total zombies..`\ \n`🗑 Cleaned` **{del_users}** `zombie (deleted) accounts from this chat..`" - await message.edit(f"{del_stats}", del_in=0) + await message.edit(f"{del_stats}", del_in=5) await CHANNEL.log( f"#ZOMBIE_CLEAN\n\n" f"CHAT: `{get_group.title}` (`{chat_id}`)\n" @@ -988,7 +814,7 @@ async def zombie_clean(message: Message): ) else: - await message.edit(r"`i don't have proper permission to do that! (*  ̄︿ ̄)`", del_in=0) + await message.edit(r"`i don't have proper permission to do that! (*  ̄︿ ̄)`", del_in=5) else: @@ -1005,7 +831,7 @@ async def zombie_clean(message: Message): del_stats = f"`Found` **{del_users}** `zombie accounts in this chat.`" await message.edit( f"🕵️‍♂️ {del_stats} " - "`you can clean them using .zombies -c`", del_in=0) + "`you can clean them using .zombies -c`", del_in=5) await CHANNEL.log( f"#ZOMBIE_CHECK\n\n" f"CHAT: `{get_group.title}` (`{chat_id}`)\n" @@ -1013,7 +839,7 @@ async def zombie_clean(message: Message): ) else: - await message.edit(f"{del_stats}", del_in=0) + await message.edit(f"{del_stats}", del_in=5) await CHANNEL.log( f"#ZOMBIE_CHECK\n\n" f"CHAT: `{get_group.title}` (`{chat_id}`)\n" @@ -1112,7 +938,7 @@ async def pin_msgs(message: Message): ) else: - await message.edit(r"`i don't have proper permission to do that! (*  ̄︿ ̄)`", del_in=0) + await message.edit(r"`i don't have proper permission to do that! (*  ̄︿ ̄)`", del_in=5) @userge.on_cmd("gpic", about={ @@ -1168,7 +994,6 @@ async def chatpic_func(message: Message): await message.edit( r"`something went wrong!! (⊙ˍ⊙)`" f"\n\n**ERROR:** `{e_f}`") - return elif message.reply_to_message.document.mime_type == "image/png": @@ -1186,13 +1011,11 @@ async def chatpic_func(message: Message): await message.edit( r"`something went wrong!! (⊙ˍ⊙)`" f"\n\n**ERROR:** `{e_f}`") - return else: await message.edit( text="`no valid message/picture reply specified,`" - " `do .help gpic for more info` ⚠", del_in=0) - return + " `do .help gpic for more info` ⚠", del_in=5) elif gpic_del: @@ -1208,15 +1031,13 @@ async def chatpic_func(message: Message): await message.edit( r"`something went wrong!! (⊙ˍ⊙)`" f"\n\n**ERROR:** `{e_f}`") - return else: await message.edit( - text="`invalid flag type, do .help gpic for more info` ⚠", del_in=0) - return + text="`invalid flag type, do .help gpic for more info` ⚠", del_in=5) else: - await message.edit(r"`i don't have proper permission to do that! (*  ̄︿ ̄)`", del_in=0) + await message.edit(r"`i don't have proper permission to do that! (*  ̄︿ ̄)`", del_in=5) @userge.on_cmd("smode", about={ @@ -1234,14 +1055,14 @@ async def chatpic_func(message: Message): 'examples': [ "{tr}smode -s30 [send to chat] (turn on 30s slow mode) ", "{tr}smode -o [send to chat] (turn off slow mode)"]}, - allow_channels=False, allow_bots=False, allow_private=False) + allow_channels=False, allow_bots=False, allow_private=False, only_admins=True) async def smode_switch(message: Message): """ turn on/off chat slow mode """ chat_id = message.chat.id - can_do_smode = await is_sudoadmin(message) get_group = await message.client.get_chat(chat_id) + check_user = await message.client.get_chat_member(message.chat.id, message.from_user.id) flags = message.flags seconds = flags.get('-s', 0) @@ -1249,14 +1070,14 @@ async def smode_switch(message: Message): hours = flags.get('-h', 0) smode_off = '-o' in flags - if can_do_smode: + if check_user.can_promote_members: if seconds: try: seconds = int(seconds) await message.client.set_slow_mode(chat_id, seconds) await message.edit( - f"`⏳ turned on {seconds} seconds slow mode for chat!`", del_in=0) + f"`⏳ turned on {seconds} seconds slow mode for chat!`", del_in=5) await CHANNEL.log( f"#SLOW_MODE\n\n" f"CHAT: `{get_group.title}` (`{chat_id}`)\n" @@ -1265,14 +1086,13 @@ async def smode_switch(message: Message): await message.edit( "`something went wrong!!, do .help smode for more info..` \n\n" f"**ERROR:** `{e_f}`") - return elif minutes: try: smode_time = int(minutes) * 60 await message.client.set_slow_mode(chat_id, smode_time) await message.edit( - f"`⏳ turned on {minutes} minutes slow mode for chat!`", del_in=0) + f"`⏳ turned on {minutes} minutes slow mode for chat!`", del_in=5) await CHANNEL.log( f"#SLOW_MODE\n\n" f"CHAT: `{get_group.title}` (`{chat_id}`)\n" @@ -1281,13 +1101,12 @@ async def smode_switch(message: Message): await message.edit( "`something went wrong!!, do .help smode for more info..` \n\n" f"**ERROR:** `{e_f}`") - return elif hours: try: smode_time = int(hours) * 3600 await message.client.set_slow_mode(chat_id, smode_time) - await message.edit("`⏳ turned on 1 hour slow mode for chat!`", del_in=0) + await message.edit("`⏳ turned on 1 hour slow mode for chat!`", del_in=5) await CHANNEL.log( f"#SLOW_MODE\n\n" f"CHAT: `{get_group.title}` (`{chat_id}`)\n" @@ -1296,12 +1115,11 @@ async def smode_switch(message: Message): await message.edit( "`something went wrong!!, do .help smode for more info..` \n\n" f"**ERROR:** `{e_f}`") - return elif smode_off: try: await message.client.set_slow_mode(chat_id, 0) - await message.edit("`⏳ turned off slow mode for chat!`", del_in=0) + await message.edit("`⏳ turned off slow mode for chat!`", del_in=5) await CHANNEL.log( f"#SLOW_MODE\n\n" f"CHAT: `{get_group.title}` (`{chat_id}`)\n" @@ -1310,11 +1128,10 @@ async def smode_switch(message: Message): await message.edit( "`something went wrong!!, do .help smode for more info..` \n\n" f"**ERROR:** `{e_f}`") - return else: await message.edit( - "`inavlid flag type/mode.. do .help smode for more info!!`", del_in=0) + "`inavlid flag type/mode.. do .help smode for more info!!`", del_in=5) else: - await message.edit(r"`i don't have proper permission to do that! (*  ̄︿ ̄)`", del_in=0) + await message.edit(r"`i don't have proper permission to do that! (*  ̄︿ ̄)`", del_in=5) diff --git a/userge/plugins/admin/gban.py b/userge/plugins/admin/gban.py index 668603419..3dbaf1fee 100644 --- a/userge/plugins/admin/gban.py +++ b/userge/plugins/admin/gban.py @@ -258,8 +258,7 @@ async def list_white(message: Message): f"**--Whitelisted Users List--**\n\n{msg}" if msg else "`whitelist empty!`") -@userge.on_filters(Filters.group & Filters.new_chat_members & ~Filters.me, - group=1, check_client=True) +@userge.on_filters(Filters.group & Filters.new_chat_members & ~Filters.me, group=1) async def gban_at_entry(message: Message): """ handle gbans """ chat_id = message.chat.id diff --git a/userge/plugins/admin/locks.py b/userge/plugins/admin/locks.py index fbfe7111b..5c878cb79 100644 --- a/userge/plugins/admin/locks.py +++ b/userge/plugins/admin/locks.py @@ -15,18 +15,6 @@ CHANNEL = userge.getCLogger(__name__) -async def is_admin(message: Message): - check_user = await message.client.get_chat_member(message.chat.id, message.from_user.id) - user_type = check_user.status - if user_type == "member": - return False - if user_type == "administrator": - return True - if user_type == "creator": - return True - return False - - @userge.on_cmd( "lock", about={ 'header': "use this to lock group permissions", @@ -36,15 +24,11 @@ async def is_admin(message: Message): 'all', 'msg', 'media', 'polls', 'invite', 'pin', 'info', 'webprev', 'inlinebots', 'animations', 'games', 'stickers'], 'examples': "{tr}lock [all | type]"}, - allow_channels=False, allow_bots=False, allow_private=False) + allow_channels=False, allow_bots=False, allow_private=False, only_admins=True) async def lock_perm(message: Message): """ lock chat permissions from tg group """ - if not await is_admin(message): - await message.edit("Are you even Admin of this chat?") - return - msg = "" media = "" stickers = "" @@ -62,7 +46,7 @@ async def lock_perm(message: Message): chat_id = message.chat.id if not lock_type: - await message.edit(text=r"`I Can't Lock Nothing! (-‸ლ)`", del_in=0) + await message.edit(text=r"`I Can't Lock Nothing! (-‸ლ)`", del_in=5) return get_perm = await message.client.get_chat(chat_id) @@ -83,7 +67,7 @@ async def lock_perm(message: Message): try: await message.client.set_chat_permissions(chat_id, ChatPermissions()) await message.edit( - text="**🔒 Locked all permission from this Chat!**", del_in=0) + text="**🔒 Locked all permission from this Chat!**", del_in=5) await CHANNEL.log( f"#LOCK\n\n" f"CHAT: `{get_perm.title}` (`{chat_id}`)\n" @@ -93,7 +77,7 @@ async def lock_perm(message: Message): except Exception as e_f: await message.edit( text=r"`i don't have permission to do that >︿<`\n\n" - f"**ERROR:** `{e_f}`", del_in=0) + f"**ERROR:** `{e_f}`", del_in=5) return @@ -142,7 +126,7 @@ async def lock_perm(message: Message): perm = "pin" else: - await message.edit(text=r"`Invalid Lock Type! ¯\_(ツ)_/¯`", del_in=0) + await message.edit(text=r"`Invalid Lock Type! ¯\_(ツ)_/¯`", del_in=5) return try: @@ -160,7 +144,7 @@ async def lock_perm(message: Message): can_invite_users=invite, can_pin_messages=pin)) - await message.edit(text=f"**🔒 Locked {perm} for this chat!**", del_in=0) + await message.edit(text=f"**🔒 Locked {perm} for this chat!**", del_in=5) await CHANNEL.log( f"#LOCK\n\n" f"CHAT: `{get_perm.title}` (`{chat_id}`)\n" @@ -170,7 +154,7 @@ async def lock_perm(message: Message): except Exception as e_f: await message.edit( text=r"`i don't have permission to do that >︿<`\n\n" - f"**ERROR:** `{e_f}`", del_in=0) + f"**ERROR:** `{e_f}`", del_in=5) @userge.on_cmd("unlock", about={ @@ -181,15 +165,11 @@ async def lock_perm(message: Message): 'all', 'msg', 'media', 'polls', 'invite', 'pin', 'info', 'webprev', 'inlinebots', 'animations', 'games', 'stickers'], 'examples': "{tr}unlock [all | type]"}, - allow_channels=False, allow_bots=False, allow_private=False) + allow_channels=False, allow_bots=False, allow_private=False, only_admins=True) async def unlock_perm(message: Message): """ unlock chat permissions from tg group """ - if not await is_admin(message): - await message.edit("Are you even Admin of this chat?") - return - umsg = "" umedia = "" ustickers = "" @@ -207,7 +187,7 @@ async def unlock_perm(message: Message): chat_id = message.chat.id if not unlock_type: - await message.edit(text=r"`I Can't Unlock Nothing! (-‸ლ)`", del_in=0) + await message.edit(text=r"`I Can't Unlock Nothing! (-‸ლ)`", del_in=5) return get_uperm = await message.client.get_chat(chat_id) @@ -241,7 +221,7 @@ async def unlock_perm(message: Message): can_add_web_page_previews=True)) await message.edit( - text="**🔓 Unlocked all permission from this Chat!**", del_in=0) + text="**🔓 Unlocked all permission from this Chat!**", del_in=5) await CHANNEL.log( f"#UNLOCK\n\n" f"CHAT: `{get_uperm.title}` (`{chat_id}`)\n" @@ -250,7 +230,7 @@ async def unlock_perm(message: Message): except Exception as e_f: await message.edit( text=r"`i don't have permission to do that >︿<`\n\n" - f"**ERROR:** `{e_f}`", del_in=0) + f"**ERROR:** `{e_f}`", del_in=5) return if unlock_type == "msg": @@ -298,7 +278,7 @@ async def unlock_perm(message: Message): uperm = "pin" else: - await message.edit(text=r"`Invalid Unlock Type! ¯\_(ツ)_/¯`", del_in=0) + await message.edit(text=r"`Invalid Unlock Type! ¯\_(ツ)_/¯`", del_in=5) return try: @@ -316,7 +296,7 @@ async def unlock_perm(message: Message): can_invite_users=uinvite, can_pin_messages=upin)) - await message.edit(text=f"**🔓 Unlocked {uperm} for this chat!**", del_in=0) + await message.edit(text=f"**🔓 Unlocked {uperm} for this chat!**", del_in=5) await CHANNEL.log( f"#UNLOCK\n\n" f"CHAT: `{get_uperm.title}` (`{chat_id}`)\n" @@ -326,21 +306,17 @@ async def unlock_perm(message: Message): except Exception as e_f: await message.edit( text=r"`i don't have permission to do that >︿<`\n\n" - f"**ERROR:** `{e_f}`", del_in=0) + f"**ERROR:** `{e_f}`", del_in=5) @userge.on_cmd("vperm", about={ 'header': "use this to view group permissions", 'description': "Allows you to view permission types on/off status in the chat."}, - allow_channels=False, allow_bots=False, allow_private=False) + allow_channels=False, allow_bots=False, allow_private=False, only_admins=True) async def view_perm(message: Message): """ check chat permissions from tg group """ - if not await is_admin(message): - await message.edit("Are you even Admin of this chat?") - return - v_perm = "" vmsg = "" vmedia = "" @@ -413,4 +389,4 @@ def convert_to_emoji(val: bool): except Exception as e_f: await message.edit( text="`Something went wrong!` 🤔\n\n" - f"**ERROR:** `{e_f}`", del_in=0) + f"**ERROR:** `{e_f}`", del_in=5) diff --git a/userge/plugins/misc/utube.py b/userge/plugins/misc/utube.py index b65a4161a..723b46189 100644 --- a/userge/plugins/misc/utube.py +++ b/userge/plugins/misc/utube.py @@ -185,7 +185,8 @@ def _supported(url): @pool.run_in_thread def _tubeDl(url: list, prog, starttime, uid=None): - _opts = {'outtmpl': os.path.join(Config.DOWN_PATH, str(starttime), '%(title)s-%(format)s.%(ext)s'), + _opts = {'outtmpl': os.path.join(Config.DOWN_PATH, str(starttime), + '%(title)s-%(format)s.%(ext)s'), 'logger': LOGGER, 'postprocessors': [ {'key': 'FFmpegMetadata'} diff --git a/userge/plugins/utils/filters.py b/userge/plugins/utils/filters.py index bfa5f8440..ed268e2ea 100644 --- a/userge/plugins/utils/filters.py +++ b/userge/plugins/utils/filters.py @@ -154,7 +154,7 @@ async def add_filter(message: Message) -> None: await message.edit(text=out, del_in=3, log=__name__) -@userge.on_filters(~Filters.me & Filters.text & FILTERS_CHATS, group=1, check_client=True) +@userge.on_filters(~Filters.me & Filters.text & FILTERS_CHATS, group=1) async def chat_filter(message: Message) -> None: """ filter handler """ if not message.from_user: diff --git a/userge/plugins/utils/notes.py b/userge/plugins/utils/notes.py index 879580ac9..6436c7be7 100644 --- a/userge/plugins/utils/notes.py +++ b/userge/plugins/utils/notes.py @@ -162,8 +162,6 @@ async def mv_to_global_note(message: Message) -> None: name="get_note", trigger='', filter_me=False, - allow_channels=False, - allow_bots=False, check_client=True) async def get_note(message: Message) -> None: """ get any saved note """ diff --git a/userge/plugins/utils/welcome.py b/userge/plugins/utils/welcome.py index 3d42fbc3e..36267eec7 100644 --- a/userge/plugins/utils/welcome.py +++ b/userge/plugins/utils/welcome.py @@ -150,13 +150,13 @@ async def viewleft(msg: Message): await raw_view(msg, 'Left', LEFT_COLLECTION) -@userge.on_new_member(WELCOME_CHATS, check_client=True) +@userge.on_new_member(WELCOME_CHATS) async def saywel(msg: Message): """ welcome message handler """ await raw_say(msg, 'Welcome', WELCOME_COLLECTION) -@userge.on_left_member(LEFT_CHATS, check_client=True) +@userge.on_left_member(LEFT_CHATS) async def sayleft(msg: Message): """ left message handler """ await raw_say(msg, 'Left', LEFT_COLLECTION)