def add_record(bot, channel_id, msg_id, message): logger = Logger.logger ori_msg_id = message.message_id user = message.from_user username = user.username user_id = user.id name = user.first_name if user.last_name: name += " " + user.last_name date = message.date.strftime("%Y-%m-%d %H:%M:%S") msg_type = "text" msg_content = "" media_id = "" if message.text: msg_type = "text" msg_content = message.text elif message.sticker: msg_type = 'sticker' media_id = message.sticker.file_id if message.sticker.emoji: msg_content = message.sticker.emoji elif message.photo: msg_type = 'photo' media_id = message.photo[-1].file_id if message.caption: msg_content = message.caption elif message.video: msg_type = 'video' media_id = message.video.file_id if message.caption: msg_content = message.caption elif message.document: msg_type = 'document' media_id = message.document.file_id if message.document.file_name: msg_content = message.document.file_name elif message.audio: msg_type = 'audio' media_id = message.audio.file_id if message.audio.title: msg_content = message.audio.title elif message.voice: msg_type = 'voice' media_id = message.voice.file_id msg_content = helper_global.parse_entity(msg_content, message.entities) if message.reply_markup and message.reply_markup.inline_keyboard: keyboard = message.reply_markup.inline_keyboard if len(keyboard) > 0 and len(keyboard[0]) > 0: query = keyboard[0][0] if query.callback_data: args = query.callback_data.split(",") if len(args) == 4 and args[0] == "notify": target_channel_id = int(args[1]) target_msg_id = int(args[2]) target_row_id = args[3] record = helper_database.get_record_by_rowid(target_row_id) if len(record) > 0 and target_channel_id == int( record[0][0]) and target_msg_id == int( record[0][1]): target_name = record[0][3] target_user_id = record[0][8] config = helper_database.get_channel_config(channel_id) if config is None: return channel_lang, channel_username = config[1], config[4] msg_content = "<b>(➤%s) </b> " % target_name.replace( '<', '<').replace('>', '>') + msg_content if channel_username is not None: logger.msg( { "channel_id": channel_id, "msg_id": msg_id, "target_user": target_user_id, "action": "notify reply" }, tag="private", log_level=80) bot.send_message( chat_id=target_user_id, text=helper_global.value( "new_reply_message", "You receive a reply message.", lang=channel_lang) + "\n" + helper_global.value( "target_message", "", lang=channel_lang) + "https://t.me/%s/%d" % (channel_username, target_msg_id)) else: link_id = abs(channel_id) % 10000000000 bot.send_message( chat_id=target_user_id, text=helper_global.value( "new_reply_message", "You receive a reply message.", lang=channel_lang) + "\n" + helper_global.value( "target_message", "", lang=channel_lang) + "https://t.me/c/%d/%d" % (link_id, target_msg_id)) return helper_database.add_record(channel_id, msg_id, username, name, msg_type, msg_content, media_id, date, user_id, ori_msg_id)
def msg_detail(bot, update, chat_id, origin_message_id, args): channel_id = int(args[1]) msg_id = int(args[2]) row_id = int(args[3]) config = helper_database.get_channel_config(channel_id) if config is None: return channel_lang = config[1] recent = config[3] admin_id = config[5] if row_id < 0: bot.answer_callback_query( callback_query_id=update.callback_query.id, text=helper_global.value("no_message_detail", "No Message", lang=channel_lang) ) return records = helper_database.get_record_by_rowid(row_id) if records is None or len(records) == 0: bot.answer_callback_query( callback_query_id=update.callback_query.id, text=helper_global.value("no_message_detail", "No Message", lang=channel_lang) ) return record = records[0] username = record[2] name = record[3] msg_type = record[4] msg_content = record[5] media_id= record[6] user_id = int(record[8]) base_offset = helper_database.get_base_offset_by_rowid(channel_id, msg_id, row_id) offset = base_offset // recent msg_from_button = [ [ InlineKeyboardButton( helper_global.value("msg_from", "Message From: ", lang=channel_lang) + name, callback_data="blank" ) ] ] admin_operation_button = [ [ InlineKeyboardButton( helper_global.value("delete_msg", "Delete Message", lang=channel_lang), callback_data="msg_delete,%d,%d,%d,%d,%d,%d" % (row_id, channel_id, msg_id, recent, offset, chat_id) ), InlineKeyboardButton( helper_global.value("unban_user", "Unban User", lang=channel_lang), callback_data="user_unban,%d,%d,%s,%d,%d" % (channel_id, user_id, "", msg_id, row_id) ) if helper_database.check_ban(channel_id, user_id) else \ InlineKeyboardButton( helper_global.value("ban_user", "Ban User", lang=channel_lang), callback_data="user_ban,%d,%d,%s,%d,%d" % (channel_id, user_id, "", msg_id, row_id) ) ] ] if str(chat_id) == str(admin_id) else [] motd_keyboard = msg_from_button + admin_operation_button + [ [ InlineKeyboardButton( helper_global.value("prev_msg", "Prev Message", lang=channel_lang), callback_data="msg_detail,%d,%d,%d" % (channel_id, msg_id, helper_database.get_next_rowid(channel_id, msg_id, row_id)) ), InlineKeyboardButton( helper_global.value("next_msg", "Next Message", lang=channel_lang), callback_data="msg_detail,%d,%d,%d" % (channel_id, msg_id, helper_database.get_prev_rowid(channel_id, msg_id, row_id)) ) ], [ InlineKeyboardButton( helper_global.value("back_to_msg_list", "Back to message list", lang=channel_lang), callback_data="msg,%d,%d,%d,%d,%d" % (channel_id, msg_id, recent, offset, chat_id) ) ] ] motd_markup = InlineKeyboardMarkup(motd_keyboard) if msg_type == "text": bot.send_message( chat_id=chat_id, message_id=origin_message_id, text=msg_content, parse_mode='HTML', reply_markup=motd_markup ) bot.delete_message( chat_id=chat_id, message_id=origin_message_id ) elif msg_type == "audio" or msg_type == "document" or msg_type == "photo" or msg_type == "video" or msg_type == "sticker" or msg_type == "voice": send_func = { "audio": bot.send_audio, "document": bot.send_document, "photo": bot.send_photo, "video": bot.send_video, "sticker": bot.send_sticker, "voice": bot.send_voice } send_func[msg_type]( chat_id, media_id, caption=msg_content, parse_mode='HTML', reply_markup=motd_markup ) bot.delete_message( chat_id=chat_id, message_id=origin_message_id ) else: bot.send_message( chat_id=chat_id, message_id=origin_message_id, text="[%s] %s" % (msg_type, msg_content), parse_mode='HTML', reply_markup=motd_markup ) bot.delete_message( chat_id=chat_id, message_id=origin_message_id )