bot.py 文件源码

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

项目:python-telegram-dialog-bot 作者: Saluev 项目源码 文件源码
def send_answer(self, bot, chat_id, answer):
        print("Sending answer %r to %s" % (answer, chat_id))
        if isinstance(answer, collections.abc.Iterable) and not isinstance(answer, str):
            # ?? ???????? ????????? ???????? -- ?????? ?????? ???? ??????????
            answer = list(map(self._convert_answer_part, answer))
        else:
            # ?? ???????? ???? ?????? -- ?????? ? ????? ????? ??????
            answer = [self._convert_answer_part(answer)]
        # ????? ???, ??? ????????? ????????? ?????????, ???? ?????? ? ???????
        # «????????» -- ?????????? ??? ??? ? ??????????? ??? ????-??????
        current_message = last_message = None
        for part in answer:
            if isinstance(part, Message):
                if current_message is not None:
                    # ?????????, ??????? ?? ????????? ??????, ???? ?? ?????????.
                    # ????????? ?? ??? ??????? ?????????, ????? ??? ?????????
                    # ?? ???????? ???????? (???? ?? ??????? ????????)
                    current_message = copy.deepcopy(current_message)
                    current_message.options.setdefault("disable_notification", True)
                    self._send_or_edit(bot, chat_id, current_message)
                current_message = part
            if isinstance(part, ReplyMarkup):
                # ???, ? ??? ? ???????! ????????? ???????? ?????????.
                # ??? ????????? -- ?? ????????, ??? ??????.
                current_message.options["reply_markup"] = part
        # ???? ?? ?????? ????????? ????????? ??????????? ?????????.
        if current_message is not None:
            self._send_or_edit(bot, chat_id, current_message)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号