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)
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)
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, original_user=previous_message.user, deaf_user=user, )
async def respond(self, user, message): return await self._make_voice( self._extract_text( not_none(await self._text_core.respond(user, message)) ) )
async def conceive(self): return await self._make_voice( self._extract_text(not_none(await self._text_core.conceive())) )
def _try_infer_from_previous_message(self, user, **_): not_none(self._previous_info) check(self._previous_info.user != user) return self._previous_info
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)
async def _on_chat_message(self, message): answer = not_none(self._backend.try_reply(message)) await self.sender.sendMessage( answer, reply_to_message_id=message["message_id"] )