fix(onebot): distinguish private poke conversations
Preserve the private conversation peer separately from the poke sender and target. Emit NapCat-compatible user_id and sender_id fields while keeping group notices unchanged. Add MsgPush and event-converter regression coverage for self-pokes across multiple friend sessions. Fixes #285.
This commit is contained in:
7 files changed
+126
-13
No files matched your search
@@ -360,7 +360,10 @@ export interface GroupInviteEvent extends QQEvent {
|
||||
|
||||
export interface FriendPokeEvent extends QQEvent {
|
||||
kind: 'friend_poke';
|
||||
userUin: number;
|
||||
/** The other participant whose private conversation contains this notice. */
|
||||
peerUin: number;
|
||||
/** The account that performed the poke, which may be the logged-in account. */
|
||||
senderUin: number;
|
||||
targetUin: number;
|
||||
action: string;
|
||||
suffix: string;
|
||||
|
||||
@@ -277,7 +277,7 @@ export function formatEvent(identity: IdentityService, event: QQEventVariant): s
|
||||
case 'group_admin':
|
||||
return `管理 ${formatGroup(identity, event.groupId)} | ${formatUser(identity, event.groupId, event.userUin)} ${event.set ? '+' : '-'}管理员`;
|
||||
case 'friend_poke':
|
||||
return `戳一戳 ${formatUser(identity, undefined, event.userUin)} -> ${formatUser(identity, undefined, event.targetUin)}`;
|
||||
return `私聊戳 ${formatUser(identity, undefined, event.peerUin)} | ${formatUser(identity, undefined, event.senderUin)} -> ${formatUser(identity, undefined, event.targetUin)}`;
|
||||
case 'group_poke':
|
||||
return `群戳 ${formatGroup(identity, event.groupId)} | ${formatUser(identity, event.groupId, event.userUin)} -> ${formatUser(identity, event.groupId, event.targetUin)}`;
|
||||
case 'friend_request':
|
||||
|
||||
@@ -257,11 +257,32 @@ function decodeFriendPoke(ctx: MsgPushContext): QQEventVariant[] {
|
||||
const templates = buildTemplateMap(grayTip.msgTemplParam ?? []);
|
||||
const actor = findTemplateValue(templates, 'uin_str1');
|
||||
const target = findTemplateValue(templates, 'uin_str2');
|
||||
const senderUin = resolveUidToUin(ctx.identity, 0, actor, parseU64OrZero(actor));
|
||||
const routeFromUin = resolveUidToUin(ctx.identity, 0, ctx.fromUid, ctx.fromUin);
|
||||
// The gray-tip template only identifies the two poke endpoints. The C2C
|
||||
// routing head owns the conversation peer: outbound notices use `to`,
|
||||
// while inbound notices use `from`, just like ordinary friend messages.
|
||||
const sentBySelf = routeFromUin > 0 && routeFromUin === ctx.selfUin;
|
||||
const peerUin = sentBySelf
|
||||
? resolveUidToUin(
|
||||
ctx.identity,
|
||||
0,
|
||||
ctx.responseHead?.toUid ?? '',
|
||||
ctx.responseHead?.toUin ?? 0,
|
||||
)
|
||||
: routeFromUin;
|
||||
if (peerUin <= 0) {
|
||||
throw new Error(
|
||||
'friend poke conversation peer is missing '
|
||||
+ `(fromUin=${ctx.fromUin} toUin=${ctx.responseHead?.toUin ?? 0} sentBySelf=${sentBySelf})`,
|
||||
);
|
||||
}
|
||||
const ev: FriendPokeEvent = {
|
||||
kind: 'friend_poke',
|
||||
time: ctx.head.timestamp,
|
||||
selfUin: ctx.selfUin,
|
||||
userUin: resolveUidToUin(ctx.identity, 0, actor, parseU64OrZero(actor)),
|
||||
peerUin,
|
||||
senderUin,
|
||||
targetUin: resolveUidToUin(ctx.identity, 0, target, parseU64OrZero(target)),
|
||||
action: findTemplateValue(templates, 'action_str', 'alt_str1'),
|
||||
suffix: findTemplateValue(templates, 'suffix_str'),
|
||||
|
||||
Reference in new issue
Block a user