def check_channel_message(bot, message): chat_id = message.chat_id if not message.forward_from_chat: bot.send_message(chat_id=chat_id, text=helper_global.value("register_cmd_invalid", "")) return chat_type = message.forward_from_chat.type if not chat_type == "channel": bot.send_message(chat_id=chat_id, text=helper_global.value("register_cmd_invalid", "")) return channel_username = message.forward_from_chat.username channel_id = message.forward_from_chat.id try: helper_database.add_channel_config(channel_id, 'zh-CN', 1, 10, channel_username, chat_id) except: helper_global.assign(str(chat_id) + "_status", "0,0") bot.send_message(chat_id=chat_id, text=helper_global.value("register_cmd_failed", "")) return helper_global.assign(str(chat_id) + "_status", "0,0") bot.send_message(chat_id=chat_id, text=helper_global.value("register_cmd_success", ""))
def check_channel_message(bot, message): chat_id = message.chat_id if not message.forward_from_chat: bot.send_message(chat_id=chat_id, text=helper_global.value("register_cmd_invalid", "", "all")) return chat_type = message.forward_from_chat.type if not chat_type == "channel": bot.send_message(chat_id=chat_id, text=helper_global.value("register_cmd_invalid", "", "all")) return channel_username = message.forward_from_chat.username channel_id = message.forward_from_chat.id user_id = message.from_user.id 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: bot.send_message(chat_id=chat_id, text=helper_global.value("register_cmd_not_admin", "", "all")) 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: bot.send_message(chat_id=chat_id, text=helper_global.value( "register_cmd_no_permission", "", "all")) return break except: bot.send_message(chat_id=chat_id, text=helper_global.value("register_cmd_no_info", "", "all")) return try: helper_database.add_channel_config(channel_id, helper_const.DEFAULT_LANG, 1, 10, channel_username, chat_id, 1) except: helper_global.assign(str(chat_id) + "_status", "0,0") bot.send_message(chat_id=chat_id, text=helper_global.value("register_cmd_failed", "", "all")) return helper_global.assign(str(chat_id) + "_status", "0,0") bot.send_message(chat_id=chat_id, text=helper_global.value("register_cmd_success", "", "all"))
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")