forked from mttu-developers/konabot
调整 celeste 过度反应的 bug
This commit is contained in:
@ -1,6 +1,7 @@
|
|||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
import subprocess
|
import subprocess
|
||||||
import tempfile
|
import tempfile
|
||||||
|
from typing import Any
|
||||||
from loguru import logger
|
from loguru import logger
|
||||||
from nonebot import on_command
|
from nonebot import on_command
|
||||||
from pydantic import BaseModel
|
from pydantic import BaseModel
|
||||||
@ -41,7 +42,12 @@ class CelesteStatus(BaseModel):
|
|||||||
celeste_status = DataManager(CelesteStatus, DATA_PATH / "celeste-status.json")
|
celeste_status = DataManager(CelesteStatus, DATA_PATH / "celeste-status.json")
|
||||||
|
|
||||||
|
|
||||||
cmd = on_command(cmd="celeste", aliases={"蔚蓝", "爬山", "鳌太线"})
|
# ↓ 这里的 Type Hinting 是为了能 fit 进去 set[str | tuple[str, ...]]
|
||||||
|
aliases: set[Any] = {"蔚蓝", "爬山", "鳌太线"}
|
||||||
|
ALLOW_CHARS = "wasdxc0123456789 \t\n\r"
|
||||||
|
|
||||||
|
|
||||||
|
cmd = on_command(cmd="celeste", aliases=aliases)
|
||||||
|
|
||||||
|
|
||||||
@cmd.handle()
|
@cmd.handle()
|
||||||
@ -57,11 +63,13 @@ async def _(msg: UniMsg, evt: Event, bot: Bot):
|
|||||||
prev = f"QQ:{bot.self_id}:" + str(msgid)
|
prev = f"QQ:{bot.self_id}:" + str(msgid)
|
||||||
|
|
||||||
actions = msg.extract_plain_text().strip().removeprefix("celeste")
|
actions = msg.extract_plain_text().strip().removeprefix("celeste")
|
||||||
for alias in {"蔚蓝", "爬山", "鳌太线"}:
|
for alias in aliases:
|
||||||
actions = actions.removeprefix(alias)
|
actions = actions.removeprefix(alias)
|
||||||
actions = actions.strip()
|
actions = actions.strip()
|
||||||
if len(actions) == 0:
|
if len(actions) == 0:
|
||||||
return
|
return
|
||||||
|
if any((c not in ALLOW_CHARS) for c in actions):
|
||||||
|
return
|
||||||
|
|
||||||
if prev is not None:
|
if prev is not None:
|
||||||
async with celeste_status.get_data() as data:
|
async with celeste_status.get_data() as data:
|
||||||
|
|||||||
Reference in New Issue
Block a user