コード例 #1
0
ファイル: phrase.py プロジェクト: marcgurevitx/comprendebot
    async def explain_challenge(self):
        tr = string.Template(
            _("Please, help me collect more phrases in my database."
              "\nSend me a new <b>phrase</b> in $language."
              "\nSpell numbers as words: <i>two</i>, <i>three</i>..., not <i>2</i>, <i>3</i>..."
              "\nYou can send many variants but only submit one."
              "\n(Send /$cmd_start if you want to skip this challenge.)"))
        tr = tr.substitute(
            language=config.CMPDBOT_LANGUAGE_HUMANS,
            cmd_start=_("start  // command"),
        )
        s = Sendable(
            type=SendableTypeCode.SND_TXT,
            value=tr,
            is_reply=False,
            buttons=[],
        )
        self.sendables.append(s)

        s = Sendable(
            type=SendableTypeCode.SND_STK,
            value=Stickers.PHR,
            is_reply=False,
            buttons=[],
        )
        self.sendables.append(s)
コード例 #2
0
ファイル: voice.py プロジェクト: marcgurevitx/comprendebot
    async def ask_voice(self, callback_data):
        phrase_id = int(callback_data)

        Phrase = get_phrase_class()
        phrase = await Phrase.select_one(id=phrase_id)

        executor_data = self.challenge.row.executor_data
        executor_data["phrase_id"] = phrase_id
        executor_data["phrase_length"] = len(phrase.row.normalized_text)
        await self.challenge.update(executor_data=Json(executor_data))

        tr = string.Template(
            _("Send voice recording for <b>$original_text</b>"
              "\nYou can send many variants but only submit one."
              "\nIf you changed your mind, pick another phrase."))
        tr = tr.substitute(original_text=phrase.row.original_text, )
        s = Sendable(
            type=SendableTypeCode.SND_TXT,
            value=tr,
            is_reply=False,
            buttons=[],
        )
        self.sendables.append(s)

        s = Sendable(
            type=SendableTypeCode.SND_STK,
            value=Stickers.VOC,
            is_reply=False,
            buttons=[],
        )
        self.sendables.append(s)
コード例 #3
0
ファイル: voice.py プロジェクト: marcgurevitx/comprendebot
    async def save_voice(self, voice_key, voice_bytes, callback_data):
        await save_binary(voice_key, voice_bytes)

        executor_data = self.challenge.row.executor_data
        phrase_id = executor_data["phrase_id"]
        phrase_length = executor_data["phrase_length"]

        Voice = get_voice_class()
        await Voice.add_from_challenge(phrase_id, phrase_length, voice_key,
                                       self.challenge)

        tr = _("Successfully saved, and soon it will become available for all."
               "\nMeanwhile, you can do the next challenge.")
        s = Sendable(
            type=SendableTypeCode.SND_TXT,
            value=tr,
            is_reply=False,
            buttons=[],
        )
        self.sendables.append(s)

        s = Sendable(
            type=SendableTypeCode.SND_STK,
            value=Stickers.OK_VOC,
            is_reply=False,
            buttons=[get_start_button()],
        )
        self.sendables.append(s)

        await self.challenge.update(is_active=False, )
コード例 #4
0
    async def explain_challenge(self):

        voices = await self.challenge.get_voices()
        buttons = [
            Button(text=f"{await v.get_masked_text()}", data=v.row.id)
            for v
            in voices
        ]
        tr = string.Template(_(
            "This challenge is about listening and understanding."
            "\nPick phrase and <b>transcribe</b> it."
            "\nSpell numbers as words: <i>two</i>, <i>three</i>..., not <i>2</i>, <i>3</i>..."
            "\nYou can send many variants but only submit one."
            "\n(Send /$cmd_start if you want to skip this challenge.)"
        ))
        tr = tr.substitute(
            cmd_start=_("start  // command"),
        )
        s = Sendable(
            type=SendableTypeCode.SND_TXT,
            value=tr,
            is_reply=False,
            buttons=buttons,
        )
        self.sendables.append(s)
コード例 #5
0
ファイル: chat.py プロジェクト: marcgurevitx/comprendebot
 async def send_simple_text(self, text):
     await self.send(
         Sendable(
             type=SendableTypeCode.SND_TXT,
             value=text,
             is_reply=False,
             buttons=[],
         ))
コード例 #6
0
 async def reject_variant(self, text, message_id):
     s = Sendable(
         type=SendableTypeCode.SND_TXT,
         value=_("⚠ You need first to press one of the buttons."),
         is_reply=True,
         buttons=[],
     )
     self.sendables.append(s)
コード例 #7
0
 async def ask_submission(self, text, message_id):
     variant_num = await self.next_variant_num()
     submit_button = Button(text=_("Submit  // button"), data=message_id)
     s = Sendable(
         type=SendableTypeCode.SND_TXT,
         value=str(variant_num),
         is_reply=True,
         buttons=[submit_button],
     )
     self.sendables.append(s)
