Python telegram.ext.CallbackQueryHandler() Examples
The following are 18
code examples of telegram.ext.CallbackQueryHandler().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
telegram.ext
, or try the search function
.
Example #1
Source File: update_rank_list.py From superCodingBot with MIT License | 6 votes |
def __init__(self, mount_point, fallback): self.mount_point = mount_point self.fallback = fallback self.rating_obj = ratings.Rating() self.utility = Utility(mount_point) self.conv_handler = ConversationHandler( entry_points=[CommandHandler('update', self.updatesel)], allow_reentry=True, states={ UPDA: [CallbackQueryHandler(self.updasel, pattern=r'\w*upd5\b')] }, fallbacks=[fallback] )
Example #2
Source File: compiler.py From superCodingBot with MIT License | 6 votes |
def __init__(self, api_key, fallback): self.compiler = HackerRankAPI(api_key=api_key) self.conv_handler = ConversationHandler( entry_points=[CommandHandler('compiler', self.compilers)], allow_reentry=True, states={ LANG: [CallbackQueryHandler(self.lang, pass_user_data=True, pattern=r'\w*comp1\b')], CODE: [CallbackQueryHandler(self.code, pass_user_data=True, pattern=r'\w*so1\b')], DECODE: [MessageHandler(Filters.text, self.decode, pass_user_data=True)], TESTCASES: [MessageHandler(Filters.text, self.testcases, pass_user_data=True)], OTHER: [MessageHandler(Filters.text, self.other, pass_user_data=True)], FILE: [MessageHandler(Filters.document, self.filer, pass_user_data=True)], FILETEST: [MessageHandler(Filters.document, self.filetest, pass_user_data=True)] }, fallbacks=[fallback] )
Example #3
Source File: codeforces.py From superCodingBot with MIT License | 6 votes |
def __init__(self, mount_point, fallback): if not os.path.exists(mount_point + 'codeforces.json'): shutil.copy('codeforces.json', mount_point + 'codeforces.json') with open(mount_point + 'codeforces.json', 'r') as codeforces: self.qcf = json.load(codeforces) self.conv_handler10 = ConversationHandler( entry_points=[CommandHandler('randomcf', self.randomcf)], allow_reentry=True, states={ QSELCF: [CallbackQueryHandler(self.qselcf, pattern=r'\w*cf1\b')] }, fallbacks=[fallback] ) # START OF CONVERSATION HANDLER FOR GETTING RANDOM QUESTION FROM CODEFORCES # FUNCTION TO GET INPUT ABOUT THE TYPE OF QUESTION FROM USER
Example #4
Source File: ques_of_the_day.py From superCodingBot with MIT License | 6 votes |
def __init__(self, mount_point, fallback): self.mount_point = mount_point self.conv_handler = ConversationHandler( entry_points=[CommandHandler('subscribe', self.subscribe)], allow_reentry=True, states={ SUBSEL: [CallbackQueryHandler(self.subsel, pattern=r'\w*sub3\b', pass_user_data=True)], SUB: [CallbackQueryHandler(self.sub, pattern=r'\w*sub2\b', pass_user_data=True)] }, fallbacks=[fallback] ) self.conv_handler1 = ConversationHandler( entry_points=[CommandHandler('unsubscribe', self.unsubsel)], allow_reentry=True, states={ UNSUB: [CallbackQueryHandler(self.unsub, pattern=r'\w*unsub4\b')] }, fallbacks=[fallback] )
Example #5
Source File: telegram_main.py From convai-bot-1337 with GNU General Public License v3.0 | 6 votes |
def __init__(self, token): self._bot = telegram.Bot(token) self._updater = Updater(bot=self._bot) dp = self._updater.dispatcher dp.add_handler(CommandHandler("start", self._start_cmd)) dp.add_handler(CommandHandler("reset", self._reset_cmd)) dp.add_handler(CommandHandler("stop", self._reset_cmd)) dp.add_handler(CommandHandler("help", self._help_cmd)) dp.add_handler(CommandHandler("text", self._text_cmd)) dp.add_handler(CommandHandler("evaluation_start", self._evaluation_start_cmd)) dp.add_handler(CommandHandler("evaluation_end", self._evaluation_end_cmd)) dp.add_handler(MessageHandler(Filters.text, self._echo_cmd)) dp.add_handler(CallbackQueryHandler(self._eval_keyboard)) dp.add_error_handler(self._error) self._users_fsm = {} self._users = {} self._text_and_qas = load_text_and_qas('data/squad-25-qas.json') self._text_ind = 0 self._evaluation = {} self._eval_suggestions = None
Example #6
Source File: competitions.py From superCodingBot with MIT License | 6 votes |
def __init__(self, clist_user_name, clist_api_key, mount_point, bot, fallback): self.clist_user_name = clist_user_name self.clist_api_key = clist_api_key self.bot = bot self.ong = None self.upc = None self.mount_point = mount_point self.utility = ContestUtility(mount_point) self.jobstores = { 'default': SQLAlchemyJobStore(url='sqlite:///' + mount_point + 'coders1.db') } self.schedule = BackgroundScheduler(jobstores=self.jobstores) self.schedule.start() self.conv_handler = ConversationHandler( entry_points=[CommandHandler('upcoming', self.upcoming)], allow_reentry=True, states={ SCHED: [CallbackQueryHandler(self.remind, pattern=r"^[0-9]*$")] }, fallbacks=[fallback] ) self.conv_handler1 = ConversationHandler( entry_points=[CommandHandler('dontRemindMe', self.removeRemind)], allow_reentry=True, states={ REMNOTI: [CallbackQueryHandler(self.remnoti, pattern=r'^.*notiplz.*$')] }, fallbacks=[fallback] )
Example #7
Source File: register.py From superCodingBot with MIT License | 6 votes |
def __init__(self, mount_point, fallback): self.mount_point = mount_point self.conv_handler = ConversationHandler( entry_points=[CommandHandler('register', self.register)], allow_reentry=True, states={ NAME: [MessageHandler(Filters.text, self.name, pass_user_data=True)], JUDGE: [CallbackQueryHandler(self.judge, pass_user_data=True, pattern=r'\w*reg1\b')], HANDLE: [MessageHandler(Filters.text, self.handle, pass_user_data=True)] }, fallbacks=[fallback] )
Example #8
Source File: towel_mode.py From vldc-bot with MIT License | 6 votes |
def add_towel_mode(upd: Updater, handlers_group: int): logger.info("registering towel-mode handlers") dp = upd.dispatcher # catch all new users and drop the towel dp.add_handler(MessageHandler(Filters.status_update.new_chat_members, catch_new_user), handlers_group) # check for reply or remove messages dp.add_handler(MessageHandler( Filters.group & ~Filters.status_update, catch_reply), handlers_group ) # "i am a bot button" dp.add_handler(CallbackQueryHandler(i_am_a_bot_btn), handlers_group) # ban quarantine users, if time is gone upd.job_queue.run_repeating(ban_user, interval=60, first=60, context={ "chat_id": get_config()["GROUP_CHAT_ID"] })
Example #9
Source File: bot.py From TranscriberBot with GNU General Public License v3.0 | 6 votes |
def __register_handlers(self): functional.apply_fn( self.message_handlers.items(), lambda h: self.__add_handler(MessageHandler( h[0], lambda b, u, **kwargs: self.__pre__hook(h[1], b, u, **kwargs))) ) functional.apply_fn( self.command_handlers.items(), lambda h: self.__add_handler(ChannelCommandHandler( h[0], lambda b, u, **kwargs: self.__pre__hook(h[1][0], b, u, **kwargs), filters=h[1][1])) ) functional.apply_fn( self.callback_handlers.items(), lambda h: self.__add_handler(CallbackQueryHandler(h[1])) ) # Decorators for adding callbacks
Example #10
Source File: telegram.py From macaw with MIT License | 5 votes |
def __init__(self, params): """ A Telegram bot interface for Macaw. Args: params(dict): A dict of parameters. The params 'logger' and 'bot_token' are mandatory. """ super().__init__(params) self.logger = self.params['logger'] self.MAX_MSG_LEN = 1000 # maximum number of characters in each response message. self.MAX_OPTION_LEN = 30 # maximum number of characters in each clickable option text. # Starting the bot by creating the Updater. # Make sure to set use_context=True to use the new context based callbacks # If you don't have a bot_token, add 'botfather' to your personal Telegram account and follow the instructions # to get a token for your bot. self.updater = Updater(self.params['bot_token'], use_context=True) self.dp = self.updater.dispatcher # Telegram command handlers (e.g., /start) self.dp.add_handler(CommandHandler('start', self.start)) self.dp.add_handler(CommandHandler('help', self.help)) # Telegram message handlers self.dp.add_handler(MessageHandler(Filters.text, self.request_handler)) self.dp.add_handler(MessageHandler(Filters.voice, self.voice_request_handler)) self.dp.add_handler(CallbackQueryHandler(self.button_click_handler)) # logging all errors self.dp.add_error_handler(self.error)
Example #11
Source File: main.py From simple-forwarder-bot with MIT License | 5 votes |
def main(): global dispatcher, updater, Token, Blacklist, admin load_config() updater = Updater(Token) dispatcher = updater.dispatcher fwd_text_handler = MessageHandler(Filters.all & (~Filters.command), read_text_message) ban_user_handler = CommandHandler('ban', ban_user) unban_user_handler = CommandHandler('unban', unban_user) callback_query_handler = CallbackQueryHandler(answer_session) dispatcher.add_handler(callback_query_handler) dispatcher.add_handler(fwd_text_handler) dispatcher.add_handler(ban_user_handler) dispatcher.add_handler(unban_user_handler) updater.start_polling()
Example #12
Source File: __main__.py From Marie-2.0-English with GNU General Public License v3.0 | 5 votes |
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) # 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) updater.idle()
Example #13
Source File: geeks_for_geeks.py From superCodingBot with MIT License | 5 votes |
def __init__(self, fallback): self.conv_handler = ConversationHandler( entry_points=[CommandHandler('geeksforgeeks', self.gfg)], allow_reentry=True, states={ GFG1: [CallbackQueryHandler(self.gfg1, pass_user_data=True, pattern=r'\w*gfg1\b')], GFG2: [CallbackQueryHandler(self.gfg2, pass_user_data=True, pattern='^.*gfg2.*$')], GFG3: [CallbackQueryHandler(self.gfg3, pass_user_data=True, pattern='^.*gfg3.*$')] }, fallbacks=[fallback] )
Example #14
Source File: codechef.py From superCodingBot with MIT License | 5 votes |
def __init__(self, cc_dict, fallback): self.cc_dict = cc_dict self.conv_handler = ConversationHandler( entry_points=[CommandHandler('randomcc', self.randomcc)], allow_reentry=True, states={ QSELCC: [CallbackQueryHandler(self.qselcc, pattern=r'\w*cc1\b')] }, fallbacks=[fallback] )
Example #15
Source File: __main__.py From EmiliaHikari with GNU General Public License v3.0 | 4 votes |
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) 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(donate_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()
Example #16
Source File: ranklist.py From superCodingBot with MIT License | 4 votes |
def __init__(self, mount_point, fallback): self.mount_point = mount_point self.utility = Utility(mount_point) self.conv_handler = ConversationHandler( entry_points=[CommandHandler('ranklist', self.ranklist)], allow_reentry=True, states={ SELECTION: [CallbackQueryHandler(self.selection, pattern=r'\w*sel1\b')], HOLO: [CallbackQueryHandler(self.holo, pattern=r'\w*list6\b')], SOLO: [CallbackQueryHandler(self.solo, pattern=r'\w*list7\b')], POLO: [MessageHandler(Filters.text, self.polo, pass_user_data=True)], XOLO: [CallbackQueryHandler(self.xolo, pass_user_data=True, pattern=r'\w*list8\b')] }, fallbacks=[fallback] )
Example #17
Source File: __main__.py From tgbot with GNU General Public License v3.0 | 4 votes |
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) # 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) updater.idle()
Example #18
Source File: __main__.py From SkittBot with GNU General Public License v3.0 | 4 votes |
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) # 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) updater.idle()