From 48e22f89d1646a7001a684f7830bc6e78f50c6f3 Mon Sep 17 00:00:00 2001 From: iwumingz Date: Sat, 9 Apr 2022 11:54:00 +0800 Subject: [PATCH] Command dict convert to constant --- core/__init__.py | 7 +++++-- core/custom.py | 14 +++++++------- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/core/__init__.py b/core/__init__.py index 81a1d10..5bcf715 100644 --- a/core/__init__.py +++ b/core/__init__.py @@ -1,4 +1,4 @@ -from .custom import command +from .custom import command, CMDS_DATA, CMDS_PREFIX from pyrogram import Client app = Client( @@ -9,5 +9,8 @@ app = Client( __all__ = ( - 'app', 'command', + 'app', + 'command', + 'CMDS_DATA', + 'CMDS_PREFIX', ) diff --git a/core/custom.py b/core/custom.py index ea7e00e..1e6b981 100644 --- a/core/custom.py +++ b/core/custom.py @@ -18,18 +18,18 @@ from pyrogram.types import Message from tools.constants import STORE_TRACE_DATA, COMMAND_YML from tools.storage import SimpleStore -command_data: Dict[str, Any] = yaml.full_load(open(COMMAND_YML, 'rb')) +CMDS_DATA: Dict[str, Any] = yaml.full_load(open(COMMAND_YML, 'rb')) +CMDS_PREFIX = CMDS_DATA.get('help').get('all_prefixes') def command(key: str): """匹配UserBot指令""" - prefixes = command_data.get('help').get('all_prefixes') - if type(command_data.get(key).get('cmd')) == str: - cmd = [command_data.get(key).get('cmd'), key] - return filters.me & filters.text & filters.command(cmd, prefixes) + if type(CMDS_DATA.get(key).get('cmd')) == str: + cmd = [CMDS_DATA.get(key).get('cmd'), key] + return filters.me & filters.text & filters.command(cmd, CMDS_PREFIX) - cmd = command_data.get(key).get('cmd') - return filters.me & filters.text & filters.command(cmd, prefixes) + cmd = CMDS_DATA.get(key).get('cmd') + return filters.me & filters.text & filters.command(cmd, CMDS_PREFIX) def is_traced():