Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 18 additions & 4 deletions config.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,20 @@



#todo
if os.uname()[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)
Expand Down Expand Up @@ -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")


17 changes: 8 additions & 9 deletions docs/index.md
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion tronx/helpers/functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion tronx/modules/share.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
118 changes: 52 additions & 66 deletions tronx/modules/update.py
Original file line number Diff line number Diff line change
Expand Up @@ -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."
}
)
}
Expand All @@ -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/{data}) 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,
)
Expand All @@ -64,76 +57,72 @@ 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/{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 to see it.", monk=True, delme=6)
file = open("output.txt", "w+")
await app.send_edit(m, "Changelog is too big, view the file below to see it.", mono=True, delme=6)
file = open("up_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"\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 ]:** [{ACTIVE_BRANCH}]({TRON_REPO}/tree/{ACTIVE_BRANCH})",
disable_web_page_preview=True,
)
repo.__del__()
return
return repo.__del__()

if app.HEROKU_API_KEY is not None:
import heroku3

Expand All @@ -143,26 +132,26 @@ 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
break
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 + "@"
Expand All @@ -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()