main_app.py 文件源码

python
阅读 24 收藏 0 点赞 0 评论 0

项目:pockebot 作者: Fillll 项目源码 文件源码
def on_chat_message(self, msg):
        content_type, chat_type, self.request_chat_id = telepot.glance(msg)
        self.mongo.chat_id = self.request_chat_id
        self.store_contacts(msg)
        self.known_user = self.is_user_known()
        self.__debug_print('>')
        # self.__debug_print(msg)

        if self.waiting_for_menu_action is True:
            await self._cancel_last()
        self.waiting_for_menu_action = False

        any_commands = self.has_command(msg)

        if 'text' not in msg:
            msg['text'] = '±notext±'

        if chat_type == 'private':

            keyboard = {'hide_keyboard': True}
            to_send_msg = self.say('pocket_error')
            self.visit_time += 1
            inbox = msg['text']

            if any_commands and (self.known_user or (not self.known_user and inbox != '/start Done' and inbox != '/start')):
                to_send_msg, keyboard = self.process_command(inbox)
            else:
                if self.known_user:
                    urls, tags = self.get_urls_and_tags(msg)
                    if len(urls) > 0 or len(tags) > 0:
                        to_send_msg, keyboard = await self.add(urls, tags, inbox)
                        if len(urls) > 0 and self.audio is True:
                            filename = self.need_audio()
                            if filename is not None:
                                f = open(join('audio', filename), 'rb')
                                await self.sender.sendVoice(f, reply_markup=keyboard)
                    else:
                        self.messages.append(msg)
                        to_send_msg, keyboard = self.say('nothing'), {'hide_keyboard': True}
                else:
                    to_send_msg = self.make_authorization()

            # Send message. Always update keyboard and always `Markdown` mode. Be careful messages
            # with `_` in text are dagerous.
            sent = await self.sender.sendMessage(to_send_msg, reply_markup=keyboard, parse_mode='Markdown')
            self._editor = telepot.aio.helper.Editor(self.bot, sent)
            self._edit_msg_ident = telepot.message_identifier(sent)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号