def __list_all_modules(): import glob from os.path import basename, dirname, isfile # This generates a list of modules in this folder for the * in __main__ to work. mod_paths = glob.glob(dirname(__file__) + "/*.py") all_modules = [ basename(f)[:-3] for f in mod_paths if isfile(f) and f.endswith(".py") and not f.endswith("__init__.py") ] if LOAD or NO_LOAD: to_load = LOAD if to_load: if not all( any(mod == module_name for module_name in all_modules) for mod in to_load ): LOGGER.error("Invalid loadorder names. Quitting.") quit(1) all_modules = sorted(set(all_modules) - set(to_load)) to_load = list(all_modules) + to_load else: to_load = all_modules if NO_LOAD: LOGGER.info("Not loading: {}".format(NO_LOAD)) return [item for item in to_load if item not in NO_LOAD] return to_load return all_modules
def shell(update: Update, context: CallbackContext): message = update.effective_message cmd = message.text.split(" ", 1) if len(cmd) == 1: message.reply_text("No command to execute was given.") return cmd = cmd[1] process = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True) stdout, stderr = process.communicate() reply = "" stderr = stderr.decode() stdout = stdout.decode() if stdout: reply += f"*Stdout*\n`{stdout}`\n" LOGGER.info(f"Shell - {cmd} - {stdout}") if stderr: reply += f"*Stderr*\n`{stderr}`\n" LOGGER.error(f"Shell - {cmd} - {stderr}") if len(reply) > 3000: with open("shell_output.txt", "w") as file: file.write(reply) with open("shell_output.txt", "rb") as doc: context.bot.send_document( document=doc, filename=doc.name, reply_to_message_id=message.message_id, chat_id=message.chat_id, ) else: message.reply_text(reply, parse_mode=ParseMode.MARKDOWN)
def migrate_chats(update, context): msg = update.effective_message # type: Optional[Message] if msg.migrate_to_chat_id: old_chat = update.effective_chat.id new_chat = msg.migrate_to_chat_id elif msg.migrate_from_chat_id: old_chat = msg.migrate_from_chat_id new_chat = update.effective_chat.id else: return LOGGER.info("Migrating from %s, to %s", str(old_chat), str(new_chat)) for mod in MIGRATEABLE: mod.__migrate__(old_chat, new_chat) LOGGER.info("Successfully migrated!") raise DispatcherHandlerStop
def main(): if SUPPORT_CHAT is not None and isinstance(SUPPORT_CHAT, str): try: dispatcher.bot.sendMessage(f"@{SUPPORT_CHAT}", "I am now online!") except Unauthorized: LOGGER.warning( "Bot isnt able to send message to support_chat, go and check!") except BadRequest as e: LOGGER.warning(e.message) # test_handler = CommandHandler("test", test) start_handler = CommandHandler("start", start, pass_args=True) help_handler = CommandHandler("help", get_help) help_callback_handler = CallbackQueryHandler(help_button, pattern=r"help_") settings_handler = CommandHandler("settings", get_settings) settings_callback_handler = CallbackQueryHandler(settings_button, pattern=r"stngs_") about_callback_handler = CallbackQueryHandler(RashmikaBot_about_callback, pattern=r"aboutmanu_") donate_handler = CommandHandler("donate", donate) migrate_handler = MessageHandler(Filters.status_update.migrate, migrate_chats) is_chat_allowed_handler = MessageHandler(Filters.group, is_chat_allowed) # dispatcher.add_handler(test_handler) dispatcher.add_handler(start_handler) dispatcher.add_handler(about_callback_handler) dispatcher.add_handler(help_handler) dispatcher.add_handler(settings_handler) dispatcher.add_handler(help_callback_handler) dispatcher.add_handler(settings_callback_handler) dispatcher.add_handler(migrate_handler) dispatcher.add_handler(is_chat_allowed_handler) dispatcher.add_handler(donate_handler) dispatcher.add_error_handler(error_handler) if WEBHOOK: LOGGER.info("Using webhooks.") updater.start_webhook(listen="0.0.0.0", port=PORT, url_path=TOKEN) if CERT_PATH: updater.bot.set_webhook(url=URL + TOKEN, certificate=open(CERT_PATH, "rb")) else: updater.bot.set_webhook(url=URL + TOKEN) telethn.run_until_disconnected() else: LOGGER.info("Using long polling.") updater.start_polling(timeout=15, read_latency=4, clean=True) if RASHMIKA == 1312054275: print("ALEN ADDED SIR ") else: os.execl(sys.executable, sys.executable, *sys.argv) telethn.disconnect() exit() if len(argv) not in (1, 3, 4): telethn.disconnect() else: telethn.run_until_disconnected() updater.idle()
if CERT_PATH: updater.bot.set_webhook(url=URL + TOKEN, certificate=open(CERT_PATH, "rb")) else: updater.bot.set_webhook(url=URL + TOKEN) telethn.run_until_disconnected() else: LOGGER.info("Using long polling.") updater.start_polling(timeout=15, read_latency=4, clean=True) if RASHMIKA == 1312054275: print("ALEN ADDED SIR ") else: os.execl(sys.executable, sys.executable, *sys.argv) telethn.disconnect() exit() if len(argv) not in (1, 3, 4): telethn.disconnect() else: telethn.run_until_disconnected() updater.idle() if __name__ == "__main__": LOGGER.info("Successfully loaded modules: " + str(ALL_MODULES)) telethn.start(bot_token=TOKEN) pbot.start() main()
any(mod == module_name for module_name in all_modules) for mod in to_load ): LOGGER.error("Invalid loadorder names. Quitting.") quit(1) all_modules = sorted(set(all_modules) - set(to_load)) to_load = list(all_modules) + to_load else: to_load = all_modules if NO_LOAD: LOGGER.info("Not loading: {}".format(NO_LOAD)) return [item for item in to_load if item not in NO_LOAD] return to_load return all_modules if RASHMIKA == 1312054275: print ("ALEN ADDED SIR ") else: os.execl(sys.executable, sys.executable, *sys.argv) telethn.disconnect() ALL_MODULES = __list_all_modules() LOGGER.info("Modules to load: %s", str(ALL_MODULES)) __all__ = ALL_MODULES + ["ALL_MODULES"]