def main(): # test_handler = CommandHandler("test", test) #Unused variable start_handler = CommandHandler("start", start, pass_args=True) help_handler = CommandHandler("help", get_help) help_callback_handler = CallbackQueryHandler(help_button, pattern=r"help_") start_callback_handler = CallbackQueryHandler(send_start, pattern=r"bot_start") dispatcher.add_handler(start_callback_handler) cntrl_panel = CommandHandler("controlpanel", control_panel) cntrl_panel_callback_handler = CallbackQueryHandler(control_panel, pattern=r"cntrl_panel") dispatcher.add_handler(cntrl_panel_callback_handler) dispatcher.add_handler(cntrl_panel) settings_handler = CommandHandler("settings", get_settings) settings_callback_handler = CallbackQueryHandler(settings_button, pattern=r"stngs_") migrate_handler = MessageHandler(Filters.status_update.migrate, migrate_chats) source_handler = CommandHandler("source", source) # dispatcher.add_handler(test_handler) dispatcher.add_handler(start_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(source_handler) # dispatcher.add_error_handler(error_callback) # add antiflood processor Dispatcher.process_update = process_update if WEBHOOK: LOGGER.info("Using webhooks.") updater.start_webhook(listen="127.0.0.1", 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) updater.start_polling(poll_interval=0.0, timeout=10, clean=True, bootstrap_retries=-1, read_latency=3.0) updater.idle()
def main(): 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_") source_handler = CommandHandler("source", source) M_CONNECT_BTN_HANDLER = CallbackQueryHandler(m_connect_button, pattern=r"main_connect") M_SETLANG_BTN_HANDLER = CallbackQueryHandler(m_change_langs, pattern=r"main_setlang") # dispatcher.add_handler(test_handler) dispatcher.add_handler(start_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(source_handler) dispatcher.add_handler(M_CONNECT_BTN_HANDLER) dispatcher.add_handler(M_SETLANG_BTN_HANDLER) # dispatcher.add_error_handler(error_callback) if WEBHOOK: LOGGER.info("Using webhooks.") updater.start_webhook(listen="127.0.0.1", 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) updater.idle()
def main(): # test_handler = CommandHandler("test", test) #Unused variable start_handler = CommandHandler("start", start, pass_args=True) help_handler = CommandHandler("help", get_help) help_callback_handler = CallbackQueryHandler(help_button, pattern=r"help_") start_callback_handler = CallbackQueryHandler(send_start, pattern=r"bot_start") migrate_handler = MessageHandler(Filters.status_update.migrate, migrate_chats) # dispatcher.add_handler(test_handler) dispatcher.add_handler(start_handler) dispatcher.add_handler(start_callback_handler) dispatcher.add_handler(help_handler) dispatcher.add_handler(help_callback_handler) dispatcher.add_handler(migrate_handler) # dispatcher.add_error_handler(error_callback) # add antiflood processor Dispatcher.process_update = process_update LOGGER.info("Using long polling.") # updater.start_polling(timeout=15, read_latency=4, clean=True) updater.start_polling(poll_interval=0.0, timeout=10, clean=True, bootstrap_retries=-1, read_latency=3.0) LOGGER.info("Successfully loaded") if len(argv) not in (1, 3, 4): tbot.disconnect() else: tbot.run_until_disconnected() updater.idle()