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)
评论列表
文章目录