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)
@@ -7,6 +7,7 @@ import {
} from './to-message';
import {
convertFriendAdd,
convertFriendInputStatus,
convertFriendPoke,
convertFriendRecall,
convertGroupAdmin,
@@ -78,6 +79,7 @@ const CONVERTERS: ConverterRegistry = {
group_essence: convertGroupEssence,
group_file_upload: convertGroupFileUpload,
friend_add: convertFriendAdd,
friend_input_status: convertFriendInputStatus,
group_msg_emoji_like: convertGroupMsgEmojiLike,
// Requests.
friend_request: convertFriendRequest,
@@ -17,6 +17,7 @@ type GroupEssence = Extract<QQEventVariant, { kind: 'group_essence' }>;
type GroupFileUpload = Extract<QQEventVariant, { kind: 'group_file_upload' }>;
type FriendAdd = Extract<QQEventVariant, { kind: 'friend_add' }>;
type GroupMsgEmojiLike = Extract<QQEventVariant, { kind: 'group_msg_emoji_like' }>;
type FriendInputStatus = Extract<QQEventVariant, { kind: 'friend_input_status' }>;
export function convertGroupMemberJoin(ctx: ConverterContext, event: GroupMemberJoin): JsonObject {
return notice(ctx, event, {
@@ -156,6 +157,18 @@ export function convertFriendAdd(ctx: ConverterContext, event: FriendAdd): JsonO
});
}
export function convertFriendInputStatus(ctx: ConverterContext, event: FriendInputStatus): JsonObject {
// Mirrors NapCat's OB11InputStatusEvent: notify/input_status with the peer's
// uin, the raw event_type (1 = typing, 3 = recording voice) and status_text.
return notice(ctx, event, {
notice_type: 'notify',
sub_type: 'input_status',
user_id: event.userUin,
event_type: event.eventType,
status_text: event.statusText,
});
}
export function convertGroupMsgEmojiLike(ctx: ConverterContext, event: GroupMsgEmojiLike): JsonObject {
const messageId = applyMessageIdResolver(
ctx.messageIdResolver, true, event.groupId, event.msgSeq, GROUP_MESSAGE_EVENT,
+1
View File
@@ -70,6 +70,7 @@ const NOTICE_KINDS = [
'group_essence',
'group_file_upload',
'friend_add',
'friend_input_status',
'group_msg_emoji_like',
] as const satisfies readonly QQEventVariant['kind'][];
+19
View File
@@ -262,3 +262,22 @@ export interface GroupReactNotify {
field13?: pb<13, uint_32>;
groupReactionData?: pb<44, GroupReactionData>;
}
// C2C input-status notify — the "对方正在输入…" push. Delivered as a system
// message (msgType 0x210 / subMsgType 0x115) whose `MsgBody.msgContent` carries
// this body. Field layout RE'd from `wrapper.linux.node`
// `aio_input_state_worker.cc::ProcessInputStateNotifySysMsg` (reads f1=fromUid,
// f2=toUid, f3=notifyItem; the item's f4 is the event type).
export interface InputStatusNotifyItem {
field2?: pb<2, uint_32>;
field3?: pb<3, uint_64>;
eventType?: pb<4, uint_32>; // 1 = 正在输入 (typing), 3 = 正在讲话 (recording voice)
field5?: pb<5, uint_32>;
statusText?: pb<6, string>;
}
export interface InputStatusNotify {
fromUid?: pb<1, string>;
toUid?: pb<2, string>;
notifyItem?: pb<3, InputStatusNotifyItem>;
}
+15 -1
View File
@@ -294,6 +294,19 @@ export interface PttTransResultEvent extends QQEvent {
text: string;
}
/**
* C2C "对方正在输入…" input-status push (Event 0x210 subType 0x115 / 277).
* `eventType` 1 = typing, 3 = recording a voice message. Mirrors NapCat's
* `onInputStatusPush` → OB11 `notice/notify` `sub_type:'input_status'`.
*/
export interface FriendInputStatusEvent extends QQEvent {
kind: 'friend_input_status';
userUin: number; // the peer whose input status changed (the typer)
userUid: string;
eventType: number; // 1 = 正在输入, 3 = 正在讲话(录音)
statusText: string;
}
export type QQEventVariant =
| FriendMessage
| GroupMessage
@@ -312,4 +325,5 @@ export type QQEventVariant =
| GroupFileUploadEvent
| FriendAddEvent
| GroupMsgEmojiLikeEvent
| PttTransResultEvent;
| PttTransResultEvent
| FriendInputStatusEvent;
@@ -10,6 +10,7 @@ import type {
FriendRecall,
FriendRequest,
GeneralGrayTipInfo,
InputStatusNotify,
NewFriend,
} from '@snowluma/proto-defs/notify';
import type { PttTransPush } from '@snowluma/proto-defs/ptt-trans';
@@ -23,6 +24,7 @@ import {
import type { MsgPushDecoder } from '../registry';
type FriendRecallEvent = Extract<QQEventVariant, { kind: 'friend_recall' }>;
type FriendInputStatusEvent = Extract<QQEventVariant, { kind: 'friend_input_status' }>;
const unknownLog = createLogger('MsgPush.Unknown');
@@ -37,6 +39,7 @@ export const decodeEvent0x210: MsgPushDecoder = (ctx) => {
case Event0x210SubType.FriendRecallSelfNotice:
return decodeFriendRecall(ctx);
case Event0x210SubType.FriendPokeNotice: return decodeFriendPoke(ctx);
case Event0x210SubType.InputStatusNotice: return decodeInputStatus(ctx);
// 179 + 226 both carry the NewFriend payload — see enum comment.
case Event0x210SubType.NewFriendNotice:
case Event0x210SubType.NewFriendNoticeAlt:
@@ -128,6 +131,34 @@ function decodeNewFriend(ctx: MsgPushContext): QQEventVariant[] {
return [ev];
}
// C2C "对方正在输入…" input-status push. Body (`InputStatusNotify`) rides in
// `body.msgContent` (= ctx.content). Layout + event-type semantics RE'd from
// `aio_input_state_worker.cc::ProcessInputStateNotifySysMsg`: the notify item's
// field 4 is the event type (1 = typing, 3 = recording voice). The client
// synthesises the status text from that type, so we do the same for OneBot
// parity (NapCat's `onInputStatusPush` → `notice/notify` `input_status`).
function decodeInputStatus(ctx: MsgPushContext): QQEventVariant[] {
const notify = protobuf_decode<InputStatusNotify>(ctx.content);
const fromUid = notify?.fromUid ?? '';
if (!fromUid) return [];
const eventType = notify.notifyItem?.eventType ?? 1;
const ev: FriendInputStatusEvent = {
kind: 'friend_input_status',
time: ctx.head.timestamp,
selfUin: ctx.selfUin,
userUin: resolveUidToUin(ctx.identity, 0, fromUid, ctx.fromUin),
userUid: fromUid,
eventType,
statusText: inputStatusText(eventType),
};
return [ev];
}
// The client's own strings (wrapper.linux.node @0xB8FFE0 / @0xB90000).
function inputStatusText(eventType: number): string {
return eventType === 3 ? '对方正在讲话...' : '对方正在输入...';
}
function decodeFriendPoke(ctx: MsgPushContext): QQEventVariant[] {
const grayTip = protobuf_decode<GeneralGrayTipInfo>(ctx.content);
if (!grayTip || (grayTip.busiType ?? 0n) !== 12n) return [];
+9
View File
@@ -67,6 +67,15 @@ export enum Event0x210SubType {
*/
NewFriendNotice = 179,
NewFriendNoticeAlt = 226,
/**
* C2C input-status notify — the "对方正在输入…" push. subMsgType 0x115 (277).
* RE-confirmed against `wrapper.linux.node`
* `aio_input_state_worker.cc::IsInputStateNotifySysMsg`, which matches exactly
* `(msg_type ^ 0x210) | (sub_msg_type ^ 0x115) == 0`. The payload
* (`InputStatusNotify`) rides in `body.msgContent`. Mirrors NapCat's
* `onInputStatusPush`.
*/
InputStatusNotice = 277,
/**
* Group-app state push (troop shortcut bar / discussion app).
*