Skip to content

Commit 03f0750

Browse files
committed
🐛 fix Channel get in event gather
1 parent a4b9df3 commit 03f0750

4 files changed

Lines changed: 19 additions & 17 deletions

File tree

‎arclet/entari/builtins/help.py‎

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
from tarina import lang
1818

1919
from arclet.entari import BasicConfModel, Session, command, metadata, plugin_config
20+
from arclet.entari.command import Match, Query
2021

2122

2223
class Config(BasicConfModel):
@@ -209,21 +210,21 @@ def generator(_page: int):
209210

210211
@disp.on_execute()
211212
async def help_exec(
212-
query: command.Match[str],
213-
page: command.Query[int] = command.Query("page.index", 1),
214-
hide: command.Query[bool] = command.Query("hide.value", False),
215-
is_namespace: command.Query[SubcommandResult | None] = command.Query("namespace"),
213+
query: Match[str],
214+
page: Query[int] = Query("page.index", 1),
215+
hide: Query[bool] = Query("hide.value", False),
216+
is_namespace: Query[SubcommandResult | None] = Query("namespace"),
216217
):
217218
return help_cmd_handle(is_namespace.result, query.result, page.result, hide.result)
218219

219220

220221
@disp.handle(priority=16)
221222
async def help_handle(
222223
session: Session,
223-
query: command.Match[str],
224-
page: command.Query[int] = command.Query("page.index", 1),
225-
hide: command.Query[bool] = command.Query("hide.value", False),
226-
is_namespace: command.Query[SubcommandResult | None] = command.Query("namespace"),
224+
query: Match[str],
225+
page: Query[int] = Query("page.index", 1),
226+
hide: Query[bool] = Query("hide.value", False),
227+
is_namespace: Query[SubcommandResult | None] = Query("namespace"),
227228
):
228229
resp = help_cmd_handle(is_namespace.result, query.result, page.result, hide.result, True)
229230
if isinstance(resp, str):

‎arclet/entari/event/send.py‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,10 @@ def check_result(self, value) -> Result[bool | MessageChain] | None:
3030
@before_send_pub.gather
3131
async def req_gather(req: SendRequest, context: Contexts):
3232
context["$account"] = req.account
33-
context["$channel"] = req.account.channel_get(req.channel)
33+
context["$channel"] = await req.account.channel_get(req.channel)
3434
context["$message"] = req.message
3535
if req.session:
36-
context["session"] = req.session
36+
context["$session"] = req.session
3737

3838

3939
@dataclass
@@ -47,14 +47,14 @@ class SendResponse:
4747

4848
send_pub = define(SendResponse, name="entari.event/after_send")
4949
send_pub.bind(provide(MessageChain, call="$message"))
50-
send_pub.bind(provide(list, target="result"))
50+
send_pub.bind(provide(list[MessageReceipt], call="$resp_result"))
5151

5252

5353
@send_pub.gather
5454
async def resp_gather(resp: SendResponse, context: Contexts):
5555
context["$account"] = resp.account
56-
context["$channel"] = resp.account.channel_get(resp.channel)
56+
context["$channel"] = await resp.account.channel_get(resp.channel)
5757
context["$message"] = resp.message
58-
context["result"] = resp.result
58+
context["$resp_result"] = resp.result
5959
if resp.session:
6060
context["$session"] = resp.session

‎arclet/entari/session.py‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -95,9 +95,9 @@ async def message_create(self, channel_id: str, content: str | Iterable[str | El
9595
msg.insert(0, reply_to)
9696
sess = None
9797
if source:
98-
sess = Session(self.account.custom(protocol_cls=EntariProtocol), source)
98+
sess = Session(self.account, source) # type: ignore
9999
sess.elements = msg
100-
res = await es.post(ev := SendRequest(self.account.custom(protocol_cls=EntariProtocol), channel_id, msg, sess))
100+
res = await es.post(ev := SendRequest(self.account, channel_id, msg, sess))
101101
msg = sess._content if sess and sess._content else ev.message
102102
if res:
103103
if res.value is False:
@@ -111,7 +111,7 @@ async def message_create(self, channel_id: str, content: str | Iterable[str | El
111111
)
112112
res = cast("list[dict]", res)
113113
resp = [MessageReceipt.parse(i) for i in res]
114-
await es.publish(SendResponse(self.account.custom(protocol_cls=EntariProtocol), channel_id, msg, resp, sess))
114+
await es.publish(SendResponse(self.account, channel_id, msg, resp, sess))
115115
return resp
116116

117117
# fmt: on
@@ -291,6 +291,7 @@ async def send(self, message: str | Iterable[str | Element], at_sender: bool = F
291291
292292
Args:
293293
message: 要发送的消息
294+
source (SatoriEvent | None): 源事件
294295
at_sender: 是否 @ 发送者,默认为 False
295296
reply_to: 是否作为回复发送,默认为 False
296297

‎main.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ async def echoimg(img: Image, session: Session):
88
await session.send_message([img])
99

1010

11-
app = Entari.load()
11+
app = Entari.load("example.yml")
1212

1313

1414
@command.on("load {plugin}")

0 commit comments

Comments
 (0)