Esempio n. 1
0
    def try_reply(self, message):
        check("photo" not in message)
        text = not_none(message.get("text"))
        source = not_none(message.get("from"))
        user = not_none(source.get("username"))

        if re.match(self.WHAT_REGEX, text) is None:
            self._previous_message_retriever.record(text, user)
            return None

        previous_message = not_none(
            self._previous_message_retriever.retrieve(message, text, user))

        self._previous_message_retriever.clean()

        return self._reply_to_deaf(previous_message.text,
                                   previous_message.user)
Esempio n. 2
0
    async def _on_chat_message(self, message):
        check(self._self_reference_detector(message))
        source = not_none(message.get("from"))
        user = not_none(source.get("username"))

        self._log.info("User {} in chat {} is talking to me".format(
            user, self.chat_id))

        intelligence_core = self._intelligence_registry.get_core(self.chat_id)

        answer = await intelligence_core.respond(user=user,
                                                 message=message.get(
                                                     "text", ""))
        if answer is None:
            self._log.info('Got "None" answer from intelligence core')
            answer = self._answer_placeholder

        await self._send_thought(answer)
Esempio n. 3
0
    async def on_callback_query(self, message):
        query_id, _, lowlevel_user_data = telepot.glance(
            message, flavor="callback_query")
        callback_data_key = int(lowlevel_user_data)
        data = not_none(self._callback_data_storage.get(callback_data_key))
        if not data.lifespan:
            self._callback_data_storage.pop(callback_data_key)

        await data.handler(query_id)
Esempio n. 4
0
 async def respond(self, user, message):
     return await self._make_voice(
         self._extract_text(
             not_none(await self._text_core.respond(user, message))))
Esempio n. 5
0
 async def conceive(self):
     return await self._make_voice(
         self._extract_text(not_none(await self._text_core.conceive())))
Esempio n. 6
0
 def _try_infer_from_previous_message(self, user, **_):
     not_none(self._previous_info)
     check(self._previous_info.user != user)
     return self._previous_info
Esempio n. 7
0
 def _try_retrieve_from_reply(self, message, **_):
     reply = not_none(message.get("reply_to_message"))
     previous_text = not_none(reply.get("text"))
     previous_source = not_none(reply.get("from"))
     previous_user = not_none(previous_source.get("username"))
     return self.Info(text=previous_text, user=previous_user)
Esempio n. 8
0
 async def _on_chat_message(self, message):
     answer = not_none(self._backend.try_reply(message))
     await self.sender.sendMessage("_{}_".format(answer),
                                   parse_mode="Markdown")