def inline(self, handler, *args, **kwargs): """Decorator that register inline query handler. :param handler: callable that process user inline query """ inline_handler = ext.InlineQueryHandler( handler, *args, **kwargs) self.ds.add_handler(inline_handler) return inline_handler
def decorator(callback): self._dispatcher.add_handler(handler=ext.InlineQueryHandler( callback=callback, pass_update_queue=pass_update_queue, pass_job_queue=pass_job_queue, pattern=pattern, pass_groups=pass_groups, pass_groupdict=pass_groupdict, pass_user_data=pass_user_data, pass_chat_data=pass_chat_data), group=group)
query = update.inline_query.query username = update.inline_query.from_user.username if not query: return gsearch_result = list(search(query, stop=1))[0] results = list() results.append( InlineQueryResultArticle(id="gsearch_cher", title='google search', description=query, input_message_content=InputTextMessageContent( username + ': <code>google </code>' + query + '\n' + gsearch_result, parse_mode=ParseMode.HTML))) bot.answer_inline_query(update.inline_query.id, results) logger.info("Inline query from " + str(update.inline_query.from_user.id)) # Add handlers to dispatcher updater.dispatcher.add_handler(tg.InlineQueryHandler(inline_google)) updater.dispatcher.add_handler(tg.CommandHandler('start', start)) updater.dispatcher.add_handler( tg.CommandHandler('list_lectures', list_lectures)) updater.dispatcher.add_handler( tg.CommandHandler('calcmass', calcmass, pass_args=True)) updater.dispatcher.add_handler( tg.CommandHandler('calccap', calccap, pass_args=True)) updater.start_polling() updater.idle()
def inline(upd, ctx): query = upd.inline_query.query start = time.perf_counter() result = [i.to_result() for i in msgs if i.search_matches(query)] end = time.perf_counter() print("finished search in", end - start, "seconds") upd.inline_query.answer(result) def create(upd, ctx): text = upd.message.text _command, _, text = text.partition('\n') title, _, content = text.partition('\n') if title and content: msgs.append(Message(title, content)) json.dump([i.to_dict() for i in msgs], open('data.json', 'w'), indent=4) upd.message.reply_text("success") else: upd.message.reply_text("fail, example:\n/create\ntitle\ncontent...") d.add_handler(x.CommandHandler('start', start)) d.add_handler(x.CommandHandler('create', create)) d.add_handler(x.InlineQueryHandler(inline)) u.start_polling() u.idle()
def main(dp, group): for i in [ tg_ext.InlineQueryHandler(inlinequery), tg_ext.CommandHandler('subs', subs_ls), ]: dp.add_handler(i, group)
if (fEx == 1): globals()['b' + query.replace('/', '')](bot, update) else: pass bot.answerInlineQuery(update.inline_query.id, results=results) # Command handlers for each callbacks rfSecuBotHelpHdlr = tgExt.CommandHandler('help', bhelp) rfSecuBotStartHdlr = tgExt.CommandHandler('start', bstart) rfSecuBotStopHdlr = tgExt.CommandHandler('stop', bstop) rfSecuBotLogHdlr = tgExt.CommandHandler('log', blog) rfSecuBotListHdlr = tgExt.CommandHandler('list', blist) rfSecuBotTestHdlr = tgExt.CommandHandler('test', btest) rfSecuBotInlineHdlr = tgExt.InlineQueryHandler(chInQuery) # Bot updater rfSecuBotUpd = tgExt.Updater(rfSecuBotToken) rfSecuBotDisp = rfSecuBotUpd.dispatcher # Add handler to dispatcher rfSecuBotDisp.addHandler(rfSecuBotHelpHdlr) rfSecuBotDisp.addHandler(rfSecuBotStartHdlr) rfSecuBotDisp.addHandler(rfSecuBotStopHdlr) rfSecuBotDisp.addHandler(rfSecuBotLogHdlr) rfSecuBotDisp.addHandler(rfSecuBotListHdlr) rfSecuBotDisp.addHandler(rfSecuBotTestHdlr) rfSecuBotDisp.addHandler(rfSecuBotInlineHdlr) rfSecuBotUpd.start_polling(poll_interval=1.0, clean=True)