feat: send test messages during bot connection checks

This commit is contained in:
xmanrui 2026-08-19 03:52:52 +08:00
parent 94da24538f
commit fb61c4235f
78 changed files with 3460 additions and 210 deletions

View file

@ -1,5 +1,9 @@
import { QQBot, typingIndicator } from '@tencent-connect/qqbot-nodejs';
import {
connectionTestTarget,
connectionTestTargetUnavailable,
} from '../shared/connection-test.mjs';
import { createQqBridgeStatus, QqHarnessBridge } from './qq-bridge.mjs';
function timeoutError() {
@ -67,6 +71,28 @@ export class QqRuntime {
return structuredClone(this.#status);
}
async sendConnectionTest(text) {
if (!this.#status.ready || !this.#bot) {
throw connectionTestTargetUnavailable('QQ机器人');
}
const ownerUserOpenid = typeof this.#config.ownerUserOpenid === 'string'
? this.#config.ownerUserOpenid.trim()
: '';
const remembered = connectionTestTarget(this.#state);
const rememberedUserOpenid = remembered?.scope === 'c2c'
&& typeof remembered.targetId === 'string'
? remembered.targetId.trim()
: '';
const target = rememberedUserOpenid
? { scope: 'c2c', targetId: rememberedUserOpenid }
: (ownerUserOpenid && ownerUserOpenid !== '*'
? { scope: 'c2c', targetId: ownerUserOpenid }
: null);
if (!target) throw connectionTestTargetUnavailable('QQ机器人');
await this.#bot.sendText(target, text);
return { sent: true };
}
async start() {
if (this.#status.ready && this.#bot) return this.status;
if (this.#starting) return this.#starting;