Feature: 创建启动通知 #53
Reference in New Issue
Block a user
No description provided.
Delete Branch "feature/startup-notification"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
PR Type
Enhancement
Description
新增 Bot 启动通知插件
等待 Bot 上线后广播重启消息
注册"启动通知"频道及其描述信息
Diagram Walkthrough
File Walkthrough
startup_notify.py
新增启动通知插件,广播 Bot 重启消息konabot/plugins/startup_notify.py
CHANNEL_STARTUP频道及PosterInfoon_startup事件,轮询等待至少一个 bot 上线broadcast发送重启通知PR Reviewer Guide 🔍
Here are some key observations to aid the review process:
无限循环风险
while True轮询等待 bot 上线没有设置超时上限。如果 bot 因配置错误等原因永远无法上线,该任务将无限循环且每 15 秒轮询一次,永远不会退出。建议增加最大重试次数或总超时时间,并在超时后记录日志退出。任务引用丢失
asyncio.create_task(task())的返回值未被保存到任何变量中。Python 文档明确指出,如果不持有对 task 的引用,它可能会被垃圾回收器在完成前回收,导致任务静默消失。应将返回值赋给一个模块级变量或集合以保持强引用。异常处理缺失
task()内部的broadcast调用如果抛出异常,由于没有 try/except 包裹,异常只会作为 "Task exception was never retrieved" 被静默忽略(尤其在 task 引用丢失的情况下)。建议在 task 内部添加异常捕获和日志记录。PR Code Suggestions ✨
Explore these optional code suggestions:
无限等待循环缺少超时机制
这个
while True循环没有超时机制。如果 bot 永远无法连接(例如配置错误),此任务将无限循环等待,造成资源泄漏。建议添加最大重试次数或超时限制。konabot/plugins/startup_notify.py [23-26]
Suggestion importance[1-10]: 5
__
Why: The suggestion correctly identifies that the
while Trueloop at lines 23-26 has no timeout or retry limit, which could lead to an infinite loop if the bot never connects. Adding a max retry count is a reasonable defensive improvement. However, this is a startup notification feature — if the bot never connects, the loop just wastes minimal resources (sleeping 15s each iteration), and the broader system likely has bigger problems. It's a valid but moderate-impact improvement.