def inline_query_result_cached_video(): return InlineQueryResultCachedVideo(TestInlineQueryResultCachedVideo.id, TestInlineQueryResultCachedVideo.video_file_id, TestInlineQueryResultCachedVideo.title, caption=TestInlineQueryResultCachedVideo.caption, description=TestInlineQueryResultCachedVideo.description, input_message_content=TestInlineQueryResultCachedVideo.input_message_content, reply_markup=TestInlineQueryResultCachedVideo.reply_markup)
def create_video_inline_result(doc: Document) -> InlineQueryResultCachedVideo: content = doc.content return InlineQueryResultCachedVideo( id=doc.internal_id, video_file_id=content['file_id'], title=doc.keywords, caption=content.get('caption'), )
def test_equality(self): a = InlineQueryResultCachedVideo(self.id, self.video_file_id, self.title) b = InlineQueryResultCachedVideo(self.id, self.video_file_id, self.title) c = InlineQueryResultCachedVideo(self.id, '', self.title) d = InlineQueryResultCachedVideo('', self.video_file_id, self.title) e = InlineQueryResultCachedVoice(self.id, '', '') assert a == b assert hash(a) == hash(b) assert a is not b assert a == c assert hash(a) == hash(c) assert a != d assert hash(a) != hash(d) assert a != e assert hash(a) != hash(e)
def handle_publishing_options(update: Update, _: CallbackContext): user: TGUser = update.effective_user try: msg, buttons = get_msg_and_buttons(user, update.inline_query.query) except ValueError: return reply_markup = make_reactions_keyboard(buttons or ['-']) msg_type = get_message_type(msg) config = { 'id': str(uuid4()), 'title': msg.text_markdown or msg.caption_markdown or "Message to publish.", 'text': msg.text_markdown, 'caption': msg.caption_markdown, 'parse_mode': ParseMode.MARKDOWN, 'reply_markup': reply_markup, # types 'photo_file_id': msg.photo and msg.photo[0].file_id, 'video_file_id': msg.video and msg.video.file_id, 'mpeg4_file_id': msg.animation and msg.animation.file_id, } if msg_type == 'photo': qr = InlineQueryResultCachedPhoto(**config) elif msg_type == 'video': qr = InlineQueryResultCachedVideo(**config) elif msg_type == 'animation': qr = InlineQueryResultCachedMpeg4Gif(**config) elif msg_type in ('text', 'link'): qr = InlineQueryResultArticle( input_message_content=InputTextMessageContent( msg.text_markdown, parse_mode=ParseMode.MARKDOWN, ), **config, ) else: return update.inline_query.answer([qr], cache_time=0, is_personal=True)
def inlinequery(update, context): """Handle the inline query.""" ### # https://python-telegram-bot.readthedocs.io/en/stable/telegram.inlinequery.html ## # There is pretty much no info except the sender in update. context is also useless. So we can't get the replied-to file. ### def ans_text(text: str = "", cache_time=1): # "To undo the folded lie," if not text: return update.inline_query.answer( [ InlineQueryResultArticle( id=uuid4(), title=text, input_message_content=InputTextMessageContent( text, disable_web_page_preview=False), ) ], cache_time=cache_time, is_personal=True, ) if not isAdmin(update, admins=graylist): ans_text( """Defenceless under the night Our world in stupor lies; Yet, dotted everywhere, Ironic points of light Flash out wherever the Just Exchange their messages: May I, composed like them Of Eros and of dust, Beleaguered by the same Negation and despair, Show an affirming flame. - Auden""", cache_time=86400, ) return with lock_inline: query = update.inline_query.query m = PDI.match(query) if m: c_id = m.group(1) c_kind = m.group(2) or "" print(f"Download ID: {c_id} {c_kind}") result = None if c_kind == "": result = InlineQueryResultCachedDocument(id=uuid4(), title=str(c_id), document_file_id=c_id) elif c_kind.startswith("vid"): result = InlineQueryResultCachedVideo(id=uuid4(), title=str(c_id), video_file_id=c_id) elif c_kind == "photo": result = InlineQueryResultCachedPhoto(id=uuid4(), title=str(c_id), photo_file_id=c_id) elif c_kind == "gif": result = InlineQueryResultCachedMpeg4Gif(id=uuid4(), title=str(c_id), mpeg4_file_id=c_id) if result: try: update.inline_query.answer([result], cache_time=1, is_personal=True) except: ans_text(traceback.format_exc()) else: ans_text(f"Invalid kind: {c_kind}") return command = "" cache_time = 1 is_personal = True no_match = True m = PC_KITSU.match(query) if m: no_match = False arg = zq(str(m.group(1))) if not arg: ans_text() return command = f"kitsu-getall {arg}" cache_time = 86400 is_personal = False m = PC_GOO.match(query) if m: no_match = False mode = str(m.group(1)) arg = zq(str(m.group(2))) if not arg: ans_text() return if mode == "g": command = f"jigoo {arg}" elif mode == "as": command = f"jias {arg}" else: # 'd' command = f"search_json_ddg=y jigoo {arg}" is_personal = False if no_match: if not isAdmin(update): ans_text("""The enlightenment driven away, The habit-forming pain, Mismanagement and grief: We must suffer them all again. - Auden""") return if query == ".x": bsh.restart() cache.clear() ans_text("Restarted") return m = PAF.match(query) if m == None: ans_text() return command = m.group(2) if m.group(1) == "n": # embed() command = "noglob " + command if not command: ans_text() return print(f"Inline command accepted: {command}") results = get_results(command) update.inline_query.answer(results, cache_time=cache_time, is_personal=is_personal)