def msg(self, bot, update):
"""
Process, wrap and deliver messages from user.
Args:
bot: Telegram Bot instance
update: Message update
"""
self.logger.debug("----\nMsg from tg user:\n%s", update.message.to_dict())
multi_slaves = False
if update.message.chat.id != update.message.from_user.id: # from group
assocs = db.get_chat_assoc(master_uid="%s.%s" % (self.channel_id, update.message.chat.id))
if len(assocs) > 1:
multi_slaves = True
reply_to = bool(getattr(update.message, "reply_to_message", None))
private_chat = update.message.chat.id == update.message.from_user.id
if (private_chat or multi_slaves) and not reply_to:
candidates = db.get_recent_slave_chats(update.message.chat.id) or\
db.get_chat_assoc(master_uid="%s.%s" % (self.channel_id, update.message.chat.id))[:5]
if candidates:
tg_err_msg = update.message.reply_text("Error: No recipient specified.\n"
"Please reply to a previous message.", quote=True)
storage_id = "%s.%s" % (update.message.chat.id, tg_err_msg.message_id)
legends, buttons = self.slave_chats_pagination(storage_id, 0, fchats=candidates)
tg_err_msg.edit_text("Error: No recipient specified.\n"
"Please reply to a previous message, "
"or choose a recipient:\n\nLegend:\n" + "\n".join(legends),
reply_markup=telegram.InlineKeyboardMarkup(buttons))
self.msg_status[storage_id] = Flags.SUGGEST_RECIPIENT
self.msg_storage[storage_id]["update"] = update.to_dict()
else:
update.message.reply_text("Error: No recipient specified.\n"
"Please reply to a previous message.", quote=True)
else:
return self.process_telegram_message(bot, update)
评论列表
文章目录