async def restart_(message: Message): """restart USERGE-X""" await message.edit("`initiating paimon restart... `", log=__name__) LOG.info("USERGE-X Services - Restart initiated") if "t" in message.flags: shutil.rmtree(Config.TMP_PATH, ignore_errors=True) if "log" in message.flags: await message.edit("Restarting <b>logs</b>...", del_in=5) await runcmd("bash run") asyncio.get_event_loop().create_task(userge.restart()) return if "d" in message.flags: shutil.rmtree(Config.DOWN_PATH, ignore_errors=True) if "h" in message.flags: if Config.HEROKU_APP: await message.edit( "`restarting paimon...`", del_in=3, ) await FROZEN.drop() Config.HEROKU_APP.restart() time.sleep(30) else: await message.edit("`Restarting [HARD] ...`", del_in=1) await FROZEN.drop() asyncio.get_event_loop().create_task(userge.restart(hard=True)) else: await message.edit("`Restarting [SOFT] ...`", del_in=1) asyncio.get_event_loop().create_task(userge.restart())
async def restart_(message: Message): """ restart USERGE-X """ await message.edit("`Restarting USERGE-X Services`", log=__name__) LOG.info("USERGE-X Services - Restart initiated") if "t" in message.flags: shutil.rmtree(Config.TMP_PATH, ignore_errors=True) if "log" in message.flags: await message.edit("Restarting <b>logs</b>...", del_in=5) await runcmd("bash run") asyncio.get_event_loop().create_task(userge.restart()) return if "d" in message.flags: shutil.rmtree(Config.DOWN_PATH, ignore_errors=True) if "h" in message.flags: if Config.HEROKU_APP: await message.edit( "`Heroku app found, trying to restart dyno...\nthis will take upto 30 sec`", del_in=3, ) Config.HEROKU_APP.restart() time.sleep(30) else: await message.edit("`Restarting [HARD] ...`", del_in=1) asyncio.get_event_loop().create_task(userge.restart(hard=True)) else: await message.edit("`Restarting [SOFT] ...`", del_in=1) asyncio.get_event_loop().create_task(userge.restart())
async def check_update(message: Message): """ check or do updates """ await message.edit("`Checking for updates, please wait....`") flags = list(message.flags) pull_from_repo = False branch = "master" if "pull" in flags: pull_from_repo = True flags.remove("pull") if len(flags) == 1: branch = flags[0] dev_branch = "alpha" if branch == dev_branch: await message.err('Can\'t update to unstable [alpha] branch. ' 'Please use other branches instead !') return repo = Repo() if branch not in repo.branches: await message.err(f'invalid branch name : {branch}') return try: out = _get_updates(repo, branch) except GitCommandError as g_e: await message.err(g_e, del_in=5) return if pull_from_repo: if out: await message.edit( f'`New update found for [{branch}], Now pulling...`') await _pull_from_repo(repo, branch) await CHANNEL.log( f"**PULLED update from [{branch}]:\n\n📄 CHANGELOG 📄**\n\n{out}" ) await message.edit( '**Userge Successfully Updated!**\n' '`Now restarting... Wait for a while!`', del_in=3) asyncio.get_event_loop().create_task(userge.restart(True)) else: active = repo.active_branch.name if active == branch: await message.err(f"already in [{branch}]!") return await message.edit( f'`Moving HEAD from [{active}] >>> [{branch}] ...`', parse_mode='md') await _pull_from_repo(repo, branch) await CHANNEL.log(f"`Moved HEAD from [{active}] >>> [{branch}] !`") await message.edit('`Now restarting... Wait for a while!`', del_in=3) asyncio.get_event_loop().create_task(userge.restart()) else: if out: change_log = f'**New UPDATE available for [{branch}]:\n\n📄 CHANGELOG 📄**\n\n' await message.edit_or_send_as_file(change_log + out, disable_web_page_preview=True) else: await message.edit(f'**Userge is up-to-date with [{branch}]**', del_in=5)
async def restart_(message: Message): """restart USERGE-X""" await message.edit("`Restarting USERGE-X Services`", log=__name__) LOG.info("USERGE-X Services - Restart initiated") if "t" in message.flags: shutil.rmtree(Config.TMP_PATH, ignore_errors=True) if "log" in message.flags: await message.edit("Restarting <b>logs</b>...", del_in=5) await runcmd("bash run") asyncio.get_event_loop().create_task(userge.restart()) return if "d" in message.flags: shutil.rmtree(Config.DOWN_PATH, ignore_errors=True) if "h" in message.flags: if Config.HEROKU_APP: update = await message.edit( "`Heroku app found, trying to restart dyno...\nthis will take upto 30 sec`" ) await FROZEN.drop() be_update = time.time() await UPDATE_MSG.update_one( {"_id": "UPDATE_MSG"}, {"$set": {"message": f"{update.chat.id}/{update.message_id}"}}, upsert=True, ) await UPDATE_MSG.update_one( {"_id": "UPDATE_MSG"}, {"$set": {"time": be_update}}, upsert=True ) Config.HEROKU_APP.restart() time.sleep(30) else: update = await message.edit("`Restarting [HARD] ...`") be_update = time.time() await UPDATE_MSG.update_one( {"_id": "UPDATE_MSG"}, {"$set": {"message": f"{update.chat.id}/{update.message_id}"}}, upsert=True, ) await UPDATE_MSG.update_one( {"_id": "UPDATE_MSG"}, {"$set": {"time": be_update}}, upsert=True ) await UPDATE_MSG.update_one( {"_id": "UPDATE_MSG"}, {"$set": {"process": "restarted"}}, upsert=True ) await FROZEN.drop() asyncio.get_event_loop().create_task(userge.restart(hard=True)) else: await message.edit("`Restarting [SOFT] ...`", del_in=1) asyncio.get_event_loop().create_task(userge.restart())
async def restart_(message: Message): """ restart userge """ await message.edit("`Restarting Userge Services`", log=__name__) LOG.info("USERGE Services - Restart initiated") if 't' in message.flags: shutil.rmtree(Config.TMP_PATH, ignore_errors=True) if 'd' in message.flags: shutil.rmtree(Config.DOWN_PATH, ignore_errors=True) if 'h' in message.flags: if Config.HEROKU_APP: await message.edit( '`Heroku app found, trying to restart dyno...\nthis will take upto 30 sec`', del_in=3) Config.HEROKU_APP.restart() time.sleep(30) else: await message.edit("`Restarting [HARD] ...`", del_in=1) asyncio.get_event_loop().create_task(userge.restart(hard=True)) else: await message.edit("`Restarting [SOFT] ...`", del_in=1) asyncio.get_event_loop().create_task(userge.restart())
async def restart_cmd_handler(message: Message): await message.edit("Restarting Userge Services", log=__name__) LOG.info("USERGE Services - Restart initiated") if Config.HEROKU_APP and '-h' in message.flags: await message.edit( '`Heroku app found, trying to restart dyno...\nthis will take upto 30 sec`', del_in=3) Config.HEROKU_APP.restart() time.sleep(30) else: await message.edit("finalizing...", del_in=1) asyncio.get_event_loop().create_task(userge.restart())
async def defreezer_(message: Message): """re-enable frozen plugin""" if "-all" in message.flags: async for plug in FROZEN.find(): old_ = plug["plug_loc"] new_ = f"{old_}.py" os.rename(old_, new_) await FROZEN.drop() await message.edit("All frozen plugins are <b>re-enabled</b> now...") await CHANNEL.log("All frozen plugins are <b>re-enabled</b>.") asyncio.get_event_loop().create_task(userge.restart()) return plugin_name = message.input_str if not plugin_name: await message.edit("`Provide a plugin name to re-enable...`", del_in=5) return found = await FROZEN.find_one({"plug_name": plugin_name}) if found: old_ = found["plug_loc"] new_ = f"{old_}.py" try: os.rename(old_, new_) except BaseException: await message.edit( f"The plugin <b>{plugin_name}</b> is already re-enabled.", del_in=5) return await FROZEN.delete_one(found) await message.edit( f"Plugin <b>{plugin_name}</b> got defrozen.\n<b>Bot restarting...</b>" ) await CHANNEL.log( f"Plugin <b>{plugin_name}</b> got defrozen.\n<b>Bot restarting...</b>" ) asyncio.get_event_loop().create_task(userge.restart()) else: await message.edit(f"`The plugin {plugin_name} is not frozen...`", del_in=5)
async def restart_(message: Message): """ restart DARKGE """ await message.edit("Restarting DARKGE Services", log=__name__) LOG.info("DARKGE-X Services - Restart initiated") if 't' in message.flags: shutil.rmtree(Config.TMP_PATH, ignore_errors=True) if 'd' in message.flags: shutil.rmtree(Config.DOWN_PATH, ignore_errors=True) if Config.HEROKU_APP and 'h' in message.flags: await message.edit( '`Heroku app found, trying to restart dyno...\nthis will take upto 30 sec`', del_in=3) Config.HEROKU_APP.restart() time.sleep(30) else: await message.edit("finalizing...", del_in=1) asyncio.get_event_loop().create_task(userge.restart())
async def freezer_(message: Message): """disable plugin temporarily""" cmd_name = message.input_str if not cmd_name: await message.edit( "`Provide a plugin name or command name to disable...`", del_in=5) return try: cmd_ = f"{Config.CMD_TRIGGER}{cmd_name}" plugin_name = userge.manager.commands[cmd_].plugin_name except BaseException: plugin_name = message.input_str try: help_ = True if plugin_name == "help" else False plugin_parent = userge.manager.plugins[plugin_name].parent loc_ = (f"userge/plugins/{plugin_parent}/{plugin_name}.py" if not help_ else "userge/plugins/help.py") old_ = loc_ new_ = loc_.replace(".py", "") except Exception as e: await message.edit( f"Provide correct plugin name...\n\n<b>ERROR:</b> {e}") return found = await FROZEN.find_one({"plug_name": plugin_name}) if found: await message.edit( f"The plugin <b>[{plugin_name}]</b> is already frozen.", del_in=5) return if os.path.exists(old_): os.rename(old_, new_) await FROZEN.insert_one({"plug_name": plugin_name, "plug_loc": new_}) await message.edit( f"Plugin <b>{plugin_name}</b> got frozen temporarily.\n<b>Bot restarting...</b>" ) await CHANNEL.log( f"Plugin <b>{plugin_name}</b> got frozen temporarily.\n<b>Bot restarting...</b>" ) asyncio.get_event_loop().create_task(userge.restart()) else: await message.edit( f"`The given plugin {plugin_name} doesn't exist...`", del_in=5)
async def set_alive_media(message: Message): """set alive media""" found = await SAVED_SETTINGS.find_one({"_id": "ALIVE_MEDIA"}) if "-c" in message.flags: if found: media_ = found["url"] else: media_ = "https://telegra.ph/file/1fb4c193b5ac0c593f528.jpg" return await message.edit( f"The alive media is set to [<b>THIS</b>]({media_}).") elif "-r" in message.flags: if not found: return await message.edit("`No alive media is set.`", del_in=5) await SAVED_SETTINGS.delete_one({"_id": "ALIVE_MEDIA"}) return await message.edit("`Alive media reset to default.`", del_in=5) reply_ = message.reply_to_message if not reply_: return await message.edit("`Reply to media to set it as alive media.`", del_in=5) type_ = msg_type(reply_) if type_ not in ["gif", "photo"]: return await message.edit("`Reply to media only.`", del_in=5) link_ = await upload_media_(message) whole_link = f"https://telegra.ph{link_}" await SAVED_SETTINGS.update_one({"_id": "ALIVE_MEDIA"}, {"$set": { "url": whole_link }}, upsert=True) await SAVED_SETTINGS.update_one({"_id": "ALIVE_MEDIA"}, {"$set": { "type": type_ }}, upsert=True) link_log = (await reply_.forward(Config.LOG_CHANNEL_ID)).link await message.edit( f"`Alive media set.` [<b>Preview</b>]({link_log})\n`Bot soft restarting, please wait...`", disable_web_page_preview=True, ) asyncio.get_event_loop().create_task(userge.restart())
async def check_update(message: Message): """ check or do updates """ await message.edit("`Checking for updates, please wait....`") flags = list(message.flags) pull_from_repo = False push_to_heroku = False branch = "master" if "pull" in flags: pull_from_repo = True flags.remove("pull") if "push" in flags: if not Config.HEROKU_APP: await message.err("HEROKU APP : could not be found !") return push_to_heroku = True flags.remove("push") if len(flags) == 1: branch = flags[0] repo = Repo() if branch not in repo.branches: await message.err(f'{branch} :geçersiz parametre') return try: out = _get_updates(repo, branch) except GitCommandError as g_e: await message.err(g_e, del_in=5) return if not (pull_from_repo or push_to_heroku): if out: change_log = f'**New UPDATE available for [{branch}]:\n\n📄 CHANGELOG 📄**\n\n' await message.edit_or_send_as_file(change_log + out, disable_web_page_preview=True) else: await message.edit(f'**USERGE-X is up-to-date with [{branch}]**', del_in=5) return if pull_from_repo: if out: await message.edit( f'`New update found for [{branch}], Now pulling...`') await _pull_from_repo(repo, branch) await CHANNEL.log( f"**PULLED update from [{branch}]:\n\n📄 CHANGELOG 📄**\n\n{out}" ) if not push_to_heroku: await message.edit( '**USERGE-X Successfully Updated!**\n' '`Now restarting... Wait for a while!`', del_in=3) asyncio.get_event_loop().create_task(userge.restart(True)) elif push_to_heroku: await _pull_from_repo(repo, branch) else: active = repo.active_branch.name if active == branch: await message.err(f"already in [{branch}]!") return await message.edit( f'`Moving HEAD from [{active}] >>> [{branch}] ...`', parse_mode='md') await _pull_from_repo(repo, branch) await CHANNEL.log(f"`Moved HEAD from [{active}] >>> [{branch}] !`") await message.edit('`Now restarting... Wait for a while!`', del_in=3) asyncio.get_event_loop().create_task(userge.restart()) if push_to_heroku: await _push_to_heroku(message, repo, branch)
async def check_update(message: Message): """ check or do updates """ await message.edit("`Memeriksa update terbaru KampangUsergay....`") if Config.HEROKU_ENV: await message.edit( "**Heroku App terdeteksi !**, Hahaha mampus ke suspen lu 😂.\n" "Yaaah heroku lu ke suspen , salah siapa update hahaha") return flags = list(message.flags) pull_from_repo = False push_to_heroku = False branch = "alpha" if "pull" in flags: pull_from_repo = True flags.remove("pull") if "push" in flags: if not Config.HEROKU_APP: await message.err("HEROKU APP : could not be found !") return # push_to_heroku = True # flags.remove("push") if len(flags) == 1: branch = flags[0] repo = Repo() if branch not in repo.branches: await message.err(f"invalid branch name : {branch}") return try: out = _get_updates(repo, branch) except GitCommandError as g_e: if "128" in str(g_e): system( f"git fetch {Config.UPSTREAM_REMOTE} {branch} && git checkout -f {branch}" ) out = _get_updates(repo, branch) else: await message.err(g_e, del_in=5) return if not (pull_from_repo or push_to_heroku): if out: change_log = ( f"**Update Terbaru KampangUsergay 🐨 [{branch}]:\n\n📄 CHANGELOG 📄**\n\n" ) await message.edit_or_send_as_file(change_log + out, disable_web_page_preview=True) else: await message.edit( f"**KampangUsergay is up-to-date with [{branch}]**", del_in=5) return if pull_from_repo: if out: await message.edit( f"`New update found for [{branch}], Proses Suspen Heroku Anda...`" ) await _pull_from_repo(repo, branch) await CHANNEL.log( f"**PULLED update from [{branch}]:\n\n📄 CHANGELOG 📄**\n\n{out}" ) if not push_to_heroku: await message.edit( "**KampangUsergay Successfully Updated!**\n" "`Now restarting... Wait for a while!`", del_in=3, ) asyncio.get_event_loop().create_task(userge.restart(True)) elif push_to_heroku: await _pull_from_repo(repo, branch) else: active = repo.active_branch.name if active == branch: await message.err(f"already in [{branch}]!") return await message.edit( f"`Moving HEAD from [{active}] >>> [{branch}] ...`", parse_mode="md") await _pull_from_repo(repo, branch) await CHANNEL.log(f"`Moved HEAD from [{active}] >>> [{branch}] !`") await message.edit("`Now restarting... Wait for a while!`", del_in=3) asyncio.get_event_loop().create_task(userge.restart()) if push_to_heroku: await _push_to_heroku(message, repo, branch)
async def check_update(message: Message): """ check or do updates """ await message.edit("`Checking for updates, please wait....`") repo = Repo() ups_rem = repo.remote(Config.UPSTREAM_REMOTE) try: ups_rem.fetch() except GitCommandError as error: await message.err(error, del_in=5) return for ref in ups_rem.refs: branch = str(ref).split('/')[-1] if branch not in repo.branches: repo.create_head(branch, ref) flags = list(message.flags) pull_from_repo = False push_to_heroku = False branch = "master" if "pull" in flags: pull_from_repo = True flags.remove("pull") if "push" in flags: push_to_heroku = True flags.remove("push") if len(flags) == 1: branch = flags[0] if branch not in repo.branches: await message.err(f'invalid branch name : {branch}') return out = '' try: for i in repo.iter_commits(f'HEAD..{Config.UPSTREAM_REMOTE}/{branch}'): out += ( f"🔨 **#{i.count()}** : " f"[{i.summary}]({Config.UPSTREAM_REPO.rstrip('/')}/commit/{i}) " f"👷 __{i.author}__\n\n") except GitCommandError as error: await message.err(error, del_in=5) return if out: if pull_from_repo: await message.edit( f'`New update found for [{branch}], Now pulling...`') await asyncio.sleep(1) repo.git.reset('--hard', 'FETCH_HEAD') await CHANNEL.log( f"**PULLED update from [{branch}]:\n\n📄 CHANGELOG 📄**\n\n{out}" ) elif not push_to_heroku: changelog_str = f'**New UPDATE available for [{branch}]:\n\n📄 CHANGELOG 📄**\n\n' await message.edit_or_send_as_file(changelog_str + out, disable_web_page_preview=True) return elif not push_to_heroku: await message.edit(f'**Userge is up-to-date with [{branch}]**', del_in=5) return if not push_to_heroku: await message.edit( '**Userge Successfully Updated!**\n' '`Now restarting... Wait for a while!`', del_in=3) asyncio.get_event_loop().create_task(userge.restart(update_req=True)) return if not Config.HEROKU_GIT_URL: await message.err("please set heroku things...") return await message.edit( f'`Now pushing updates from [{branch}] to heroku...\n' 'this will take upto 5 min`\n\n' f'* **Restart** after 5 min using `{Config.CMD_TRIGGER}restart -h`\n\n' '* After restarted successfully, check updates again :)') if "heroku" in repo.remotes: remote = repo.remote("heroku") remote.set_url(Config.HEROKU_GIT_URL) else: remote = repo.create_remote("heroku", Config.HEROKU_GIT_URL) remote.push(refspec=f'{branch}:master', force=True) await message.edit( f"**HEROKU APP : {Config.HEROKU_APP.name} is up-to-date with [{branch}]**" )
async def check_update(message: Message): """ check or do updates """ await message.edit("`Checking for updates, please wait....`") repo = Repo() try: repo.remote(Config.UPSTREAM_REMOTE).fetch() except GitCommandError as error: await message.err(error, del_in=5) return flags = list(message.flags) pull_from_repo = False push_to_heroku = False branch = "alpha" if "pull" in flags: pull_from_repo = True flags.remove("pull") if "push" in flags: push_to_heroku = True flags.remove("push") if len(flags) == 1: branch = flags[0] if branch not in repo.branches: await message.err(f'invalid branch name : {branch}') return out = '' try: for i in repo.iter_commits(f'HEAD..{Config.UPSTREAM_REMOTE}/{branch}'): out += (f"🔨 **#{i.count()}** : " f"[{i.summary}]({Config.UPSTREAM_REPO.rstrip('/')}/commit/{i}) " f"👷 __{i.author}__\n\n") except GitCommandError as error: await message.err(error, del_in=5) return if out: if pull_from_repo: await message.edit(f'`New update found for [{branch}], Now pulling...`') await asyncio.sleep(1) repo.git.checkout(branch, force=True) repo.git.reset('--hard', branch) repo.git.pull(Config.UPSTREAM_REMOTE, branch, force=True) await CHANNEL.log(f"**PULLED update from [{branch}]:\n\n📄 CHANGELOG 📄**\n\n{out}") elif not push_to_heroku: changelog_str = f'**New UPDATE available for [{branch}]:\n\n📄 CHANGELOG 📄**\n\n' await message.edit_or_send_as_file(changelog_str + out, disable_web_page_preview=True) return elif not push_to_heroku: if pull_from_repo: active = repo.active_branch.name await message.edit( f'`Moving HEAD from [{active}] >>> [{branch}] ...`', parse_mode='md') await asyncio.sleep(1) repo.git.checkout(branch, force=True) repo.git.reset('--hard', branch) await CHANNEL.log(f"`Moved HEAD from [{active}] >>> [{branch}] !`") await message.edit('`Now restarting... Wait for a while!`', del_in=3) asyncio.get_event_loop().create_task(userge.restart()) else: await message.edit(f'**USERGE-X is up-to-date with [{branch}]**', del_in=5) return if not push_to_heroku: await message.edit( '**USERGE-X Successfully Updated!**\n' '`Now restarting... Wait for a while!`', del_in=3) asyncio.get_event_loop().create_task(userge.restart(True)) return if not Config.HEROKU_APP: await message.err("HEROKU APP : could not be found !") return sent = await message.edit( f'`Now pushing updates from [{branch}] to heroku...\n' 'this will take upto 5 min`\n\n' f'* **Restart** after 5 min using `{Config.CMD_TRIGGER}restart -h`\n\n' '* After restarted successfully, check updates again :)') try: await _push_to_heroku(sent, branch) except GitCommandError as g_e: LOG.exception(g_e) await sent.err(f"{g_e}, {Config.CMD_TRIGGER}restart -h and try again!") else: await sent.edit(f"**HEROKU APP : {Config.HEROKU_APP.name} is up-to-date with [{branch}]**")
async def check_update(message: Message): """ check or do updates """ await message.edit("`Verificando atualizações, por favor aguarde....`") flags = list(message.flags) pull_from_repo = False push_to_heroku = False branch = "master" if "pull" in flags: pull_from_repo = True flags.remove("pull") if "push" in flags: if not Config.HEROKU_APP: await message.err("HEROKU APP : could not be found !") return push_to_heroku = True flags.remove("push") if len(flags) == 1: branch = flags[0] dev_branch = "alpha" if branch == dev_branch: await message.err( 'Não é possivel atualizar para instável [alpha] branch. ' 'Por favor, use outra branch ao invés !') return repo = Repo() if branch not in repo.branches: await message.err(f'nome de branch inválido : {branch}') return try: out = _get_updates(repo, branch) except GitCommandError as g_e: await message.err(g_e, del_in=5) return if not (pull_from_repo or push_to_heroku): if out: change_log = f'**Novo UPDATE disponível para [{branch}]:\n\n📄 CHANGELOG 📄**\n\n' await message.edit_or_send_as_file(change_log + out, disable_web_page_preview=True) else: await message.edit(f'**Userge está atualizado com [{branch}]**', del_in=5) return if pull_from_repo: if out: await message.edit( f'`Nova atualização encontrada para [{branch}], Agora puxando...`' ) await _pull_from_repo(repo, branch) await CHANNEL.log( f"**PULLED atualização de [{branch}]:\n\n📄 CHANGELOG 📄**\n\n{out}" ) if not push_to_heroku: await message.edit( '**Userge atualizado com sucesso!**\n' '`Agora reiniciando ... Aguarde um pouco!`', del_in=3) asyncio.get_event_loop().create_task(userge.restart(True)) elif push_to_heroku: await _pull_from_repo(repo, branch) else: active = repo.active_branch.name if active == branch: await message.err(f"Já está em [{branch}]!") return await message.edit( f'`Movendo HEAD de [{active}] >>> [{branch}] ...`', parse_mode='md') await _pull_from_repo(repo, branch) await CHANNEL.log(f"`Moveu HEAD de [{active}] >>> [{branch}] !`") await message.edit('`Agora reiniciando ... Aguarde um pouco!`', del_in=3) asyncio.get_event_loop().create_task(userge.restart()) if push_to_heroku: await _push_to_heroku(message, repo, branch)
async def check_update(message: Message): """check or do updates""" await message.edit("`Checking for updates, please wait....`") try: repo = Repo() except InvalidGitRepositoryError: repo = Repo.init() if UPSTREAM_REMOTE in repo.remotes: ups_rem = repo.remote(UPSTREAM_REMOTE) else: ups_rem = repo.create_remote(UPSTREAM_REMOTE, Config.UPSTREAM_REPO) ups_rem.fetch() for ref in ups_rem.refs: branch = str(ref).split('/')[-1] if branch not in repo.branches: repo.create_head(branch, ref) flags = list(message.flags) if "run" in flags: run_updater = True flags.remove("run") else: run_updater = False if len(flags) == 1: branch = flags[0] else: branch = repo.active_branch.name if branch not in repo.branches: await message.err(f'invalid branch name : {branch}') return out = '' try: for i in repo.iter_commits(f'HEAD..{UPSTREAM_REMOTE}/{branch}'): out += f"🔨 **#{i.count()}** : [{i.summary}]({Config.UPSTREAM_REPO.rstrip('/')}/commit/{i}) " + \ f"👷 __{i.committer}__\n\n" except GitCommandError as error: await message.err(error, del_in=5) return if not out: await message.edit(f'**Userge is up-to-date with [{branch}]**', del_in=5) return if not run_updater: changelog_str = f'**New UPDATE available for [{branch}]:\n\n📄 CHANGELOG 📄**\n\n' await message.edit_or_send_as_file(changelog_str + out, disable_web_page_preview=True) else: await message.edit( f'`New update found for [{branch}], trying to update...`') repo.git.reset('--hard', 'FETCH_HEAD') await CHANNEL.log( f"**UPDATING Userge from [{branch}]:\n\n📄 CHANGELOG 📄**\n\n{out}" ) if Config.HEROKU_GIT_URL: await message.edit( '`Heroku app found, pushing update...\nthis will take upto 1 min`', del_in=3) if "heroku" in repo.remotes: remote = repo.remote("heroku") remote.set_url(Config.HEROKU_GIT_URL) else: remote = repo.create_remote("heroku", Config.HEROKU_GIT_URL) remote.push(refspec=f'{branch}:master', force=True) else: await message.edit( '**Userge Successfully Updated!**\n' '__Now restarting... Wait for a while!__`', del_in=3) asyncio.get_event_loop().create_task(userge.restart())
async def check_update(message: Message): """ check or do updates """ await message.edit("`Checking for updates, please wait....`") if Config.HEROKU_ENV: await message.edit( "**Heroku App detected !**, Updates have been disabled for Safety.\n" "Your Bot Will Auto Update when Heroku restart") return flags = list(message.flags) pull_from_repo = False push_to_heroku = False branch = "alpha" if "pull" in flags: pull_from_repo = True flags.remove("pull") if "push" in flags: if not Config.HEROKU_APP: await message.err("HEROKU APP : could not be found !") return # push_to_heroku = True # flags.remove("push") if len(flags) == 1: branch = flags[0] repo = Repo() if branch not in repo.branches: await message.err(f"invalid branch name : {branch}") return try: out = _get_updates(repo, branch) except GitCommandError as g_e: if "128" in str(g_e): system( f"git fetch {Config.UPSTREAM_REMOTE} {branch} && git checkout -f {branch}" ) out = _get_updates(repo, branch) else: await message.err(g_e, del_in=5) return if not (pull_from_repo or push_to_heroku): if out: change_log = ( f"**New UPDATE available for [{branch}]:\n\n📄 CHANGELOG 📄**\n\n" ) await message.edit_or_send_as_file(change_log + out, disable_web_page_preview=True) else: await message.edit(f"**USERGE-X is up-to-date with [{branch}]**", del_in=5) return if pull_from_repo: if out: await message.edit( f"`New update found for [{branch}], Now pulling...`") await _pull_from_repo(repo, branch) await CHANNEL.log( f"**PULLED update from [{branch}]:\n\n📄 CHANGELOG 📄**\n\n{out}" ) if not push_to_heroku: await message.edit( "**USERGE-X Successfully Updated!**\n" "`Now restarting... Wait for a while!`", del_in=3, ) asyncio.get_event_loop().create_task(userge.restart(True)) elif push_to_heroku: await _pull_from_repo(repo, branch) else: active = repo.active_branch.name if active == branch: await message.err(f"already in [{branch}]!") return await message.edit( f"`Moving HEAD from [{active}] >>> [{branch}] ...`", parse_mode="md") await _pull_from_repo(repo, branch) await CHANNEL.log(f"`Moved HEAD from [{active}] >>> [{branch}] !`") await message.edit("`Now restarting... Wait for a while!`", del_in=3) asyncio.get_event_loop().create_task(userge.restart()) if push_to_heroku: await _push_to_heroku(message, repo, branch)
async def check_update(message: Message): """check or do updates""" await message.edit("`Checking for updates, please wait....`") if Config.HEROKU_ENV: await message.edit( "**Heroku App detected !** Updates have been disabled for Safety.\n" f"To check changelog do `{Config.CMD_TRIGGER}fetchup`, and to pull updates do `{Config.CMD_TRIGGER}restart -h`." ) return flags = list(message.flags) pull_from_repo = False push_to_heroku = False branch = "alpha" u_repo = Config.UPSTREAM_REPO u_repo = u_repo.replace("/", " ") git_u_n = u_repo.split()[2] if "pull" in flags: pull_from_repo = True flags.remove("pull") if "push" in flags: if not Config.HEROKU_APP: await message.err("HEROKU APP : could not be found !") return # push_to_heroku = True # flags.remove("push") if "pr" in flags: branch = "master" out = _get_updates_pr(git_u_n, branch) if "prp" in flags: await message.edit("Updating <b><u>Userge-Plugins</u></b>...", log=__name__) await runcmd("bash run") asyncio.get_event_loop().create_task(userge.restart()) if len(flags) == 1: branch = flags[0] repo = Repo() if branch not in repo.branches: await message.err(f"invalid branch name : {branch}") return try: out = _get_updates(repo, branch) except GitCommandError as g_e: if "128" in str(g_e): system( f"git fetch {Config.UPSTREAM_REMOTE} {branch} && git checkout -f {branch}" ) out = _get_updates(repo, branch) else: await message.err(g_e, del_in=5) return if not (pull_from_repo or push_to_heroku): if out: change_log = ( f"**New UPDATE available for [{branch}]:\n\n📄 CHANGELOG 📄**\n\n" ) await message.edit_or_send_as_file(change_log + out, disable_web_page_preview=True) else: await message.edit(f"**USERGE-X is up-to-date with [{branch}]**", del_in=5) return if pull_from_repo: if out: await message.edit( f"`New update found for [{branch}], Now pulling...`") await _pull_from_repo(repo, branch) await CHANNEL.log( f"**PULLED update from [{branch}]:\n\n📄 CHANGELOG 📄**\n\n{out}" ) if not push_to_heroku: update = await message.edit( "**USERGE-X update process started!**\n" "`Now restarting... Wait for a while!`", ) be_update = time() await UPDATE_MSG.update_one( {"_id": "UPDATE_MSG"}, { "$set": { "message": f"{update.chat.id}/{update.message_id}" } }, upsert=True, ) await UPDATE_MSG.update_one({"_id": "UPDATE_MSG"}, {"$set": { "time": be_update }}, upsert=True) await UPDATE_MSG.update_one({"_id": "UPDATE_MSG"}, {"$set": { "process": "updated" }}, upsert=True) asyncio.get_event_loop().create_task(userge.restart(True)) elif push_to_heroku: await _pull_from_repo(repo, branch) else: active = repo.active_branch.name if active == branch: await message.err(f"already in [{branch}]!") return await message.edit( f"`Moving HEAD from [{active}] >>> [{branch}] ...`", parse_mode="md") await _pull_from_repo(repo, branch) await CHANNEL.log(f"`Moved HEAD from [{active}] >>> [{branch}] !`") await message.edit("`Now restarting... Wait for a while!`", del_in=3) asyncio.get_event_loop().create_task(userge.restart()) if push_to_heroku: await _push_to_heroku(message, repo, branch)