diff --git a/core/parser.py b/core/parser.py index cb5eed69..c0c34eb1 100644 --- a/core/parser.py +++ b/core/parser.py @@ -12,9 +12,6 @@ from core.template import sendMessage, Nudge database = BotDB() -command_list = Modules - - async def parser(kwargs: dict): """ 接收消息必经的预处理器 @@ -42,7 +39,7 @@ async def parser(kwargs: dict): if display[0] in command_prefix: # 检查消息前缀 command = re.sub(r'^' + display[0], '', display) command_first_word = command.split(' ')[0] # 切割消息 - if command_first_word in command_list['command']: # 检查触发命令是否在模块列表中 + if command_first_word in Modules['command']: # 检查触发命令是否在模块列表中 if Group in kwargs: await Nudge(kwargs) check_command_enable = database.check_enable_modules(kwargs[Group].id, command_first_word) # 检查群组是否开启模块 @@ -51,46 +48,46 @@ async def parser(kwargs: dict): command_first_word) if check_command_enable_self: kwargs['trigger_msg'] = command # 触发该命令的消息,去除消息前缀 - kwargs['help_list'] = command_list['help'] # 帮助列表 - await command_list['command'][command_first_word](kwargs) # 将dict传入下游模块 + kwargs['help_list'] = Modules['help'] # 帮助列表 + await Modules['command'][command_first_word](kwargs) # 将dict传入下游模块 else: await sendMessage(kwargs, f'此模块未启用,请管理员在群内发送~enable {command_first_word}启用本模块。') elif 'TEST' in kwargs: kwargs['trigger_msg'] = command # 触发该命令的消息,去除消息前缀 - kwargs['help_list'] = command_list['help'] # 帮助列表 - await command_list['command'][command_first_word](kwargs) # 将dict传入下游模块 + kwargs['help_list'] = Modules['help'] # 帮助列表 + await Modules['command'][command_first_word](kwargs) # 将dict传入下游模块 else: check_command_enable_self = database.check_enable_modules_self(kwargs[Friend].id, command_first_word) # 检查个人是否开启模块 if check_command_enable_self: kwargs['trigger_msg'] = command - kwargs['help_list'] = command_list['help'] - await command_list['command'][command_first_word](kwargs) - elif command_first_word in command_list['essential']: # 若触发的对象命令为基础命令 + kwargs['help_list'] = Modules['help'] + await Modules['command'][command_first_word](kwargs) + elif command_first_word in Modules['essential']: # 若触发的对象命令为基础命令 await Nudge(kwargs) kwargs['trigger_msg'] = command - kwargs['function_list'] = command_list['modules_function'] # 所有可用模块列表 - kwargs['friend_function_list'] = command_list['friend_modules_function'] - kwargs['help_list'] = command_list['help'] - await command_list['essential'][command_first_word](kwargs) - elif command_first_word in command_list['admin']: # 若触发的对象为超管命令 + kwargs['function_list'] = Modules['modules_function'] # 所有可用模块列表 + kwargs['friend_function_list'] = Modules['friend_modules_function'] + kwargs['help_list'] = Modules['help'] + await Modules['essential'][command_first_word](kwargs) + elif command_first_word in Modules['admin']: # 若触发的对象为超管命令 if database.check_superuser(kwargs): # 检查是否为超管 kwargs['trigger_msg'] = command - kwargs['function_list'] = command_list['modules_function'] - await command_list['admin'][command_first_word](kwargs) + kwargs['function_list'] = Modules['modules_function'] + await Modules['admin'][command_first_word](kwargs) else: await sendMessage(kwargs, '权限不足') # 正则模块部分 if Group in kwargs: - for regex in command_list['regex']: # 遍历正则模块列表 + for regex in Modules['regex']: # 遍历正则模块列表 check_command_enable = database.check_enable_modules(kwargs[Group].id, regex) # 检查群组是否打开模块 if check_command_enable: check_command_enable_self = database.check_enable_modules_self(kwargs[Member].id, regex) # 检查个人是否打开模块 if check_command_enable_self: - await command_list['regex'][regex](kwargs) # 将整条dict传入下游正则模块 + await Modules['regex'][regex](kwargs) # 将整条dict传入下游正则模块 if Friend in kwargs: - for regex in command_list['regex']: + for regex in Modules['regex']: check_command_enable_self = database.check_enable_modules_self(kwargs[Friend].id, regex) if check_command_enable_self: - await command_list['regex'][regex](kwargs) + await Modules['regex'][regex](kwargs)