Esempio n. 1
0
def inline_search(bot, update):
    page = 0
    results = list()
    opts = {}

    query = update.inline_query.query

    if update.inline_query.offset != '':
        page = int(update.inline_query.offset)

    logger.info(u"Inline query: '{}' (page={})".format(query, page))

    res = bot.index.search(query, {
        "hitsPerPage": 10,
        "page": page,
    })

    for hit in res["hits"]:
        results.append(
            InlineQueryResultCachedGif(id=hit["objectID"],
                                       gif_file_id=hit["file_id"]))

    next_page = page + 1
    if next_page < res["nbPages"]:
        opts['next_offset'] = str(next_page)

    update.inline_query.answer(results, **opts)
Esempio n. 2
0
def inline_query_result_cached_gif():
    return InlineQueryResultCachedGif(TestInlineQueryResultCachedGif.id,
                                      TestInlineQueryResultCachedGif.gif_file_id,
                                      title=TestInlineQueryResultCachedGif.title,
                                      caption=TestInlineQueryResultCachedGif.caption,
                                      input_message_content=TestInlineQueryResultCachedGif.input_message_content,
                                      reply_markup=TestInlineQueryResultCachedGif.reply_markup)
Esempio n. 3
0
def get_list_items_by_type(nt_list: NotetonList,
                           user: NotetonUser) -> List[InlineQueryResult]:
    items = NotetonUsersManager.get_items_of_list(user.id, nt_list)
    answer_items = []
    for item in items:
        id_ = item.id
        item_ = None
        if nt_list.type == NotetonList.TYPE_ARTICLE:
            ans_text = InputTextMessageContent(item.text)
            item_ = InlineQueryResultArticle(id=id_,
                                             title=item.text,
                                             input_message_content=ans_text)
        elif nt_list.type == NotetonList.TYPE_IMAGE:
            item_ = InlineQueryResultCachedPhoto(id=id_,
                                                 photo_file_id=item.file_id)
        elif nt_list.type == NotetonList.TYPE_STICKER:
            item_ = InlineQueryResultCachedSticker(
                id=id_, sticker_file_id=item.file_id)
        elif nt_list.type == NotetonList.TYPE_GIF:
            item_ = InlineQueryResultCachedGif(id=id_,
                                               gif_file_id=item.file_id)
        elif nt_list.type == NotetonList.TYPE_AUDIO:
            item_ = InlineQueryResultCachedAudio(id=id_,
                                                 audio_file_id=item.file_id)
        elif nt_list.type == NotetonList.TYPE_DOCUMENT:
            item_ = InlineQueryResultCachedDocument(
                id=id_, title=item.title, document_file_id=item.file_id)
        if item_:
            answer_items.append(item_)
    return answer_items
Esempio n. 4
0
def inline_query(bot, update):
    limit = 10
    offset = 0
    results = list()

    query = update.inline_query.query

    if update.inline_query.offset != '':
        offset = int(update.inline_query.offset)

    logger.info(u"Inline query: '{}' (offset={})".format(query, offset))

    gifs = Gif.select().limit(limit).offset(offset)

    if query:
        terms = stemmer.stem_text(query)
        gifs = (gifs.join(GifIndex, on=(Gif.id == GifIndex.docid)).where(
            GifIndex.match(terms)).order_by(GifIndex.bm25()))
    else:
        gifs = gifs.order_by(Gif.rank.desc())

    for gif in gifs:
        results.append(
            InlineQueryResultCachedGif(id=str(gif.id),
                                       gif_file_id=gif.file_id))

    opts = {}
    if results:
        if len(results) == limit:
            opts['next_offset'] = offset + limit

    print results
    update.inline_query.answer(results, **opts)
def create_animation_inline_result(
        doc: Document) -> InlineQueryResultCachedGif:
    content = doc.content
    return InlineQueryResultCachedGif(
        id=doc.internal_id,
        gif_file_id=content['file_id'],
        title=doc.keywords,
        caption=content.get('caption'),
    )
    def test_equality(self):
        a = InlineQueryResultCachedGif(self.id_, self.gif_file_id)
        b = InlineQueryResultCachedGif(self.id_, self.gif_file_id)
        c = InlineQueryResultCachedGif(self.id_, '')
        d = InlineQueryResultCachedGif('', self.gif_file_id)
        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)
Esempio n. 7
0
def inline_monkey(update, context):
    query = update.inline_query.query

    if not query:
        return

    results = list()
    message = send_monkey(STORAGE_CHAT_ID, query.upper())
    results.append(
        InlineQueryResultCachedGif(
            id=query.upper(),
            gif_file_id=message.animation.file_id,
        ))
    context.bot.answer_inline_query(update.inline_query.id, results)
Esempio n. 8
0
def inlinequery(update: Update, context: CallbackContext):
    """Handle the inline query."""
    query = update.inline_query.query.lower()

    results = []
    for keyword in Keyword.select().where(Keyword.text == query):
        for gif in keyword.gif:
            result = InlineQueryResultCachedGif(
                id=uuid4(),
                gif_file_id=gif.file_id,
            )
            if not result in results:
                results.append(result)

    update.inline_query.answer(results)
Esempio n. 9
0
def _inline_query_result_from_entry(entry_type, entry):
    if entry_type == EntryType.STICKER:
        return InlineQueryResultCachedSticker(id=entry, sticker_file_id=entry)
    elif entry_type == EntryType.GIF:
        return InlineQueryResultCachedGif(id=entry, gif_file_id=entry)