async def upstream(ups): check = ups.message.sender_id if int(check) != int(OWNER_ID): return lol = await ups.reply("`Checking for updates, please wait....`") conf = ups.pattern_match.group(1) off_repo = UPSTREAM_REPO_URL force_update = False try: txt = "`Oops.. Updater cannot continue " txt += "please add heroku apikey, name`\n\n**LOGTRACE:**\n" repo = Repo() except NoSuchPathError as error: await lol.edit(f"{txt}\n`directory {error} is not found`") repo.__del__() return except GitCommandError as error: await lol.edit(f"{txt}\n`Early failure! {error}`") repo.__del__() return except InvalidGitRepositoryError as error: if conf != "now": await lol.edit( f"**Unfortunately, the directory {error} does not seem to be a git repository.\ \nBut we can fix that by force updating the bot using** `/update now`" ) return repo = Repo.init() origin = repo.create_remote("upstream", off_repo) origin.fetch() force_update = True 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 lol.edit( f"**[UPDATER]:**` Looks like you are using your own custom branch ({ac_br}). " "in that case, Updater is unable to identify " "which branch is to be merged. " "please checkout to any official branch`") repo.__del__() return try: repo.create_remote("upstream", off_repo) except BaseException: pass ups_rem = repo.remote("upstream") ups_rem.fetch(ac_br) changelog = await gen_chlog(repo, f"HEAD..upstream/{ac_br}") if not changelog and not force_update: await lol.edit("\n`Your bot is` **up-to-date** \n") repo.__del__() return if conf != "now" and not force_update: changelog_str = ( f"**New UPDATE available for {ac_br}\n\nCHANGELOG:**\n`{changelog}`" ) if len(changelog_str) > 4096: await lol.edit("`Changelog is too big, view the file to see it.`") file = open("output.txt", "w+") file.write(changelog_str) file.close() await tbot.send_file( ups.chat_id, "output.txt", reply_to=ups.id, ) remove("output.txt") else: await lol.edit(changelog_str) await ups.respond("**do** `/update now` **to update**") return if force_update: await lol.edit( "`Force-Syncing to latest master bot code, please wait...`") else: await lol.edit("`Still Running ....`") if HEROKU_API_KEY is not None: heroku = heroku3.from_key(HEROKU_API_KEY) heroku_app = None heroku_applications = heroku.apps() if not HEROKU_APP_NAME: await lol.edit( "`Please set up the HEROKU_APP_NAME variable to be able to update your bot.`" ) repo.__del__() return for app in heroku_applications: if app.name == HEROKU_APP_NAME: heroku_app = app break if heroku_app is None: await lol.edit( f"{txt}\n`Invalid Heroku credentials for updating userbot dyno.`" ) repo.__del__() return await lol.edit("`[Updater]\ Your bot is being deployed, please wait for it to complete.\nIt may take upto 5 minutes `" ) ups_rem.fetch(ac_br) repo.git.reset("--hard", "FETCH_HEAD") heroku_git_url = heroku_app.git_url.replace( "https://", "https://*****:*****@") if "heroku" in repo.remotes: remote = repo.remote("heroku") remote.set_url(heroku_git_url) else: remote = repo.create_remote("heroku", heroku_git_url) try: remote.push(refspec="HEAD:refs/heads/master", force=True) except GitCommandError as error: await lol.edit(f"{txt}\n`Here is the error log:\n{error}`") repo.__del__() return await lol.edit("Successfully Updated!\n" "Restarting.......") else: try: ups_rem.pull(ac_br) except GitCommandError: repo.git.reset("--hard", "FETCH_HEAD") reqs_upgrade = await updateme_requirements() await lol.edit("`Successfully Updated!\n" "restarting......`") args = [sys.executable, "-m", "julia"] execle(sys.executable, *args, environ) return
async def upstream(event): "For .update command, check if the bot is up to date, update if specified" await event.edit("**Checking for updates, please wait...**") conf = event.pattern_match.group(1).strip() off_repo = UPSTREAM_REPO_URL force_update = False try: txt = "**Oops.. Updater cannot continue due to " txt += "some problems**\n`LOGTRACE:`\n" repo = Repo() except NoSuchPathError as error: await event.edit(f"{txt}\n**Directory** `{error}` **was not found.**") return repo.__del__() except GitCommandError as error: await event.edit(f"{txt}\n**Early failure!** `{error}`") return repo.__del__() except InvalidGitRepositoryError as error: if conf is None: return await event.edit( f"**Unfortunately, the directory {error} " "does not seem to be a git repository.\n" "But we can fix that by force updating the userbot using **" "`.update now.`") repo = Repo.init() origin = repo.create_remote("upstream", off_repo) origin.fetch() force_update = True 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 != UPSTREAM_REPO_BRANCH: await event.edit( f"**Looks like you are using your own custom branch: ({ac_br}). \n" "Please switch to** `master` **branch.**") return repo.__del__() try: repo.create_remote("upstream", off_repo) except BaseException: pass ups_rem = repo.remote("upstream") ups_rem.fetch(ac_br) changelog = await gen_chlog(repo, f"HEAD..upstream/{ac_br}") """ - Special case for deploy - """ if conf == "deploy": await event.edit( "**Perfoming a Power Update, Please Wait. It Usually Takes 5 min.**" ) await deploy(event, repo, ups_rem, ac_br, txt) return if changelog == "" and not force_update: await event.edit( f"**Your userbot is up-to-date with `{UPSTREAM_REPO_BRANCH}`!**") return repo.__del__() if conf == "" and force_update is False: await print_changelogs(event, ac_br, changelog) await event.delete() return await event.respond( "**Do** `.update now` **or** `.update deploy` **to update.**") if force_update: await event.edit( "**Force-syncing to latest stable userbot code, please wait...**") if conf == "now": await event.edit("**Perfoming a quick update, please wait...**") await update(event, repo, ups_rem, ac_br) return
async def upstream(event): "For .update command, check if the bot is up to date, update if specified" await event.edit("**Verificando atualizações, por favor aguarde...**") conf = event.pattern_match.group(1).strip() off_repo = UPSTREAM_REPO_URL force_update = False try: txt = "**Ops .. O atualizador não pode continuar devido a " txt += "alguns problemas**\n`LOGTRACE:`\n" repo = Repo() except NoSuchPathError as error: await event.edit( f"{txt}\n**Diretório** `{error}` **não foi encontrado.**") return repo.__del__() except GitCommandError as error: await event.edit(f"{txt}\n**Falha no início!** `{error}`") return repo.__del__() except InvalidGitRepositoryError as error: if conf is None: return await event.edit( f"**Infelizmente, o diretório {error} " "não parece ser um repositório git.\n" "Mas podemos consertar isso forçando a atualização do userbot usando **" "`.update now.`") repo = Repo.init() origin = repo.create_remote("upstream", off_repo) origin.fetch() force_update = True 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 != UPSTREAM_REPO_BRANCH: await event.edit( f"**Parece que você está usando seu próprio branch personalizado: ({ac_br}). \n" "Por favor mude para** `master` ") return repo.__del__() try: repo.create_remote("upstream", off_repo) except BaseException: pass ups_rem = repo.remote("upstream") ups_rem.fetch(ac_br) changelog = await gen_chlog(repo, f"HEAD..upstream/{ac_br}") """ - Special case for deploy - """ if conf == "deploy": await event.edit( "**Fazendo uma atualização completa...**\n__Isso geralmente leva menos de 5 minutos, aguarde.__" ) await deploy(event, repo, ups_rem, ac_br, txt) return if changelog == "" and not force_update: await event.edit(f"Seu userbot está **atualizado** !") return repo.__del__() if conf == "" and not force_update: await print_changelogs(event, ac_br, changelog) await event.delete() return await event.respond( "**Use** `.update deploy` **para atualizar.**") if force_update: await event.edit( "**Forçando a sincronização com o código do userbot estável mais recente, aguarde...**" ) if conf == "now": await event.edit( "**Fazendo uma atualização rápida, por favor aguarde...**") await update(event, repo, ups_rem, ac_br) return
async def upstream(event): "For .update command, check if the bot is up to date, update if specified" await event.edit("`Mengecek Pembaruan, Silakan Menunggu....`") conf = event.pattern_match.group(1) off_repo = UPSTREAM_REPO_URL force_update = False try: txt = "`Pembaruan Tidak Dapat Di Lanjutkan Karna " txt += "Beberapa Masalah Terjadi`\n\n**LOGTRACE:**\n" repo = Repo() except NoSuchPathError as error: await event.edit(f"{txt}\n`Directory {error} Tidak Dapat Di Temukan`") return repo.__del__() except GitCommandError as error: await event.edit(f"{txt}\n`Gagal Awal! {error}`") return repo.__del__() except InvalidGitRepositoryError as error: if conf is None: return await event.edit( f"`Sayangnya, Directory {error} Tampaknya Bukan Dari Repo." "\nTapi Kita Bisa Memperbarui Paksa Userbot Menggunakan .update now.`" ) repo = Repo.init() origin = repo.create_remote("upstream", off_repo) origin.fetch() force_update = True 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 != UPSTREAM_REPO_BRANCH: await event.edit( "**[UPDATER]:**\n" f"`Looks like you are using your own custom branch ({ac_br}). " "in that case, Updater is unable to identify " "which branch is to be merged. " "please checkout to any official branch`" ) return repo.__del__() try: repo.create_remote("upstream", off_repo) except BaseException: pass ups_rem = repo.remote("upstream") ups_rem.fetch(ac_br) changelog = await gen_chlog(repo, f"HEAD..upstream/{ac_br}") if changelog == "" and force_update is False: await event.edit(f"\n**✥ Man-Userbot Sudah Versi Terbaru**\n") await asyncio.sleep(15) await event.delete() return repo.__del__() if conf is None and force_update is False: changelog_str = f"**✥ Pembaruan Untuk Man-Userbot [{ac_br}] :\n\n✥ Pembaruan:**\n`{changelog}`" if len(changelog_str) > 4096: await event.edit("`Changelog Terlalu Besar, Lihat File Untuk Melihatnya.`") file = open("output.txt", "w+") file.write(changelog_str) file.close() await event.client.send_file( event.chat_id, "output.txt", reply_to=event.id, ) remove("output.txt") else: await event.edit(changelog_str) return await event.respond( "✥ **Perintah Untuk Update Man-Userbot**\n >`.update now`\n >`.update deploy`\n\n__Untuk Meng Update Fitur Terbaru Dari Man-Userbot.__" ) if force_update: await event.edit( "`Sinkronisasi Paksa Ke Kode Userbot Stabil Terbaru, Harap Tunggu .....`" ) else: await event.edit("`✣ Proses Update Man-Userbot, Loading....1%`") await event.edit("`✣ Proses Update Man-Userbot, Loading....12%`") await event.edit("`✣ Proses Update Man-Userbot, Loading....25%`") await event.edit("`✣ Proses Update Man-Userbot, Loading....46%`") await event.edit("`✣ Proses Update Man-Userbot, Loading....76%`") await event.edit("`✣ Proses Update Man-Userbot, Updating...92%`") await event.edit("`✣ Proses Update Man-Userbot, Tunggu Sebentar....100%`") if conf == "now": await update(event, repo, ups_rem, ac_br) await asyncio.sleep(10) await event.delete() elif conf == "deploy": await deploy(event, repo, ups_rem, ac_br, txt) await asyncio.sleep(10) await event.delete() return
async def upstream(ups): ".update əmri ilə botunun yeni versiyada olub olmadığını yoxlaya bilərsiz." await ups.edit(LANG['DETECTING']) conf = ups.pattern_match.group(1) off_repo = UPSTREAM_REPO_URL force_update = False try: txt = "`Yenilənmə uğursuz oldu! Bəzi problemlərlə qarşılaşdım.`\n\n**LOG:**\n" repo = Repo() except NoSuchPathError as error: await ups.edit(f'{txt}\n`{error} {LANG["NOT_FOUND"]}.`') repo.__del__() return except GitCommandError as error: await ups.edit(f'{txt}\n`{LANG["GIT_ERROR"]} {error}`') repo.__del__() return except InvalidGitRepositoryError as error: if conf != "now": await ups.edit(f"`{error} {LANG['NOT_GIT']}`") return repo = Repo.init() origin = repo.create_remote('upstream', off_repo) origin.fetch() force_update = True repo.create_head('master', origin.refs.seden) repo.heads.seden.set_tracking_branch(origin.refs.sql) repo.heads.seden.checkout(True) ac_br = repo.active_branch.name if ac_br != 'master': await ups.edit(LANG['INVALID_BRANCH']) repo.__del__() return try: repo.create_remote('upstream', off_repo) except BaseException: pass ups_rem = repo.remote('upstream') ups_rem.fetch(ac_br) changelog = await gen_chlog(repo, f'HEAD..upstream/{ac_br}') if not changelog and not force_update: await ups.edit(LANG['UPDATE'].format(ac_br)) repo.__del__() return if conf != "now" and not force_update: changelog_str = LANG['WAS_UPDATE'].format(ac_br, changelog) if len(changelog_str) > 4096: await ups.edit(LANG['BIG']) file = open("cyber.txt", "w+") file.write(changelog_str) file.close() await ups.client.send_file( ups.chat_id, "cyber.txt", reply_to=ups.id, ) remove("cyber.txt") else: await ups.edit(changelog_str) await ups.respond(LANG['DO_UPDATE']) return if force_update: await ups.edit(LANG['FORCE_UPDATE']) else: await ups.edit(LANG['UPDATING']) # Bot Heroku. if HEROKU_APIKEY is not None: import heroku3 heroku = heroku3.from_key(HEROKU_APIKEY) heroku_app = None heroku_applications = heroku.apps() if not HEROKU_APPNAME: await ups.edit(LANG['INVALID_APPNAME']) repo.__del__() return for app in heroku_applications: if app.name == HEROKU_APPNAME: heroku_app = app break if heroku_app is None: await ups.edit(LANG['INVALID_HEROKU'].format(txt)) repo.__del__() return await ups.edit(LANG['HEROKU_UPDATING']) ups_rem.fetch(ac_br) repo.git.reset("--hard", "FETCH_HEAD") heroku_git_url = heroku_app.git_url.replace( "https://", "https://*****:*****@") if "heroku" in repo.remotes: remote = repo.remote("heroku") remote.set_url(heroku_git_url) else: remote = repo.create_remote("heroku", heroku_git_url) try: remote.push(refspec="HEAD:refs/heads/master", force=True) except GitCommandError as error: await ups.edit(f'{txt}\n`{LANG["ERRORS"]}:\n{error}`') repo.__del__() return await ups.edit(LANG['SUCCESSFULLY']) else: # Klasik yenilənmə try: ups_rem.pull(ac_br) except GitCommandError: repo.git.reset("--hard", "FETCH_HEAD") await update_requirements() await ups.edit(LANG['SUCCESSFULLY']) # Bot Heroku args = [sys.executable, "main.py"] execle(sys.executable, *args, environ) return
async def upstream(ups): "For .update command, check if the bot is up to date, update if specified" await ups.edit("`Checking for updates, please wait....`") conf = ups.pattern_match.group(1) off_repo = UPSTREAM_REPO_URL force_update = False try: txt = "`Oops.. Updater cannot continue " txt += "please add heroku apikey, name`\n\n**LOGTRACE:**\n" repo = Repo() except NoSuchPathError as error: await ups.edit(f'{txt}\n`directory {error} is not found`') repo.__del__() return except GitCommandError as error: await ups.edit(f'{txt}\n`Early failure! {error}`') repo.__del__() return except InvalidGitRepositoryError as error: if conf != "now": await ups.edit( f"`Unfortunately, the directory {error} does not seem to be a git repository.\ \nBut we can fix that by force updating the userbot using .update now.`" ) return repo = Repo.init() origin = repo.create_remote('upstream', off_repo) origin.fetch() force_update = True 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 ups.edit( f'**[UPDATER]:**` Looks like you are using your own custom branch ({ac_br}). ' 'in that case, Updater is unable to identify ' 'which branch is to be merged. ' 'please checkout to any official branch`') repo.__del__() return try: repo.create_remote('upstream', off_repo) except BaseException: pass ups_rem = repo.remote('upstream') ups_rem.fetch(ac_br) changelog = await gen_chlog(repo, f'HEAD..upstream/{ac_br}') if not changelog and not force_update: await ups.edit(f'\n`{JAVES_NNAME} is` **up-to-date** \n') repo.__del__() return if conf != "now" and not force_update: changelog_str = f'**New UPDATE available for {JAVES_NNAME}\n\nCHANGELOG:**\n`{changelog}`' if len(changelog_str) > 4096: await ups.edit("`Changelog is too big, view the file to see it.`") file = open("output.txt", "w+") file.write(changelog_str) file.close() await ups.client.send_file( ups.chat_id, "output.txt", edit_to=ups.id, ) remove("output.txt") else: await ups.edit(changelog_str) await ups.respond('do \"`.update now`\" to update') return if force_update: await ups.edit( '`Force-Syncing to latest stable userbot code, please wait...`') else: await ups.edit('`Finiding your heroku app.....`') # We're in a Heroku Dyno, handle it's memez. if HEROKU_APIKEY is not None: import heroku3 heroku = heroku3.from_key(HEROKU_APIKEY) heroku_app = None heroku_applications = heroku.apps() if not HEROKU_APPNAME: await ups.edit( '`Please set up the HEROKU_APPNAME variable to be able to update userbot.`' ) repo.__del__() return for app in heroku_applications: if app.name == HEROKU_APPNAME: heroku_app = app break if heroku_app is None: await ups.edit( f'{txt}\n`Invalid Heroku credentials for updating userbot dyno.`' ) repo.__del__() return await ups.edit(f'`[Updater]\ {JAVES_NNAME} dyno build in progress, please wait for it to complete.\nIt may take 7 minutes `' ) ups_rem.fetch(ac_br) repo.git.reset("--hard", "FETCH_HEAD") heroku_git_url = heroku_app.git_url.replace( "https://", "https://*****:*****@") if "heroku" in repo.remotes: remote = repo.remote("heroku") remote.set_url(heroku_git_url) else: remote = repo.create_remote("heroku", heroku_git_url) try: remote.push(refspec="HEAD:refs/heads/master", force=True) except GitCommandError as error: await ups.edit(f'{txt}\n`Here is the error log:\n{error}`') repo.__del__() return await ups.edit('Successfully Updated!\n' 'Restarting.......') else: # Classic Updater, pretty straightforward. try: ups_rem.pull(ac_br) except GitCommandError: repo.git.reset("--hard", "FETCH_HEAD") reqs_upgrade = await update_requirements() await ups.edit('`Successfully Updated!\n' 'restarting......`') # Spin a new instance of bot args = [sys.executable, "-m", "userbot"] execle(sys.executable, *args, environ) return
async def upstream(ups): pagal = await eor(ups, "`Checking for updates, please wait....`") conf = ups.pattern_match.group(1) 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 eod(pagal, f"{txt}\n`directory {error} is not found`", time=10) repo.__del__() return except GitCommandError as error: await eod(pagal, f"{txt}\n`Early failure! {error}`", time=10) repo.__del__() return except InvalidGitRepositoryError as error: if conf != "now": await eod( pagal, f"**Unfortunately, the directory {error} does not seem to be a git repository.Or Maybe it just needs a sync verification with {GIT_REPO_NAME} But we can fix that by force updating the userbot using** `.update now.`", time=30, ) return repo = Repo.init() origin = repo.create_remote("upstream", off_repo) origin.fetch() repo.create_head("main", origin.refs.main) repo.heads.main.set_tracking_branch(origin.refs.main) repo.heads.main.checkout(True) ac_br = repo.active_branch.name if ac_br != "main": await eod( pagal, f"**[UPDATER]:**` You are on ({ac_br})\n Please change to main branch.`", ) repo.__del__() return try: repo.create_remote("upstream", off_repo) except BaseException: pass ups_rem = repo.remote("upstream") ups_rem.fetch(ac_br) changelog = await gen_chlog(repo, f"HEAD..upstream/{ac_br}") if "now" not in conf: if changelog: changelog_str = f"**New UPDATE available for [[{ac_br}]]({UPSTREAM_REPO_URL}/tree/{ac_br}):\n\nCHANGELOG**\n\n{changelog}" if len(changelog_str) > 4096: await eor(pagal, "`Changelog is too big, view the file to see it.`") file = open("output.txt", "w+") file.write(changelog_str) file.close() await ups.client.send_file( ups.chat_id, "output.txt", caption=f"Do `{hndlr}update now` to update.", reply_to=ups.id, ) remove("output.txt") else: return await eod( pagal, f"{changelog_str}\n\nDo `{hndlr}update now` to update.") else: await eod( pagal, f"\n`Your BOT is` **up-to-date** `with` **[[{ac_br}]]({UPSTREAM_REPO_URL}/tree/{ac_br})**\n", time=10, ) repo.__del__() return if Var.HEROKU_API is not None: import heroku3 heroku = heroku3.from_key(Var.HEROKU_API) heroku_app = None heroku_applications = heroku.apps() if not Var.HEROKU_APP_NAME: await eod( pagal, "`Please set up the HEROKU_APP_NAME variable to be able to update userbot.`", time=10, ) repo.__del__() return for app in heroku_applications: if app.name == Var.HEROKU_APP_NAME: heroku_app = app break if heroku_app is None: await eod( pagal, f"{txt}\n`Invalid Heroku credentials for updating userbot dyno.`", time=10, ) repo.__del__() return await eor( pagal, "`Userbot dyno build in progress, please wait for it to complete.`" ) ups_rem.fetch(ac_br) repo.git.reset("--hard", "FETCH_HEAD") heroku_git_url = heroku_app.git_url.replace( "https://", "https://*****:*****@") if "heroku" in repo.remotes: remote = repo.remote("heroku") remote.set_url(heroku_git_url) else: remote = repo.create_remote("heroku", heroku_git_url) try: remote.push(refspec=f"HEAD:refs/heads/{ac_br}", force=True) except GitCommandError as error: await eod(pagal, f"{txt}\n`Here is the error log:\n{error}`", time=10) repo.__del__() return await eod(pagal, "`Successfully Updated!\nRestarting, please wait...`", time=60) else: # Classic Updater, pretty straightforward. try: ups_rem.pull(ac_br) except GitCommandError: repo.git.reset("--hard", "FETCH_HEAD") await updateme_requirements() await eod( pagal, "`Successfully Updated!\nBot is restarting... Wait for a second!`", ) # Spin a new instance of bot args = [sys.executable, "./resources/startup/deploy.sh"] execle(sys.executable, *args, environ) return
async def upstream(event): event = await event.edit("`Pulling the Marcususerbot repo wait a sec ....`" ) off_repo = "https://github.com/hackelite01/Marcus-userbot" cmd = f"rm -rf .git" try: await runcmd(cmd) except BaseException: pass try: txt = "`Oops.. Updater cannot continue due to " txt += "some problems occured`\n\n**LOGTRACE:**\n" repo = Repo() except NoSuchPathError as error: await event.edit(f"{txt}\n`directory {error} is not found`") return repo.__del__() except GitCommandError as error: await event.edit(f"{txt}\n`Early failure! {error}`") return repo.__del__() except InvalidGitRepositoryError: repo = Repo.init() origin = repo.create_remote("upstream", off_repo) origin.fetch() repo.create_head("master", origin.refs.master) repo.heads.master.set_tracking_branch(origin.refs.master) repo.heads.master.checkout(True) try: repo.create_remote("upstream", off_repo) except BaseException: pass ac_br = repo.active_branch.name ups_rem = repo.remote("upstream") ups_rem.fetch(ac_br) await event.edit("`Deploying userbot, please wait....`") await deploy(event, repo, ups_rem, ac_br, txt)
async def upstream(ups): "For .update command, check if the bot is up to date, update if specified" await ups.edit('**Ricerca update in corso....**') conf = ups.pattern_match.group(1) off_repo = UPSTREAM_REPO_URL force_update = False try: txt = "`Oops.. Updater cannot continue due to " txt += "some problems occured`\n\n**LOGTRACE:**\n" repo = Repo() except NoSuchPathError as error: await ups.edit(f'{txt}\n`directory {error} is not found`') repo.__del__() return except GitCommandError as error: await ups.edit(f'{txt}\n`Early failure! {error}`') repo.__del__() return except InvalidGitRepositoryError as error: if conf != "now": await ups.edit( f"Unfortunately, the directory {error} does not seem to be a git repository.\ \nBut we can fix that by force updating the userbot using `.update now.`" ) return repo = Repo.init() origin = repo.create_remote('upstream', off_repo) origin.fetch() force_update = True 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 ups.edit( f'**[UPDATER]: Sembra che stai utilizzando un ramo custom** ({ac_br}). ' '**in tal caso, Updater è in grado di identificare**' '**quale ramo deve essere unito.**' '**Per favore aggiorna a qualsiasi branch ufficiale**') repo.__del__() return try: repo.create_remote('upstream', off_repo) except BaseException: pass ups_rem = repo.remote('upstream') ups_rem.fetch(ac_br) changelog = await gen_chlog(repo, f'HEAD..upstream/{ac_br}') if not changelog and not force_update: await ups.edit(f'\n`Il tuo UbOT è` **up-to-date** **{ac_br}**\n') repo.__del__() return if conf != "now" and not force_update: changelog_str = f'**New UPDATE avviabile per [{ac_br}]:\n\nCHANGELOG:**\n`{changelog}`' if len(changelog_str) > 4096: await ups.edit( '**Il changelog delle modifiche è troppo grande,leggi il file.**' ) file = open("output.txt", "w+") file.write(changelog_str) file.close() await ups.client.send_file( ups.chat_id, "output.txt", reply_to=ups.id, ) remove("output.txt") else: await ups.edit(changelog_str) await ups.respond('Premi \"`.update now`\" per aggiornare') return if force_update: await ups.edit( '**Forza aggiornamento ubot code stabile, attendere...**') else: await ups.edit('**Ubot in aggiornamento attendere....**') # We're in a Heroku Dyno, handle it's memez. if HEROKU_API_KEY is not None: import heroku3 heroku = heroku3.from_key(HEROKU_API_KEY) heroku_app = None heroku_applications = heroku.apps() if not HEROKU_APP_NAME: await ups.edit( '**Invalid APP Name. Inserisci il nome del bot nella Var `HEROKU_APP_NAME.**' ) repo.__del__() return for app in heroku_applications: if app.name == HEROKU_APP_NAME: heroku_app = app break if heroku_app is None: await ups.edit( f'{txt}\n**Credenziali heroku invalide per aggiornare Ubot.**') repo.__del__() return await ups.edit( '**Ubot dyno in progressione, attendi 5 mins il completamento**') ups_rem.fetch(ac_br) repo.git.reset("--hard", "FETCH_HEAD") heroku_git_url = heroku_app.git_url.replace( "https://", "https://*****:*****@") if "heroku" in repo.remotes: remote = repo.remote("heroku") remote.set_url(heroku_git_url) else: remote = repo.create_remote("heroku", heroku_git_url) try: remote.push(refspec="HEAD:refs/heads/master", force=True) except GitCommandError as error: await ups.edit(f'{txt}\n`Here is the error log:\n{error}`') repo.__del__() return await ups.edit('**Update in corso...**\n' '**Riavvio, attendi 5 minuti e premi `.alive`**') else: # Classic Updater, pretty straightforward. try: ups_rem.pull(ac_br) except GitCommandError: repo.git.reset("--hard", "FETCH_HEAD") reqs_upgrade = await update_requirements() await ups.edit('**Update in corso...**\n' '**Attendi 5 minuti e premi `.alive`**') # Spin a new instance of bot args = [sys.executable, "-m", "userbot"] execle(sys.executable, *args, environ) return
async def upstream(event): "For .update command, check if the bot is up to date, update if specified" xx = await edit_or_reply(event, "`Mengecek Pembaruan, Tunggu Sebentar...`") conf = event.pattern_match.group(1).strip() off_repo = b64decode( "aHR0cHM6Ly9naXRodWIuY29tL21yaXNtYW5heml6L01hbi1Vc2VyYm90").decode( "utf-8") force_update = False try: txt = ("**Pembaruan Tidak Dapat Di Lanjutkan Karna " + "Terjadi Beberapa ERROR**\n\n**LOGTRACE:**\n") repo = Repo() except NoSuchPathError as error: await xx.edit( f"{txt}\n**Directory** `{error}` **Tidak Dapat Di Temukan.**") return repo.__del__() except GitCommandError as error: await xx.edit(f"{txt}\n**Kegagalan awal!** `{error}`") return repo.__del__() except InvalidGitRepositoryError as error: if conf is None: return await xx.edit( f"**Sayangnya, Directory {error} Tampaknya Bukan Dari Repo. Tapi Kita Bisa Memperbarui Paksa Userbot Menggunakan** `{cmd}update deploy`" ) repo = Repo.init() origin = repo.create_remote("upstream", off_repo) origin.fetch() force_update = True 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 try: repo.create_remote("upstream", off_repo) except BaseException: pass ups_rem = repo.remote("upstream") ups_rem.fetch(ac_br) changelog = await gen_chlog(repo, f"HEAD..upstream/{ac_br}") if conf == "deploy": await xx.edit( "`[HEROKU]: Update Deploy Man-Userbot Sedang Dalam Proses...`") await deploy(xx, repo, ups_rem, ac_br, txt) return if changelog == "" and not force_update: await edit_delete(xx, "**✥ Man-Userbot Sudah Versi Terbaru**") return repo.__del__() if conf == "" and not force_update: await print_changelogs(xx, ac_br, changelog) await xx.delete() return await event.respond( f"**Ketik** `{cmd}update deploy` **untuk Mengupdate Userbot.**") if force_update: await xx.edit( "**Sinkronisasi Paksa Ke Kode Userbot Terbaru, Harap Tunggu...**") if conf == "now": for commit in changelog.splitlines(): if (commit.startswith("- [NQ]") and HEROKU_APP_NAME is not None and HEROKU_API_KEY is not None): return await xx.edit( f"**Quick update telah dinonaktifkan untuk pembaruan ini Gunakan** `{cmd}update deploy` **sebagai gantinya.**" ) await xx.edit("**Perfoming a quick update, please wait...**") await update(xx, repo, ups_rem, ac_br) return
async def upstream(ups): "For .update command, check if the bot is up to date, update if specified" await ups.edit("Sedang Memeriksa Pembaruan, Silahkan Tunggu") conf = ups.pattern_match.group(1) off_repo = UPSTREAM_REPO_URL force_update = False try: txt = "`Oops.. Updater cannot continue due to " txt += "some problems occured`\n\n**LOGTRACE:**\n" repo = Repo() except NoSuchPathError as error: await ups.edit(f'{txt}\n`directory {error} is not found`') repo.__del__() return except GitCommandError as error: await ups.edit(f'{txt}\n`Early failure! {error}`') repo.__del__() return except InvalidGitRepositoryError as error: if conf != "now": await ups.edit( f"`Unfortunately, the directory {error} does not seem to be a git repository.\ \nBut we can fix that by force updating the userbot using .update now.`" ) return repo = Repo.init() origin = repo.create_remote('upstream', off_repo) origin.fetch() force_update = True repo.create_head('sql-extended', origin.refs.sql - extended) repo.heads.sql - extended.set_tracking_branch(origin.refs.sql - extended) repo.heads.sql - extended.checkout(True) ac_br = repo.active_branch.name if ac_br != 'sql-extended': await ups.edit( f'**[UPDATER]:**` Looks like you are using your own custom branch ({ac_br}). ' 'in that case, Updater is unable to identify ' 'which branch is to be merged. ' 'please checkout to any official branch`') repo.__del__() return try: repo.create_remote('upstream', off_repo) except BaseException: pass ups_rem = repo.remote('upstream') ups_rem.fetch(ac_br) changelog = await gen_chlog(repo, f'HEAD..upstream/{ac_br}') if not changelog and not force_update: await ups.edit( f'\nBOT Kamu Telah **Terupdate** Dengan **{ac_br}**\n****Creator:** [NFS乛Rizky戈手](https://t.me/AkameNFS)**' ) repo.__del__() return if conf != "now" and not force_update: changelog_str = f'**New UPDATE available for [{ac_br}]:\n\nCHANGELOG:**\n`{changelog}`' if len(changelog_str) > 4096: await ups.edit("`Changelog is too big, view the file to see it.`") file = open("output.txt", "w+") file.write(changelog_str) file.close() await ups.client.send_file( ups.chat_id, "output.txt", reply_to=ups.id, ) remove("output.txt") else: await ups.edit(changelog_str) await ups.respond('Ketik \".update now\" Untuk Memperbarui') return if force_update: await ups.edit('Silahkan Tunggu....') else: await ups.edit('Bot Updated by **NFS乛Rizky戈手**') # We're in a Heroku Dyno, handle it's memez. if HEROKU_APIKEY is not None: import heroku3 heroku = heroku3.from_key(HEROKU_APIKEY) heroku_app = None heroku_applications = heroku.apps() if not HEROKU_APPNAME: await ups.edit( '`[HEROKU MEMEZ] Please set up the HEROKU_APPNAME variable to be able to update userbot.`' ) repo.__del__() return for app in heroku_applications: if app.name == HEROKU_APPNAME: heroku_app = app break if heroku_app is None: await ups.edit( f'{txt}\n`Invalid Heroku credentials for updating userbot dyno.`' ) repo.__del__() return await ups.edit('`[HEROKU MEMEZ]\ \nUserbot dyno build in progress, please wait for it to complete.`' ) ups_rem.fetch(ac_br) repo.git.reset("--hard", "FETCH_HEAD") heroku_git_url = heroku_app.git_url.replace( "https://", "https://*****:*****@") if "heroku" in repo.remotes: remote = repo.remote("heroku") remote.set_url(heroku_git_url) else: remote = repo.create_remote("heroku", heroku_git_url) try: remote.push(refspec="HEAD:refs/heads/sql-extended", force=True) except GitCommandError as error: await ups.edit(f'{txt}\n`Here is the error log:\n{error}`') repo.__del__() return await ups.edit('`Berhasil Diperbarui!\n' 'Restarting, please wait...`') else: # Classic Updater, pretty straightforward. try: ups_rem.pull(ac_br) except GitCommandError: repo.git.reset("--hard", "FETCH_HEAD") reqs_upgrade = await update_requirements() await ups.edit( 'Berhasil Diperbarui!\n' 'Bot Sedang Direstart... Tunggu Beberapa Detik\n**Creator:** **[NFS乛Rizky戈手](https://t.me/AkameNFS)**' ) # Spin a new instance of bot args = [sys.executable, "-m", "userbot"] execle(sys.executable, *args, environ) return
async def upstream(event): "Para o comando .update, checa se o bot está atualizado, atualiza se especificado" await event.edit("`Checando por atualizações, aguarde....`") conf = event.pattern_match.group(1) off_repo = UPSTREAM_REPO_URL force_update = False try: txt = "`Oops.. Atualizador não obteve êxito devido a " txt += "um problema ocorreu`\n\n**LOGTRACE:**\n" repo = Repo() except NoSuchPathError as error: await event.edit(f"{txt}\n`diretório {error} não encontrado`") return repo.__del__() except GitCommandError as error: await event.edit(f"{txt}\n`Falha ao inicializar! {error}`") return repo.__del__() except InvalidGitRepositoryError as error: if conf is None: return await event.edit( f"`Infelizmente, o diretório {error} não parece ser um repositório GitHub." "\nMas podemos consertar isso forçando a atualização do userbot usando .update now.`" ) repo = Repo.init() origin = repo.create_remote("upstream", off_repo) origin.fetch() force_update = True 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 != UPSTREAM_REPO_BRANCH: await event.edit( "**[UPDATER]:**\n" f"`Parece que você está tentando usar uma branch personalizada ({ac_br}). " "nesse caso, o atualizador não pode verificar " "qual branch deve ser atualizada. " "por favor, verifique a branch principal`") return repo.__del__() try: repo.create_remote("upstream", off_repo) except BaseException: pass ups_rem = repo.remote("upstream") ups_rem.fetch(ac_br) changelog = await gen_chlog(repo, f"HEAD..upstream/{ac_br}") if changelog == "" and force_update is False: await event.edit( f"\n`{UPDATER_ALIAS} está` **atualizado** `com` **{UPSTREAM_REPO_BRANCH}**\n" ) return repo.__del__() if conf is None and force_update is False: changelog_str = f"**Nova ATUALIZAÇÃO disponível para [{ac_br}]:\n\nLISTA DE MUDANÇAS:**\n`{changelog}`" if len(changelog_str) > 4096: await event.edit( "`Lista de mudanças muito grande, enviando como arquivo.`") file = open("output.txt", "w+") file.write(changelog_str) file.close() await event.client.send_file( event.chat_id, "output.txt", reply_to=event.id, ) remove("output.txt") else: await event.edit(changelog_str) return await event.respond( '`Digite ".update now" ou ".update deploy" para atualizar`') if force_update: await event.edit( "`Sincronizando com o último código estável do userbot, aguarde...`" ) else: await event.edit("`Atualizando PurpleBot...`") if conf == "now": await update(event, repo, ups_rem, ac_br) elif conf == "deploy": await deploy(event, repo, ups_rem, ac_br, txt) return
async def upstream(event): "For .update command, check if the bot is up to date, update if specified" await event.edit("`Checking for updates, please wait....`") conf = event.pattern_match.group(1) off_repo = UPSTREAM_REPO_URL force_update = False try: txt = "`Oops.. Updater cannot continue due to " txt += "some problems occured`\n\n**LOGTRACE:**\n" repo = Repo() except NoSuchPathError as error: await event.edit(f'{txt}\n`directory {error} is not found`') return repo.__del__() except GitCommandError as error: await event.edit(f'{txt}\n`Early failure! {error}`') return repo.__del__() except InvalidGitRepositoryError as error: if conf is None: return await event.edit( f"`Unfortunately, the directory {error} does not seem to be a git repository." "\nBut we can fix that by force updating the userbot using .update now.`" ) repo = Repo.init() origin = repo.create_remote("upstream", off_repo) origin.fetch() force_update = True 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 != UPSTREAM_REPO_BRANCH: await event.edit( '**[UPDATER]:**\n' f'`Looks like you are using your own custom branch ({ac_br}). ' 'in that case, Updater is unable to identify ' 'which branch is to be merged. ' 'please checkout to any official branch`') return repo.__del__() try: repo.create_remote('upstream', off_repo) except BaseException: pass ups_rem = repo.remote('upstream') ups_rem.fetch(ac_br) changelog = await gen_chlog(repo, f'HEAD..upstream/{ac_br}') if changelog == '' and force_update is False: await event.edit( f'\n`BOT N0N3 --- \n` sudah **versi terbaru**\n`BRANCH:`**{UPSTREAM_REPO_BRANCH}**\n' ) await asyncio.sleep(15) await event.delete() return repo.__del__() if conf is None and force_update is False: changelog_str = f'**UPDATE Terbaru Untuk this bot [{ac_br}]:\n\nPERUBAHAN:**\n`{changelog}`' if len(changelog_str) > 4096: await event.edit("`Changelog is too big, view the file to see it.`" ) file = open("output.txt", "w+") file.write(changelog_str) file.close() await event.client.send_file( event.chat_id, "output.txt", reply_to=event.id, ) remove("output.txt") else: await event.edit(changelog_str) return await event.respond( '`Command to Update\n >.update now\n >.update deploy\n\nuntuk mengupdate fitur terbaru.`' ) if force_update: await event.edit( '`Force-Syncing to latest stable userbot code, please wait...`') else: await event.edit('`Proses Update N0N3 ---, ....ЁЯЫая╕П`') await event.edit('`Proses Update N0N3 ---, loading....ЁЯЫая╕П`') await event.edit('`Proses Update N0N3 ---, updating....ЁЯЫая╕П`') await event.edit('`Proses Update N0N3 ---, silahkan tunggu....ЁЯЫая╕П`' ) if conf == "now": await update(event, repo, ups_rem, ac_br) await asyncio.sleep(10) await event.delete() elif conf == "deploy": await deploy(event, repo, ups_rem, ac_br, txt) await asyncio.sleep(10) await event.delete() return
async def upstream(event): conf = event.pattern_match.group(1).strip() event = await edit_or_reply(event, "`Checking for new updates...`") off_repo = UPSTREAM_REPO_URL force_update = False if HEROKU_API_KEY is None or HEROKU_APP_NAME is None: return await edit_or_reply( event, "Set `HEROKU_APP_NAME` and `HEROKU_API_KEY` to update your bot 🥴" ) try: txt = "😕 `Updater cannot continue due to some problems occured`\n\n**LOGTRACE:**\n" repo = Repo() except NoSuchPathError as error: await event.edit(f"{txt}\n`directory {error} not found`") return repo.__del__() except GitCommandError as error: await event.edit(f"{txt}\n`Early failure! {error}`") return repo.__del__() except InvalidGitRepositoryError as error: if conf is None: return await event.edit(f"`The directory {error} " "does not seem to be a git repository.\n" "Fix that by force updating! Using " f"`.update now.`") repo = Repo.init() origin = repo.create_remote("upstream", off_repo) origin.fetch() force_update = True 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 != UPSTREAM_REPO_BRANCH: await event.edit( f"`Looks like you are using your own custom git branch ( {ac_br} ). " "Please checkout to official branch that is ( master )`") return repo.__del__() try: repo.create_remote("upstream", off_repo) except BaseException: pass ups_rem = repo.remote("upstream") ups_rem.fetch(ac_br) changelog = await gen_chlog(repo, f"HEAD..upstream/{ac_br}") if changelog == "" and not force_update: await event.edit("\n**😎 Lêɠêɳ̃dẞø† is UP-TO-DATE.**" f"\n\n**Version :** {LEGENDversion}" f"\n**Owner :** {legend_mention}" "\nRelease Date : 16 December 2021" f"\n**Git Branch :** {UPSTREAM_REPO_BRANCH}\n") return repo.__del__() if conf == "" and not force_update: await print_changelogs(event, ac_br, changelog) await event.delete() return await event.respond( f"🌚 Do `.update build` to update your **Legendẞø†** !!") if force_update: await event.edit("\n**😎 Lêɠêɳ̃dẞø† is UP-TO-DATE.**" f"\n\n**Version :** {LEGENDversion}" f"\n**Owner :** {legend_mention}" "\nRelease Date : 16 December 2021" f"\n**Git Branch :** {UPSTREAM_REPO_BRANCH}\n") if conf == "now": await event.edit("`Update In Progress! Please Wait....`") await update(event, repo, ups_rem, ac_br) return
async def upstream(ups): check = ups.message.sender_id if int(check) != int(OWNER_ID): return lol = await ups.reply("`Checking for updates, please wait....`") conf = ups.pattern_match.group(1) off_repo = UPSTREAM_REPO_URL force_update = False try: txt = "`Oops.. Updater cannot continue " repo = Repo() except NoSuchPathError as error: await lol.edit(f"{txt}\n`directory {error} is not found`") repo.__del__() return except GitCommandError as error: await lol.edit(f"{txt}\n`Early failure! {error}`") repo.__del__() return except InvalidGitRepositoryError as error: repo = Repo.init() origin = repo.create_remote("upstream", off_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 lol.edit( f"**[UPDATER]:**` Looks like you are using your own custom branch ({ac_br}). " "in that case, Updater is unable to identify " "which branch is to be merged. " "please checkout to any official branch`") repo.__del__() return try: repo.create_remote("upstream", off_repo) except BaseException: pass ups_rem = repo.remote("upstream") ups_rem.fetch(ac_br) changelog = await gen_chlog(repo, f"HEAD..upstream/{ac_br}") if not changelog and not force_update: await lol.edit("\n`Your bot is` **up-to-date** \n") repo.__del__() return if conf != "now" and not force_update: changelog_str = ( f"**New UPDATE available for {ac_br}\n\nCHANGELOG:**\n`{changelog}`" ) if len(changelog_str) > 4096: await lol.edit("`Changelog is too big, view the file to see it.`") file = open("output.txt", "w+") file.write(changelog_str) file.close() await tbot.send_file( ups.chat_id, "output.txt", reply_to=ups.id, ) remove("output.txt") else: await lol.edit(changelog_str) await ups.respond("**do** `/update now` **to update**") return if force_update: await lol.edit( "`Force-Syncing to latest master bot code, please wait...`") else: await lol.edit("`Still Running ....`") try: ups_rem.pull(ac_br) except GitCommandError: repo.git.reset("--hard", "FETCH_HEAD") await lol.edit("`Successfully Updated!\n" "restarting......`") args = [sys.executable, "-m", "julia"] execle(sys.executable, *args, environ) return
async def upstream(ups): "For .update command, check if the bot is up to date, update if specified" conf = ups.pattern_match.group(1) await ups.edit("Checking for updates, please wait....") off_repo = UPSTREAM_REPO_URL force_update = False try: txt = "Oops.. Updater cannot continue due to " txt += "some problems occured`\n\n**LOGTRACE:**\n" repo = Repo() except NoSuchPathError as error: await ups.edit(f'{txt}\ndirectory {error} is not found') repo.__del__() return except GitCommandError as error: await ups.edit(f'{txt}\nEarly failure! {error}') repo.__del__() return except InvalidGitRepositoryError as error: if conf != "now": await ups.edit( f"Hey, did you type update🤔.....Okie..My dear sweet master..🤗\ \nPlease do type |.update now| to update your DARK-COBRA😎.") return repo = Repo.init() origin = repo.create_remote('upstream', off_repo) origin.fetch() force_update = True 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 ups.edit( f'**[UPDATER]:**` Looks like you are using your own custom branch ({ac_br}). ' 'in that case, Updater is unable to identify ' 'which branch is to be merged. ' 'please checkout to any official branch`') repo.__del__() return try: repo.create_remote('upstream', off_repo) except BaseException: pass ups_rem = repo.remote('upstream') ups_rem.fetch(ac_br) changelog = await gen_chlog(repo, f'HEAD..upstream/{ac_br}') if not changelog and not force_update: await ups.edit( f'\n`Your BOT is` **up-to-date** `with` **{ac_br}**\n') repo.__del__() return if conf != "now" and not force_update: changelog_str = f'**New UPDATE available for [{ac_br}]:\n\nCHANGELOG:**\n`{changelog}`' if len(changelog_str) > 4096: await ups.edit("`Changelog is too big, view the file to see it.`") file = open("output.txt", "w+") file.write(changelog_str) file.close() await ups.client.send_file( ups.chat_id, "output.txt", reply_to=ups.id, ) remove("output.txt") else: await ups.edit(changelog_str) await ups.respond("do `.update now` to update") return if force_update: await ups.edit( 'Force-Syncing to latest stable userbot code, please wait master...😅😅' ) else: await ups.edit( 'Updating userbot, please wait....you arey best boss🤗😇') if HEROKU_API_KEY is not None: import heroku3 heroku = heroku3.from_key(HEROKU_API_KEY) heroku_app = None heroku_applications = heroku.apps() if not HEROKU_APP_NAME: await ups.edit( 'CAT Please set up the `HEROKU_APP_NAME` variable to be able to update userbot.' ) repo.__del__() return for app in heroku_applications: if app.name == HEROKU_APP_NAME: heroku_app = app break if heroku_app is None: await ups.edit( f'{txt}\n`Invalid Heroku credentials for updating userbot dyno.`' ) repo.__del__() return ups_rem.fetch(ac_br) repo.git.reset("--hard", "FETCH_HEAD") heroku_git_url = heroku_app.git_url.replace( "https://", "https://*****:*****@") if "heroku" in repo.remotes: remote = repo.remote("heroku") remote.set_url(heroku_git_url) else: remote = repo.create_remote("heroku", heroku_git_url) await ups.edit( "Updating and Deploying New Update. Please wait for 5 minutes then use `.alive` to check if i'm working or not, you are my best boss...🤗🤗😎.. Just after this update a restart will take place..that's all- your DARK COBRA by @hellboi_atul " ) remote.push(refspec="HEAD:refs/heads/master", force=True) else: try: ups_rem.pull(ac_br) except GitCommandError: repo.git.reset("--hard", "FETCH_HEAD") reqs_upgrade = await update_requirements() await ups.edit('`Successfully Updated!\n' 'Bot is restarting... Wait for a second!`') # Spin a new instance of bot args = [sys.executable, "-m", "userbot"] execle(sys.executable, *args, environ) return
async def upstream(ups): pagal = await eor(ups, get_string("upd_1")) conf = ups.pattern_match.group(1) off_repo = UPSTREAM_REPO_URL try: txt = get_string("upd_2") repo = Repo() except NoSuchPathError as error: await eod(pagal, f"{txt}\n`directory {error} is not found`", time=10) repo.__del__() return except GitCommandError as error: await eod(pagal, f"{txt}\n`Early failure! {error}`", time=10) repo.__del__() return except InvalidGitRepositoryError as error: if conf != "now": await eod( pagal, f"**Unfortunately, the directory {error} does not seem to be a git repository.Or Maybe it just needs a sync verification with {GIT_REPO_NAME} But we can fix that by force updating the userbot using** `.update now.`", time=30, ) return repo = Repo.init() origin = repo.create_remote("upstream", off_repo) origin.fetch() repo.create_head("main", origin.refs.main) repo.heads.main.set_tracking_branch(origin.refs.main) repo.heads.main.checkout(True) ac_br = repo.active_branch.name try: repo.create_remote("upstream", off_repo) except BaseException: pass ups_rem = repo.remote("upstream") ups_rem.fetch(ac_br) changelog, tl_chnglog = await gen_chlog(repo, f"HEAD..upstream/{ac_br}") if "now" not in conf: if changelog: changelog_str = ( changelog + f"\n\nUse <code>{hndlr}update now</code> to update!") tldr_str = tl_chnglog + f"\n\nUse {hndlr}update now to update!" if len(changelog_str) > 4096: await eor(pagal, get_string("upd_4")) file = open(f"ultroid_updates.txt", "w+") file.write(tldr_str) file.close() await ups.client.send_file( ups.chat_id, f"ultroid_updates.txt", caption=get_string("upd_5").format(hndlr), reply_to=ups.id, ) remove(f"ultroid_updates.txt") else: return await eod(pagal, changelog_str, parse_mode="html") else: await eod( pagal, get_string("upd_7").format(ac_br, UPSTREAM_REPO_URL, ac_br), time=10, ) repo.__del__() return if Var.HEROKU_API is not None: import heroku3 heroku = heroku3.from_key(Var.HEROKU_API) heroku_app = None heroku_applications = heroku.apps() if not Var.HEROKU_APP_NAME: await eod( pagal, "`Please set up the `HEROKU_APP_NAME` variable to be able to update userbot.`", time=10, ) repo.__del__() return for app in heroku_applications: if app.name == Var.HEROKU_APP_NAME: heroku_app = app break if heroku_app is None: await eod( pagal, f"{txt}\n`Invalid Heroku credentials for updating userbot dyno.`", time=10, ) repo.__del__() return await eor( pagal, "`Userbot dyno build in progress, please wait for it to complete.`", ) ups_rem.fetch(ac_br) repo.git.reset("--hard", "FETCH_HEAD") heroku_git_url = heroku_app.git_url.replace( "https://", "https://*****:*****@", ) if "heroku" in repo.remotes: remote = repo.remote("heroku") remote.set_url(heroku_git_url) else: remote = repo.create_remote("heroku", heroku_git_url) try: remote.push(refspec=f"HEAD:refs/heads/{ac_br}", force=True) except GitCommandError as error: await eod(pagal, f"{txt}\n`Here is the error log:\n{error}`", time=10) repo.__del__() return await eod(pagal, "`Successfully Updated!\nRestarting, please wait...`", time=60) else: # Classic Updater, pretty straightforward. try: ups_rem.pull(ac_br) except GitCommandError: repo.git.reset("--hard", "FETCH_HEAD") await updateme_requirements() await eod( pagal, "`Successfully Updated!\nBot is restarting... Wait for a second!`", ) # Spin a new instance of bot execl(sys.executable, sys.executable, "-m", "pyUltroid") return
async def jarvis_update(ups): conf = ups.pattern_match.group(1) if ups.is_reply: reply = await ups.get_reply_message() reply_user = await ups.client.get_entity(reply.from_id) ren = reply_user.id if ren == MYID: "Jarvis botu güncəlləyir..." usp = await ups.reply(LANG['DETECTING']) off_repo = UPSTREAM_REPO_URL force_update = False try: txt = "`Güncəlləmə edərkən xəta baş verdi! `\n\n**LOG:**\n" repo = Repo() except NoSuchPathError as error: await usp.edit(f'{txt}\n`{error} {LANG["NOT_FOUND"]}.`') repo.__del__() return except GitCommandError as error: await usp.edit(f'{txt}\n`{LANG["GIT_ERROR"]} {error}`') repo.__del__() return except InvalidGitRepositoryError as error: if conf != "now": await usp.edit(f"`{error} {LANG['NOT_GIT']}`") return repo = Repo.init() origin = repo.create_remote('upstream', off_repo) origin.fetch() force_update = True repo.create_head('master', origin.refs.seden) repo.heads.seden.set_tracking_branch(origin.refs.sql) repo.heads.seden.checkout(True) ac_br = repo.active_branch.name if ac_br != 'master': await usp.edit(LANG['INVALID_BRANCH']) repo.__del__() return try: repo.create_remote('upstream', off_repo) except BaseException: pass ups_rem = repo.remote('upstream') ups_rem.fetch(ac_br) changelog = await gen_chlog(repo, f'HEAD..upstream/{ac_br}') if not changelog and not force_update: await usp.edit(LANG['UPDATE'].format(ac_br)) repo.__del__() return if force_update: await usp.edit(LANG['FORCE_UPDATE']) else: await usp.edit(LANG['UPDATING']) if HEROKU_APIKEY is not None: import heroku3 heroku = heroku3.from_key(HEROKU_APIKEY) heroku_app = None heroku_applications = heroku.apps() if not HEROKU_APPNAME: await usp.edit(LANG['INVALID_APPNAME']) repo.__del__() return for app in heroku_applications: if app.name == HEROKU_APPNAME: heroku_app = app break if heroku_app is None: await usp.edit(LANG['INVALID_HEROKU'].format(txt)) repo.__del__() return await usp.edit(LANG['HEROKU_UPDATING']) ups_rem.fetch(ac_br) repo.git.reset("--hard", "FETCH_HEAD") heroku_git_url = heroku_app.git_url.replace( "https://", "https://*****:*****@") if "heroku" in repo.remotes: remote = repo.remote("heroku") remote.set_url(heroku_git_url) else: remote = repo.create_remote("heroku", heroku_git_url) try: remote.push(refspec="HEAD:refs/heads/master", force=True) except GitCommandError as error: await usp.edit(f'{txt}\n`{LANG["ERRORS"]}:\n{error}`') repo.__del__() return await usp.edit(LANG['SUCCESSFULLY']) else: try: ups_rem.pull(ac_br) except GitCommandError: repo.git.reset("--hard", "FETCH_HEAD") await update_requirements() await usp.edit(LANG['SUCCESSFULLY']) args = [sys.executable, "main.py"] execle(sys.executable, *args, environ) return else: if conf != 'all' or AUTO_UPDATE == False: return "Jarvis bütün botları güncəlləyir..." usp = await ups.reply(LANG['DETECTING']) off_repo = UPSTREAM_REPO_URL force_update = False try: txt = "`Güncəlləmə uğursuz oldu! Bəzi xətalarla qarşılaşdıq.`\n\n**LOG:**\n" repo = Repo() except NoSuchPathError as error: await usp.edit(f'{txt}\n`{error} {LANG["NOT_FOUND"]}.`') repo.__del__() return except GitCommandError as error: await usp.edit(f'{txt}\n`{LANG["GIT_ERROR"]} {error}`') repo.__del__() return except InvalidGitRepositoryError as error: if conf != "now": await usp.edit(f"`{error} {LANG['NOT_GIT']}`") return repo = Repo.init() origin = repo.create_remote('upstream', off_repo) origin.fetch() force_update = True repo.create_head('master', origin.refs.seden) repo.heads.seden.set_tracking_branch(origin.refs.sql) repo.heads.seden.checkout(True) ac_br = repo.active_branch.name if ac_br != 'master': await usp.edit(LANG['INVALID_BRANCH']) repo.__del__() return try: repo.create_remote('upstream', off_repo) except BaseException: pass ups_rem = repo.remote('upstream') ups_rem.fetch(ac_br) changelog = await gen_chlog(repo, f'HEAD..upstream/{ac_br}') if not changelog and not force_update: await usp.edit(LANG['UPDATE'].format(ac_br)) repo.__del__() return if force_update: await usp.edit(LANG['FORCE_UPDATE']) else: await usp.edit(LANG['UPDATING']) if HEROKU_APIKEY is not None: import heroku3 heroku = heroku3.from_key(HEROKU_APIKEY) heroku_app = None heroku_applications = heroku.apps() if not HEROKU_APPNAME: await usp.edit(LANG['INVALID_APPNAME']) repo.__del__() return for app in heroku_applications: if app.name == HEROKU_APPNAME: heroku_app = app break if heroku_app is None: await usp.edit(LANG['INVALID_HEROKU'].format(txt)) repo.__del__() return await usp.edit(LANG['HEROKU_UPDATING']) ups_rem.fetch(ac_br) repo.git.reset("--hard", "FETCH_HEAD") heroku_git_url = heroku_app.git_url.replace( "https://", "https://*****:*****@") if "heroku" in repo.remotes: remote = repo.remote("heroku") remote.set_url(heroku_git_url) else: remote = repo.create_remote("heroku", heroku_git_url) try: remote.push(refspec="HEAD:refs/heads/master", force=True) except GitCommandError as error: await usp.edit(f'{txt}\n`{LANG["ERRORS"]}:\n{error}`') repo.__del__() return await usp.edit(LANG['SUCCESSFULLY']) else: try: ups_rem.pull(ac_br) except GitCommandError: repo.git.reset("--hard", "FETCH_HEAD") await update_requirements() await usp.edit(LANG['SUCCESSFULLY']) args = [sys.executable, "main.py"] execle(sys.executable, *args, environ) return else: return
async def upstream(event): "For .update command, check if the bot is up to date, update if specified" await event.edit("**Memeriksa pembaruan, harap tunggu...**") conf = event.pattern_match.group(1).strip() off_repo = UPSTREAM_REPO_URL force_update = False try: txt = "**Ups .. Updater tidak dapat melanjutkan karena " txt += "beberapa masalah**\n`LOGTRACE:`\n" repo = Repo() except NoSuchPathError as error: await event.edit(f"{txt}\n**Direktori** `{error}` **tidak ditemukan.**") return repo.__del__() except GitCommandError as error: await event.edit(f"{txt}\n**Kegagalan awal!** `{error}`") return repo.__del__() except InvalidGitRepositoryError as error: if conf is None: return await event.edit( f"**Sayangnya, direktori {error} " "tampaknya bukan repositori git.\n" "Tapi kamu bisa memperbaikinya dengan memperbarui paksa userbot menggunakan **" "`.update now.`" ) repo = Repo.init() origin = repo.create_remote("upstream", off_repo) origin.fetch() force_update = True 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 != UPSTREAM_REPO_BRANCH: await event.edit( f"**Sepertinya Anda menggunakan branch kustom Anda sendiri: ({ac_br}). \n" "Silakan beralih ke** `master` **branch.**" ) return repo.__del__() try: repo.create_remote("upstream", off_repo) except BaseException: pass ups_rem = repo.remote("upstream") ups_rem.fetch(ac_br) changelog = await gen_chlog(repo, f"HEAD..upstream/{ac_br}") """ - Special case for deploy - """ if conf == "deploy": await event.edit( "**Melakukan pembaruan penuh...**\nIni biasanya membutuhkan waktu kurang dari 5 menit, mohon tunggu." ) await deploy(event, repo, ups_rem, ac_br, txt) return if changelog == "" and not force_update: await event.edit( f"**ProjectDark sudah diperbarui dengan `{UPSTREAM_REPO_BRANCH}`!**" ) return repo.__del__() if conf == "" and not force_update: await print_changelogs(event, ac_br, changelog) await event.delete() return await event.respond( "**Lakukan** `.update now` **atau** `.update deploy` **untuk memperbaharui.**" ) if force_update: await event.edit( "**Sinkronisasi paksa ke kode userbot stabil terbaru, harap tunggu...**" ) if conf == "now": await event.edit("**Melakukan pembaruan cepat, harap tunggu...**") await update(event, repo, ups_rem, ac_br) return
async def upstream(event): "For .update command, check if the bot is up to date, update if specified" await event.edit("`Checking for updates, please wait....`") conf = event.pattern_match.group(1) off_repo = UPSTREAM_REPO_URL force_update = False try: txt = "`Oops.. Updater cannot continue due to " txt += "some problems occured`\n\n**LOGTRACE:**\n" repo = Repo() except NoSuchPathError as error: await event.edit(f"{txt}\n`directory {error} is not found`") return repo.__del__() except GitCommandError as error: await event.edit(f"{txt}\n`Early failure! {error}`") return repo.__del__() except InvalidGitRepositoryError as error: if conf is None: return await event.edit( f"`Unfortunately, the directory {error} does not seem to be a git repository." "\nBut we can fix that by force updating the userbot using .update now.`" ) repo = Repo.init() origin = repo.create_remote("upstream", off_repo) origin.fetch() force_update = True 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 != UPSTREAM_REPO_BRANCH: await event.edit( "**[UPDATER]:**\n" f"`Looks like you are using your own custom branch ({ac_br}). " "in that case, Updater is unable to identify " "which branch is to be merged. " "please checkout to any official branch`") return repo.__del__() try: repo.create_remote("upstream", off_repo) except BaseException: pass ups_rem = repo.remote("upstream") ups_rem.fetch(ac_br) changelog = await gen_chlog(repo, f"HEAD..upstream/{ac_br}") if changelog == "" and not force_update: await event.edit( f"\n`{TERM_ALIAS} is` **updated-af🤘🤘**\n`BRANCH:`**{UPSTREAM_REPO_BRANCH}**\n" ) return repo.__del__() if conf is None and not force_update: changelog_str = ( f"**New UPDATE available for [{ac_br}]:\n\nCHANGELOG:**\n`{changelog}`" ) if len(changelog_str) > 4096: await event.edit("`Changelog is too big, view the file to see it.`" ) with open("output.txt", "w+") as file: file.write(changelog_str) await event.client.send_file( event.chat_id, "output.txt", reply_to=event.id, ) remove("output.txt") else: await event.edit(changelog_str) return await event.respond('`do ".update now/deploy" to update`') if force_update: await event.edit( "`Force-Syncing to latest stable userbot code, please wait...`") else: await event.edit("`Updating UserBot, please wait....`") if conf == "now": await update(event, repo, ups_rem, ac_br) elif conf == "deploy": await deploy(event, repo, ups_rem, ac_br, txt) return
async def upstream(event): "For .update command, check if the bot is up to date, update if specified" await event.edit( "`Mengecek pembaruan,silahkan menunggu, Sabar Ya Sayang....🚀`") conf = event.pattern_match.group(1) off_repo = UPSTREAM_REPO_URL force_update = False try: txt = "`Maaf King Pembaruan Tidak Dapat Di Lanjutkan Karna " txt += "Beberapa Masalah Terjadi`\n\n**LOGTRACE:**\n" repo = Repo() except NoSuchPathError as error: await event.edit(f'{txt}\n`Directory {error} Tidak Dapat Di Temukan`') return repo.__del__() except GitCommandError as error: await event.edit(f'{txt}\n`Gagal Awal! {error}`') return repo.__del__() except InvalidGitRepositoryError as error: if conf is None: return await event.edit( f"`Sayangnya, Directory {error} Tampaknya Bukan Dari Repo." "\nTapi Kita Bisa Memperbarui Paksa Userbot Menggunakan .update now.`" ) repo = Repo.init() origin = repo.create_remote("upstream", off_repo) origin.fetch() force_update = True 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 != UPSTREAM_REPO_BRANCH: await event.edit( '**[UPDATER]:**\n' f'`Sepertinya Anda menggunakan repo kustom Anda sendiri ({ac_br}). ' 'dalam hal ini, Updater tidak dapat mengidentifikasi ' 'repo mana yang akan digabungkan. ' 'silakan checkout ke repo resmi mana pun`') return repo.__del__() try: repo.create_remote('upstream', off_repo) except BaseException: pass ups_rem = repo.remote('upstream') ups_rem.fetch(ac_br) changelog = await gen_chlog(repo, f'HEAD..upstream/{ac_br}') if changelog == '' and force_update is False: await event.edit( f'\n__Flicks-Userbot__ **Sudah Versi Terbaru, Owner Lagi Males Update😒**\n' ) await asyncio.sleep(15) await event.delete() return repo.__del__() if conf is None and force_update is False: changelog_str = f'**✣ Pembaruan Untuk** __Flicks-Userbot__ **[main]**:\n\n**⎆ Pembaruan :**\n`{changelog}`' if len(changelog_str) > 4096: await event.edit( "`Changelog Terlalu Besar, Lihat File Untuk Melihatnya.`") file = open("output.txt", "w+") file.write(changelog_str) file.close() await event.client.send_file( event.chat_id, "output.txt", reply_to=event.id, ) remove("output.txt") else: await event.edit(changelog_str) return await event.respond( '**Perintah Untuk Update** __Flicks-Userbot__\n• ** Perintah ** `.update now`\n• ** Perintah ** `.update deploy`\n\n__Untuk Meng Update Fitur Terbaru Dari Flicks-Userbot.__' ) if force_update: await event.edit( '`Sinkronisasi Paksa Ke Kode Userbot Stabil Terbaru, Harap Tunggu .....`' ) else: await event.edit('`⎆ Proses Update 😭Flicks⚡, Loading....1%`') await event.edit('`⎆ Proses Update 🤪Gans⚡, Loading....20%`') await event.edit('`⎆ Proses Update 🥴Userbot⚡, Loading....35%`') await event.edit('`⎆ Proses Update 😎Sedang⚡, Loading....77%`') await event.edit('`⎆ Proses Update 😁Di Update⚡, Updating...90%`') await event.edit( '`⎆ Proses Update 🤡Mohon Bersabar⚡, Mohon Menunggu King....100%`') if conf == "now": await update(event, repo, ups_rem, ac_br) await asyncio.sleep(10) await event.delete() elif conf == "deploy": await deploy(event, repo, ups_rem, ac_br, txt) await asyncio.sleep(10) await event.delete() return
async def upstream(ups): "For .update command, check if the bot is up to date, update if specified" await ups.edit("`Searching for new updates, if any...`") conf = ups.pattern_match.group(1) off_repo = UPSTREAM_REPO_URL force_updateme = False try: txt = "`Oops.. Updater cannot continue as " txt += "some problems occured`\n\n**LOGTRACE:**\n" repo = Repo() except NoSuchPathError as error: await ups.edit(f"{txt}\n`directory {error} is not found`") repo.__del__() return except GitCommandError as error: await ups.edit(f"{txt}\n`Early failure! {error}`") repo.__del__() return except InvalidGitRepositoryError as error: if conf != "now": await ups.edit( f"**Unfortunately, the directory {error} does not seem to be a git repository.\ \nOr Maybe it just needs a sync verification with {GIT_REPO_NAME}\ \nBut we can fix that by force updating the userbot using** `{xxxx}update now`." ) return repo = Repo.init() origin = repo.create_remote("upstream", off_repo) origin.fetch() force_updateme = True 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 ups.edit( f"**[UPDATER]:**` Looks like you are using your own custom branch ({ac_br}). " "in that case, Updater is unable to identify " "which branch is to be merged. " "Please checkout the official branch of Mlobot`") repo.__del__() return try: repo.create_remote("upstream", off_repo) except BaseException: pass ups_rem = repo.remote("upstream") ups_rem.fetch(ac_br) changelog = await gen_chlog(repo, f"HEAD..upstream/{ac_br}") if not changelog and not force_updateme: await ups.edit( f"\n`Your BOT is` **up-to-date** `with` **[[{ac_br}]]({UPSTREAM_REPO_URL}/tree/{ac_br})**\n" ) repo.__del__() return if conf != "now" and not force_updateme: changelog_str = ( f"**New UPDATE available for [[{ac_br}]]({UPSTREAM_REPO_URL}/tree/{ac_br}):**\n\n" + "**CHANGELOG**\n\n" + f"{changelog}") if len(changelog_str) > 4096: await ups.edit("`Changelog is too big, view the file to see it.`") file = open("output.txt", "w+") file.write(changelog_str) file.close() await ups.client.send_file( ups.chat_id, "output.txt", reply_to=ups.id, ) remove("output.txt") else: await ups.edit(changelog_str) await ups.respond(f"Do `{xxxx}update now` to update") return if force_updateme: await ups.edit( "`Force-Syncing to latest stable userbot code, please wait...`") else: await ups.edit("`Updating userbot, please wait....`") # We're in a Heroku Dyno, handle it's memez. if Var.HEROKU_API_KEY is not None: import heroku3 heroku = heroku3.from_key(Var.HEROKU_API_KEY) heroku_app = None heroku_applications = heroku.apps() if not Var.HEROKU_APP_NAME: await ups.edit( "`Please set up the HEROKU_APP_NAME variable to be able to update userbot.`" ) repo.__del__() return for app in heroku_applications: if app.name == Var.HEROKU_APP_NAME: heroku_app = app break if heroku_app is None: await ups.edit( f"{txt}\n`Invalid Heroku credentials for updating userbot dyno.`" ) repo.__del__() return await ups.edit( "`Userbot dyno build in progress, please wait for it to complete.`" ) ups_rem.fetch(ac_br) repo.git.reset("--hard", "FETCH_HEAD") heroku_git_url = heroku_app.git_url.replace( "https://", "https://*****:*****@") if "heroku" in repo.remotes: remote = repo.remote("heroku") remote.set_url(heroku_git_url) else: remote = repo.create_remote("heroku", heroku_git_url) try: remote.push(refspec="HEAD:refs/heads/master", force=True) except GitCommandError as error: await ups.edit(f"{txt}\n`Here is the error log:\n{error}`") repo.__del__() return await ups.edit("`Successfully Updated!\n" "Restarting, please wait...`") else: # Classic Updater, pretty straightforward. try: ups_rem.pull(ac_br) except GitCommandError: repo.git.reset("--hard", "FETCH_HEAD") await updateme_requirements() await ups.edit("`Successfully Updated!\n" "Bot is restarting... Wait for a second!`") # Spin a new instance of bot args = [sys.executable, "-m", "userbot"] execle(sys.executable, *args, environ) return
async def upstream(ups): ".update komutu ile botunun güncel olup olmadığını denetleyebilirsin." await ups.edit("`Güncellemeler denetleniyor...`") conf = ups.pattern_match.group(1) off_repo = UPSTREAM_REPO_URL force_update = False try: txt = "`Güncelleme başarısız oldu!" txt += "Bazı sorunlarla karşılaştık.`\n\n**LOG:**\n" repo = Repo() except NoSuchPathError as error: await ups.edit(f'{txt}\n`{error} klasörü bulunamadı.`') repo.__del__() return except GitCommandError as error: await ups.edit(f'{txt}\n`Git hatası! {error}`') repo.__del__() return except InvalidGitRepositoryError as error: if conf != "now": await ups.edit(f"`{error} klasörü bir git reposu gibi görünmüyor.\ \nFakat bu sorunu .update now komutuyla botu zorla güncelleyerek çözebilirsin.`" ) return repo = Repo.init() origin = repo.create_remote('upstream', off_repo) origin.fetch() force_update = True repo.create_head('master', origin.refs.seden) repo.heads.seden.set_tracking_branch(origin.refs.sql) repo.heads.seden.checkout(True) ac_br = repo.active_branch.name if ac_br != 'master': await ups.edit( f'**[Güncelleyici]:**` Galiba Asena botunu modifiye ettin ve kendi branşını kullanıyorsun: ({ac_br}). ' 'Bu durum güncelleyicinin kafasını karıştırıyor,' 'Güncelleme nereden çekilecek?' 'Lütfen seden botunu resmi repodan kullan.`') repo.__del__() return try: repo.create_remote('upstream', off_repo) except BaseException: pass ups_rem = repo.remote('upstream') ups_rem.fetch(ac_br) changelog = await gen_chlog(repo, f'HEAD..upstream/{ac_br}') if not changelog and not force_update: await ups.edit(f'\n`Botun` **tamamen güncel!** `Branch:` **{ac_br}**\n' ) repo.__del__() return if conf != "now" and not force_update: changelog_str = f'**{ac_br} için yeni güncelleme mevcut!\n\nDeğişiklikler:**\n`{changelog}`' if len(changelog_str) > 4096: await ups.edit( "`Değişiklik listesi çok büyük, dosya olarak görüntülemelisin.`" ) file = open("degisiklikler.txt", "w+") file.write(changelog_str) file.close() await ups.client.send_file( ups.chat_id, "degisiklikler.txt", reply_to=ups.id, ) remove("degisiklikler.txt") else: await ups.edit(changelog_str) await ups.respond( '`Güncellemeyi yapmak için \".update now\" komutunu kullan.`') return if force_update: await ups.edit('`Güncel stabil userbot kodu zorla eşitleniyor...`') else: await ups.edit('`Bot güncelleştiriliyor...`') # Bot bir Heroku dynosunda çalışıyor, bu da bazı sıkıntıları beraberinde getiriyor. if HEROKU_APIKEY is not None: import heroku3 heroku = heroku3.from_key(HEROKU_APIKEY) heroku_app = None heroku_applications = heroku.apps() if not HEROKU_APPNAME: await ups.edit( '`[HEROKU MEMEZ] Güncelleyiciyi kullanabilmek için HEROKU_APPNAME değişkenini tanımlamalısın.`' ) repo.__del__() return for app in heroku_applications: if app.name == HEROKU_APPNAME: heroku_app = app break if heroku_app is None: await ups.edit( f'{txt}\n`Heroku değişkenleri yanlış veya eksik tanımlanmış.`') repo.__del__() return await ups.edit('`[GÜNCELLEME]\ \nUserBot\'unuz daha iyi olacağınıza emin olabilirsiniz :) Bu işlem maksimum 10 dakika sürmektedir.`' ) ups_rem.fetch(ac_br) repo.git.reset("--hard", "FETCH_HEAD") heroku_git_url = heroku_app.git_url.replace( "https://", "https://*****:*****@") if "heroku" in repo.remotes: remote = repo.remote("heroku") remote.set_url(heroku_git_url) else: remote = repo.create_remote("heroku", heroku_git_url) try: remote.push(refspec="HEAD:refs/heads/master", force=True) except GitCommandError as error: await ups.edit(f'{txt}\n`Karşılaşılan hatalar burada:\n{error}`') repo.__del__() return await ups.edit('`Güncelleme başarıyla tamamlandı!\n' 'Yeniden başlatılıyor...`') else: # Klasik güncelleyici, oldukça basit. try: ups_rem.pull(ac_br) except GitCommandError: repo.git.reset("--hard", "FETCH_HEAD") await update_requirements() await ups.edit('`Güncelleme başarıyla tamamlandı!\n' 'Yeniden başlatılıyor...`') # Bot için Heroku üzerinde yeni bir instance oluşturalım. args = [sys.executable, "main.py"] execle(sys.executable, *args, environ) return
async def upstream(event): "For .update command, check if the bot is up to date, update if specified" conf = event.pattern_match.group(1).strip() event = await edit_or_reply(event, "`Checking for updates, please wait....`") off_repo = UPSTREAM_REPO_URL force_update = False try: txt = "`Oops.. Updater cannot continue due to " txt += "some problems occured`\n\n**LOGTRACE:**\n" repo = Repo() except NoSuchPathError as error: await event.edit(f"{txt}\n`directory {error} is not found`") return repo.__del__() except GitCommandError as error: await event.edit(f"{txt}\n`Early failure! {error}`") return repo.__del__() except InvalidGitRepositoryError as error: if conf is None: return await event.edit( f"`Unfortunately, the directory {error} " "does not seem to be a git repository.\n" "But we can fix that by force updating the userbot using " ".update now.`") repo = Repo.init() origin = repo.create_remote("upstream", off_repo) origin.fetch() force_update = True 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 != UPSTREAM_REPO_BRANCH: await event.edit( "**[UPDATER]:**\n" f"`Looks like you are using your own custom branch ({ac_br}). " "in that case, Updater is unable to identify " "which branch is to be merged. " "please checkout to any official branch`") return repo.__del__() try: repo.create_remote("upstream", off_repo) except BaseException: pass ups_rem = repo.remote("upstream") ups_rem.fetch(ac_br) changelog = await gen_chlog(repo, f"HEAD..upstream/{ac_br}") """ - Special case for deploy - """ if conf == "deploy": await event.edit("`Deploying userbot, please wait....`") await deploy(event, repo, ups_rem, ac_br, txt) return if changelog == "" and not force_update: await event.edit("\n`CATUSERBOT is` **up-to-date** `with` " f"**{UPSTREAM_REPO_BRANCH}**\n") return repo.__del__() if conf == "" and force_update is False: await print_changelogs(event, ac_br, changelog) await event.delete() return await event.respond( 'do "[`.update now`] or [`.update deploy`]" to update.Check `.info updater` for details' ) if force_update: await event.edit( "`Force-Syncing to latest stable userbot code, please wait...`") if conf == "now": await event.edit("`Updating userbot, please wait....`") await update(event, repo, ups_rem, ac_br) return
async def upstream(event): "For .update command, check if the bot is up to date, update if specified" await event.edit("`Mendapatkan informasi...`") conf = event.pattern_match.group(1).strip() off_repo = UPSTREAM_REPO_URL force_update = False try: txt = "`Oops.. Pembaruan tidak bisa dilanjutkan " txt += "terjadi beberapa masalah`\n\n**JEJAK LOG** :\n" repo = Repo() except NoSuchPathError as error: await event.edit(f"{txt}\n`direktori {error} tidak ditemukan`") return repo.__del__() except GitCommandError as error: await event.edit(f"{txt}\n`Kegagalan awal! {error}`") return repo.__del__() except InvalidGitRepositoryError as error: if conf is None: return await event.edit( f"`Sayangnya, direktori {error} tersebut " "tampaknya bukan repositori git." "\nTapi kita bisa memperbaikinya dengan memperbarui " "paksa userbot menggunakan “.update now.”`") repo = Repo.init() origin = repo.create_remote("upstream", off_repo) origin.fetch() force_update = True 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 != UPSTREAM_REPO_BRANCH: await event.edit( "**[PEMBARUAN]** :\n" f"`Sepertinya Anda menggunakan kustom branch ({ac_br}) Anda sendiri. " "dalam hal ini, Pembaruan tidak dapat mengidentifikasi " "branch mana yang akan digabungkan. " "Silahkan periksa branch resmi`") return repo.__del__() try: repo.create_remote("upstream", off_repo) except BaseException: pass ups_rem = repo.remote("upstream") ups_rem.fetch(ac_br) changelog = await gen_chlog(repo, f"HEAD..upstream/{ac_br}") """ - Special case for deploy - """ if conf == "deploy": await event.edit("`Menerapkan userbot, tunggu sebentar...`") await deploy(event, repo, ups_rem, ac_br, txt) return if changelog == "" and force_update is False: await event.edit( f"\n**{HEROKU_APP_NAME}** `sudah` **terbaru** `dengan` " f"**{UPSTREAM_REPO_BRANCH}**\n") return repo.__del__() await event.delete() if conf == "" and force_update is False: await print_changelogs(event, ac_br, changelog) await event.delete() return await event.respond( "`ketik “.update now/deploy” untuk memperbarui.`") if force_update: await event.edit( "`Sinkronisasi paksa ke kode userbot stabil terbaru, tunggu sebentar...`" ) if conf == "now": await event.edit("`Memperbarui userbot, tunggu sebentar...`") await update(event, repo, ups_rem, ac_br) return
async def upstream(event): "بالنسبة لأمر التحديث ، تحقق مما إذا كان بوت اكسس محدثًا ، أو قم بالتحديث إذا تم بتحديثه" conf = event.pattern_match.group(1).strip() event = await edit_or_reply( event, "𓆰 𝑺𝑶𝑼𝑹𝑪𝑬 𝑰𝑪𝑺𝑺 - 𝑼𝑷𝑫𝑨𝑻𝑬 𝑴𝑺𝑮 𓆪\n 𓍹ⵧⵧⵧⵧⵧⵧⵧⵧⵧⵧⵧⵧⵧⵧⵧⵧⵧⵧⵧⵧ𓍻\n**⪼ جاري البحث عن التحديثات 🌐.. 𓆰،**", ) off_repo = UPSTREAM_REPO force_update = False if HEROKU_API_KEY is None or HEROKU_APP_NAME is None: return await edit_or_reply( event, "𓆰 𝑺𝑶𝑼𝑹𝑪𝑬 𝑰𝑪𝑺𝑺 - 𝑼𝑷𝑫𝑨𝑻𝑬 𝑴𝑺𝑮 𓆪\n 𓍹ⵧⵧⵧⵧⵧⵧⵧⵧⵧⵧⵧⵧⵧⵧⵧⵧⵧⵧⵧⵧ𓍻\n** ⪼ اضبط المتغيرات المطلوبة أولاً لتحديث بوت اكسس 𓆰،**", ) try: txt = "`عفوًا .. لا يمكن لبرنامج التحديث المتابعة بسبب " txt += "حدثت بعض المشاكل`\n\n**تتبع السجل:**\n" repo = Repo() except NoSuchPathError as error: await event.edit(f"{txt}\nالدليل {error} غير موجود") return repo.__del__() except GitCommandError as error: await event.edit(f"{txt}\n`فشل مبكر! {error}`") return repo.__del__() except InvalidGitRepositoryError as error: if conf is None: return await event.edit( f"`Unfortunately, the directory {error} " "does not seem to be a git repository.\n" "But we can fix that by force updating the userbot using " ".update now.`" ) repo = Repo.init() origin = repo.create_remote("upstream", off_repo) origin.fetch() force_update = True 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 != UPSTREAM_REPO_BRANCH: await event.edit( "**[UPDATER]:**\n" f"`Looks like you are using your own custom branch ({ac_br}). " "in that case, Updater is unable to identify " "which branch is to be merged. " "please checkout to any official branch`" ) return repo.__del__() try: repo.create_remote("upstream", off_repo) except BaseException: pass ups_rem = repo.remote("upstream") ups_rem.fetch(ac_br) changelog = await gen_chlog(repo, f"HEAD..upstream/{ac_br}") # Special case for deploy if conf == "البوت": await event.edit( "𓆰 𝑺𝑶𝑼𝑹𝑪𝑬 𝑰𝑪𝑺𝑺 - 𝑼𝑷𝑫𝑨𝑻𝑬 𝑴𝑺𝑮 𓆪\n𓍹ⵧⵧⵧⵧⵧⵧⵧⵧⵧⵧⵧⵧⵧⵧⵧⵧⵧⵧⵧⵧ𓍻\n**⪼ يتم تنصيب التحديث انتظر 🌐 𓆰،**" ) await deploy(event, repo, ups_rem, ac_br, txt) return if changelog == "" and not force_update: await event.edit( "\n𓆰 𝑺𝑶𝑼𝑹𝑪𝑬 𝑰𝑪𝑺𝑺 - 𝑼𝑷𝑫𝑨𝑻𝑬 𝑴𝑺𝑮 𓆪\n𓍹ⵧⵧⵧⵧⵧⵧⵧⵧⵧⵧⵧⵧⵧⵧⵧⵧⵧⵧⵧⵧ𓍻\n**⪼ سورس اكسس محدث لأخر اصدار ༗. **" ) return repo.__del__() if conf == "" and not force_update: await print_changelogs(event, ac_br, changelog) await event.delete() return await event.respond( "𓆰 𝑺𝑶𝑼𝑹𝑪𝑬 𝑰𝑪𝑺𝑺 - 𝑼𝑷𝑫𝑨𝑻𝑬 𝑴𝑺𝑮 𓆪\n 𓍹ⵧⵧⵧⵧⵧⵧⵧⵧⵧⵧⵧⵧⵧⵧⵧⵧⵧⵧⵧⵧ𓍻\n⪼ اضغط هنا **للتحديث السريع ↫ **[`{}تحديث الان`] او اضغط هنا **لتنصيب التحديث** وقد يستغرق 5 دقائق ↫ [`{}تحديث البوت`]".format(T, T) ) if force_update: await event.edit( "`Force-Syncing to latest stable userbot code, please wait...`" ) if conf == "الان": await event.edit( "𓆰 𝑺𝑶𝑼𝑹𝑪𝑬 𝑰𝑪𝑺𝑺 - 𝑼𝑷𝑫𝑨𝑻𝑬 𝑴𝑺𝑮 𓆪\n 𓍹ⵧⵧⵧⵧⵧⵧⵧⵧⵧⵧⵧⵧⵧⵧⵧⵧⵧⵧⵧⵧ𓍻\n**⪼ يتم تحديث بوت اكسس انتظر 🌐..𓆰،**" ) await update(event, repo, ups_rem, ac_br) return
async def upstream(event): await event.edit("`Getting information....`") conf = event.pattern_match.group(1).strip() off_repo = UPSTREAM_REPO_URL force_update = False try: txt = "`Oops.. Updater cannot continue due to " txt += "some problems occured`\n\n**LOGTRACE:**\n" repo = Repo() except NoSuchPathError as error: await event.edit(f"{txt}\n`directory {error} is not found`") return repo.__del__() except GitCommandError as error: await event.edit(f"{txt}\n`Early failure! {error}`") return repo.__del__() except InvalidGitRepositoryError as error: if conf is None: return await event.edit( f"`Unfortunately, the directory {error} " "does not seem to be a git repository.\n" "But we can fix that by force updating the userbot using " ".update now.`") repo = Repo.init() origin = repo.create_remote("upstream", off_repo) origin.fetch() force_update = True repo.create_head("staging", origin.refs.staging) repo.heads.staging.set_tracking_branch(origin.refs.staging) repo.heads.staging.checkout(True) ac_br = repo.active_branch.name if ac_br != UPSTREAM_REPO_BRANCH: await event.edit( "**[UPDATER]:**\n" f"`Looks like you are using your own custom branch ({ac_br}). " "in that case, Updater is unable to identify " "which branch is to be merged. " "please checkout to any official branch`") return repo.__del__() try: repo.create_remote("upstream", off_repo) except BaseException: pass ups_rem = repo.remote("upstream") ups_rem.fetch(ac_br) changelog = await gen_chlog(repo, f"HEAD..upstream/{ac_br}") if conf == "deploy": await event.edit("`Deploying userbot, please wait....`") await deploy(event, repo, ups_rem, ac_br, txt) await asyncio.sleep(15) await event.delete() return if changelog == "" and not force_update: await event.edit( f'\n`🔥XBOT-REMIX🔥\n` sudah **versi terbaru**\n`BRANCH:`**{UPSTREAM_REPO_BRANCH}**\n' ) await asyncio.sleep(15) await event.delete() return repo.__del__() if conf == "" and not force_update: await print_changelogs(event, ac_br, changelog) return if force_update: await event.edit( "`Force-Syncing to latest stable userbot code, please wait...`") if conf == "now": await event.edit('`Proses Update XBOT-REMIX, ....🛠️`') await event.edit('`Proses Update XBOT-REMIX, loading....🛠️`') await event.edit('`Proses Update XBOT-REMIX, updating....🛠️`') await event.edit('`Proses Update XBOT-REMIX, silahkan tunggu....🛠️`') await update(event, repo, ups_rem, ac_br) await asyncio.sleep(15) await event.delete() return
async def upstream(ups): "For .update command, check if the bot is up to date, update if specified" conf = ups.pattern_match.group(1) await ups.edit("Checking for updates, please wait....") off_repo = UPSTREAM_REPO_URL force_update = False try: txt = "Oops.. Updater cannot continue due to " txt += "some problems occured`\n\n**LOGTRACE:**\n" repo = Repo() except NoSuchPathError as error: await ups.edit(f'{txt}\ndirectory {error} is not found') repo.__del__() return except GitCommandError as error: await ups.edit(f'{txt}\nEarly failure! {error}') repo.__del__() return except InvalidGitRepositoryError as error: if conf != "now": await ups.edit(f"**Hey ßoss!!!**😁😁\n__To get the Latest update of the UserBot \n©Lucif3rHun\n\n do |`.update now`| 😎😎 ") return repo = Repo.init() origin = repo.create_remote('upstream', off_repo) origin.fetch() force_update = True 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 ups.edit( f'**[UPDATER]:**` Looks like you are using your own custom branch ({ac_br}). ' 'in that case, Updater is unable to identify ' 'which branch is to be merged. ' 'please checkout to any official branch`') repo.__del__() return try: repo.create_remote('upstream', off_repo) except BaseException: pass ups_rem = repo.remote('upstream') ups_rem.fetch(ac_br) changelog = await gen_chlog(repo, f'HEAD..upstream/{ac_br}') if not changelog and not force_update: await ups.edit( f'\n**{ac_br} master your bot is already up to date..**\n') repo.__del__() return if conf != "now" and not force_update: changelog_str = f'**New UPDATE available for [{ac_br}]:\n\nCHANGELOG:**\n`{changelog}`' if len(changelog_str) > 4096: await ups.edit("`Changelog is too big, view the file to see it.`") file = open("output.txt", "w+") file.write(changelog_str) file.close() await ups.client.send_file( ups.chat_id, "output.txt", reply_to=ups.id, ) remove("output.txt") else: await ups.edit(changelog_str) await ups.respond("do `.update now` to update") return if force_update: await ups.edit('Force-Syncing to latest stable userbot code, please wait master...😅😅') else: await ups.edit('`Updating userbot, please wait....you arey best boss🤗😇') if HEROKU_API_KEY is not None: import heroku3 heroku = heroku3.from_key(HEROKU_API_KEY) heroku_app = None heroku_applications = heroku.apps() if not HEROKU_APP_NAME: await ups.edit('Please set up the `HEROKU_APP_NAME` variable to be able to update userbot.') repo.__del__() return for app in heroku_applications: if app.name == HEROKU_APP_NAME: heroku_app = app break if heroku_app is None: await ups.edit( f'{txt}\n`Invalid Heroku credentials for updating userbot dyno.`' ) repo.__del__() return ups_rem.fetch(ac_br) repo.git.reset("--hard", "FETCH_HEAD") heroku_git_url = heroku_app.git_url.replace( "https://", "https://*****:*****@") if "heroku" in repo.remotes: remote = repo.remote("heroku") remote.set_url(heroku_git_url) else: remote = repo.create_remote("heroku", heroku_git_url) await ups.edit("`⬛⬛⬛⬛ \n⬛✳️✳️⬛ \n⬛✳️✳️⬛ \n⬛⬛⬛⬛`") await asyncio.sleep(1) await ups.edit("`⬛⬛⬛⬛ \n⬛🔴🔴⬛ \n⬛🔴🔴⬛ \n⬛⬛⬛⬛`") await asyncio.sleep(1) await ups.edit("`⬛⬛⬛⬛ \n⬛🌕🌕⬛ \n⬛🌕🌕⬛ \n⬛⬛⬛⬛`") await asyncio.sleep(1) await ups.edit("`⬛⬛⬛⬛ \n⬛🔵🔵⬛ \n⬛🔵🔵⬛ \n⬛⬛⬛⬛`") await asyncio.sleep(1) await ups.edit("`⬛⬛⬛⬛ \n⬛❇️❇️⬛ \n⬛❇️❇️⬛ \n⬛⬛⬛⬛`") await asyncio.sleep(1) await ups.edit("`⚜️Updating UserBot⚜️\n\nYou are the 👑KING👑 Boss!!\n\nPlease wait 5-10min😁😁\nThen try .alive to check` 😎😎\n\n**Powered by :-**\n©Lucif3rHun") remote.push(refspec="HEAD:refs/heads/master", force=True) else: try: ups_rem.pull(ac_br) except GitCommandError: repo.git.reset("--hard", "FETCH_HEAD") reqs_upgrade = await update_requirements() await ups.edit('`Successfully Updated!\n' 'Bot is restarting... Wait for a second!`') # Spin a new instance of bot args = [sys.executable, "-m", "userbot"] execle(sys.executable, *args, environ) return
async def upstream(event): "For .update command, check if the bot is up to date, update if specified" await event.edit("`Checking for updates, please wait....`") conf = event.pattern_match.group(1) off_repo = UPSTREAM_REPO_URL force_update = False try: txt = "`Hamdehh.. Updater tidak bisa melanjutkan karena " txt += "beberapa masalah`\n\n**LOGTRACE:**\n" repo = Repo() except NoSuchPathError as error: await event.edit(f"{txt}\n`directory {error} is not found`") return repo.__del__() except GitCommandError as error: await event.edit(f"{txt}\n`Early failure! {error}`") return repo.__del__() except InvalidGitRepositoryError as error: if conf is None: return await event.edit( f"`Unfortunately, the directory {error} does not seem to be a git repository." "\nBut we can fix that by force updating the userbot using .update now.`" ) repo = Repo.init() origin = repo.create_remote("upstream", off_repo) origin.fetch() force_update = True 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 != UPSTREAM_REPO_BRANCH: await event.edit( "**[PEMBARUAN]:**\n" f"`Looks like you are using your own custom branch ({ac_br}). " "in that case, Updater is unable to identify " "which branch is to be merged. " "please checkout to any official branch`") return repo.__del__() try: repo.create_remote("upstream", off_repo) except BaseException: pass ups_rem = repo.remote("upstream") ups_rem.fetch(ac_br) changelog = await gen_chlog(repo, f"HEAD..upstream/{ac_br}") if changelog == "" and force_update is False: await event.edit( f"\n`jhehehe4ubot yang` **terbaru** `dengan` **{UPSTREAM_REPO_BRANCH}**\n" ) return repo.__del__() if conf is None and force_update is False: changelog_str = ( f"**Update terbaru tersedia untuk [{ac_br}]:\n\nCHANGELOG:**\n`{changelog}`" ) if len(changelog_str) > 4096: await event.edit("`Changelog is too big, view the file to see it.`" ) file = open("changelog.txt", "w+") file.write(changelog_str) file.close() await event.client.send_file( event.chat_id, "changelog.txt", reply_to=event.id, ) remove("changelog.txt") else: await event.edit(changelog_str) return await event.respond('`do ".update now/deploy" to update`') if force_update: await event.edit( "`Force-Syncing to latest stable userbot code, please wait...`") else: await event.edit("`Memperbarui jhehehe4ubot, mohon bersabar....`") if conf == "now": await update(event, repo, ups_rem, ac_br) elif conf == "deploy": await deploy(event, repo, ups_rem, ac_br, txt) return
class DepositionRepo: """ A class to interface with git repos for depositions. You *MUST* use the 'with' statement when using this class to ensure that changes are committed.""" def __init__(self, uuid, initialize=False): self._repo = None self._uuid = uuid self._initialize = initialize self._entry_dir = None self._modified_files = False self._live_metadata = None self._original_metadata = None self._lock_path = os.path.join(querymod.configuration['repo_path'], str(uuid), '.git', 'api.lock') def __enter__(self): """ Get a session cookie to use for future requests. """ self._entry_dir = os.path.join(querymod.configuration['repo_path'], str(self._uuid)) if not os.path.exists(self._entry_dir) and not self._initialize: raise querymod.RequestError('No deposition with that ID exists!') try: if self._initialize: self._repo = Repo.init(self._entry_dir) with open(self._lock_path, "w") as f: f.write(str(os.getpid())) self._repo.config_writer().set_value("user", "name", "BMRBDep").release() self._repo.config_writer().set_value("user", "email", "*****@*****.**").release() os.mkdir(os.path.join(self._entry_dir, 'data_files')) else: counter = 100 while os.path.exists(self._lock_path): counter -= 1 time.sleep(random.random()) if counter <= 0: raise querymod.ServerError('Could not acquire entry directory lock.') with open(self._lock_path, "w") as f: f.write(str(os.getpid())) self._repo = Repo(self._entry_dir) except NoSuchPathError: raise querymod.RequestError("'%s' is not a valid deposition ID." % self._uuid, status_code=404) return self def __exit__(self, exc_type, exc_value, traceback): """ End the current session.""" # If nothing changed the commit won't do anything self.commit("Repo closed with changed but without a manual commit... Potential software bug.") self._repo.close() self._repo.__del__() try: os.unlink(self._lock_path) except OSError: raise querymod.ServerError('Could not remove entry lock file.') @property def metadata(self): """ Return the metadata dictionary. """ if not self._live_metadata: self._live_metadata = json.loads(self.get_file('submission_info.json')) self._original_metadata = self._live_metadata.copy() return self._live_metadata def get_entry(self): """ Return the NMR-STAR entry for this entry. """ entry_location = os.path.join(self._entry_dir, 'entry.str') try: return querymod.pynmrstar.Entry.from_file(entry_location) except Exception as e: raise querymod.ServerError('Error loading an entry!\nError: %s\nEntry location:%s\nEntry text:\n%s' % (e.message, entry_location, open(entry_location, "r").read())) def write_entry(self, entry): """ Save an entry in the standard place. """ try: self.metadata['last_ip'] = flask.request.environ['REMOTE_ADDR'] except RuntimeError: pass self.write_file('entry.str', str(entry), root=True) def get_file(self, filename, raw_file=False, root=True): """ Returns the current version of a file from the repo. """ filename = secure_filename(filename) if not root: filename = os.path.join('data_files', filename) try: file_obj = open(os.path.join(self._entry_dir, filename), "r") if raw_file: return file_obj else: return file_obj.read() except IOError: raise querymod.RequestError('No file with that name saved for this entry.') def get_data_file_list(self): """ Returns the list of data files associated with this deposition. """ return os.listdir(os.path.join(self._entry_dir, 'data_files')) def delete_data_file(self, filename): """ Delete a data file by name.""" filename = secure_filename(filename) os.unlink(os.path.join(self._entry_dir, 'data_files', filename)) self._modified_files = True def write_file(self, filename, data, root=False): """ Adds (or overwrites) a file to the repo. """ try: self.metadata['last_ip'] = flask.request.environ['REMOTE_ADDR'] except RuntimeError: pass filename = secure_filename(filename) filepath = filename if not root: filepath = os.path.join('data_files', filename) with open(os.path.join(self._entry_dir, filepath), "wb") as fo: fo.write(data) self._modified_files = True return filename def commit(self, message): """ Commits the changes to the repository with a message. """ # Check if the metadata has changed if self._live_metadata != self._original_metadata: self.write_file('submission_info.json', json.dumps(self._live_metadata, indent=2, sort_keys=True), root=True) self._original_metadata = self._live_metadata.copy() # No recorded changes if not self._modified_files: return False # See if they wrote the same value to an existing file if not self._repo.untracked_files and not [item.a_path for item in self._repo.index.diff(None)]: return False # Add the changes, commit self._repo.git.add(all=True) self._repo.git.commit(message=message) self._modified_files = False return True
async def upstream(event): "For .update command, check if the bot is up to date, update if specified" await event.edit("`Memeriksa pembaruan, silakan tunggu....`") conf = event.pattern_match.group(1) off_repo = UPSTREAM_REPO_URL force_update = False try: txt = "`UPS.. Pembaruan tidak dapat dilanjutkan karena " txt += "beberapa masalah terjadi`\n\n**LOGTRACE:**\n" repo = Repo() except NoSuchPathError as error: await event.edit(f'{txt}\n`direktori {error} tidak ditemukan`') return repo.__del__() except GitCommandError as error: await event.edit(f'{txt}\n`Kegagalan awal! {error}`') return repo.__del__() except InvalidGitRepositoryError as error: if conf is None: return await event.edit( f"`Sayangnya, direktori {error} sepertinya bukan repositori git." "\nTapi kita bisa memperbaikinya dengan paksa memperbarui userbot menggunakan .update now.`" ) repo = Repo.init() origin = repo.create_remote('upstream', off_repo) origin.fetch() force_update = True 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 != UPSTREAM_REPO_BRANCH: await event.edit( '**[PEMBARUAN]:**\n' f'`Sepertinya Anda menggunakan cabang Anda sendiri Suai ({ac_br}). ' 'dalam hal ini, Pembaruan tidak dapat mengidentifikasi ' 'cabang mana yang akan digabung. ' 'silakan periksa untuk setiap cabang resmi`') return repo.__del__() try: repo.create_remote('upstream', off_repo) except BaseException: pass ups_rem = repo.remote('upstream') ups_rem.fetch(ac_br) changelog = await gen_chlog(repo, f'HEAD..upstream/{ac_br}') if changelog == '' and force_update is False: await event.edit( f'\n`USERBOT Anda` ** ter-update ** `dengan` **{UPSTREAM_REPO_BRANCH}**\n') return repo.__del__() if conf is None and force_update is False: changelog_str = f'**PEMBARUAN baru tersedia untuk [{ac_br}]:\n\nCHANGELOG:**\n`{changelog}`' if len(changelog_str) > 4096: await event.edit("`Changelog terlalu besar, lihat berkas untuk melihatnya.`") file = open("output.txt", "w+") file.write(changelog_str) file.close() await event.client.send_file( event.chat_id, "output.txt", reply_to=event.id, ) remove("output.txt") else: await event.edit(changelog_str) return await event.respond('`ketik perintah ".update now/deploy" untuk memperbarui`') if force_update: await event.edit( '`Paksa sinkronisasi untuk kode userbot terakhir stabil, Mohon tunggu...`') else: await event.edit('`Memperbarui userbot, Mohon tunggu....`') if conf == "now": await update(event, repo, ups_rem, ac_br) elif conf == "deploy": await deploy(event, repo, ups_rem, ac_br, txt) return