def main(): if SUPPORT_CHAT is not None and isinstance(SUPPORT_CHAT, str): try: dispatcher.bot.sendMessage(f"@{SUPPORT_CHAT}", "Me the sage of the six paths is back to serve you.✨") 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) 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(Masha_about_callback, pattern=r"masha_") source_callback_handler = CallbackQueryHandler(Source_about_callback, pattern=r"source_") donate_handler = CommandHandler("donate", donate) migrate_handler = MessageHandler(Filters.status_update.migrate, migrate_chats) # dispatcher.add_handler(test_handler) dispatcher.add_handler(start_handler) dispatcher.add_handler(help_handler) dispatcher.add_handler(about_callback_handler) dispatcher.add_handler(source_callback_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(donate_handler) dispatcher.add_error_handler(error_callback) 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) else: LOGGER.info("Using long polling.") updater.start_polling(timeout=15, read_latency=4, clean=True) if len(argv) not in (1, 3, 4): telethn.disconnect() else: telethn.run_until_disconnected() updater.idle()
) def list_errors(update: Update, context: CallbackContext): if update.effective_user.id not in DEV_USERS: return e = { k: v for k, v in sorted( errors.items(), key=lambda item: item[1], reverse=True) } msg = "<b>Errors List:</b>\n" for x in e: msg += f"• <code>{x}:</code> <b>{e[x]}</b> #{x.identifier}\n" msg += f"{len(errors)} have occurred since startup." if len(msg) > 4096: with open("errors_msg.txt", "w+") as f: f.write(msg) context.bot.send_document( update.effective_chat.id, open("errors_msg.txt", "rb"), caption=f"Too many errors have occured..", parse_mode="html", ) return update.effective_message.reply_text(msg, parse_mode="html") dispatcher.add_error_handler(error_callback) dispatcher.add_handler(CommandHandler("errors", list_errors))