Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 18 additions & 1 deletion astrbot/builtin_stars/astrbot/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
FILTERS,
USER_SESSIONS,
SessionController,
SessionFilter,
SessionWaiter,
session_waiter,
)
Expand All @@ -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
Expand Down Expand Up @@ -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:
Expand Down