🐛 fix: key erro when command not found

This commit is contained in:
yanyongyu 2020-09-08 14:36:21 +08:00
parent e0e23283c1
commit b3a796e726

View File

@ -60,9 +60,15 @@ class TrieRule:
def get_value(cls, bot: Bot, event: Event, def get_value(cls, bot: Bot, event: Event,
state: dict) -> Tuple[Dict[str, Any], Dict[str, Any]]: state: dict) -> Tuple[Dict[str, Any], Dict[str, Any]]:
if event.type != "message": if event.type != "message":
state["_prefix"] = {} state["_prefix"] = {"raw_command": None, "command": None}
state["_suffix"] = {} state["_suffix"] = {"raw_command": None, "command": None}
return {}, {} return {
"raw_command": None,
"command": None
}, {
"raw_command": None,
"command": None
}
prefix = None prefix = None
suffix = None suffix = None
@ -77,19 +83,31 @@ class TrieRule:
state["_prefix"] = { state["_prefix"] = {
"raw_command": prefix.key, "raw_command": prefix.key,
"command": prefix.value "command": prefix.value
} if prefix else {} } if prefix else {
"raw_command": None,
"command": None
}
state["_suffix"] = { state["_suffix"] = {
"raw_command": suffix.key, "raw_command": suffix.key,
"command": suffix.value "command": suffix.value
} if suffix else {} } if suffix else {
"raw_command": None,
"command": None
}
return ({ return ({
"raw_command": prefix.key, "raw_command": prefix.key,
"command": prefix.value "command": prefix.value
} if prefix else {}, { } if prefix else {
"raw_command": None,
"command": None
}, {
"raw_command": suffix.key, "raw_command": suffix.key,
"command": suffix.value "command": suffix.value
} if suffix else {}) } if suffix else {
"raw_command": None,
"command": None
})
def startswith(msg: str) -> Rule: def startswith(msg: str) -> Rule: