feat(onebot): report C2C input status as notify/input_status

Decode the 0x210/0x115 input-state sys_msg (RE'd from wrapper.linux.node
aio_input_state_worker) into a friend_input_status event and map it to a
notify/input_status notice, matching NapCat's onInputStatusPush.
event_type 1 = typing, 3 = recording voice; status_text synthesised to
match the client's own strings.
This commit is contained in:
DrSmoothl committed 2026-07-07 01:26:31 +08:00
1 parent d35e276730
commit 852870db59
8 files changed
+138 -1

No files matched your search

@@ -14,6 +14,7 @@ import type { GroupMemberInfo, QQGroupInfo } from '@snowluma/protocol/qq-info';
// inline-extract the kind.
import type {
GroupChange, NewFriend, FriendRecall, OperatorInfo, SelfJoinInGroup, GroupAdmin,
InputStatusNotify,
} from '@snowluma/proto-defs/notify';
import type { PushMsg } from '@snowluma/proto-defs/message';
import type {
@@ -254,6 +255,53 @@ describe('parseMsgPush Event0x210 subType=179/226 (NewFriend → friend_add)', (
});
});
describe('parseMsgPush Event0x210 subType=277 (input status → 对方正在输入)', () => {
// RE'd from wrapper.linux.node aio_input_state_worker.cc: 0x210/0x115 sys_msg,
// body = InputStatusNotify {fromUid, toUid, notifyItem{eventType@f4}}.
type FriendInputStatusEvent = Extract<QQEventVariant, { kind: 'friend_input_status' }>;
function makeInputStatusPacket(fromUid: string, eventType: number): PacketInfo {
const content = protobuf_encode<InputStatusNotify>({
fromUid,
toUid: 'u_self',
notifyItem: { eventType },
});
return makeEvent0x210PacketAny(277, content);
}
it('emits friend_input_status (typing) for eventType 1', () => {
const member = makeGroupMember(77777, 'u_typer');
const [event] = parseMsgPush(
makeInputStatusPacket(member.uid, 1),
makeIdentity([member]),
) as FriendInputStatusEvent[];
expect(event.kind).toBe('friend_input_status');
expect(event.userUin).toBe(77777);
expect(event.eventType).toBe(1);
expect(event.statusText).toBe('对方正在输入...');
});
it('surfaces eventType 3 as the voice-recording status text', () => {
const member = makeGroupMember(77777, 'u_typer');
const [event] = parseMsgPush(
makeInputStatusPacket(member.uid, 3),
makeIdentity([member]),
) as FriendInputStatusEvent[];
expect(event.eventType).toBe(3);
expect(event.statusText).toBe('对方正在讲话...');
});
it('drops a body with no fromUid (nothing to key user_id on)', () => {
const events = parseMsgPush(
makeEvent0x210PacketAny(277, protobuf_encode<InputStatusNotify>({ notifyItem: { eventType: 1 } })),
makeIdentity(),
);
expect(events).toEqual([]);
});
});
describe('parseMsgPush Event0x210 subType=139 (self-recall direction)', () => {
// 138 = friend recalled their own message sent to bot
// (peer in friend_recall event = fromUid)