def help(bot, update): logger = Logger.logger chat_id = update.message.chat_id logger.msg({ "user_id": chat_id }, tag="help", log_level=80) helper_global.send_intro_template(bot, chat_id, helper_const.DEFAULT_LANG, "help", "help_cmd_text")
def register(bot, update): logger = Logger.logger from_id = update.message.from_user.id chat_id = update.message.chat_id logger.msg({"user_id": from_id}, tag="register", log_level=80) helper_global.assign(str(from_id) + "_status", "0,1") helper_global.send_intro_template(bot, chat_id, helper_const.DEFAULT_LANG, "register", "register_cmd_text")
def option(bot, update, args): logger = Logger.logger if args is None or len(args) == 0: lang = helper_const.DEFAULT_LANG else: lang = args[0] chat_id = update.message.chat_id logger.msg({"user_id": chat_id}, tag="option", log_level=80) records = helper_database.get_channel_info_by_user(chat_id) if records is None or len(records) == 0: helper_global.send_intro_template(bot, chat_id, helper_const.DEFAULT_LANG, "option_no_channel", "option_no_channel") return #Prepare keyboard lang_list = helper_const.LANG_LIST width = helper_const.LANG_WIDTH current_lang = lang key = "option" motd_keyboard = [[ InlineKeyboardButton( "@" + record[1] if record[1] else "id: " + str(record[0]), callback_data="option|%s,%s" % (lang, record[0])) ] for record in records] + [[ InlineKeyboardButton(helper_global.value("option_finish", "", lang), callback_data="option_finish|%s" % lang) ]] + [[ InlineKeyboardButton( lang_list[width * idx + delta] + (" (*)" if lang_list[width * idx + delta] == current_lang else ""), callback_data="%s|%s" % (key, lang_list[width * idx + delta])) for delta in range(width) ] for idx in range(len(lang_list) // width)] + [[ InlineKeyboardButton( lang_list[idx] + (" (*)" if lang_list[idx] == current_lang else ""), callback_data="%s|%s" % (key, lang_list[idx])) for idx in range(width * (len(lang_list) // width), len(lang_list)) ]] motd_markup = InlineKeyboardMarkup(motd_keyboard) bot.send_message(chat_id=chat_id, text=helper_global.value("option_choose_channel", "", lang=lang), reply_markup=motd_markup)
def check_channel_message(bot, message): logger = Logger.logger chat_id = message.chat_id if not message.forward_from_chat: helper_global.send_intro_template(bot, chat_id, helper_const.DEFAULT_LANG, "register_invalid", "register_cmd_invalid") return chat_type = message.forward_from_chat.type if not chat_type == "channel": helper_global.send_intro_template(bot, chat_id, helper_const.DEFAULT_LANG, "register_invalid", "register_cmd_invalid") return channel_username = message.forward_from_chat.username channel_id = message.forward_from_chat.id user_id = message.from_user.id logger.msg( { "user_id": chat_id, "channel_id": channel_id, "action": "check channel" }, tag="private", log_level=90) bot_id = int(helper_const.BOT_TOKEN.split(":")[0]) try: chat_members = bot.get_chat_administrators(chat_id=channel_id).result() chat_member_ids = [member.user.id for member in chat_members] if not user_id in chat_member_ids: helper_global.send_intro_template(bot, chat_id, helper_const.DEFAULT_LANG, "register_not_admin", "register_cmd_not_admin") return for member in chat_members: if member.user.id == bot_id: post_permission = member.can_post_messages if member.can_post_messages else False edit_permission = member.can_edit_messages if member.can_edit_messages else False delete_permission = member.can_delete_messages if member.can_delete_messages else False if not post_permission or not edit_permission or not delete_permission: helper_global.send_intro_template( bot, chat_id, helper_const.DEFAULT_LANG, "register_no_permission", "register_cmd_no_permission") return break except: helper_global.send_intro_template(bot, chat_id, helper_const.DEFAULT_LANG, "register_no_info", "register_cmd_no_info") return try: helper_database.add_channel_config(channel_id, helper_const.DEFAULT_LANG, 1, 10, channel_username, chat_id, 1, 1) except: helper_global.assign(str(chat_id) + "_status", "0,0") helper_global.send_intro_template(bot, chat_id, helper_const.DEFAULT_LANG, "register_failed", "register_cmd_failed") return helper_global.assign(str(chat_id) + "_status", "0,0") helper_global.send_intro_template(bot, chat_id, helper_const.DEFAULT_LANG, "register_success", "register_cmd_success")
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)