让回复 celeste 允许不用带有前缀
This commit is contained in:
@ -3,7 +3,7 @@ import subprocess
|
||||
import tempfile
|
||||
from typing import Any
|
||||
from loguru import logger
|
||||
from nonebot import on_command
|
||||
from nonebot import on_message
|
||||
from pydantic import BaseModel
|
||||
|
||||
from nonebot.adapters import Event, Bot
|
||||
@ -43,15 +43,11 @@ celeste_status = DataManager(CelesteStatus, DATA_PATH / "celeste-status.json")
|
||||
|
||||
|
||||
# ↓ 这里的 Type Hinting 是为了能 fit 进去 set[str | tuple[str, ...]]
|
||||
aliases: set[Any] = {"蔚蓝", "爬山", "鳌太线"}
|
||||
aliases: set[Any] = {"celeste", "蔚蓝", "爬山", "鳌太线"}
|
||||
ALLOW_CHARS = "wasdxc0123456789 \t\n\r"
|
||||
|
||||
|
||||
cmd = on_command(cmd="celeste", aliases=aliases)
|
||||
|
||||
|
||||
@cmd.handle()
|
||||
async def _(msg: UniMsg, evt: Event, bot: Bot):
|
||||
async def get_prev(evt: Event, bot: Bot) -> str | None:
|
||||
prev = None
|
||||
if isinstance(evt, OB11MessageEvent):
|
||||
if evt.reply is not None:
|
||||
@ -61,8 +57,30 @@ async def _(msg: UniMsg, evt: Event, bot: Bot):
|
||||
if seg.type == 'reply':
|
||||
msgid = seg.get('id')
|
||||
prev = f"QQ:{bot.self_id}:" + str(msgid)
|
||||
if prev is not None:
|
||||
async with celeste_status.get_data() as data:
|
||||
prev = data.records.get(prev)
|
||||
return prev
|
||||
|
||||
actions = msg.extract_plain_text().strip().removeprefix("celeste")
|
||||
|
||||
async def match_celeste(evt: Event, bot: Bot, msg: UniMsg) -> bool:
|
||||
prev = await get_prev(evt, bot)
|
||||
text = msg.extract_plain_text().strip()
|
||||
if any(text.startswith(a) for a in aliases):
|
||||
return True
|
||||
if prev is not None:
|
||||
return True
|
||||
return False
|
||||
|
||||
|
||||
# cmd = on_command(cmd="celeste", aliases=aliases)
|
||||
cmd = on_message(rule=match_celeste)
|
||||
|
||||
|
||||
@cmd.handle()
|
||||
async def _(msg: UniMsg, evt: Event, bot: Bot):
|
||||
prev = await get_prev(evt, bot)
|
||||
actions = msg.extract_plain_text().strip()
|
||||
for alias in aliases:
|
||||
actions = actions.removeprefix(alias)
|
||||
actions = actions.strip()
|
||||
@ -71,10 +89,6 @@ async def _(msg: UniMsg, evt: Event, bot: Bot):
|
||||
if any((c not in ALLOW_CHARS) for c in actions):
|
||||
return
|
||||
|
||||
if prev is not None:
|
||||
async with celeste_status.get_data() as data:
|
||||
prev = data.records.get(prev)
|
||||
|
||||
await ensure_artifact(arti_ccleste_wrap_linux)
|
||||
await ensure_artifact(arti_ccleste_wrap_windows)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user