From 6f937f87cd06554d04c569458a17eaccddf8c704 Mon Sep 17 00:00:00 2001 From: LoCCai <105721394+LoCCai@users.noreply.github.com> Date: Sat, 10 Oct 2026 07:34:34 +0000 Subject: [PATCH] fix(onebot11): support SnowLuma group message reactions --- .github/workflows/ruff.yml | 2 ++ pyproject.toml | 1 + .../builtins/plugins/with/__init__.py | 6 +++--- src/nonebot_plugin_alconna/matcher.py | 6 +++--- .../uniseg/adapters/onebot11/exporter.py | 9 ++++++++- src/nonebot_plugin_alconna/uniseg/builder.py | 2 +- 6 files changed, 18 insertions(+), 8 deletions(-) diff --git a/.github/workflows/ruff.yml b/.github/workflows/ruff.yml index fad612f..46def23 100644 --- a/.github/workflows/ruff.yml +++ b/.github/workflows/ruff.yml @@ -15,3 +15,5 @@ jobs: - name: Run Ruff Lint uses: chartboost/ruff-action@v1 + with: + version: "0.16.2" diff --git a/pyproject.toml b/pyproject.toml index 61e6491..f3b8ea9 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -120,6 +120,7 @@ ignore = [ "PLC0415", # 你别管我为什么不在顶层 import "PLC0105", # 我们已经用 R 表示协变,Q 表示逆变了 "PLR0913", # 参数就那么多的,你用 builder 什么的不是更逆天? + "PLR0917", # Preserve positional arguments in the existing public API. "SIM108", # 迫真 simplicy "RUF001", # String contains ambiguous `,` (FULLWIDTH COMMA). Did you mean `,` (COMMA)? "RUF002", # Docstring contains ambiguous `,` (FULLWIDTH COMMA). Did you mean `,` (COMMA)? diff --git a/src/nonebot_plugin_alconna/builtins/plugins/with/__init__.py b/src/nonebot_plugin_alconna/builtins/plugins/with/__init__.py index cc3481e..3735855 100644 --- a/src/nonebot_plugin_alconna/builtins/plugins/with/__init__.py +++ b/src/nonebot_plugin_alconna/builtins/plugins/with/__init__.py @@ -1,5 +1,5 @@ import asyncio -import datetime +import datetime as dt import json from arclet.alconna import namespace @@ -55,7 +55,7 @@ async def unset(target: MsgTarget): await with_.finish("取消设置成功") @with_.handle() - async def _(name: Match[str], target: MsgTarget, time: Match[datetime.datetime]): + async def _(name: Match[str], target: MsgTarget, time: Match[dt.datetime]): key = json.dumps(target.dump(only_scope=True), ensure_ascii=False) if not name.available: if key not in data: @@ -66,7 +66,7 @@ async def _(name: Match[str], target: MsgTarget, time: Match[datetime.datetime]) data[key] = name.result if time.available: asyncio.get_running_loop().call_later( - abs((time.result - datetime.datetime.now()).total_seconds()), remove, key # noqa: DTZ005 + abs((time.result - dt.datetime.now()).total_seconds()), remove, key # noqa: DTZ005 ) await with_.finish("设置前缀成功") diff --git a/src/nonebot_plugin_alconna/matcher.py b/src/nonebot_plugin_alconna/matcher.py index 68a215a..ce396ea 100644 --- a/src/nonebot_plugin_alconna/matcher.py +++ b/src/nonebot_plugin_alconna/matcher.py @@ -954,8 +954,8 @@ def ensure_context(self, bot: Bot, event: Event): def on_alconna( command: Alconna | str, - rule: None | Rule | T_RuleChecker = None, - after_rule: None | Rule | T_RuleChecker = None, + rule: Rule | T_RuleChecker | None = None, + after_rule: Rule | T_RuleChecker | None = None, skip_for_unmatch: bool = True, auto_send_output: bool | None = None, aliases: set[str] | tuple[str, ...] | None = None, @@ -966,7 +966,7 @@ def on_alconna( use_cmd_start: bool | None = None, use_cmd_sep: bool | None = None, response_self: bool | None = None, - permission: None | Permission | T_PermissionChecker = None, + permission: Permission | T_PermissionChecker | None = None, *, handlers: list[T_Handler | Dependent] | None = None, temp: bool = False, diff --git a/src/nonebot_plugin_alconna/uniseg/adapters/onebot11/exporter.py b/src/nonebot_plugin_alconna/uniseg/adapters/onebot11/exporter.py index 62d6d00..45f4ea1 100644 --- a/src/nonebot_plugin_alconna/uniseg/adapters/onebot11/exporter.py +++ b/src/nonebot_plugin_alconna/uniseg/adapters/onebot11/exporter.py @@ -238,7 +238,14 @@ async def reaction(self, emoji: Emoji, mid: Any, bot: Bot, context: Target | Eve code=emoji.id, is_add=not delete, ) - elif app_name == "NapCat.Onebot": + elif app_name in ("NapCat.Onebot", "SnowLuma"): + if app_name == "SnowLuma": + # SnowLuma implements the NapCat reaction API for group messages only. + if isinstance(context, Target): + if context.private or context.channel: + return + elif getattr(context, "group_id", None) is None: + return await bot.call_api( "set_msg_emoji_like", message_id=int(message_id), diff --git a/src/nonebot_plugin_alconna/uniseg/builder.py b/src/nonebot_plugin_alconna/uniseg/builder.py index c2158c4..2a78981 100644 --- a/src/nonebot_plugin_alconna/uniseg/builder.py +++ b/src/nonebot_plugin_alconna/uniseg/builder.py @@ -29,7 +29,7 @@ class MessageBuilder(Generic[TS], metaclass=ABCMeta): @abstractmethod def get_adapter(cls) -> SupportAdapter: ... - def wildcard_build(self, seg: TS) -> Segment | None | list[Segment]: + def wildcard_build(self, seg: TS) -> Segment | list[Segment] | None: return None def __init__(self):