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:
8 files changed
+138
-1
No files matched your search
@@ -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 [];
|
||||
|
||||
@@ -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).
|
||||
*
|
||||
|
||||
Reference in new issue
Block a user