From af4cc6f25a52d8402ae773ecc07f9109a21283bc Mon Sep 17 00:00:00 2001 From: RF-Tar-Railt <3165388245@qq.com> Date: Sun, 26 Nov 2023 17:21:31 +0800 Subject: [PATCH] chore(core): ctx.self as ContextSelector --- avilla/core/context/__init__.py | 5 +++-- avilla/core/context/_roles.py | 5 +++++ avilla/qqapi/perform/event/message.py | 13 ++++++++++++- 3 files changed, 20 insertions(+), 3 deletions(-) diff --git a/avilla/core/context/__init__.py b/avilla/core/context/__init__.py index 0d1d97f7..be727dd2 100644 --- a/avilla/core/context/__init__.py +++ b/avilla/core/context/__init__.py @@ -21,6 +21,7 @@ ContextMedium, ContextRequestSelector, ContextSceneSelector, + ContextSelfSelector, ) from ._selector import ContextSelector @@ -43,7 +44,7 @@ class Context: client: ContextClientSelector endpoint: ContextEndpointSelector scene: ContextSceneSelector - self: Selector + self: ContextSelfSelector mediums: list[ContextMedium] cache: ContextCache | dict[str, Any] @@ -70,7 +71,7 @@ def __init__( self.client = ContextClientSelector.from_selector(self, client) self.endpoint = ContextEndpointSelector.from_selector(self, endpoint) self.scene = ContextSceneSelector.from_selector(self, scene) - self.self = selft + self.self = ContextSelfSelector.from_selector(self, selft) self.mediums = [ContextMedium(ContextSelector.from_selector(self, medium)) for medium in mediums or []] self.cache = {"meta": prelude_metadatas or {}} diff --git a/avilla/core/context/_roles.py b/avilla/core/context/_roles.py index 3edf2bf5..7bd7de5a 100644 --- a/avilla/core/context/_roles.py +++ b/avilla/core/context/_roles.py @@ -38,6 +38,11 @@ def expects_request(self) -> ContextRequestSelector: raise ValueError(f"endpoint {self!r} is not a request endpoint") +class ContextSelfSelector(ContextSelector): + def trigger_activity(self, activity: str): + return self.context[ActivityTrigger.trigger](self.activity(activity)) + + class ContextSceneSelector(ContextSelector): def leave_scene(self): return self.context[SceneCapability.leave](self) diff --git a/avilla/qqapi/perform/event/message.py b/avilla/qqapi/perform/event/message.py index 546d758b..a06da99f 100644 --- a/avilla/qqapi/perform/event/message.py +++ b/avilla/qqapi/perform/event/message.py @@ -125,6 +125,12 @@ async def group_at_message(self, event_type: ..., raw_event: dict): if i := message.get(Reference): reply = group.message(i[0].message_id) message = message.exclude(Reference) + if message.content and isinstance(message.content[0], Text): + text = message.content[0].text.lstrip() # type: ignore + if not text: + message.content.pop(0) + else: + message.content[0] = Text(text) msg = Message( id=raw_event["id"], scene=group, @@ -214,7 +220,12 @@ async def c2c_message(self, event_type: ..., raw_event: dict): if i := message.get(Reference): reply = friend.message(i[0].message_id) message = message.exclude(Reference) - + if message.content and isinstance(message.content[0], Text): + text = message.content[0].text.lstrip() # type: ignore + if not text: + message.content.pop(0) + else: + message.content[0] = Text(text) msg = Message( id=raw_event["id"], scene=friend,