Skip to content

Commit

Permalink
chore(core): ctx.self as ContextSelector
Browse files Browse the repository at this point in the history
  • Loading branch information
RF-Tar-Railt committed Nov 26, 2023
1 parent 1a83a81 commit af4cc6f
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 3 deletions.
5 changes: 3 additions & 2 deletions avilla/core/context/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
ContextMedium,
ContextRequestSelector,
ContextSceneSelector,
ContextSelfSelector,
)
from ._selector import ContextSelector

Expand All @@ -43,7 +44,7 @@ class Context:
client: ContextClientSelector
endpoint: ContextEndpointSelector
scene: ContextSceneSelector
self: Selector
self: ContextSelfSelector
mediums: list[ContextMedium]

cache: ContextCache | dict[str, Any]
Expand All @@ -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 {}}
Expand Down
5 changes: 5 additions & 0 deletions avilla/core/context/_roles.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
13 changes: 12 additions & 1 deletion avilla/qqapi/perform/event/message.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit af4cc6f

Please sign in to comment.