From ae48394962e4f2fedb9e52bf0d84d65d7bdaa4b1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E0=BF=87=E2=80=A2=E1=BA=9E=E1=97=B4=E1=97=A9S=D4=B5?= =?UTF-8?q?=E2=80=A2=E0=BF=87?= <80647839+beastzx18@users.noreply.github.com> Date: Sun, 30 Jan 2022 11:00:05 +0530 Subject: [PATCH 01/10] Create index.md --- docs/index.md | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/docs/index.md b/docs/index.md index 4af8eeb4..086ebf09 100644 --- a/docs/index.md +++ b/docs/index.md @@ -1,25 +1,24 @@ ## Welcome to tron -Everything that you want to know about tron is here. +Everything that you want to know about tron is given here. ### Introduction -Currently there is only one person working on this project, ofc that's me ! I started this project in December 29, 2020. -Its a small project for educational purpose + timepass, it is based on python language with pyrogram library, i am just a beginner in this field so the updates of this userbot must be slow and small. +Currently there is only one person working on this project, ofc that's me ! I started this project in August 20, 2021. This date is when i changed my tron repo from private to public, i was working on this repo before this date, but we will take this as the creation date of tron userbot. +Its a small project for educational purpose & timepass, it is based on python language with pyrogram library, i am just a beginner in this field & i am trying my best to maintain this project. -### Features & bot information +### Features & ub information -So i am not dividing my updates in different versions of my Userbots, because its incomplete and there are so many changes i do in bots every day so giving updates information and and assigning versions to my Userbot is not good right now. -Tron is built with two clients, one is the main userbot and second one is the assistant, i have added some modules for tronuserbot and plugins for assistant. -I have provided a inline help menu to make it easy for the beginners to look for plugins and commands. +Tron is built with two pyrogram clients, one is the main userbot and second one is the assistant (bot), the main userbot have modules whereas the assistant have plugins. +I have provided a inline help menu to make it easy for the beginners to look for modules and commands. ### Deployment -Tue userbot can be deployed in railway or heroku, both deployments have little bugs right now, we'll solve those as soon as possible. +Tue userbot can be deployed in heroku, it is also deployable by localhost methods. ### Contact me -My telegram username: @beastzv +My telegram username: main: @Beastzx, Alt: @Beastzx18 From 58a2b97ff4021e484e49bb4797dd9637afdb1fb0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E0=BF=87=E2=80=A2=E1=BA=9E=E1=97=B4=E1=97=A9S=D4=B5?= =?UTF-8?q?=E2=80=A2=E0=BF=87?= <80647839+beastzx18@users.noreply.github.com> Date: Sun, 30 Jan 2022 11:32:13 +0530 Subject: [PATCH 02/10] Update config.py --- config.py | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/config.py b/config.py index 658c8779..4091fe2c 100644 --- a/config.py +++ b/config.py @@ -3,6 +3,20 @@ +#todo +if os.unname()[1] == "localhost": + response = os.system("pip3 install -r requirements.txt") + if response == 0: + print("Successfully Installed all requirements") + else: + print("Failed to install requirements") + + + + +# if you deploy this bot by localhost method, then replace all the necessary part of variables given below after '=' sign with your desired 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. #------------------------------------------------------------------------------------------------------------- class Config(object): # api id of your telegram account (required) @@ -65,19 +79,19 @@ class Config(object): BOT_NAME = os.getenv("BOT_NAME", "NORA") # your assistants alive pic (optional) BOT_PIC = os.getenv("BOT_PIC", "https://telegra.ph/file/4d93e5fa480b5e53d898f.jpg") - # provide this if bot fails to get username of bot + # provide this if bot fails to get username of bot (optional) BOT_USERNAME = os.getenv("BOT_USERNAME") - # telegram id of bot + # telegram id of bot if failed to get automatically (optional) BOT_ID = os.getenv("BOT_ID") # without this the bot will not work (required) TOKEN = os.getenv("TOKEN") # --------------------- - # thumbnail used while uploading plugin, etc. + # thumbnail used while uploading plugins, etc. (optional) THUMB_PIC = os.getenv("THUMB_PIC", "material/images/tron.png") # --------------------- # your telegraph account name (default: Tronuserbot) TL_NAME = os.getenv("TL_NAME") - # this will be shown before (as a prefix) the texts in the help dex + # this will be shown before (as a prefix) the texts in the help dex (default: None) HELP_EMOJI = os.getenv("HELP_EMOJI") From 929eb9b0f5a40f70ad9ba99f3c4d9faeb32081d2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E0=BF=87=E2=80=A2=E1=BA=9E=E1=97=B4=E1=97=A9S=D4=B5?= =?UTF-8?q?=E2=80=A2=E0=BF=87?= <80647839+beastzx18@users.noreply.github.com> Date: Sun, 30 Jan 2022 18:51:58 +0530 Subject: [PATCH 03/10] Update functions.py --- tronx/helpers/functions.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tronx/helpers/functions.py b/tronx/helpers/functions.py index 9ee1fc6d..1d3ed75b 100644 --- a/tronx/helpers/functions.py +++ b/tronx/helpers/functions.py @@ -170,7 +170,7 @@ async def send_edit( try: if delme > 0: - asyncio.create_task(self.sleep(m, sec=delme, del_msg=True)) + asyncio.create_task(self.sleep(m, sec=delme, delme=True)) except Exception as e: await self.error(m, e) From bc5f32254c038422073109ac36054cf3fda0e82c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E0=BF=87=E2=80=A2=E1=BA=9E=E1=97=B4=E1=97=A9S=D4=B5?= =?UTF-8?q?=E2=80=A2=E0=BF=87?= <80647839+beastzx18@users.noreply.github.com> Date: Sun, 30 Jan 2022 20:08:46 +0530 Subject: [PATCH 04/10] Update share.py --- tronx/modules/share.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tronx/modules/share.py b/tronx/modules/share.py index 8b99b25b..538482b1 100644 --- a/tronx/modules/share.py +++ b/tronx/modules/share.py @@ -93,7 +93,7 @@ async def install_module(_, m: Message): if download_loc: await app.send_edit(m, f"**Installed module:** `{doc_name}`", delme=5) data = open(download_loc, "r") - await app.aexec(data.read(), app, m) + await app.aexec(m, data.read()) else: await app.send_edit(m, f"Failed to install module {doc_name}", mono=True, delme=4) except Exception as e: From 1ae26a314329249da258049f89d634cfaaef4204 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E0=BF=87=E2=80=A2=E1=BA=9E=E1=97=B4=E1=97=A9S=D4=B5?= =?UTF-8?q?=E2=80=A2=E0=BF=87?= <80647839+beastzx18@users.noreply.github.com> Date: Sun, 30 Jan 2022 20:11:01 +0530 Subject: [PATCH 05/10] Update config.py --- config.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config.py b/config.py index 4091fe2c..401224da 100644 --- a/config.py +++ b/config.py @@ -4,7 +4,7 @@ #todo -if os.unname()[1] == "localhost": +if os.uname()[1] == "localhost": response = os.system("pip3 install -r requirements.txt") if response == 0: print("Successfully Installed all requirements") From a46002b2225432917c14d059b64491ba526a18c2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E0=BF=87=E2=80=A2=E1=BA=9E=E1=97=B4=E1=97=A9S=D4=B5?= =?UTF-8?q?=E2=80=A2=E0=BF=87?= <80647839+beastzx18@users.noreply.github.com> Date: Mon, 31 Jan 2022 09:57:00 +0530 Subject: [PATCH 06/10] Update update.py --- tronx/modules/update.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tronx/modules/update.py b/tronx/modules/update.py index e28845c8..d7bb2fc9 100644 --- a/tronx/modules/update.py +++ b/tronx/modules/update.py @@ -129,11 +129,11 @@ async def upstream(_, m): else: await app.send_edit( m, - f"\n[ STATUS ]: Your bot is upto date with **version:** `{app.userbot_version}` and **branch:** **[[{ac_br}]]({UPSTREAM_REPO_URL}/tree/{ac_br})**\n", + f"**[ STATUS ]:** Your bot is upto date !\n**[VERSION]:** `{app.userbot_version}`\n**[BRANCH]:** [{ac_br}]({UPSTREAM_REPO_URL}/tree/{ac_br})", disable_web_page_preview=True, ) - repo.__del__() - return + return repo.__del__() + if app.HEROKU_API_KEY is not None: import heroku3 From f9d6358f55f60a610830a09516bf376cddc09198 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E0=BF=87=E2=80=A2=E1=BA=9E=E1=97=B4=E1=97=A9S=D4=B5?= =?UTF-8?q?=E2=80=A2=E0=BF=87?= <80647839+beastzx18@users.noreply.github.com> Date: Mon, 31 Jan 2022 19:19:25 +0530 Subject: [PATCH 07/10] Update update.py --- tronx/modules/update.py | 112 ++++++++++++++++++---------------------- 1 file changed, 49 insertions(+), 63 deletions(-) diff --git a/tronx/modules/update.py b/tronx/modules/update.py index d7bb2fc9..7421df77 100644 --- a/tronx/modules/update.py +++ b/tronx/modules/update.py @@ -19,7 +19,7 @@ "update", { "update" : "To check if new update is available or not.", - "update now" : "To update userbot to latest version." + "update [ now ]" : "To update userbot to latest version." } ) } @@ -28,30 +28,23 @@ -UPSTREAM_REPO_URL = "https://github.com/beastzx18/tron" - -requirements_path = path.join( - path.dirname(path.dirname(path.dirname(__file__))), "requirements.txt" -) - - +TRON_REPO = app.UPSTREAM_REPO async def gen_chlog(repo, diff): ch_log = "" - d_form = "On %d/%m/%y at %H:%M:%S" - for c in repo.iter_commits(diff): - ch_log += f"**#{c.count()}** : {c.committed_datetime.strftime(d_form)} : [{c.summary}]({UPSTREAM_REPO_URL.rstrip('/')}/commit/{c}) by `{c.author}`\n" + dateform = "On %d/%m/%y at %H:%M:%S" + for data in repo.iter_commits(diff): + ch_log += f"**#{data.count()}** : {data.committed_datetime.strftime(dateform)} : [{data.summary}]({TRON_REPO.rstrip('/')}/commit/{c}) by `{data.author}`\n" return ch_log -async def updateme_requirements(): - reqs = str(requirements_path) +async def install_requirements(): try: process = await asyncio.create_subprocess_shell( - " ".join([sys.executable, "-m", "pip", "install", "-r", reqs]), + " ".join([sys.executable, "-m", "pip", "install", "-r", "requirements.txt"]), stdout=asyncio.subprocess.PIPE, stderr=asyncio.subprocess.PIPE, ) @@ -64,72 +57,68 @@ async def updateme_requirements(): @app.on_message(gen("update")) -async def upstream(_, m): +async def update_ub(_, m): + cmd = False + errtext = "Some problem occurred:\n\n" + await app.send_edit(m, "Checking for updates, please wait . . .", mono=True) + if app.long(m) > 1: cmd = m.command - else: - cmd = False - off_repo = UPSTREAM_REPO_URL + try: - txt = "`Oops . . . Updater cannot continue due to " - txt += "some problems occured`\n\n**LOGTRACE:**\n" repo = Repo() - except NoSuchPathError as error: - await app.send_edit(m, f"{txt}\n`directory {error} is not found`") - repo.__del__() - return - except GitCommandError as error: - await app.send_edit(m, f"{txt}\n`Early failure! {error}`") - repo.__del__() - return - except InvalidGitRepositoryError as error: + except NoSuchPathError as e: + await app.send_edit(m, f"{errtext}`{e}`") + return repo.__del__() + + except GitCommandError as e: + await app.send_edit(m, f"{errtext}`{e}`") + return repo.__del__() + + except InvalidGitRepositoryError as e: repo = Repo.init() - origin = repo.create_remote("upstream", off_repo) + origin = repo.create_remote("upstream", TRON_REPO) origin.fetch() repo.create_head("master", origin.refs.master) repo.heads.master.set_tracking_branch(origin.refs.master) repo.heads.master.checkout(True) - ac_br = repo.active_branch.name - if ac_br != "master": - await app.send_edit( - m, - f"**[UPDATER]:**` You are on ({ac_br})\n Please change to master branch.`" - ) - repo.__del__() - return + ACTIVE_BRANCH = repo.active_branch.name + if ACTIVE_BRANCH != "master": + await app.send_edit(m, f"**[ UPDATER ]:** You are on [ {ACTIVE_BRANCH} ]\n\nPlease change to `master` branch.`") + return repo.__del__() + try: - repo.create_remote("upstream", off_repo) + repo.create_remote("upstream", TRON_REPO) except BaseException: pass ups_rem = repo.remote("upstream") - ups_rem.fetch(ac_br) - changelog = await gen_chlog(repo, f"HEAD..upstream/{ac_br}") + ups_rem.fetch(ACTIVE_BRANCH) + changelog = await gen_chlog(repo, f"{ACTIVE_BRANCH}") if cmd is False: if changelog: - changelog_str = f"**New UPDATE available for [[{ac_br}]]({UPSTREAM_REPO_URL}/tree/{ac_br}):\n\nCHANGELOG**\n\n{changelog}" + changelog_str = f"**New update is available for [{ACTIVE_BRANCH}]({TRON_REPO}/tree/{ac_br}):\n\n[CHANGE LOG]:**\n\n{changelog}" if len(changelog_str) > 4096: - await app.send_edit(m, "Changelog is too big, view the file to see it.", monk=True, delme=6) + await app.send_edit(m, "Changelog is too big, view the file below to see it.", mono=True, delme=6) file = open("output.txt", "w+") file.write(changelog_str) file.close() await app.send_document( m.chat.id, - "output.txt", + "up_output.txt", caption="[ STATUS ]: Do `.update now` to update.", - reply_to_message_id=send_message_id, ) - remove("output.txt") + remove("up_output.txt") else: return await app.send_edit( m, - f"{changelog_str}\n\n[ STATUS ]: Do `.update now` to update.", + f"{changelog_str}\n\n[ UPDATE ]: Do `.update now` to update.", disable_web_page_preview=True, ) else: await app.send_edit( m, - f"**[ STATUS ]:** Your bot is upto date !\n**[VERSION]:** `{app.userbot_version}`\n**[BRANCH]:** [{ac_br}]({UPSTREAM_REPO_URL}/tree/{ac_br})", + f"**[ STATUS ]:** Your bot is upto date !\n**[ VERSION ]:** `{app.userbot_version}`\n**[ BRANCH ]:** [{ACTIVE_BRANCH}]({TRON_REPO}/tree/{ACTIVE_BRANCH})", disable_web_page_preview=True, ) return repo.__del__() @@ -143,10 +132,10 @@ async def upstream(_, m): if not app.HEROKU_APP_NAME: await app.send_edit( m, - "`Please set up the HEROKU_APP_NAME variable to be able to update userbot.`" + "`Please set up the [ HEROKU_APP_NAME ] variable to be able to update userbot.`" ) - repo.__del__() - return + return repo.__del__() + for bars in heroku_applications: if bars.name == app.HEROKU_APP_NAME: heroku_app = bars @@ -154,15 +143,15 @@ async def upstream(_, m): if heroku_app is None: await app.send_edit( m, - f"{txt}\n`Invalid Heroku credentials for updating userbot.`" + f"Invalid Heroku credentials for updating userbot." ) - repo.__del__() - return + return repo.__del__() + msg = await app.send_edit( m, "`Userbot update in progress, please wait for few minutes . . .`" ) - ups_rem.fetch(ac_br) + ups_rem.fetch(ACTIVE_BRANCH) repo.git.reset("--hard", "FETCH_HEAD") heroku_git_url = heroku_app.git_url.replace( "https://", "https://api:" + app.HEROKU_API_KEY + "@" @@ -173,26 +162,23 @@ async def upstream(_, m): else: remote = repo.create_remote("heroku", heroku_git_url) try: - remote.push(refspec=f"HEAD:refs/heads/{ac_br}", force=True) + remote.push(refspec=f"HEAD:refs/heads/{ACTIVE_BRANCH}", force=True) except GitCommandError as error: pass try: - await msg.edit("`Successfully Updated!\nRestarting, Please wait . . .`") + await msg.edit("Successfully Updated!\nRestarting, Please wait . . .", mono=True) except Exception: await app.send_edit(m, "Successfully Updated!\nRestarting, please wait . . .", mono=True, delme=5) else: try: - ups_rem.pull(ac_br) + ups_rem.pull(ACTIVE_BRANCH) except GitCommandError: repo.git.reset("--hard", "FETCH_HEAD") await updateme_requirements() await app.send_edit( m, - "Successfully Updated!\nBot is restarting . . . Wait for few seconds !", + "Successfully updated Userbot!\nBot is restarting . . .", mono=True, delme=8 ) - - args = [sys.executable, "./resources/startup/deploy.sh"] - execle(sys.executable, *args, environ) - return + await install_requirements() From 65854af37e3d330a135a54a894b1d042d9e1fd5e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E0=BF=87=E2=80=A2=E1=BA=9E=E1=97=B4=E1=97=A9S=D4=B5?= =?UTF-8?q?=E2=80=A2=E0=BF=87?= <80647839+beastzx18@users.noreply.github.com> Date: Mon, 31 Jan 2022 19:25:07 +0530 Subject: [PATCH 08/10] Update update.py --- tronx/modules/update.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tronx/modules/update.py b/tronx/modules/update.py index 7421df77..0d580ddb 100644 --- a/tronx/modules/update.py +++ b/tronx/modules/update.py @@ -35,7 +35,7 @@ async def gen_chlog(repo, diff): ch_log = "" dateform = "On %d/%m/%y at %H:%M:%S" for data in repo.iter_commits(diff): - ch_log += f"**#{data.count()}** : {data.committed_datetime.strftime(dateform)} : [{data.summary}]({TRON_REPO.rstrip('/')}/commit/{c}) by `{data.author}`\n" + ch_log += f"**#{data.count()}** : {data.committed_datetime.strftime(dateform)} : [{data.summary}]({TRON_REPO.rstrip('/')}/commit/{data}) by `{data.author}`\n" return ch_log From 90b149161812b0c298227ce021c560dbb42cbe05 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E0=BF=87=E2=80=A2=E1=BA=9E=E1=97=B4=E1=97=A9S=D4=B5?= =?UTF-8?q?=E2=80=A2=E0=BF=87?= <80647839+beastzx18@users.noreply.github.com> Date: Mon, 31 Jan 2022 19:34:02 +0530 Subject: [PATCH 09/10] Update update.py --- tronx/modules/update.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tronx/modules/update.py b/tronx/modules/update.py index 0d580ddb..64cd2d80 100644 --- a/tronx/modules/update.py +++ b/tronx/modules/update.py @@ -97,7 +97,7 @@ async def update_ub(_, m): changelog = await gen_chlog(repo, f"{ACTIVE_BRANCH}") if cmd is False: if changelog: - changelog_str = f"**New update is available for [{ACTIVE_BRANCH}]({TRON_REPO}/tree/{ac_br}):\n\n[CHANGE LOG]:**\n\n{changelog}" + changelog_str = f"**New update is available for [{ACTIVE_BRANCH}]({TRON_REPO}/tree/{ACTIVE_BRANCH}):\n\n[CHANGE LOG]:**\n\n{changelog}" if len(changelog_str) > 4096: await app.send_edit(m, "Changelog is too big, view the file below to see it.", mono=True, delme=6) file = open("output.txt", "w+") From 1d2b26f1f7d8d32fdc6bf3c248d5f6ba0d3106e6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E0=BF=87=E2=80=A2=E1=BA=9E=E1=97=B4=E1=97=A9S=D4=B5?= =?UTF-8?q?=E2=80=A2=E0=BF=87?= <80647839+beastzx18@users.noreply.github.com> Date: Mon, 31 Jan 2022 19:38:09 +0530 Subject: [PATCH 10/10] Update update.py --- tronx/modules/update.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tronx/modules/update.py b/tronx/modules/update.py index 64cd2d80..90f1152c 100644 --- a/tronx/modules/update.py +++ b/tronx/modules/update.py @@ -100,7 +100,7 @@ async def update_ub(_, m): changelog_str = f"**New update is available for [{ACTIVE_BRANCH}]({TRON_REPO}/tree/{ACTIVE_BRANCH}):\n\n[CHANGE LOG]:**\n\n{changelog}" if len(changelog_str) > 4096: await app.send_edit(m, "Changelog is too big, view the file below to see it.", mono=True, delme=6) - file = open("output.txt", "w+") + file = open("up_output.txt", "w+") file.write(changelog_str) file.close() await app.send_document(