Little improve

This commit is contained in:
Richard Chien 2018-07-06 14:24:18 +08:00
parent 946d0a11cd
commit 1b3980b5d2
2 changed files with 3 additions and 5 deletions

View File

@ -8,14 +8,13 @@ from typing import Any, Optional
from aiocqhttp import CQHttp from aiocqhttp import CQHttp
from aiocqhttp.message import Message from aiocqhttp.message import Message
from . import default_config
from .log import logger from .log import logger
class NoneBot(CQHttp): class NoneBot(CQHttp):
def __init__(self, config_object: Any = None): def __init__(self, config_object: Any = None):
if config_object is None: if config_object is None:
config_object = default_config from . import default_config as config_object
super_kwargs = {k.lower(): v for k, v in config_object.__dict__.items() super_kwargs = {k.lower(): v for k, v in config_object.__dict__.items()
if k.isupper() and not k.startswith('_')} if k.isupper() and not k.startswith('_')}
@ -64,7 +63,7 @@ class NoneBot(CQHttp):
return os.path.join(parent, os.path.basename(rel_path)) return os.path.join(parent, os.path.basename(rel_path))
_bot = None _bot: Optional[NoneBot] = None
def init(config_object: Any = None) -> None: def init(config_object: Any = None) -> None:
@ -93,7 +92,6 @@ def get_bot() -> NoneBot:
""" """
if _bot is None: if _bot is None:
raise ValueError('NoneBot instance has not been initialized') raise ValueError('NoneBot instance has not been initialized')
# noinspection PyTypeChecker
return _bot return _bot

View File

@ -89,7 +89,7 @@ def on_command(name: Union[str, Tuple[str]], *,
if not name: if not name:
raise ValueError('the name of a command must not be empty') raise ValueError('the name of a command must not be empty')
cmd_name = name if isinstance(name, tuple) else (name,) cmd_name = (name,) if isinstance(name, str) else name
current_parent = _registry current_parent = _registry
for parent_key in cmd_name[:-1]: for parent_key in cmd_name[:-1]:
current_parent[parent_key] = current_parent.get(parent_key) or {} current_parent[parent_key] = current_parent.get(parent_key) or {}