From f38c3e1c30ac53290f7d05d543ade5566f3e0026 Mon Sep 17 00:00:00 2001 From: Richard Chien Date: Fri, 21 Dec 2018 23:39:45 +0800 Subject: [PATCH] Fix command finding bug --- docs/changelog.md | 4 ++++ none/command.py | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/docs/changelog.md b/docs/changelog.md index 4cebcffd..295e2533 100644 --- a/docs/changelog.md +++ b/docs/changelog.md @@ -4,6 +4,10 @@ sidebar: auto # 更新日志 +## next + +- 修复调用不存在的多级命令(例如 `/echo/nonexist`)时,抛出异常导致 WebSocket 连接断开的问题 + ## v0.4.3 - 自然语言处理器支持响应只有机器人昵称而没有实际内容的消息,通过 `on_natural_language` 的 `allow_empty_message` 参数开启(默认关闭) diff --git a/none/command.py b/none/command.py index d1513631..7b8d1ea1 100644 --- a/none/command.py +++ b/none/command.py @@ -164,7 +164,7 @@ def _find_command(name: Union[str, CommandName_T]) -> Optional[Command]: cmd_tree = _registry for part in cmd_name[:-1]: - if part not in cmd_tree: + if part not in cmd_tree or not isinstance(cmd_tree[part], dict): return None cmd_tree = cmd_tree[part]