refactor: replace polling with event-driven updates

Trigger account detection and group requests from observed changes. Remove native stage log forwarding and its lifecycle state, and simplify the README.
This commit is contained in:
手瓜一十雪 committed 2026-10-19 09:56:20 +08:00
1 parent 1b74747251
commit e5cfec01bd
33 files changed
+1314 -1958

No files matched your search

@@ -3,36 +3,53 @@ import type { FriendMessage } from '../../events';
import type { MsgPushDecoder } from '../registry';
import { decodeRichBody } from '../rich-body-decoder';
/**
* A private "qun.invite" ark card (someone DMs the bot a group-invite card)
* carries the only sequence the server accepts when the bot later approves the
* invite via 0x10c8 — the `msgseq` embedded in its `mqqapi://group/invite_join`
* jumpUrl, applied with eventType=2 / filtered=false. The MSF invite push
* (PkgType 87) never carries it. Parse it out so `set_group_add_request` can
* use it. See issue #125.
*/
/** Read the approval tuple from a QQ group-invitation card. */
function parseGroupInviteCard(jsonText: string): { groupUin: number; sequence: number } | null {
if (!jsonText.includes('group/invite_join')) {
const card: unknown = JSON.parse(jsonText);
if (
!card ||
typeof card !== 'object' ||
!('app' in card) ||
(card.app !== 'com.tencent.qun.invite' && card.app !== 'com.tencent.tuwen.lua')
) {
return null;
}
const m = jsonText.match(/mqqapi:\/\/group\/invite_join[^"\\\s]*/);
if (!m) {
if (
!('meta' in card) ||
!card.meta ||
typeof card.meta !== 'object' ||
!('news' in card.meta) ||
!card.meta.news ||
typeof card.meta.news !== 'object' ||
!('jumpUrl' in card.meta.news) ||
typeof card.meta.news.jumpUrl !== 'string'
) {
return null;
}
const query = m[0].split('?')[1] ?? '';
const params = new URLSearchParams(query);
const groupUin = Number(params.get('groupcode') ?? 0);
const sequence = Number(params.get('msgseq') ?? 0);
const url = URL.parse(card.meta.news.jumpUrl);
if (!Number.isSafeInteger(groupUin) || !Number.isSafeInteger(sequence)) {
if (
!url ||
url.protocol !== 'mqqapi:' ||
url.hostname !== 'group' ||
url.pathname !== '/invite_join'
) {
return null;
}
if (groupUin <= 0 || sequence <= 0) {
return null;
const groupUin = Number(url.searchParams.get('groupcode'));
const sequence = Number(url.searchParams.get('msgseq'));
if (
!Number.isSafeInteger(groupUin) ||
groupUin <= 0 ||
!Number.isSafeInteger(sequence) ||
sequence <= 0
) {
throw new Error('group invitation card has an invalid approval tuple');
}
return { groupUin, sequence };
@@ -21,7 +21,7 @@ export const decodeGroupJoinRequest: MsgPushDecoder = (ctx) => {
fromUid: join.targetUid ?? '',
subType: 'add',
message: '',
flag: 'add:' + (join.groupUin ?? 0) + ':' + (join.targetUid ?? ''),
flag: '',
};
return [ev];
};
@@ -29,7 +29,7 @@ export const decodeGroupJoinRequest: MsgPushDecoder = (ctx) => {
export const decodeGroupInvitation: MsgPushDecoder = (ctx) => {
const invitation = protobuf_decode<GroupInvitation>(ctx.content);
if (!invitation?.info?.inner) {
if (invitation?.cmd !== 87 || !invitation.info?.inner) {
return [];
}
@@ -45,7 +45,7 @@ export const decodeGroupInvitation: MsgPushDecoder = (ctx) => {
invitedUid: inner.targetUid ?? '',
subType: 'invite',
message: '',
flag: 'invite:' + (inner.groupUin ?? 0) + ':' + (inner.invitorUid ?? ''),
flag: '',
};
return [ev];
};
@@ -67,7 +67,7 @@ export const decodeGroupInvite: MsgPushDecoder = (ctx) => {
invitedUin: ctx.selfUin,
subType: 'invite',
message: '',
flag: 'invite:' + (invite.groupUin ?? 0) + ':' + (invite.invitorUid ?? ''),
flag: '',
};
return [ev];
};