コード例 #8
0
    async def ask_transcription(self, callback_data):
        voice_id = int(callback_data)

        Voice = get_voice_class()
        voice = await Voice.select_one(id=voice_id)

        executor_data = self.challenge.row.executor_data
        executor_data["voice_id"] = voice_id
        executor_data["phrase_id"] = voice.row.phrase_id
        await self.challenge.update(executor_data=Json(executor_data))

        voice_binary = await retrieve_binary(voice.row.s3_key)

        tr = _(
            "Now write transcription."
            "\nYou can send many variants but only submit one."
            "\nEditing a variant also works."
            "\nIf you changed your mind, pick another phrase."
        )
        s = Sendable(
            type=SendableTypeCode.SND_TXT,
            value=tr,
            is_reply=False,
            buttons=[],
        )
        self.sendables.append(s)

        s = Sendable(
            type=SendableTypeCode.SND_STK,
            value=Stickers.TRS,
            is_reply=False,
            buttons=[],
        )
        self.sendables.append(s)

        s = Sendable(
            type=SendableTypeCode.SND_VOC,
            value=voice_binary,
            is_reply=False,
            buttons=[],
        )
        self.sendables.append(s)
コード例 #9
0
ファイル: phrase.py プロジェクト: marcgurevitx/comprendebot
    async def save_phrase(self, text, message_id):
        Phrase = get_phrase_class()
        await Phrase.add_from_challenge(text, self.challenge)

        tr = _("Successfully saved. Thank you for help!"
               "\nYou can do the next challenge now.")
        s = Sendable(
            type=SendableTypeCode.SND_TXT,
            value=tr,
            is_reply=False,
            buttons=[],
        )
        self.sendables.append(s)

        s = Sendable(
            type=SendableTypeCode.SND_STK,
            value=Stickers.OK_PHR,
            is_reply=False,
            buttons=[get_start_button()],
        )
        self.sendables.append(s)

        await self.challenge.update(is_active=False, )
コード例 #10
0
ファイル: voice.py プロジェクト: marcgurevitx/comprendebot
 async def explain_challenge(self):
     phrases = await self.challenge.get_phrases()
     buttons = [
         Button(text=p.row.original_text, data=p.row.id) for p in phrases
     ]
     tr = string.Template(
         _("This challenge is about reading out loud."
           "\nIt will gain you points when other users transcribe your recording."
           "\nPick phrase and send me the <b>voice</b>."
           "\nYou can send many variants but only submit one."
           "\n(Send /$cmd_start if you want to skip this challenge.)"))
     tr = tr.substitute(cmd_start=_("start  // command"), )
     s = Sendable(
         type=SendableTypeCode.SND_TXT,
         value=tr,
         is_reply=False,
         buttons=buttons,
     )
     self.sendables.append(s)
コード例 #11
0
    async def save_transcription(self, text, callback_data):
        executor_data = self.challenge.row.executor_data
        voice_id = executor_data["voice_id"]
        phrase_id = executor_data["phrase_id"]

        Phrase = get_phrase_class()
        phrase = await Phrase.select_one(id=phrase_id)
        Voice = get_voice_class()
        voice = await Voice.select_one(id=voice_id)

        length = voice.row.length

        tr = string.Template(_(
            "The original phrase was <b>$original_text</b> with length of $length."
        ))
        tr = tr.substitute(
            original_text=phrase.row.original_text,
            length=length,
        )
        reply_fragments = [tr]

        distance = get_distance(text, phrase.row.normalized_text)
        if distance > 0:
            xp = max(length - distance, 0)
            tr = string.Template(_(
                "You've transcribed it differently with the distance of $distance."
                "\nGained XP = max(length - distance, 0) = max($length - $distance, 0) = $xp."
            ))
            tr = tr.substitute(
                distance=distance,
                length=length,
                xp=xp,
            )
            reply_fragments.append(tr)
        else:
            xp = length
            tr = string.Template(_(
                "And you transcribed it right!"
                "\nGained XP = $xp."
            ))
            tr = tr.substitute(
                xp=xp,
            )
            reply_fragments.append(tr)

        Transcription = get_transcription_class()
        await Transcription.add_from_challenge(voice_id, text, distance, self.challenge)

        Person = get_person_class()
        total_xp = await Person.increase_xp(
            xp,
            person_trs_id=self.challenge.row.person_id,
            person_voc_id=voice.row.person_id,
            person_phr_id=phrase.row.person_id,
        )
        tr = string.Template(_(
            "Total XP now is $total_xp."
        ))
        tr = tr.substitute(
            total_xp=total_xp,
        )
        reply_fragments.append(tr)

        s = Sendable(
            type=SendableTypeCode.SND_TXT,
            value="\n".join(reply_fragments),
            is_reply=False,
            buttons=[],
        )
        self.sendables.append(s)

        sticker = get_metal_sticker(length, distance)
        s = Sendable(
            type=SendableTypeCode.SND_STK,
            value=sticker,
            is_reply=False,
            buttons=[get_start_button()],
        )
        self.sendables.append(s)

        await self.challenge.update(
            is_active=False,
        )