def start(bot, update, args): if args is None or len(args) == 0: text = helper_global.value("start_cmd_text", "") bot.send_message(chat_id=update.message.chat_id, text=text) return params = args[0].split("_") channel_id = int(params[1]) msg_id = int(params[2]) chat_id = update.message.chat_id if chat_id < 0: return if helper_database.check_ban(channel_id, chat_id): bot.send_message(chat_id=update.message.chat_id, text=helper_global.value("banned_prompt", "You are banned.")) return config = helper_database.get_channel_config(channel_id) if config is None: return recent, username = config[3], config[4] if params[0] == "add": helper_global.assign(str(chat_id) + "_status", params[1] + "," + params[2]) if username is not None: bot.send_message(chat_id=update.message.chat_id, text=helper_global.value("start_comment_mode", "") + "\n" + helper_global.value("target_message", "") + "https://t.me/%s/%d" % (username, msg_id)) else: bot.send_message(chat_id=update.message.chat_id, text=helper_global.value("start_comment_mode", "")) elif params[0] == "show": offset = 0 channel_username = config[4] records = helper_database.get_recent_records(channel_id, msg_id, recent, offset) # Prepare Keyboard msg_buttons = helper_global.records_to_buttons(records, channel_id, msg_id) motd_keyboard = msg_buttons + [[ InlineKeyboardButton( helper_global.value("prev_page", "Prev Page"), callback_data="msg,%d,%d,%d,%d,%d" % (channel_id, msg_id, recent, offset + 1, chat_id) ), InlineKeyboardButton( helper_global.value("next_page", "Next Page"), callback_data="msg,%d,%d,%d,%d,%d" % (channel_id, msg_id, recent, offset - 1, chat_id) ) ]] motd_markup = InlineKeyboardMarkup(motd_keyboard) prompt_text = helper_global.value("comment_header", "") if channel_username is not None and len(channel_username) > 0: prompt_text = "https://t.me/%s/%a\n" % (channel_username, msg_id) + prompt_text bot.send_message( chat_id=update.message.chat_id, text=prompt_text, parse_mode=telegram.ParseMode.HTML, reply_markup=motd_markup )
def start(bot, update, args): logger = Logger.logger if args is None or len(args) == 0: chat_id = update.message.chat_id logger.msg({"user_id": chat_id}, tag="start", log_level=80) helper_global.send_intro_template(bot, chat_id, helper_const.DEFAULT_LANG, "start", "start_cmd_text") return params = args[0].split("_") channel_id = int(params[1]) msg_id = int(params[2]) chat_id = update.message.chat_id logger.msg({"user_id": chat_id, "args": args}, tag="start", log_level=90) if chat_id < 0: return config = helper_database.get_channel_config(channel_id) if config is None: return channel_lang = config[1] recent, username = config[3], config[4] if helper_database.check_ban(channel_id, chat_id): bot.send_message(chat_id=update.message.chat_id, text=helper_global.value("banned_prompt", "You are banned.", lang=channel_lang)) return if params[0] == "add": helper_global.assign( str(chat_id) + "_status", params[1] + "," + params[2]) motd_keyboard = [[ InlineKeyboardButton( helper_global.value("reply_to", "Reply", lang=channel_lang) + "...", switch_inline_query_current_chat=" ") ]] motd_markup = InlineKeyboardMarkup(motd_keyboard) comment_id = helper_database.get_comment_id(channel_id, msg_id) suffix = "" if username is not None: if comment_id is not None: suffix = "\n" + helper_global.value( "target_comment", "", lang=channel_lang ) + "https://t.me/%s/%d" % (username, comment_id) bot.send_message( chat_id=update.message.chat_id, text=helper_global.value( "start_comment_mode", "", lang=channel_lang) + "\n" + helper_global.value("target_message", "", lang=channel_lang) + "https://t.me/%s/%d" % (username, msg_id) + suffix, reply_markup=motd_markup) else: link_id = abs(channel_id) % 10000000000 if comment_id is not None: suffix = "\n" + helper_global.value( "target_comment", "", lang=channel_lang ) + "https://t.me/%d/%d" % (link_id, comment_id) bot.send_message( chat_id=update.message.chat_id, text=helper_global.value( "start_comment_mode", "", lang=channel_lang) + "\n" + helper_global.value("target_message", "", lang=channel_lang) + "https://t.me/c/%d/%d" % (link_id, msg_id) + suffix, reply_markup=motd_markup) elif params[0] == "show": offset = 0 channel_username = config[4] records = helper_database.get_recent_records(channel_id, msg_id, recent, offset) # Prepare Keyboard msg_buttons = helper_global.records_to_buttons(records, channel_id, msg_id) motd_keyboard = msg_buttons + [[ InlineKeyboardButton( helper_global.value( "prev_page", "Prev Page", lang=channel_lang), callback_data="msg,%d,%d,%d,%d,%d" % (channel_id, msg_id, recent, offset + 1, chat_id)), InlineKeyboardButton( helper_global.value( "next_page", "Next Page", lang=channel_lang), callback_data="msg,%d,%d,%d,%d,%d" % (channel_id, msg_id, recent, offset - 1, chat_id)) ]] motd_markup = InlineKeyboardMarkup(motd_keyboard) prompt_text = helper_global.value("comment_header", "", lang=channel_lang) if channel_username is not None and len(channel_username) > 0: prompt_text = "https://t.me/%s/%a\n" % (channel_username, msg_id) + prompt_text bot.send_message(chat_id=update.message.chat_id, text=prompt_text, parse_mode=telegram.ParseMode.HTML, reply_markup=motd_markup)
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 )