From d4769ec993874187e25576dc76c5f7612f9638ed Mon Sep 17 00:00:00 2001 From: beastzx18 Date: Wed, 23 Feb 2022 21:50:17 +0530 Subject: [PATCH 1/7] updating resources --- app.json | 140 ++++++++++++++++++++++++----------------------- requirements.txt | 2 +- runtime.txt | 2 +- 3 files changed, 74 insertions(+), 70 deletions(-) diff --git a/app.json b/app.json index 19813df1..786cd047 100644 --- a/app.json +++ b/app.json @@ -1,71 +1,75 @@ { - "name": "Trôn", - "description": "Tron Is A Multifunctional Telegram Userbot with Custom Settings.", - "logo": "https://telegra.ph/file/8d62a8fe005a8077188ec.jpg", - "keywords": [ - "userbot", - "plugins", - "development", - "tools", - "pyrogram", - "productivity" - ], - "repository": "https://github.com/beastzx18/Tron/", - "website": "https://t.me/tronuserbot", - "success_url": "/welcome", - "env": { - "API_ID": { - "description": "Login here -> my.telegram.org to get pair of keys", - "value": "", - "required": true - }, - "API_HASH": { - "description": "Again You Will Find This Here -> my.telegram.org", - "value": "", - "required": true - }, - "SESSION": { - "description": "Visit here & create https://replit.com/@vs423502/Tron-Session?v=1", - "value": "", - "required": true - }, - "PREFIX": { - "description": "This Is The Handle Of Your All Commands You Can Change It To -> [ . , ? ' / + - * ] Any Symbol That You Like.", - "value": ".", - "required": true - }, - "HEROKU_API_KEY": { - "description": "Your heroku api key, Go To Heroku >> Profile Icon >> Account settings >> Scroll Down >> Reveal >> Copy.", - "value": "", - "required": true - }, - "HEROKU_APP_NAME": { - "description": "Your Heroku app name, Look Top First Slot You Have Just Filled At The Top, That's The Value.", - "value": "", - "required": true - }, - "TIME_ZONE": { - "description": "For Time Plugin. Change It To Your Time Zone or If You Don't Know Leave As it is.", - "value": "Asia/Kolkata", - "required": true - }, - "LOG_CHAT": { - "description": "A Private Telegram Group Id To Store Your Logs.", - "required": true - }, - "TOKEN": { - "description": "Go to @botfather in telegram and make a new bot and get the bot token.", - "required": true - } - }, - "addons": [{ - "plan": "heroku-postgresql", - "options": { - "version": "12" - } - }], - "buildpacks": [{ - "url": "heroku/python" - }] + "name": "Trôn", + "description": "Tron Is A Multifunctional Telegram Userbot with Custom Settings.", + "logo": "https://telegra.ph/file/8d62a8fe005a8077188ec.jpg", + "keywords": [ + "userbot", + "plugins", + "development", + "tools", + "pyrogram", + "productivity" + ], + "repository": "https://github.com/beastzx18/Tron/", + "website": "https://t.me/tronuserbot", + "success_url": "/welcome", + "env": { + "API_ID": { + "description": "Login here -> my.telegram.org to get pair of keys", + "value": "", + "required": true + }, + "API_HASH": { + "description": "Again You Will Find This Here -> my.telegram.org", + "value": "", + "required": true + }, + "SESSION": { + "description": "Visit here & create https://replit.com/@beastzx18/Tronuserbot-session", + "value": "", + "required": true + }, + "PREFIX": { + "description": "This Is The Handler Of Your All Commands You Can Change It To -> [ . , ? ' / + - * ] Any Symbol That You Like.", + "value": ".", + "required": true + }, + "HEROKU_API_KEY": { + "description": "Your heroku api key, Go To Heroku >> Profile Icon >> Account settings >> Scroll Down >> Reveal >> Copy.", + "value": "", + "required": true + }, + "HEROKU_APP_NAME": { + "description": "Your Heroku app name, Look Top First Slot You Have Just Filled At The Top, That's The Value.", + "value": "", + "required": true + }, + "TIME_ZONE": { + "description": "For Time Plugin. Change It To Your Time Zone or If You Don't Know Leave As it is.", + "value": "Asia/Kolkata", + "required": true + }, + "LOG_CHAT": { + "description": "A Private Telegram Group Id To Store Your Logs.", + "required": true + }, + "TOKEN": { + "description": "Go to @botfather in telegram and make a new bot and get the bot token.", + "required": true + } + }, + "addons": [ + { + "plan": "heroku-postgresql", + "options": { + "version": "12" + } + } + ], + "buildpacks": [ + { + "url": "heroku/python" + } + ] } diff --git a/requirements.txt b/requirements.txt index 8b70754e..c94b1822 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,4 +1,4 @@ -pyrogram +pyrogram==1.4.7 pytube telegraph heroku3 diff --git a/runtime.txt b/runtime.txt index 7ea5722c..e19f0bb0 100644 --- a/runtime.txt +++ b/runtime.txt @@ -1 +1 @@ -python-3.9.5 +python-3.9.5 From a635c64050d79c17254346b46a5902b63578927b Mon Sep 17 00:00:00 2001 From: beastzx18 Date: Wed, 23 Feb 2022 22:08:38 +0530 Subject: [PATCH 2/7] improvement in text --- .github/workflows/codeql-analysis.yml | 6 +++--- docs/_config.yml | 2 +- docs/index.md | 4 ++-- tronx/README.md | 10 +--------- tronx/__main__.py | 18 ++++++++++-------- 5 files changed, 17 insertions(+), 23 deletions(-) diff --git a/.github/workflows/codeql-analysis.yml b/.github/workflows/codeql-analysis.yml index d39e4372..b1959304 100644 --- a/.github/workflows/codeql-analysis.yml +++ b/.github/workflows/codeql-analysis.yml @@ -12,12 +12,12 @@ name: "CodeQL" on: - push: + push: branches: [ master ] - pull_request: + pull_request: # The branches below must be a subset of the branches above branches: [ master ] - schedule: + schedule: - cron: '32 13 * * 0' jobs: diff --git a/docs/_config.yml b/docs/_config.yml index cc35c1df..75e25358 100644 --- a/docs/_config.yml +++ b/docs/_config.yml @@ -1 +1 @@ -theme: jekyll-theme-modernist \ No newline at end of file +theme: jekyll-theme-modernist diff --git a/docs/index.md b/docs/index.md index 086ebf09..861004ec 100644 --- a/docs/index.md +++ b/docs/index.md @@ -1,6 +1,6 @@ ## Welcome to tron -Everything that you want to know about tron is given here. +Here the information about tron is given, it is always updated if any changes are made in tronuserbot. ### Introduction @@ -16,7 +16,7 @@ I have provided a inline help menu to make it easy for the beginners to look for ### Deployment -Tue userbot can be deployed in heroku, it is also deployable by localhost methods. +The userbot can be deployed in heroku, it is also deployable by localhost methods you can do this only if you download and install all the packages from requirements.txt file. ### Contact me diff --git a/tronx/README.md b/tronx/README.md index 8998cb1a..eb1a6b79 100644 --- a/tronx/README.md +++ b/tronx/README.md @@ -1,9 +1 @@ -# Files location - -* database/postgres -* helpers -* methods/decorators -* modules -* plugins -* ____init____.py -* ____main____.py +### This directory stores all the necessary files which are needed to run the bot, deleting or altering any of the file will give error. diff --git a/tronx/__main__.py b/tronx/__main__.py index 7080da7d..294e58c6 100644 --- a/tronx/__main__.py +++ b/tronx/__main__.py @@ -13,11 +13,12 @@ async def start_assistant(): this function starts the pyrogram bot client. """ if app.bot: + print("Activating assistant.") await app.bot.start() - app.log.info("Assistant activated, startup in progress . . .\n") + print("Assistant activated.\n") else: - app.log.info("Assistant start unsuccessful, please check that you have given the bot token.\n") - app.log.info("skipping assistant start !") + print("Assistant start unsuccessful, please check that you have given the bot token.\n") + print("skipping assistant start !") @@ -27,11 +28,12 @@ async def start_userbot(): this function starts the pyrogram userbot client. """ if app: + print("Activating userbot.") await app.start() - app.log.info("Userbot activated, startup in progress . . .\n") + print("Userbot activated.\n") else: - app.log.info("Userbot startup unsuccessful, please check everything again ...") - app.log.info("Couldn't load modules of userbot") + print("Userbot startup unsuccessful, please check everything again ...") + print("Couldn't load modules of userbot") @@ -42,10 +44,10 @@ async def start_bot(): clients custom 'import_module' to start clients & import modules. """ print("___________________________________. Welcome to Tron corporation .___________________________________\n\n\n") - print("PLUGINS: Installing . . .\n\n") + print("PLUGINS: Installing.\n\n") plugins = app.import_module("tronx/plugins/", exclude=app.NoLoad()) print(f"\n\n{plugins} plugins Loaded\n\n") - print("MODULES: Installing . . .\n\n") + print("MODULES: Installing.\n\n") modules = app.import_module("tronx/modules/", exclude=app.NoLoad()) print(f"\n\n{modules} modules Loaded") await start_assistant() From f04a124e09fc9498dc3936f406604ed0cf64e262 Mon Sep 17 00:00:00 2001 From: beastzx18 Date: Wed, 23 Feb 2022 23:58:54 +0530 Subject: [PATCH 3/7] code refinement --- tronx/__main__.py | 7 +- tronx/modules/admin.py | 603 +++++++++++++++++++++-------------------- 2 files changed, 320 insertions(+), 290 deletions(-) diff --git a/tronx/__main__.py b/tronx/__main__.py index 294e58c6..93a2d55c 100644 --- a/tronx/__main__.py +++ b/tronx/__main__.py @@ -13,7 +13,7 @@ async def start_assistant(): this function starts the pyrogram bot client. """ if app.bot: - print("Activating assistant.") + print("Activating assistant.\n") await app.bot.start() print("Assistant activated.\n") else: @@ -28,7 +28,7 @@ async def start_userbot(): this function starts the pyrogram userbot client. """ if app: - print("Activating userbot.") + print("Activating userbot.\n") await app.start() print("Userbot activated.\n") else: @@ -49,9 +49,10 @@ async def start_bot(): print(f"\n\n{plugins} plugins Loaded\n\n") print("MODULES: Installing.\n\n") modules = app.import_module("tronx/modules/", exclude=app.NoLoad()) - print(f"\n\n{modules} modules Loaded") + print(f"\n\n{modules} modules Loaded\n\n") await start_assistant() await start_userbot() + print("You successfully deployed Tronuserbot, try .ping or .alive to test it.") await idle() # block execution diff --git a/tronx/modules/admin.py b/tronx/modules/admin.py index 62a375a4..b7c98523 100644 --- a/tronx/modules/admin.py +++ b/tronx/modules/admin.py @@ -51,7 +51,7 @@ def to_seconds(format, number): # number: int, format: s, m, h, d @app.on_message(gen("ban", allow = ["sudo", "channel"])) -async def ban_members(_, m: Message): +async def ban_handler(_, m: Message): try: # return if used in private if m.chat.type in private: @@ -62,48 +62,47 @@ async def ban_members(_, m: Message): cmd = m.command ban_time = False - if await app.IsAdmin(m) is True: - if reply: - user = await app.get_chat_member(m.chat.id, reply.from_user.id) - if app.long(m) > 1: - arg = cmd[1] + if app.long(m) == 1 and not reply: + return await app.send_edit(m, "Reply or give some id | username after command.", mono=True, delme=4) + + if await app.IsAdmin(m) is False: + return await app.send_edit(m, "You're not an admin here or you don't have enough admin rights.", mono=True, delme=4) + + if reply: + user = await app.get_chat_member(m.chat.id, reply.from_user.id) + if app.long(m) > 1: + arg = cmd[1] + ban_time = to_seconds(arg[-1], int(arg.replace(arg[-1], ""))) + + elif not reply: + if app.long(m) > 1: + user = await app.get_chat_member(m.chat.id, cmd[1]) + if app.long(m) > 2: + arg = cmd[2] ban_time = to_seconds(arg[-1], int(arg.replace(arg[-1], ""))) - elif not reply: - if app.long(m) == 1: - return await app.send_edit(m, "Give me user id | username or reply to the user you want to ban . . .", mono=True) - elif app.long(m) > 1: - user = await app.get_chat_member(m.chat.id, cmd[1]) - if app.long(m) > 2: - arg = cmd[2] - ban_time = to_seconds(arg[-1], int(arg.replace(arg[-1], ""))) - else: - return await app.send_edit(m, "Something went wrong !", mono=True) - - if user: - if user.user.is_self: - return await app.send_edit(m, "You can't ban yourself !", mono=True) - elif user.status == "administrator": - return await app.send_edit(m, "How am i supposed to ban an admin ?", mono=True) - elif user.status == "creator": - return await app.send_edit(m, "How am i supposed to ban a creator of a group ?", mono=True) - else: - return await app.send_edit(m, "Something went wrong !", mono=True) + if user: + if user.user.is_self: + return await app.send_edit(m, "You can't ban yourself !", mono=True, delme=4) + elif user.status == "administrator": + return await app.send_edit(m, "How am i supposed to ban an admin ?", mono=True, delme=4) + elif user.status == "creator": + return await app.send_edit(m, "How am i supposed to ban a creator of a group ?", mono=True, delme=4) + else: + return await app.send_edit(m, "Something went wrong !", mono=True, delme=4) - m = await app.send_edit(m, "⏳ • Hold on . . .", mono=True) - if ban_time: - await app.ban_chat_member(m.chat.id, user.user.id, time.time() + ban_time) - await app.send_edit(m, f"Banned {user.user.mention} for {arg} ") - else: - await app.ban_chat_member(m.chat.id, user.user.id) - await app.send_edit(m, f"Banned {user.user.mention} in this chat !") + m = await app.send_edit(m, "⏳ • Hold on . . .", mono=True) + if ban_time: + await app.ban_chat_member(m.chat.id, user.user.id, time.time() + ban_time) + await app.send_edit(m, f"Banned {user.user.mention} for {arg}", delme=4) else: - return await app.send_edit(m, "Sorry, You are not an admin here !", delme=1, mono=True) + await app.ban_chat_member(m.chat.id, user.user.id) + await app.send_edit(m, f"Banned {user.user.mention} in this chat.", delme=4) except (UsernameInvalid, UsernameNotOccupied): - await app.send_edit(m, "The provided username | id is invalid !", mono=True, delme=5) + await app.send_edit(m, "The provided username | id is invalid !", mono=True, delme=4) except UserNotParticipant: - await app.send_edit(m, "This user doesn't exist in this group !", mono=True, delme=5) + await app.send_edit(m, "This user doesn't exist in this group !", mono=True, delme=4) except Exception as e: await app.error(m, e) @@ -111,26 +110,28 @@ async def ban_members(_, m: Message): @app.on_message(gen("banall", allow = ["channel"])) -async def ban_all(_, m): +async def banall_handler(_, m: Message): try: await app.private(m) - if await app.IsAdmin(m) is True: - count = 0 - data = [] - data.clear() - if app.long(m) == 1: - return await app.send_edit(m, "Use '`confirm`' text after command to ban all members . . .", delme=2) - elif app.long(m) > 1 and m.command[1] == "confirm": - async for x in app.iter_chat_members(m.chat.id): - if x.status == "member": - await app.ban_chat_member(m.chat.id, x.user.id) - count += 1 - m = await app.send_edit(m, f"Banned {x.user.mention} . . .") - await app.send_edit(m, f"Banned {count} members !") - elif app.long(m) > 1 and m.command[1] != "confirm": - await app.send_edit(m, "Use '`confirm`' text after command to ban all members . . .", delme=2, mono=True) - else: - await app.send_edit(m, "`Sorry, you are not an admin here . . .`", delme=2, mono=True) + if await app.IsAdmin(m) is False: + return await app.send_edit(m, "You're not an admin or you don't have enough admin rights.", mono=True, delme=4) + + count = 0 + data = [] + data.clear() + + if app.long(m) == 1: + return await app.send_edit(m, "Use '`confirm`' text after command to ban all members.", mono=True, delme=4) + elif app.long(m) > 1 and m.command[1] == "confirm": + async for x in app.iter_chat_members(m.chat.id): + if x.status == "member": + await app.ban_chat_member(m.chat.id, x.user.id) + count += 1 + m = await app.send_edit(m, f"Banned {x.user.mention} . . .") + await app.send_edit(m, f"Banned {count} members !") + elif app.long(m) > 1 and m.command[1] != "confirm": + await app.send_edit(m, "Use '`confirm`' text after command to ban all members.", mono=True, delme=4) + except Exception as e: await app.error(m, e) @@ -138,7 +139,7 @@ async def ban_all(_, m): @app.on_message(gen("unban", allow = ["sudo", "channel"])) -async def unban_members(_, m: Message): +async def unban_handler(_, m: Message): try: if m.chat.type in private: return await app.private(m) @@ -146,37 +147,41 @@ async def unban_members(_, m: Message): reply = m.reply_to_message user = False - if await app.IsAdmin(m) is True: - if reply: - user = await app.get_chat_member(m.chat.id, reply.from_user.id) - elif not reply: - if app.long(m) == 1: - return await app.send_edit(m, "Give me user id | username or reply to that user you want to unban . . .", mono=True, delme=4) - if app.long(m) > 1: - user = await app.get_chat_member(m.chat.id, m.command[1]) - else: - return await app.send_edit(m, "Something went wrong !", mono=True, delme=4) - - if user: - if user.user.is_self: - return await app.send_edit(m, "You can't Unban yourself !", mono=True) - elif user.status == "administrator": - return await app.send_edit(m, "How am i supposed to ban an admin ?", mono=True) - elif user.status == "creator": - return await app.send_edit(m, "How am i supposed to ban a creator of a group ?", mono=True) - else: - return await app.send_edit(m, "Something went wrong !", mono=True) + if not reply and app.long(m) == 1: + return await app.send_edit(m, "Reply to a user or give me the username | id of that user.", mono=True, delme=4) + + if await app.IsAdmin(m) is False: + return await app.send_edit(m, "You're not an admin or you don't have enough admin rights.", mono=True, delme=4) + + if reply: + user = await app.get_chat_member(m.chat.id, reply.from_user.id) + elif not reply: + if app.long(m) > 1: + user = await app.get_chat_member(m.chat.id, m.command[1]) + else: + return await app.send_edit(m, "Something went wrong !", mono=True, delme=4) + + if user: + if user.user.is_self: + return await app.send_edit(m, "You can't unban yourself !", mono=True, delme=4) + elif user.status == "administrator": + return await app.send_edit(m, "How am i supposed to unban an admin ?", mono=True, delme=4) + elif user.status == "creator": + return await app.send_edit(m, "How am i supposed to unban a creator of a group ?", mono=True, delme=4) + else: + return await app.send_edit(m, "Something went wrong !", mono=True, delme=4) - await app.send_edit(m, "Unbanning . . .", mono=True) - await app.unban_chat_member(m.chat.id, user.user.id) - await app.send_edit(m, f"Unbanned {user.user.mention} in this chat !") + m = await app.send_edit(m, "Unbanning . . .", mono=True) + done = await app.unban_chat_member(m.chat.id, user.user.id) + if done: + await app.send_edit(m, f"Unbanned {user.user.mention} in this chat.", delme=4) else: - return await app.send_edit(m, "Sorry, You Are Not An Admin Here !", delme=1, mono=True) + await app.send_edit(m, "Failed to unabn this user.", mono=True, delme=4) except (UsernameInvalid, UsernameNotOccupied): - await app.send_edit(m, "The provided username | id is invalid !", mono=True, delme=5) + await app.send_edit(m, "The provided username | id is invalid !", mono=True, delme=4) except UserNotParticipant: - await app.send_edit(m, "This user doesn't exist in this group !", mono=True, delme=5) + await app.send_edit(m, "This user doesn't exist in this group !", mono=True, delme=4) except Exception as e: await app.error(m, e) @@ -197,7 +202,7 @@ async def mute_user(chat_id, user_id, duration=0): can_invite_users=True, can_pin_messages=False ), - until_date=duration + until_date=duration ) @@ -205,7 +210,7 @@ async def mute_user(chat_id, user_id, duration=0): @app.on_message(gen("mute", allow = ["sudo"])) -async def mute_users(_, m: Message): +async def mute_handler(_, m: Message): try: if m.chat.type in private: return await app.private(m) @@ -215,46 +220,48 @@ async def mute_users(_, m: Message): mute_time = False cmd = m.command - if await app.IsAdmin(m) is True: - if reply: - user = await app.get_chat_member(m.chat.id, reply.from_user.id) - if app.long(m) > 1: - arg = cmd[1] + if not reply and app.long(m) == 1: + return await app.send_edit(m, "Reply to a user or give me username | id of that user.", mono=True, delme=4) + + if await app.IsAdmin(m) is False: + return await app.send_edit(m, "You're not an admin or you don't have enough admin rights.", mono=True, delme=4) + + if reply: + user = await app.get_chat_member(m.chat.id, reply.from_user.id) + if app.long(m) > 1: + arg = cmd[1] + mute_time = to_seconds(arg[-1], int(arg.replace(arg[-1], ""))) + + elif not reply: + if app.long(m) > 1: + user = await app.get_chat_member(m.chat.id, m.command[1]) + if app.long(m) > 2: + arg = cmd[2] mute_time = to_seconds(arg[-1], int(arg.replace(arg[-1], ""))) - elif not reply: - if app.long(m) == 1: - return await app.send_edit(m, "Give me user id | username or reply to that user you want to unban . . .", mono=True, delme=4) - if app.long(m) > 1: - user = await app.get_chat_member(m.chat.id, m.command[1]) - if app.long(m) > 2: - arg = cmd[2] - mute_time = to_seconds(arg[-1], int(arg.replace(arg[-1], ""))) - else: - return await app.send_edit(m, "Something went wrong !", mono=True, delme=4) - - if user: - if user.user.is_self: - return await app.send_edit(m, "You can't mute yourself !", mono=True) - elif user.status == "administrator": - return await app.send_edit(m, "How am i supposed to mute an admin ?", mono=True) - elif user.status == "creator": - return await app.send_edit(m, "How am i supposed to mute a creator of a group ?", mono=True) - else: - return await app.send_edit(m, "Something went wrong !", mono=True) + else: + return await app.send_edit(m, "Something went wrong !", mono=True, delme=4) + + if user: + if user.user.is_self: + return await app.send_edit(m, "You can't mute yourself !", mono=True, delme=4) + elif user.status == "administrator": + return await app.send_edit(m, "How am i supposed to mute an admin ?", mono=True, delme=4) + elif user.status == "creator": + return await app.send_edit(m, "How am i supposed to mute a creator of a group ?", mono=True, delme=4) + else: + return await app.send_edit(m, "Something went wrong !", mono=True, delme=4) - if mute_time: - await mute_user(m.chat.id, user.user.id, int(time.time() + mute_time)) - await app.send_edit(m, f"Muted {user.user.mention} for {arg}") - else: - await mute_user(m.chat.id, user.user.id) - await app.send_edit(m, f"Muted {user.user.mention} in this chat for forever.") + if mute_time: + await mute_user(m.chat.id, user.user.id, int(time.time() + mute_time)) + await app.send_edit(m, f"Muted {user.user.mention} for {arg}") else: - return await app.send_edit(m, "Sorry, You Are Not An Admin Here !", delme=1, mono=True) + await mute_user(m.chat.id, user.user.id) + await app.send_edit(m, f"Muted {user.user.mention} in this chat for forever.", delme=4) except (UsernameInvalid, UsernameNotOccupied): - await app.send_edit(m, "The provided username | id is invalid !", mono=True, delme=5) + await app.send_edit(m, "The provided username | id is invalid !", mono=True, delme=4) except UserNotParticipant: - await app.send_edit(m, "This user doesn't exist in this group !", mono=True, delme=5) + await app.send_edit(m, "This user doesn't exist in this group !", mono=True, delme=4) except Exception as e: await app.error(m, e) @@ -262,7 +269,7 @@ async def mute_users(_, m: Message): @app.on_message(gen("unmute", allow = ["sudo"])) -async def unmute_users(_, m: Message): +async def unmute_handler(_, m: Message): try: if m.chat.type in private: return await app.private(m) @@ -270,49 +277,50 @@ async def unmute_users(_, m: Message): reply = m.reply_to_message user = False - if await app.IsAdmin(m) is True: - if reply: - user = await app.get_chat_member(m.chat.id, reply.from_user.id) - elif not reply: - if app.long(m) == 1: - return await app.send_edit(m, "Give me user id | username or reply to that user you want to unban . . .", mono=True, delme=4) - if app.long(m) > 1: - user = await app.get_chat_member(m.chat.id, m.command[1]) - else: - return await app.send_edit(m, "Something went wrong !", mono=True, delme=4) - - if user: - if user.user.is_self: - return await app.send_edit(m, "You can't Unmute yourself !", mono=True) - elif user.status == "administrator": - return await app.send_edit(m, "How do i unmute an admin ?", mono=True) - elif user.status == "creator": - return await app.send_edit(m, "How do i unmute a creator ?", mono=True) - else: - return await app.send_edit(m, "Something went wrong !", mono=True) + if not reply and app.long(m) == 1: + return await app.send_edit(m, "Reply to a user or give me the username | id of that user.", mono=True, delme=4) - await app.restrict_chat_member( - m.chat.id, - user.user.id, - permissions=ChatPermissions( - can_send_messages=True, - can_send_media_messages=True, - can_send_other_messages=True, - can_add_web_page_previews=True, - can_send_polls=True, - can_change_info=False, - can_invite_users=True, - can_pin_messages=False - ) - ) - await app.send_edit(m, f"Unmuted {user.user.mention} in this chat !") + if await app.IsAdmin(m) is False: + return await app.send_edit(m, "You're not an admin or you don't have enough admin rights.", mono=True, delme=4) + + if reply: + user = await app.get_chat_member(m.chat.id, reply.from_user.id) + elif not reply: + if app.long(m) > 1: + user = await app.get_chat_member(m.chat.id, m.command[1]) + else: + return await app.send_edit(m, "Something went wrong !", mono=True, delme=4) + + if user: + if user.user.is_self: + return await app.send_edit(m, "You can't unmute yourself !", mono=True, delme=4) + elif user.status == "administrator": + return await app.send_edit(m, "How do i unmute an admin ?", mono=True, delme=4) + elif user.status == "creator": + return await app.send_edit(m, "How do i unmute a creator ?", mono=True, delme=4) else: - return await app.send_edit(m, "Sorry, You Are Not An Admin Here !", delme=1, mono=True) + return await app.send_edit(m, "Something went wrong !", mono=True, delme=4) + + await app.restrict_chat_member( + m.chat.id, + user.user.id, + permissions=ChatPermissions( + can_send_messages=True, + can_send_media_messages=True, + can_send_other_messages=True, + can_add_web_page_previews=True, + can_send_polls=True, + can_change_info=False, + can_invite_users=True, + can_pin_messages=False + ) + ) + await app.send_edit(m, f"Unmuted {user.user.mention} in this chat.", delme=4) except (UsernameInvalid, UsernameNotOccupied): - await app.send_edit(m, "The provided username | id is invalid !", mono=True, delme=5) + await app.send_edit(m, "The provided username | id is invalid !", mono=True, delme=4) except UserNotParticipant: - await app.send_edit(m, "This user doesn't exist in this group !", mono=True, delme=5) + await app.send_edit(m, "This user doesn't exist in this group !", mono=True, delme=4) except Exception as e: await app.error(m, e) @@ -320,7 +328,7 @@ async def unmute_users(_, m: Message): @app.on_message(gen("kick", allow = ["sudo", "channel"])) -async def kick_users(_, m: Message): +async def kick_handler(_, m: Message): try: if m.chat.type in private: return await app.private(m) @@ -328,37 +336,39 @@ async def kick_users(_, m: Message): reply = m.reply_to_message user = False - if await app.IsAdmin(m) is True: - if reply: - user = await app.get_chat_member(m.chat.id, reply.from_user.id) - elif not reply: - if app.long(m) == 1: - return await app.send_edit(m, "Give me user id | username or reply to that user you want to unban . . .", mono=True, delme=4) - if app.long(m) > 1: - user = await app.get_chat_member(m.chat.id, m.command[1]) - else: - return await app.send_edit(m, "Something went wrong !", mono=True, delme=4) - - if user: - if user.user.is_self: - return await app.send_edit(m, "You can't kick yourself !", mono=True) - elif user.status == "administrator": - return await app.send_edit(m, "How am i supposed to kick an admin ?", mono=True) - elif user.status == "creator": - return await app.send_edit(m, "How am i supposed to kick a creator of a group ?", mono=True) - else: - return await app.send_edit(m, "Something went wrong !", mono=True) + if not reply and app.long(m) == 1: + return await app.send_edit(m, "Reply to a user or give me username | id of that user.", mono=True, delme=4) + + if await app.IsAdmin(m) is False: + return await app.send_edit(m, "You're not admin or you don't have enough admin rights.", mono=True, delme=4) + + if reply: + user = await app.get_chat_member(m.chat.id, reply.from_user.id) + else: + if app.long(m) > 1: + user = await app.get_chat_member(m.chat.id, m.command[1]) + + if user: + if user.user.is_self: + return await app.send_edit(m, "You can't kick yourself !", mono=True) + elif user.status == "administrator": + return await app.send_edit(m, "How am i supposed to kick an admin ?", mono=True) + elif user.status == "creator": + return await app.send_edit(m, "How am i supposed to kick a creator of a group ?", mono=True) + else: + return await app.send_edit(m, "Something went wrong.", mono=True, delme=4) - await app.send_edit(m, "Kicking . . .", mono=True) - await app.kick_user(m.chat.id, user.user.id) - await app.send_edit(m, f"Kicked {user.user.mention} in this chat !") + m = await app.send_edit(m, "Kicking . . .", mono=True) + done = await app.kick_user(m.chat.id, user.user.id) + if done: + await app.send_edit(m, f"Kicked {user.user.mention} in this chat.", delme=4) else: - return await app.send_edit(m, "Sorry, You Are Not An Admin Here !", delme=1, mono=True) + await app.send_edit(m, "Failed to kick to user.", mono=True, delme=4) except (UsernameInvalid, UsernameNotOccupied): - await app.send_edit(m, "The provided username | id is invalid !", mono=True, delme=5) + await app.send_edit(m, "The provided username | id is invalid !", mono=True, delme=4) except UserNotParticipant: - await app.send_edit(m, "This user doesn't exist in this group !", mono=True, delme=5) + await app.send_edit(m, "This user doesn't exist in this group !", mono=True, delme=4) except Exception as e: await app.error(m, e) @@ -366,25 +376,33 @@ async def kick_users(_, m: Message): @app.on_message(gen("pin", allow = ["sudo", "channel"])) -async def pin_message(_, m: Message): - reply = m.reply_to_message +async def pin_handler(_, m: Message): try: + reply = m.reply_to_message + if m.chat.type in private: if not reply: - return await app.send_edit("reply to some message, so that i can pin ", mono=True, delme=5) + return await app.send_edit("Reply to some message, so that i can pin that message.", mono=True, delme=4) + + done = await reply.pin() + if done: + return await app.send_edit(m, "Pinned message !", mono=True, delme=4) + else: + return await app.send_edit(m, "Failed to pin message.", mono=True, delme=4) + + if await app.IsAdmin(m) is False: + return await app.send_edit(m, "You're not an admin here or you don't have enough admin rights.", mono=True, delme=4) + + if reply: + m = await app.send_edit(m, "⏳ • Hold on . . .", mono=True) + done = await reply.pin() + if done: + await app.send_edit(m, "Pinned message.", mono=True, delme=4) else: - await reply.pin() - return await app.send_edit(m, "Pinned message !", mono=True, delme=5) - - if await app.IsAdmin(m) is True: - if reply: - m = await app.send_edit(m, "⏳ • Hold on . . .", mono=True) - done = await reply.pin() - await app.send_edit(m, "Pinned message!", mono=True) if done else await app.send_edit(m, "Failed to pin message", delme=2, mono=True) - elif not reply: - await app.send_edit(m, "Reply to a message so that I can pin that message . . .", delme=2, mono=True) + await app.send_edit(m, "Failed to pin message.", mono=True, delme=4) else: - await app.send_edit(m, "Sorry, you don't have permissions to perform this action !", mono=True, delme=5) + await app.send_edit(m, "Reply to a message so that I can pin that message.", mono=True, delme=4) + except Exception as e: await app.error(m, e) @@ -392,25 +410,32 @@ async def pin_message(_, m: Message): @app.on_message(gen("unpin", allow = ["sudo", "channel"])) -async def unpin_message(_, m: Message): +async def unpin_handler(_, m: Message): try: + cmd = m.command reply = m.reply_to_message + if not reply and app.long(m) == 1: + return await app.send_edit(m, "Reply to a message or use `all` as a prefix to unpin all pinned message.", mono=True, delme=4) + if reply: m = await app.send_edit(m, "⏳ • Hold on . . .", mono=True) done = await reply.unpin() - await app.send_edit(m, "Unpinned message !", mono=True) if done else await app.send_edit(m, "Failed to unpin message . . .", delme=2, mono=True) + if done: + await app.send_edit(m, "Unpinned message.", mono=True) + else: + await app.send_edit(m, "Failed to unpin message.", mono=True, delme=4) elif not reply and app.long(m) > 1: - cmd = m.command[1] - if cmd == "all": + if cmd[1] == "all": done = await app.unpin_all_chat_messages(m.chat.id) - await app.send_edit(m, "Unpinned all pinned messages . . .", mono=True) if done else await app.send_edit(m, "Failed to unpin all messages . . .", delme=2, mono=True) - elif cmd != "all": - await app.send_edit(m, "Reply to a pinned message to unpin or use 'all' as suffix to unpin all pinned messages . . .", delme=2, mono=True) + if done: + await app.send_edit(m, "Unpinned all pinned messages . . .", mono=True) + else: + await app.send_edit(m, "Failed to unpin all messages.", mono=True, delme=4) + elif cmd[1] != "all": + await app.send_edit(m, "Reply to a pinned message to unpin or use `all` as a suffix to unpin all pinned messages.", mono=True, delme=4) else: - await app.send_edit(m, "Failed to unpin messages . . .", delme=2, mono=True) - elif not reply and app.long(m) == 1: - await app.send_edit(m, "Reply to the pinned message to unpin it !", mono=True, delme=5) + await app.send_edit(m, "Failed to unpin all messages.", mono=True, delme=4) except Exception as e: await error(m, e) @@ -418,7 +443,7 @@ async def unpin_message(_, m: Message): @app.on_message(gen("promote", allow = ["sudo", "channel"])) -async def promote_users(_, m: Message): +async def promote_handler(_, m: Message): try: if m.chat.type in private: return await app.private(m) @@ -426,51 +451,54 @@ async def promote_users(_, m: Message): reply = m.reply_to_message user = False - if await app.IsAdmin(m) is True: - if reply: - user = await app.get_chat_member(m.chat.id, reply.from_user.id) - elif not reply: - if app.long(m) == 1: - return await app.send_edit(m, "Give me user id | username or reply to that user you want to unban . . .", mono=True, delme=4) - if app.long(m) > 1: - user = await app.get_chat_member(m.chat.id, m.command[1]) - else: - return await app.send_edit(m, "Something went wrong !", mono=True, delme=4) - - if user: - if user.user.is_self: - return await app.send_edit(m, "You can't promote yourself !", mono=True) - elif user.status == "administrator": - return await app.send_edit(m, "How am i supposed to promote already promoted user ?", mono=True) - elif user.status == "creator": - return await app.send_edit(m, "How am i supposed to promote a creator of a group ? wth ?", mono=True) - else: - return await app.send_edit(m, "Something went wrong !", mono=True) + if app.long(m) == 1 and not reply: + return await app.send_edit(m, "Reply to user or give me username | id of that user.", mono=True, delme=4) - await app.promote_chat_member( - m.chat.id, - user.user.id, - is_anonymous=False, - can_change_info=True, - can_manage_voice_chats=True, - can_manage_chat=True, - can_delete_messages=True, - can_edit_messages=True, - can_invite_users=True, - can_promote_members=False, - can_restrict_members=True, - can_pin_messages=True, - can_post_messages=True, - ) - m = app.send_edit(m, "Promoting . . .", mono=True) - await app.send_edit(m, f"Promoted {user.user.mention} in this chat !") + if await app.IsAdmin(m) is False: + return await app.send_edit(m, "You're not admin or you don't have enough admin rights.", mono=True, delme=4) + + if reply: + user = await app.get_chat_member(m.chat.id, reply.from_user.id) + else: + if app.long(m) > 1: + user = await app.get_chat_member(m.chat.id, m.command[1]) else: - return await app.send_edit(m, "Sorry, You Are Not An Admin Here !", delme=1, mono=True) + return await app.send_edit(m, "Something went wrong !", mono=True, delme=4) + + if user: + if user.user.is_self: + return await app.send_edit(m, "You can't promote yourself !", mono=True) + elif user.status == "administrator": + return await app.send_edit(m, "How am i supposed to promote already promoted user ?", mono=True) + elif user.status == "creator": + return await app.send_edit(m, "How am i supposed to promote a creator of a group ? wth ?", mono=True) + else: + return await app.send_edit(m, "Something went wrong !", mono=True) + + await app.promote_chat_member( + m.chat.id, + user.user.id, + is_anonymous=False, + can_change_info=True, + can_manage_voice_chats=True, + can_manage_chat=True, + can_delete_messages=True, + can_edit_messages=True, + can_invite_users=True, + can_promote_members=False, + can_restrict_members=True, + can_pin_messages=True, + can_post_messages=True, + ) + m = app.send_edit(m, "Promoting . . .", mono=True) + await app.send_edit(m, f"Promoted {user.user.mention} in this chat !") + else: + return await app.send_edit(m, "Sorry, You Are Not An Admin Here !", delme=1, mono=True) except (UsernameInvalid, UsernameNotOccupied): - await app.send_edit(m, "The provided username | id is invalid !", mono=True, delme=5) + await app.send_edit(m, "The provided username | id is invalid !", mono=True, delme=4) except UserNotParticipant: - await app.send_edit(m, "This user doesn't exist in this group !", mono=True, delme=5) + await app.send_edit(m, "This user doesn't exist in this group !", mono=True, delme=4) except Exception as e: await app.error(m, e) @@ -478,7 +506,7 @@ async def promote_users(_, m: Message): @app.on_message(gen("demote", allow = ["sudo", "channel"])) -async def demote_users(_, m: Message): +async def demote_handler(_, m: Message): try: if m.chat.type in private: return await app.private(m) @@ -486,48 +514,49 @@ async def demote_users(_, m: Message): reply = m.reply_to_message user = False - if await app.IsAdmin(m) is True: - if reply: - user = await app.get_chat_member(m.chat.id, reply.from_user.id) - elif not reply: - if app.long(m) == 1: - return await app.send_edit(m, "Give me user id | username or reply to that user you want to unban . . .", mono=True, delme=4) - if app.long(m) > 1: - user = await app.get_chat_member(m.chat.id, m.command[1]) - else: - return await app.send_edit(m, "Something went wrong !", mono=True, delme=4) + if await app.IsAdmin(m) is False: + return await app.send_edit(m, "You're not an admin here or you don't have enough rights.", mono=True, delme=4) - if user: - if user.user.is_self: - return await app.send_edit(m, "You can't demote yourself !", mono=True) - elif user.status == "creator": - return await app.send_edit(m, "How am i supposed to demote a creator of a group ?", mono=True) - else: - return await app.send_edit(m, "Something went wrong !", mono=True) - - await app.promote_chat_member( - m.chat.id, - user.user.id, - is_anonymous=False, - can_change_info=False, - can_manage_voice_chats=False, - can_manage_chat=False, - can_delete_messages=False, - can_edit_messages=False, - can_invite_users=False, - can_promote_members=False, - can_restrict_members=False, - can_pin_messages=False, - can_post_messages=False, - ) - m = await app.send_edit(m, "Demoting . . .", mono=True) - await app.send_edit(m, f"Demoted {user.user.mention} in this chat !") + if app.long(m) == 1 and not reply: + return await app.send_edit(m, "Reply to user or give me username | id of that user.", mono=True, delme=4) + + if reply: + user = await app.get_chat_member(m.chat.id, reply.from_user.id) else: - return await app.send_edit(m, "Sorry, You Are Not An Admin Here !", delme=1, mono=True) + if app.long(m) > 1: + user = await app.get_chat_member(m.chat.id, m.command[1]) + else: + return await app.send_edit(m, "Something went wrong !", mono=True, delme=4) + + if user: + if user.user.is_self: + return await app.send_edit(m, "You can't demote yourself !", mono=True) + elif user.status == "creator": + return await app.send_edit(m, "How am i supposed to demote a creator of a group ?", mono=True) + else: + return await app.send_edit(m, "Something went wrong !", mono=True) + + await app.promote_chat_member( + m.chat.id, + user.user.id, + is_anonymous=False, + can_change_info=False, + can_manage_voice_chats=False, + can_manage_chat=False, + can_delete_messages=False, + can_edit_messages=False, + can_invite_users=False, + can_promote_members=False, + can_restrict_members=False, + can_pin_messages=False, + can_post_messages=False, + ) + m = await app.send_edit(m, "Demoting . . .", mono=True) + await app.send_edit(m, f"Demoted {user.user.mention} in this chat !") except (UsernameInvalid, UsernameNotOccupied): - await app.send_edit(m, "The provided username | id is invalid !", mono=True, delme=5) + await app.send_edit(m, "The provided username | id is invalid !", mono=True, delme=4) except UserNotParticipant: - await app.send_edit(m, "This user doesn't exist in this group !", mono=True, delme=5) + await app.send_edit(m, "This user doesn't exist in this group !", mono=True, delme=4) except Exception as e: await app.error(m, e) From 90c871c4b6a43f1f311954956900336b720911d7 Mon Sep 17 00:00:00 2001 From: beastzx18 Date: Thu, 24 Feb 2022 00:36:11 +0530 Subject: [PATCH 4/7] minor update --- tronx/clients/utils.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/tronx/clients/utils.py b/tronx/clients/utils.py index 26a39d9f..30d71016 100644 --- a/tronx/clients/utils.py +++ b/tronx/clients/utils.py @@ -1,15 +1,13 @@ -import os import time import pyrogram -import platform +from logging import getLogger, WARNING from pysimplelog import Logger from config import Config -from typing import Union, List from telegraph import Telegraph from tronx.methods import Methods +from pyrogram import __version__ as pyro_version from pyrogram.types import Message -from pyrogram.errors import PeerIdInvalid from tronx.database import Database from tronx.helpers import Helpers @@ -22,7 +20,7 @@ class Utils(Methods, Config, Database, Helpers): userbot_version = "v.0.0.5" assistant_version = "v.0.0.1" python_version = str(platform.python_version()) - pyrogram_version = str(pyrogram.__version__) + pyrogram_version = str(pyro_version) # containers / @@ -41,7 +39,9 @@ class Utils(Methods, Config, Database, Helpers): # debugging / + getLogger("pyrogram").setLevel(WARNING) # turn off pyrogram logging log = Logger(timezone=Config.TIME_ZONE) + log.set_name("") # Ex: Logger some message, `Logger` name will empty # telegraph / From 22f07133f7ca432d5f85fed83f83f36813f3033f Mon Sep 17 00:00:00 2001 From: beastzx18 Date: Thu, 24 Feb 2022 00:45:13 +0530 Subject: [PATCH 5/7] restore --- tronx/clients/utils.py | 1 + 1 file changed, 1 insertion(+) diff --git a/tronx/clients/utils.py b/tronx/clients/utils.py index 30d71016..5a255f1e 100644 --- a/tronx/clients/utils.py +++ b/tronx/clients/utils.py @@ -1,5 +1,6 @@ import time import pyrogram +import platform from logging import getLogger, WARNING from pysimplelog import Logger From 2314cd78f2d13514a16dbc2889baf70b7106e67e Mon Sep 17 00:00:00 2001 From: beastzx18 Date: Thu, 24 Feb 2022 00:57:33 +0530 Subject: [PATCH 6/7] bugfix --- tronx/modules/admin.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/tronx/modules/admin.py b/tronx/modules/admin.py index b7c98523..34e893c5 100644 --- a/tronx/modules/admin.py +++ b/tronx/modules/admin.py @@ -462,8 +462,6 @@ async def promote_handler(_, m: Message): else: if app.long(m) > 1: user = await app.get_chat_member(m.chat.id, m.command[1]) - else: - return await app.send_edit(m, "Something went wrong !", mono=True, delme=4) if user: if user.user.is_self: From 6b173b2423f829a4bcbbc83e66464175f313d22e Mon Sep 17 00:00:00 2001 From: beastzx18 Date: Thu, 24 Feb 2022 01:04:25 +0530 Subject: [PATCH 7/7] bugfix --- tronx/modules/admin.py | 4 ---- 1 file changed, 4 deletions(-) diff --git a/tronx/modules/admin.py b/tronx/modules/admin.py index 34e893c5..47ed821c 100644 --- a/tronx/modules/admin.py +++ b/tronx/modules/admin.py @@ -490,8 +490,6 @@ async def promote_handler(_, m: Message): ) m = app.send_edit(m, "Promoting . . .", mono=True) await app.send_edit(m, f"Promoted {user.user.mention} in this chat !") - else: - return await app.send_edit(m, "Sorry, You Are Not An Admin Here !", delme=1, mono=True) except (UsernameInvalid, UsernameNotOccupied): await app.send_edit(m, "The provided username | id is invalid !", mono=True, delme=4) @@ -523,8 +521,6 @@ async def demote_handler(_, m: Message): else: if app.long(m) > 1: user = await app.get_chat_member(m.chat.id, m.command[1]) - else: - return await app.send_edit(m, "Something went wrong !", mono=True, delme=4) if user: if user.user.is_self: