def inline_query_result_voice():
    return InlineQueryResultVoice(
        type=TestInlineQueryResultVoice.type,
        id=TestInlineQueryResultVoice.id,
        voice_url=TestInlineQueryResultVoice.voice_url,
        title=TestInlineQueryResultVoice.title,
        voice_duration=TestInlineQueryResultVoice.voice_duration,
        caption=TestInlineQueryResultVoice.caption,
        input_message_content=TestInlineQueryResultVoice.input_message_content,
        reply_markup=TestInlineQueryResultVoice.reply_markup)
    def test_equality(self):
        a = InlineQueryResultVoice(self.id, self.voice_url, self.title)
        b = InlineQueryResultVoice(self.id, self.voice_url, self.title)
        c = InlineQueryResultVoice(self.id, "", self.title)
        d = InlineQueryResultVoice("", self.voice_url, self.title)
        e = InlineQueryResultAudio(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 inline_query_result_voice():
    return InlineQueryResultVoice(
        type=TestInlineQueryResultVoice.type_,
        id=TestInlineQueryResultVoice.id_,
        voice_url=TestInlineQueryResultVoice.voice_url,
        title=TestInlineQueryResultVoice.title,
        voice_duration=TestInlineQueryResultVoice.voice_duration,
        caption=TestInlineQueryResultVoice.caption,
        parse_mode=TestInlineQueryResultVoice.parse_mode,
        caption_entities=TestInlineQueryResultVoice.caption_entities,
        input_message_content=TestInlineQueryResultVoice.input_message_content,
        reply_markup=TestInlineQueryResultVoice.reply_markup,
    )
예제 #4
0
def inlinequery(bot, update):
    """Inline query handler"""
    query = update.inline_query.query
    inline_results = list()

    results = search_instants(query)

    for instant in results:
        inline_results.append(InlineQueryResultVoice(id=uuid4(),
                                                     title=instant["text"],
                                                     voice_url=instant["url"]))

    bot.answerInlineQuery(update.inline_query.id, results=inline_results[:40])
예제 #5
0
def inlinequery(update: Update, context: CallbackContext) -> None:
    """Handle the inline query."""
    query = update.inline_query.query
    query = query.strip().lower()
    results = [
        InlineQueryResultVoice(
            id=uuid4(),
            type='voice',
            title=audio['title'],
            caption=audio['title'],
            voice_url=audio['src'],
        ) for audio in scrape(query)
    ]

    update.inline_query.answer(results)
예제 #6
0
def long_result_to_audio_result(result: InlineQueryResultArticle) -> InlineQueryResultVoice:
    title = result.title
    audio_url = get_audio_url(title)
    if not audio_url:
        text = result.input_message_content.message_text
        speech = polly_client.synthesize_speech(VoiceId='Enrique',
                                                OutputFormat='ogg_vorbis',
                                                Text=text,)
        audio_url = upload_audio(speech['AudioStream'].read(), title)

    result_id = normalize_str(f"audio-{result.id}")
    return InlineQueryResultVoice(
        result_id[:63],
        audio_url,
        title,
    )
예제 #7
0
    def _inlinequery_handler(self, update, context):
        query_sound = update.inline_query.query
        user_dict = update.effective_user

        self._sound_bank.create_user_if_it_does_not_exist(user_id=user_dict['id'],
                                                          username=user_dict['username'],
                                                          first_name=user_dict['first_name'],
                                                          last_name=user_dict['last_name'])

        sounds = self._sound_bank.sounds_for_user(user_id=user_dict['id'], query=query_sound)

        results = [
            InlineQueryResultVoice(id=sound.sound_id(), voice_url=sound.url(), title=sound.title()) for sound in sounds
        ]

        update.inline_query.answer(results[:MAX_INLINE_QUERY_RESULTS])
    def test_equality(self):
        a = InlineQueryResultLocation(self.id_, self.longitude, self.latitude, self.title)
        b = InlineQueryResultLocation(self.id_, self.longitude, self.latitude, self.title)
        c = InlineQueryResultLocation(self.id_, 0, self.latitude, self.title)
        d = InlineQueryResultLocation('', self.longitude, self.latitude, self.title)
        e = InlineQueryResultVoice(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)
예제 #9
0
    def test_equality(self):
        a = InlineQueryResultAudio(self.id_, self.audio_url, self.title)
        b = InlineQueryResultAudio(self.id_, self.title, self.title)
        c = InlineQueryResultAudio(self.id_, '', self.title)
        d = InlineQueryResultAudio('', self.audio_url, self.title)
        e = InlineQueryResultVoice(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)
예제 #10
0
    def test_equality(self):
        a = InlineQueryResultPhoto(self.id_, self.photo_url, self.thumb_url)
        b = InlineQueryResultPhoto(self.id_, self.photo_url, self.thumb_url)
        c = InlineQueryResultPhoto(self.id_, "", self.thumb_url)
        d = InlineQueryResultPhoto("", self.photo_url, self.thumb_url)
        e = InlineQueryResultVoice(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 test_equality(self):
        a = InlineQueryResultDocument(self.id_, self.document_url, self.title, self.mime_type)
        b = InlineQueryResultDocument(self.id_, self.document_url, self.title, self.mime_type)
        c = InlineQueryResultDocument(self.id_, '', self.title, self.mime_type)
        d = InlineQueryResultDocument('', self.document_url, self.title, self.mime_type)
        e = InlineQueryResultVoice(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 test_equality(self):
        a = InlineQueryResultContact(self.id_, self.phone_number, self.first_name)
        b = InlineQueryResultContact(self.id_, self.phone_number, self.first_name)
        c = InlineQueryResultContact(self.id_, '', self.first_name)
        d = InlineQueryResultContact('', self.phone_number, self.first_name)
        e = InlineQueryResultVoice(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 test_equality(self):
        a = InlineQueryResultGame(self.id, self.game_short_name)
        b = InlineQueryResultGame(self.id, self.game_short_name)
        c = InlineQueryResultGame(self.id, '')
        d = InlineQueryResultGame('', self.game_short_name)
        e = InlineQueryResultVoice(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)
예제 #14
0
    def test_equality(self):
        a = InlineQueryResultMpeg4Gif(self.id, self.mpeg4_url, self.thumb_url)
        b = InlineQueryResultMpeg4Gif(self.id, self.mpeg4_url, self.thumb_url)
        c = InlineQueryResultMpeg4Gif(self.id, "", self.thumb_url)
        d = InlineQueryResultMpeg4Gif("", self.mpeg4_url, self.thumb_url)
        e = InlineQueryResultVoice(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 test_equality(self):
        a = InlineQueryResultGif(self.id_, self.gif_url, self.thumb_url)
        b = InlineQueryResultGif(self.id_, self.gif_url, self.thumb_url)
        c = InlineQueryResultGif(self.id_, '', self.thumb_url)
        d = InlineQueryResultGif('', self.gif_url, self.thumb_url)
        e = InlineQueryResultVoice(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)
예제 #16
0
def inline_translate(update: Update, context: CallbackContext):
    global LANGUAGE
    query = update.inline_query.query
    LANGUAGE = clients.get(str(update.inline_query.from_user.id))
    if not query:
        return
    name = str(randint(0, 1000))
    results = [
        InlineQueryResultArticle(
            id=1,
            title='text',
            input_message_content=InputTextMessageContent(
                query + ' : ' + ts.google(query, to_language=LANGUAGE))),
        InlineQueryResultVoice(id=2,
                               voice_url=name,
                               title='speech',
                               caption=query)
    ]
    gTTS(text=query,
         lang=clients.get(str(update.inline_query.from_user.id)),
         lang_check=False).save(name)
    context.bot.answer_inline_query(update.inline_query.id, results)
예제 #17
0
    def test_equality(self):
        a = InlineQueryResultVenue(self.id, self.longitude, self.latitude, self.title,
                                   self.address)
        b = InlineQueryResultVenue(self.id, self.longitude, self.latitude, self.title,
                                   self.address)
        c = InlineQueryResultVenue(self.id, '', self.latitude, self.title, self.address)
        d = InlineQueryResultVenue('', self.longitude, self.latitude, self.title,
                                   self.address)
        e = InlineQueryResultVoice(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)
예제 #18
0
파일: bot.py 프로젝트: OgerBot/toOgerBot
def inline_translate(update, context):
    query = update.inline_query.query
    results = []

    load_audios()  # load audios
    audio_id = []
    if 2 < len(query) < 16 or query.lower() == "ja":
        for i in range(len(audio_titles)):
            if query.lower() in audio_titles_lowered[i]:
                audio_id.append(i)
                if len(audio_id) == 3:
                    break

    if audio_id == [] and (
            not query or len(query) < 16
    ):  # no audio fitting the search -> pick one at random
        audio_id = [random.randint(0, len(audio_titles))]

    for aud_id in audio_id:
        audiofile, title = audio_files[aud_id], audio_titles[aud_id]
        #title = OgerTranslator.translate(title)
        results.append(
            InlineQueryResultVoice(id="voice" + str(aud_id),
                                   voice_url=audiofile,
                                   title=title,
                                   caption=title))

    if query:
        translation = OgerTranslator.translate(query)
        results.append(
            InlineQueryResultArticle(
                id=hash(query),
                title='Meddlfrängische Übersetzung.',
                input_message_content=InputTextMessageContent(translation),
                thumb_url='https://www.oger.ml/oger.png',
                description=translation))
    results.reverse()  # s.t. translation is the first option
    context.bot.answer_inline_query(update.inline_query.id, results)
예제 #19
0
    def test_equality(self):
        a = InlineQueryResultVideo(self.id, self.video_url, self.mime_type,
                                   self.thumb_url, self.title)
        b = InlineQueryResultVideo(self.id, self.video_url, self.mime_type,
                                   self.thumb_url, self.title)
        c = InlineQueryResultVideo(self.id, '', self.mime_type, self.thumb_url,
                                   self.title)
        d = InlineQueryResultVideo('', self.video_url, self.mime_type,
                                   self.thumb_url, self.title)
        e = InlineQueryResultVoice(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)