def main(): test_handler = CommandHandler("", 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("تنظیمات", get_settings) settings_callback_handler = CallbackQueryHandler(settings_button, pattern=r"stngs_") 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(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) # add antiflood processor Dispatcher.process_update = process_update 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) updater.idle()
def main(): # 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) about_handler = CommandHandler("about", about, pass_args=True) settings_callback_handler = CallbackQueryHandler(settings_button, pattern=r"stngs_") 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(settings_handler) dispatcher.add_handler(help_callback_handler) dispatcher.add_handler(settings_callback_handler) dispatcher.add_handler(migrate_handler) dispatcher.add_handler(about_handler) # dispatcher.add_error_handler(error_callback) # add antiflood processor Dispatcher.process_update = process_update if WEBHOOK: LOGGER.info(get_string("main", "WEBHOOKS", DEFAULT_LANG)) # 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(get_string("main", "LONG_POLLING", DEFAULT_LANG)) # LONG_POLLING updater.start_polling(timeout=15, read_latency=4) updater.idle()
def main(): # 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) updater.idle()
def main(): 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_") 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(settings_handler) dispatcher.add_handler(help_callback_handler) dispatcher.add_handler(settings_callback_handler) dispatcher.add_handler(migrate_handler) dispatcher.add_handler(donate_handler) 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) if len(argv) not in (1, 3, 4): telethn.disconnect() else: telethn.run_until_disconnected() updater.idle()
def main(): test_handler = MessageHandler(Filters.all, test, edited_updates=True, message_updates=False) start_handler = CommandHandler("start", start, pass_args=True) help_handler = CommandHandler("help", get_help) help_callback_handler = CallbackQueryHandler(help_button, pattern=r"help_") 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(help_callback_handler) dispatcher.add_handler(migrate_handler) dispatcher.add_handler(donate_handler) # dispatcher.add_error_handler(error_callback) if WEBHOOK: print("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: print("Using long polling.") updater.start_polling(timeout=15, read_latency=4) updater.idle()
def main(): dispatcher.add_error_handler(error_callback) # dispatcher.add_error_handler(error_handler) if WEBHOOK: log.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: log.info(f"Kigyo started, Using long polling. | BOT: [@{dispatcher.bot.username}]") KigyoINIT.bot_id = dispatcher.bot.id KigyoINIT.bot_username = dispatcher.bot.username KigyoINIT.bot_name = dispatcher.bot.first_name updater.start_polling(timeout=15, read_latency=4, allowed_updates=Update.ALL_TYPES, drop_pending_updates=KInit.DROP_UPDATES) if len(argv) not in (1, 3, 4): telethn.disconnect() else: telethn.run_until_disconnected() updater.idle()
def main(): test_handler = CommandHandler("test", test) start_handler = CommandHandler("start", start, pass_args=True) start_callback_handler = CallbackQueryHandler(send_start, pattern=r"bot_start") dispatcher.add_handler(start_callback_handler) 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) migrate_handler = MessageHandler(Filters.status_update.migrate, migrate_chats) M_CONNECT_BTN_HANDLER = CallbackQueryHandler(m_connect_button, pattern=r"main_connect") # 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_handler(M_CONNECT_BTN_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("Bot is running...") updater.start_polling(timeout=15, read_latency=4) # if len(argv) not in (1, 3, 4): # tbot.disconnect() # else: # tbot.run_until_disconnected() updater.idle()
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) updater.idle() CHATS_CNT = {} CHATS_TIME = {} def process_update(self, update): # An error happened while polling if isinstance(update, TelegramError): try: self.dispatch_error(None, update) except Exception: self.logger.exception('An uncaught error was raised while handling the error') return
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) updater.idle() if __name__ == '__main__': LOGGER.info("Successfully loaded modules: " + str(ALL_MODULES)) main()