Skip to content

Commit 8069bbd

Browse files
committed
[melobot] Better arguments passing for hook invoke method
1 parent 250af1d commit 8069bbd

File tree

7 files changed

+10
-11
lines changed

7 files changed

+10
-11
lines changed

src/melobot/_hook.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ async def emit(
4444
self,
4545
hook_type: HookEnumT,
4646
wait: bool = False,
47+
/,
4748
*,
4849
args: tuple | None = None,
4950
kwargs: dict[str, Any] | None = None,

src/melobot/adapter/base.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ async def __adapter_input_loop__(self, src: InSourceT) -> NoReturn:
185185
event = await self._event_factory.create(packet)
186186
with _EVENT_BUILD_INFO_CTX.unfold(EventBuildInfo(self, src)):
187187
await self._life_bus.emit(
188-
AdapterLifeSpan.BEFORE_EVENT, wait=True, args=(event,)
188+
AdapterLifeSpan.BEFORE_EVENT, True, args=(event,)
189189
)
190190
asyncio.create_task(self.dispatcher.broadcast(event))
191191
except Exception:
@@ -223,7 +223,7 @@ async def __adapter_launch__(self) -> AsyncGenerator[Self, None]:
223223

224224
finally:
225225
if self._inited:
226-
await self._life_bus.emit(AdapterLifeSpan.STOPPED, wait=True)
226+
await self._life_bus.emit(AdapterLifeSpan.STOPPED, True)
227227

228228
@final
229229
def filter_out(
@@ -260,9 +260,7 @@ async def call_output(self, action: ActionT) -> tuple[ActionHandle, ...]:
260260
else:
261261
osrcs = (self.out_srcs[0],) if len(self.out_srcs) else ()
262262

263-
await self._life_bus.emit(
264-
AdapterLifeSpan.BEFORE_ACTION, wait=True, args=(action,)
265-
)
263+
await self._life_bus.emit(AdapterLifeSpan.BEFORE_ACTION, True, args=(action,))
266264
return tuple(
267265
ActionHandle(action, osrc, self._output_factory, self._echo_factory)
268266
for osrc in osrcs

src/melobot/bot/base.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -367,7 +367,7 @@ async def core_run(self) -> None:
367367
for t in self._tasks:
368368
t.cancel()
369369

370-
await self._life_bus.emit(BotLifeSpan.STOPPED, wait=True)
370+
await self._life_bus.emit(BotLifeSpan.STOPPED, True)
371371
self.logger.info(f"{self} 已安全停止运行")
372372
self._running = False
373373

@@ -402,7 +402,7 @@ async def close(self) -> None:
402402
if not self._running:
403403
raise BotError(f"{self} 未在运行中,不能停止运行")
404404

405-
await self._life_bus.emit(BotLifeSpan.CLOSE, wait=True)
405+
await self._life_bus.emit(BotLifeSpan.CLOSE, True)
406406
self._rip_signal.set()
407407

408408
async def restart(self) -> NoReturn:

src/melobot/io/base.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ async def __aexit__(
117117
try:
118118
await self.close()
119119
finally:
120-
await self._life_bus.emit(SourceLifeSpan.STOPPED, wait=True)
120+
await self._life_bus.emit(SourceLifeSpan.STOPPED, True)
121121
return None
122122

123123
def on(

src/melobot/protocols/onebot/v11/io/duplex_http.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ async def _respond(self, request: aiohttp.web.Request) -> aiohttp.web.Response:
7070
and raw.get("meta_event_type") == "lifecycle"
7171
and raw.get("sub_type") == "connect"
7272
):
73-
await self._life_bus.emit(SourceLifeSpan.RESTARTED, wait=False)
73+
await self._life_bus.emit(SourceLifeSpan.RESTARTED, False)
7474
self.logger.generic_obj(
7575
"收到上报,未格式化的字典", str(raw), level=LogLevel.DEBUG
7676
)

src/melobot/protocols/onebot/v11/io/forward.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ async def open(self) -> None:
155155

156156
if self._restart_flag.is_set():
157157
self._restart_flag.clear()
158-
await self._life_bus.emit(SourceLifeSpan.RESTARTED, wait=False)
158+
await self._life_bus.emit(SourceLifeSpan.RESTARTED, False)
159159

160160
def opened(self) -> bool:
161161
return self._opened.is_set()

src/melobot/protocols/onebot/v11/io/reverse.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ async def _input_loop(self, ws: ServerConnection) -> None:
7272

7373
if self._restart_flag.is_set():
7474
self._restart_flag.clear()
75-
await self._life_bus.emit(SourceLifeSpan.RESTARTED, wait=False)
75+
await self._life_bus.emit(SourceLifeSpan.RESTARTED, False)
7676

7777
while True:
7878
try:

0 commit comments

Comments
 (0)