mirror of
https://github.com/nonebot/nonebot2.git
synced 2024-11-30 17:15:08 +08:00
Fix on_command bug
This commit is contained in:
parent
7da2043f94
commit
1392382244
@ -74,7 +74,8 @@ async def calculate_permission(bot: CQHttp, ctx: Dict[str, Any]) -> int:
|
||||
return permission
|
||||
|
||||
|
||||
def on_command(name: Union[str, Tuple[str]], aliases: Iterable = (),
|
||||
def on_command(name: Union[str, Tuple[str]], *,
|
||||
aliases: Iterable = (),
|
||||
permission: int = perm.EVERYONE) -> Callable:
|
||||
def deco(func: Callable) -> Callable:
|
||||
if not isinstance(name, (str, tuple)):
|
||||
@ -85,7 +86,7 @@ def on_command(name: Union[str, Tuple[str]], aliases: Iterable = (),
|
||||
cmd_name = name if isinstance(name, tuple) else (name,)
|
||||
current_parent = _registry
|
||||
for parent_key in cmd_name[:-1]:
|
||||
current_parent[parent_key] = {}
|
||||
current_parent[parent_key] = current_parent.get(parent_key) or {}
|
||||
current_parent = current_parent[parent_key]
|
||||
cmd = Command(name=cmd_name, func=func, permission=permission)
|
||||
current_parent[cmd_name[-1]] = cmd
|
||||
|
@ -2,7 +2,7 @@ import none
|
||||
from none.command import Session
|
||||
|
||||
|
||||
@none.on_command('weather', aliases=('天气',))
|
||||
@none.on_command(('weather', 'weather'), aliases=('天气',))
|
||||
async def weather(session: Session):
|
||||
city = session.require_arg('city', prompt='你想知道哪个城市的天气呢?')
|
||||
other = session.require_arg('other', prompt='其他信息?')
|
||||
@ -13,3 +13,8 @@ async def weather(session: Session):
|
||||
async def _(session: Session):
|
||||
if session.current_key:
|
||||
session.args[session.current_key] = session.current_arg.strip()
|
||||
|
||||
|
||||
@none.on_command(('weather', 'suggestion'), aliases=('生活指数', '生活提示'))
|
||||
async def suggestion(session: Session):
|
||||
await session.send('suggestion')
|
||||
|
Loading…
Reference in New Issue
Block a user