feat(onebot): emit bot_status on account session edges

Give downstream bots a notice when an account comes up or goes down, so they can handle their own alerts. Operator notification channels are unchanged.
This commit is contained in:
DrSmoothl committed 2026-09-16 17:04:06 +08:00
1 parent f2d58d2f79
commit ad36d47cf0
9 files changed
+307 -10

No files matched your search

+29
View File
@@ -1,5 +1,6 @@
import { describe, expect, it } from 'vitest';
import {
isBotStatusEvent,
isGroupMessageEvent,
isMessageEvent,
isMetaEvent,
@@ -248,6 +249,34 @@ describe('isNoticeEvent', () => {
expect(isNoticeEvent(nulled)).toBe(false);
});
it('accepts bot_status notices and rejects incomplete ones', () => {
expect(isBotStatusEvent({
time: 19,
self_id: 10000,
post_type: 'notice',
notice_type: 'bot_status',
sub_type: 'online',
user_id: 10000,
})).toBe(true);
expect(isBotStatusEvent({
time: 20,
self_id: 10000,
post_type: 'notice',
notice_type: 'bot_status',
sub_type: 'offline',
user_id: 10000,
})).toBe(true);
expect(isBotStatusEvent(NOTICE)).toBe(false);
expect(isBotStatusEvent({
time: 21,
self_id: 10000,
post_type: 'notice',
notice_type: 'bot_status',
sub_type: 'flap',
user_id: 10000,
})).toBe(false);
});
it('rejects other post types', () => {
expect(isNoticeEvent(PRIVATE_MESSAGE)).toBe(false);
expect(isNoticeEvent(REQUEST)).toBe(false);