diff --git a/astrbot/builtin_stars/astrbot/main.py b/astrbot/builtin_stars/astrbot/main.py index e0053a29de..d9f18a4bba 100644 --- a/astrbot/builtin_stars/astrbot/main.py +++ b/astrbot/builtin_stars/astrbot/main.py @@ -13,6 +13,7 @@ FILTERS, USER_SESSIONS, SessionController, + SessionFilter, SessionWaiter, session_waiter, ) @@ -27,6 +28,22 @@ def _iter_message_components(event: AstrMessageEvent): return tuple(messages) +class _SenderSessionFilter(SessionFilter): + """Session filter scoped to a specific (conversation, sender) pair. + + Used by the empty-mention waiter so that only the user who initiated the + empty mention (not every member of the group) can satisfy the waiter. + """ + + def filter(self, ev: AstrMessageEvent) -> str: + sender_id = ev.get_sender_id() or "" + if not sender_id: + # Fall back to a value that will not accidentally collide with a + # legitimate session key from another member. + sender_id = "__unknown_sender__" + return f"{ev.unified_msg_origin}:{sender_id}" + + class Main(star.Star): def __init__(self, context: star.Context) -> None: self.context = context @@ -126,7 +143,7 @@ async def empty_mention_waiter( controller.stop() try: - await empty_mention_waiter(event) + await empty_mention_waiter(event, session_filter=_SenderSessionFilter()) except TimeoutError: pass except Exception as e: