@@ -418,15 +418,7 @@ async def send_forward_from_message_ids(group_id: int, title: str, user_id: int,
418418async def main ():
419419 log .info ("程序启动, WS_URL=%s, 通知群=%d, 白名单=%s" , WS_URL , INTERNAL_GROUP_ID , WHITELIST )
420420 log .info ("里程碑阈值(分钟): %s" , MILESTONES )
421-
422- try :
423- await client .send_group_msg (
424- group_id = str (INTERNAL_GROUP_ID ),
425- message = "🤖 客服机器人已启动,开始监听消息。" ,
426- )
427- log .info ("启动通知已发送至群 %d" , INTERNAL_GROUP_ID )
428- except Exception as e :
429- log .error ("发送启动通知失败: %s" , e , exc_info = True )
421+ startup_notified = False
430422
431423 # 启动定时巡检后台任务
432424 asyncio .create_task (monitor_loop ())
@@ -435,6 +427,17 @@ async def main():
435427 while True :
436428 log .info ("正在连接 WebSocket..." )
437429 async for event in client :
430+ if not startup_notified :
431+ try :
432+ await client .send_group_msg (
433+ group_id = str (INTERNAL_GROUP_ID ),
434+ message = "🤖 客服机器人已启动,开始监听消息。" ,
435+ )
436+ startup_notified = True
437+ log .info ("启动通知已发送至群 %d" , INTERNAL_GROUP_ID )
438+ except Exception as e :
439+ log .error ("发送启动通知失败: %s" , e , exc_info = True )
440+
438441 log .debug ("收到事件: type=%s, post_type=%s" , type (event ).__name__ , getattr (event , 'post_type' , '?' ))
439442 match event :
440443 # 0. 自动通过好友申请
0 commit comments