From 48282ceb6c74f79df0748a2d71ca24ae30010238 Mon Sep 17 00:00:00 2001 From: passthem Date: Wed, 25 Feb 2026 15:08:23 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E5=90=AF=E5=8A=A8=E9=80=9A?= =?UTF-8?q?=E7=9F=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- konabot/plugins/startup_notify.py | 33 +++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 konabot/plugins/startup_notify.py diff --git a/konabot/plugins/startup_notify.py b/konabot/plugins/startup_notify.py new file mode 100644 index 0000000..6798de5 --- /dev/null +++ b/konabot/plugins/startup_notify.py @@ -0,0 +1,33 @@ +import asyncio +from nonebot import get_driver +from nonebot_plugin_alconna import UniMessage +from konabot.plugins.poster.poster_info import register_poster_info, PosterInfo +from konabot.plugins.poster.service import broadcast + + +CHANNEL_STARTUP = "启动通知" + + +register_poster_info(CHANNEL_STARTUP, PosterInfo( + aliases=set(), + description="当 Bot 重启时告知", +)) + +driver = get_driver() + +@driver.on_startup +async def _(): + # 要尽量保证接受讯息的服务存在 + # 所以在这里我们要等待一定时间后再发信 + async def task(): + while True: + if len(driver.bots) >= 1: + break + await asyncio.sleep(15) + + # 在这个时候,需求的 bot 已经上线,再等待一小会 + await asyncio.sleep(3) + await broadcast(CHANNEL_STARTUP, UniMessage.text("此方 BOT 重启好了")) + + asyncio.create_task(task()) + -- 2.49.0