mirror of
https://github.com/hansjone/dsh-im-ops.git
synced 2026-10-13 23:36:36 +08:00
feat: send test messages during bot connection checks
This commit is contained in:
parent
94da24538f
commit
fb61c4235f
78 changed files with 3460 additions and 210 deletions
|
|
@ -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;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue