diff --git a/config.py b/config.py index 401224da..e321d012 100644 --- a/config.py +++ b/config.py @@ -1,11 +1,12 @@ import os +import pkg_resources -#todo +# todo if os.uname()[1] == "localhost": - response = os.system("pip3 install -r requirements.txt") + response = os.system("pip3 install -r requirements.txt --no-cache-dir") if response == 0: print("Successfully Installed all requirements") else: @@ -14,16 +15,17 @@ -# if you deploy this bot by localhost method, then replace all the necessary part of variables given below after '=' sign with your desired values. +# if you deployed this userbot using localhost method, then replace all the necessary parts of the variables given below after '=' sign with the required values. # for example edit like 'API_ID = 1234567' instead of 'API_ID = os.getenv("API_ID")' -# Note: don't touch anything else given below except the values you wanna change otherwise you'll face errors. +# Warning: don't touch anything else given below except the values you wanna change otherwise you'll get errors. #------------------------------------------------------------------------------------------------------------- class Config(object): + """ configuration class """ # api id of your telegram account (required) - API_ID = os.getenv("API_ID") + API_ID = int(os.getenv("API_ID")) # api hash of your telegram account (required) API_HASH = os.getenv("API_HASH") - # Create a session from session.py (required) + # create a session using command [ python3 session.py ] or use repl.it (required) SESSION = os.getenv("SESSION") # ------------------ # temporary download location (required) @@ -31,49 +33,49 @@ class Config(object): # official repo for updates UPSTREAM_REPO = os.getenv("UPSTREAM_REPO", "https://github.com/beastzx18/Tron.git") # ------------------ - # heroku api key (required if hosted on heroku) + # heroku api key (required -> if hosted on heroku) HEROKU_API_KEY = os.getenv("HEROKU_API_KEY") - # heroku app name (required if hosted on heroku) + # heroku app name (required -> if hosted on heroku) HEROKU_APP_NAME = os.getenv("HEROKU_APP_NAME") # database url (required) DB_URI = os.getenv("DATABASE_URL") # ------------------ - # these users can use your bot / userbot - SUDO_USERS = os.getenv("SUDO_USERS") + # these users can use your userbot + SUDO_USERS = [int(x) for x in os.getenv("SUDO_USERS", "").split()] # splits on spaces # a group to store logs, etc (required) - LOG_CHAT = os.getenv("LOG_CHAT") - # command handler, if you give ! (exclamation) then you can do like this !ping => pong ! + LOG_CHAT = int(os.getenv("LOG_CHAT")) + # command handler, if you give (exclamation symbol = !) then you can do like this command: !ping => result: pong ! PREFIX = os.getenv("PREFIX", ".") - # for more info visit docs.pyrogram.org, workers section (required) - WORKERS = os.getenv("WORKERS", 8) - # exclude official plugins from installing - NO_LOAD = os.getenv("NO_LOAD") + # for more info visit docs.pyrogram.org, workers section + WORKERS = int(os.getenv("WORKERS", 8)) + # exclude official plugins from installing, give a space between plugin names + NO_LOAD = [int(x) for x in os.getenv("NO_LOAD", "").split()] # splits on spaces # default reason for afk plugin AFK_TEXT = os.getenv("AFK_TEXT", "I am busy Now !") # ------------------ # add True to enable (default: False) PMPERMIT = os.getenv("PMPERMIT", False) - # pmpermit pic - PMPERMIT_PIC = os.getenv("PMPERMIT_PIC", False) + # pmpermit pic (optional) + PMPERMIT_PIC = os.getenv("PMPERMIT_PIC") # custom pmpermit security text (optional) PMPERMIT_TEXT = os.getenv("PMPERMIT_TEXT", "Hey ! This is [Tron Userbot](https://t.me/tronuserbot) Security System.\n**You will be blocked if you spammed my owner's pm**\nCurrently My Owner is busy! So Wait Until He Arrives. šŸ‘šŸ»\nAnd Better Not To Spam His here!") - # pmpermit warn limit - PM_LIMIT = os.getenv("PM_LIMIT", 4) - # this is used in time plugin + # pmpermit warn limit (optional) + PM_LIMIT = int(os.getenv("PM_LIMIT", 4)) + # this is used to get your accurate time TIME_ZONE = os.getenv("TIME_ZONE", "Asia/Kolkata") # ------------------- # your custom name (default: telegram name) USER_NAME = os.getenv("USER_NAME") - # your custom bio (default: None) + # your custom bio (default: telegram bio) USER_BIO = os.getenv("USER_BIO") - # used for alive plugin (default: official tronuserbot logo image) + # used for alive plugin (default: tronuserbot logo image) USER_PIC = os.getenv("USER_PIC", "https://telegra.ph/file/1073e200f9d8e70b91f0d.jpg") # add your telegram id if bot fails to get your id USER_ID = os.getenv("USER_ID") # add your username if bot fails to get your username USER_USERNAME = os.getenv("USER_USERNAME") # -------------------- - # this bio will be shown in /help menu (default: official bio from bot) + # this bio will be shown in '/help' menu (default: official bio from bot) BOT_BIO = os.getenv("BOT_BIO") # your assistants custom name (default: NORA) BOT_NAME = os.getenv("BOT_NAME", "NORA") @@ -83,7 +85,7 @@ class Config(object): BOT_USERNAME = os.getenv("BOT_USERNAME") # telegram id of bot if failed to get automatically (optional) BOT_ID = os.getenv("BOT_ID") - # without this the bot will not work (required) + # access token of your bot, without this the bot will not work (required) TOKEN = os.getenv("TOKEN") # --------------------- # thumbnail used while uploading plugins, etc. (optional) diff --git a/material/images/sample.jpg b/material/images/sample.jpg deleted file mode 100644 index 535bb2a0..00000000 Binary files a/material/images/sample.jpg and /dev/null differ diff --git a/material/images/white.jpg b/material/images/white.jpg deleted file mode 100644 index a13ee499..00000000 Binary files a/material/images/white.jpg and /dev/null differ diff --git a/session.py b/session.py index b468d068..1754be94 100644 --- a/session.py +++ b/session.py @@ -26,9 +26,8 @@ API_ID = input("\nEnter your API_ID: ") - -while not API_ID.isdigit() and (len(API_ID) < 7 or len(API_ID) > 7): - print("\n\nPlease enter a digit.\n\n") +while not (API_ID.isdigit() and len(API_ID) == 7): + print("\n\nPlease enter a 7 digit API_ID.\n\n") API_ID = input("Enter your API_ID (1234567): ") @@ -39,7 +38,7 @@ # create a new pyrogram session -with Client(":memory:", api_id=int(API_ID), api_hash=API_HASH, hide_password=True) as app: +with Client(":memory:", api_id=int(API_ID), api_hash=API_HASH) as app: app.send_message("me", f"This Is Your Tron Userbot • [ `SESSION` ]\n\n```{app.export_session_string()}```\n\nāš ļøā€¢ Don't share this with anyone !!\n\nCreate Again • [ Press Here](https://replit.com/@beastzx18/Tron-Userbot-Session)", disable_web_page_preview=True,) - print("Your String Session Is Successfully Saved In Telegram Saved Messages !! Don't Share It With Anyone!! Anyone having your session can use your telegram account !") + print("Your String Session Is Successfully Saved In Telegram Saved (Cloud) Messages !! Don't Share It With Anyone!! Anyone having your session can use (hack) your telegram account !") diff --git a/tronx/__main__.py b/tronx/__main__.py index 0e9cf334..5214056b 100644 --- a/tronx/__main__.py +++ b/tronx/__main__.py @@ -41,10 +41,10 @@ async def start_bot(): """ __main__ startup """ print("___________________________________. Welcome to Tron corporation .___________________________________\n\n\n") print("PLUGINS: Installing . . .\n\n") - _plugs = app.import_module("tronx/plugins/") + _plugs = app.import_module("tronx/plugins/", exclude=app.NoLoad()) print(f"\n\n{_plugs} plugins Loaded\n\n") print("MODULES: Installing . . .\n\n") - _mods = app.import_module("tronx/modules/") + _mods = app.import_module("tronx/modules/", exclude=app.NoLoad()) print(f"\n\n{_mods} modules Loaded") await start_assistant() await start_userbot() diff --git a/tronx/helpers/__init__.py b/tronx/helpers/__init__.py index b8d9bee7..e06d4ff0 100644 --- a/tronx/helpers/__init__.py +++ b/tronx/helpers/__init__.py @@ -5,6 +5,7 @@ from .utilities import Utilities from .bot import Bot from .user import User +from .others import Others from .filters import * @@ -16,6 +17,7 @@ class Helpers( Strings, Utilities, Bot, - User + User, + Others ): pass diff --git a/tronx/helpers/decorators.py b/tronx/helpers/decorators.py index a91972cc..5abe724b 100644 --- a/tronx/helpers/decorators.py +++ b/tronx/helpers/decorators.py @@ -8,7 +8,7 @@ class Decorators(object): def alert_user(self, func): async def wrapper(_, cb: CallbackQuery): - if cb.from_user and not cb.from_user.id == self.id: + if cb.from_user and not (cb.from_user.id == self.id or cb.from_user.id in self.SudoUsers()): await cb.answer( f"Sorry, but you can't use this userbot ! make your own userbot at @tronuserbot", show_alert=True diff --git a/tronx/helpers/filters.py b/tronx/helpers/filters.py index fd125a51..67003408 100644 --- a/tronx/helpers/filters.py +++ b/tronx/helpers/filters.py @@ -28,29 +28,32 @@ def regex( pattern: Union[str, Pattern], flags: int = 0, - only_me: bool = True, + allow_sudo: bool = True, allow_forward: bool = False, allow_channel: bool = False, allow_edit: bool = True ): - async def func(flt, _, update: Update): - if only_me: - if not (update.from_user - and update.from_user.is_self - ): + async def func(flt, client: Client, update: Update): + + # works for you & sudo | only for you + if allow_sudo: + if update.from_user and not (update.from_user.is_self or update.from_user.id in client.SudoUsers()): + return False + elif not allow_sudo: + if update.from_user and not update.from_user.is_self: return False - if allow_forward is False: - if update.forward_date: + if not allow_forward: + if update.forward_date: return False - if allow_channel is False: - if update.chat.type == "channel": + if not allow_channel: + if update.chat.type == "channel": return False - if allow_edit is False: - if update.edit_date: + if not allow_edit: + if update.edit_date: return False if isinstance(update, Message): @@ -88,7 +91,7 @@ def gen( commands: Union[str, List[str]], prefixes: Union[str, List[str]] = myprefix(), case_sensitive: bool = True, - only_me: bool = True, + allow_sudo: bool = True, allow_forward: bool = False, allow_channel: bool = False, allow_edit: bool = True, @@ -110,8 +113,11 @@ async def func(flt, client: Client, message: Message): if not text: return False - # works only for you - if only_me: + # works for you & sudo | only for you + if allow_sudo: + if message.from_user and not (message.from_user.is_self or message.from_user.id in client.SudoUsers()): + return False + elif not allow_sudo: if message.from_user and not message.from_user.is_self: return False diff --git a/tronx/helpers/functions.py b/tronx/helpers/functions.py index 6964f3f3..5631f43b 100644 --- a/tronx/helpers/functions.py +++ b/tronx/helpers/functions.py @@ -45,18 +45,21 @@ def showtime(self): async def edit_text(self, m: Message, text, disable_web_page_preview=False, parse_mode="combined"): """this is a alias function for send_edit function""" try: - await m.edit( - text, - parse_mode=parse_mode, - disable_web_page_preview=disable_web_page_preview, - ) - except MessageIdInvalid: - await self.send_message( - m.chat.id, - text, - disable_web_page_preview=disable_web_page_preview, - parse_mode=parse_mode - ) + if m.from_user and m.from_user.is_self: + await m.edit( + text, + parse_mode=parse_mode, + disable_web_page_preview=disable_web_page_preview, + ) + elif m.from_user and not m.from_user.is_self: # for sudo users + await self.send_message( + m.chat.id, + text, + disable_web_page_preview=disable_web_page_preview, + parse_mode=parse_mode + ) + except Exception as e: + self.log.info(e) async def error(self, m: Message, e, edit_error=False): diff --git a/tronx/helpers/others.py b/tronx/helpers/others.py new file mode 100644 index 00000000..d42f660e --- /dev/null +++ b/tronx/helpers/others.py @@ -0,0 +1,12 @@ +class Others(object): + def NoLoad(self): + noloadvar = self.getdv("NO_LOAD") + data_list = noloadvar.split() if noloadvar else False + return data_list or self.NO_LOAD or [] + + + def SudoUsers(self): + sudovar = self.getdv("SUDO_USERS") + data_list = [int(x) for x in sudovar.split()] if sudovar else False + return data_list or self.SUDO_USERS or [] + diff --git a/tronx/modules/dv.py b/tronx/modules/dv.py index 42270608..ff7f964a 100644 --- a/tronx/modules/dv.py +++ b/tronx/modules/dv.py @@ -27,7 +27,7 @@ -@app.on_message(gen("setdv")) +@app.on_message(gen("setdv", allow_sudo=False)) async def set_dv_var(_, m: Message): if app.long(m) == 2: await app.send_edit(m, "Please give me key with a value . . . ", mono=True, delme=2) @@ -49,7 +49,7 @@ async def set_dv_var(_, m: Message): -@app.on_message(gen("deldv")) +@app.on_message(gen("deldv", allow_sudo=False)) async def del_dv_var(_, m: Message): if app.long(m) == 1: await app.send_edit(m, "Give me some key to delete that a var from database . . . ", mono=True, delme=2) @@ -66,7 +66,7 @@ async def del_dv_var(_, m: Message): -@app.on_message(gen("getdv")) +@app.on_message(gen("getdv", allow_sudo=False)) async def get_dv_var(_, m: Message): if app.long(m) == 1: await app.send_edit(m, "Give me some key to get value that a var from database . . . ", mono=True, delme=2) @@ -86,7 +86,7 @@ async def get_dv_var(_, m: Message): -@app.on_message(gen("pm")) +@app.on_message(gen("pm", allow_sudo=False)) async def get_database_var(_, m: Message): arg = m.command if app.long(m) < 2: @@ -114,7 +114,7 @@ async def get_database_var(_, m: Message): -@app.on_message(gen("alldv")) +@app.on_message(gen("alldv", allow_sudo=False)) async def get_all_dv(_, m: Message): if bool(app.getalldv()) is True: await app.send_edit(m, "Getting all database vars . . .", mono=True)