Merge pull request 'Feature: 创建启动通知' (#53) from feature/startup-notification into master
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
Reviewed-on: #53
This commit is contained in:
33
konabot/plugins/startup_notify.py
Normal file
33
konabot/plugins/startup_notify.py
Normal file
@ -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())
|
||||||
|
|
||||||
Reference in New Issue
Block a user