@qwen-code/channel-qqbot 0.27.0 → 0.27.2-preview.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/QQChannel.d.ts +14 -0
- package/dist/QQChannel.d.ts.map +1 -1
- package/dist/QQChannel.js +120 -24
- package/dist/QQChannel.js.map +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +122 -0
- package/dist/index.js.map +1 -1
- package/dist/login.d.ts +7 -0
- package/dist/login.d.ts.map +1 -1
- package/dist/login.js +21 -1
- package/dist/login.js.map +1 -1
- package/dist/types.d.ts +16 -0
- package/dist/types.d.ts.map +1 -1
- package/package.json +2 -2
package/dist/QQChannel.d.ts
CHANGED
|
@@ -127,6 +127,8 @@ export declare class QQChannel extends ChannelBase {
|
|
|
127
127
|
private _keywordTriggerCache;
|
|
128
128
|
/** Rate-limit timestamps for keyword non-match log entries (chatId → last log ms). */
|
|
129
129
|
private _lastKeywordNoMatchLog;
|
|
130
|
+
/** Rate-limit timestamps for forwarded-bot notices (chatId → last log ms). */
|
|
131
|
+
private _lastForwardedBotLog;
|
|
130
132
|
/** Accumulation buffer for cron/non-prompt textChunk events. */
|
|
131
133
|
private cronBuffer;
|
|
132
134
|
/** Named handler for permanent textChunk listener (cron/non-prompt). */
|
|
@@ -942,6 +944,18 @@ export declare class QQChannel extends ChannelBase {
|
|
|
942
944
|
private extractBotOpenId;
|
|
943
945
|
/** Check if a message ID was already processed (reconnect replay dedup). */
|
|
944
946
|
private isDuplicate;
|
|
947
|
+
/**
|
|
948
|
+
* One rate-limited stderr line per chat per minute when a forwarded bot
|
|
949
|
+
* message is handed to the base channel. Forwarding is the one enabled path
|
|
950
|
+
* whose only brake is the model's own judgement, so an operator needs to see
|
|
951
|
+
* it is live; the line carries no sender name or payload, only the sanitized
|
|
952
|
+
* chat id.
|
|
953
|
+
*
|
|
954
|
+
* Worded as "dispatched", not "forwarded": the base channel still runs its
|
|
955
|
+
* own gates (e.g. `requireMention`) after this point, so a dispatched message
|
|
956
|
+
* is not necessarily one the model saw.
|
|
957
|
+
*/
|
|
958
|
+
private logForwardedBotMessage;
|
|
945
959
|
/**
|
|
946
960
|
* Extract common group-message fields shared by handleGroup and handleGroupAll.
|
|
947
961
|
* Returns null when the message has no meaningful text after @-tag stripping.
|
package/dist/QQChannel.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"QQChannel.d.ts","sourceRoot":"","sources":["../src/QQChannel.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,EACL,WAAW,EAWZ,MAAM,yBAAyB,CAAC;AACjC,OAAO,KAAK,EAEV,aAAa,EACb,kBAAkB,EAClB,kBAAkB,EAClB,2BAA2B,EAC3B,QAAQ,EACR,aAAa,EACb,aAAa,EACd,MAAM,yBAAyB,CAAC;
|
|
1
|
+
{"version":3,"file":"QQChannel.d.ts","sourceRoot":"","sources":["../src/QQChannel.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,EACL,WAAW,EAWZ,MAAM,yBAAyB,CAAC;AACjC,OAAO,KAAK,EAEV,aAAa,EACb,kBAAkB,EAClB,kBAAkB,EAClB,2BAA2B,EAC3B,QAAQ,EACR,aAAa,EACb,aAAa,EACd,MAAM,yBAAyB,CAAC;AA2EjC,MAAM,MAAM,iBAAiB,GACzB,cAAc,GACd,iBAAiB,GACjB,iBAAiB,GACjB,qBAAqB,CAAC;AAE1B,qBAAa,aAAc,SAAQ,KAAK;IAEpC,QAAQ,CAAC,IAAI,EAAE,iBAAiB;gBAAvB,IAAI,EAAE,iBAAiB,EAChC,OAAO,EAAE,MAAM;CAKlB;AAoKD,8DAA8D;AAC9D,wBAAgB,aAAa,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAEjD;AAuFD,qBAAa,SAAU,SAAQ,WAAW;IACxC,OAAO,CAAC,EAAE,CAA0B;IACpC,OAAO,CAAC,WAAW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AC,YAAY;IASpB,OAAO,CAAC,eAAe;YAUT,kBAAkB;IA2FhC,OAAO,CAAC,SAAS;IAkFjB,OAAO,CAAC,WAAW;IA6GnB,OAAO,CAAC,cAAc;IAqLtB,OAAO,CAAC,kBAAkB;IAU1B,OAAO,CAAC,mBAAmB;YAqBb,mBAAmB;YA4FnB,oBAAoB;CA2BnC"}
|
package/dist/QQChannel.js
CHANGED
|
@@ -27,6 +27,22 @@ import { fetchAccessToken, fetchGatewayUrl, getApiBase, requestQQApi, sendQQMess
|
|
|
27
27
|
import { buildModerationTools, } from './moderation-tools.js';
|
|
28
28
|
/** QQ Bot OPENID format: exactly 32 uppercase hex chars (bot and sender OPENIDs). */
|
|
29
29
|
const QQ_OPENID_RE = /^[A-F0-9]{32}$/i;
|
|
30
|
+
/**
|
|
31
|
+
* Marks a forwarded bot's message as machine-authored: `[bot] ` goes into the
|
|
32
|
+
* self-prefixed sender line, and the same word rides on the envelope
|
|
33
|
+
* (`senderTag`) so ChannelBase renders it on the paths where it owns the
|
|
34
|
+
* prefix (message routes, DM without a prefix). One definition, both carriers.
|
|
35
|
+
*/
|
|
36
|
+
const QQ_BOT_SENDER_TAG = 'bot';
|
|
37
|
+
const QQ_BOT_TAG = `[${QQ_BOT_SENDER_TAG}] `;
|
|
38
|
+
/**
|
|
39
|
+
* The two prompt lines that tell the model what `[bot]` means and how to stop
|
|
40
|
+
* replying. One definition: the default prompt embeds them, and an operator's
|
|
41
|
+
* own `instructions` gets them appended (connect() re-runs, so the append is
|
|
42
|
+
* idempotent per line).
|
|
43
|
+
*/
|
|
44
|
+
const FORWARD_BOT_INSTRUCTION = '消息前缀 [bot] 表示该消息来自另一个机器人(不是人类成员);是否回复由你自主判断。';
|
|
45
|
+
const NOREPLY_INSTRUCTION = '不想回复时只输出 <noreply> 即可,消息不会发出。';
|
|
30
46
|
export class DeliveryError extends Error {
|
|
31
47
|
code;
|
|
32
48
|
constructor(code, message) {
|
|
@@ -232,6 +248,8 @@ export class QQChannel extends ChannelBase {
|
|
|
232
248
|
_keywordTriggerCache = null;
|
|
233
249
|
/** Rate-limit timestamps for keyword non-match log entries (chatId → last log ms). */
|
|
234
250
|
_lastKeywordNoMatchLog = new Map();
|
|
251
|
+
/** Rate-limit timestamps for forwarded-bot notices (chatId → last log ms). */
|
|
252
|
+
_lastForwardedBotLog = new Map();
|
|
235
253
|
/** Accumulation buffer for cron/non-prompt textChunk events. */
|
|
236
254
|
cronBuffer = new Map();
|
|
237
255
|
/** Named handler for permanent textChunk listener (cron/non-prompt). */
|
|
@@ -763,7 +781,10 @@ export class QQChannel extends ChannelBase {
|
|
|
763
781
|
'你是通过 QQ Bot 与用户对话的 AI 助手。',
|
|
764
782
|
'支持 Markdown 格式,回复自然流畅即可。',
|
|
765
783
|
'消息前缀 [atMention=true] 表示该消息 @了你,[atMention=false] 表示未 @你。',
|
|
766
|
-
|
|
784
|
+
...(this.qqConfig.forwardBotMessages === true
|
|
785
|
+
? [FORWARD_BOT_INSTRUCTION]
|
|
786
|
+
: []),
|
|
787
|
+
NOREPLY_INSTRUCTION,
|
|
767
788
|
'',
|
|
768
789
|
'以下规则仅适用于群聊消息。C2C 私聊中请始终正常回复。',
|
|
769
790
|
'## 群聊唤醒与静默规则',
|
|
@@ -798,6 +819,18 @@ export class QQChannel extends ChannelBase {
|
|
|
798
819
|
}
|
|
799
820
|
this.config.instructions = parts.join('\n');
|
|
800
821
|
}
|
|
822
|
+
else if (this.qqConfig.forwardBotMessages === true) {
|
|
823
|
+
// Operator-supplied instructions replace the default prompt wholesale,
|
|
824
|
+
// which would drop the feature's own brake (what `[bot]` means and how to
|
|
825
|
+
// stay silent). Attach it to the operator text. Per-line `includes` guard
|
|
826
|
+
// makes the append idempotent: connect() re-runs on every reconnect.
|
|
827
|
+
const supplements = [FORWARD_BOT_INSTRUCTION, NOREPLY_INSTRUCTION];
|
|
828
|
+
const existing = this.config.instructions;
|
|
829
|
+
const missing = supplements.filter((line) => !existing.includes(line));
|
|
830
|
+
if (missing.length > 0) {
|
|
831
|
+
this.config.instructions = [existing, ...missing].join('\n');
|
|
832
|
+
}
|
|
833
|
+
}
|
|
801
834
|
for (let attempt = 0; attempt < 3; attempt++) {
|
|
802
835
|
try {
|
|
803
836
|
await this.fetchToken();
|
|
@@ -1221,6 +1254,7 @@ export class QQChannel extends ChannelBase {
|
|
|
1221
1254
|
}
|
|
1222
1255
|
this.cronBuffer.clear();
|
|
1223
1256
|
this._lastKeywordNoMatchLog.clear();
|
|
1257
|
+
this._lastForwardedBotLog.clear();
|
|
1224
1258
|
this.flushQQState();
|
|
1225
1259
|
this.backupGlobalSessions();
|
|
1226
1260
|
if (this.readyTimeout) {
|
|
@@ -4430,9 +4464,19 @@ export class QQChannel extends ChannelBase {
|
|
|
4430
4464
|
async fetchToken() {
|
|
4431
4465
|
const safeName = this.name.replace(/[^A-Za-z0-9_-]/g, '_');
|
|
4432
4466
|
const credsFile = getCredsFilePath(safeName);
|
|
4467
|
+
// Only a daemon worker has no operator watching. A stream cannot tell
|
|
4468
|
+
// "piped to a human-visible tee" from "piped to a worker" — both are
|
|
4469
|
+
// pipes — so key on the explicit context the supervisor stamps on every
|
|
4470
|
+
// child it spawns (QWEN_CODE_SERVE=1, set in
|
|
4471
|
+
// cli/src/serve/channel-worker-supervisor.ts and not scrubbed).
|
|
4472
|
+
const daemonWorker = process.env['QWEN_CODE_SERVE'] === '1';
|
|
4433
4473
|
let appID = this.qqConfig.appID;
|
|
4434
4474
|
let appSecret = this.qqConfig.appSecret;
|
|
4435
|
-
|
|
4475
|
+
// The credentials file is keyed by channel name under one shared QWEN_HOME,
|
|
4476
|
+
// so in a daemon it can hold a bot bound by a different workspace. The
|
|
4477
|
+
// workspace channel config is the daemon's only source of truth; adopting
|
|
4478
|
+
// that file would connect this workspace to someone else's bot.
|
|
4479
|
+
if (!daemonWorker && (!appID || !appSecret)) {
|
|
4436
4480
|
const saved = loadCredentials(credsFile);
|
|
4437
4481
|
if (saved) {
|
|
4438
4482
|
appID = saved.appId;
|
|
@@ -4442,6 +4486,9 @@ export class QQChannel extends ChannelBase {
|
|
|
4442
4486
|
}
|
|
4443
4487
|
}
|
|
4444
4488
|
if (!appID || !appSecret) {
|
|
4489
|
+
if (daemonWorker) {
|
|
4490
|
+
throw new Error(`QQ channel "${this.name}" has no appID/appSecret. Bind it by QR from the channel management UI, or set appID and appSecret in the channel config.`);
|
|
4491
|
+
}
|
|
4445
4492
|
process.stderr.write(`[QQ:${this.name}] No credentials, scan QR code with QQ...\n`);
|
|
4446
4493
|
const creds = await qrCodeLogin();
|
|
4447
4494
|
appID = creds.appId;
|
|
@@ -4937,6 +4984,24 @@ export class QQChannel extends ChannelBase {
|
|
|
4937
4984
|
}
|
|
4938
4985
|
return false;
|
|
4939
4986
|
}
|
|
4987
|
+
/**
|
|
4988
|
+
* One rate-limited stderr line per chat per minute when a forwarded bot
|
|
4989
|
+
* message is handed to the base channel. Forwarding is the one enabled path
|
|
4990
|
+
* whose only brake is the model's own judgement, so an operator needs to see
|
|
4991
|
+
* it is live; the line carries no sender name or payload, only the sanitized
|
|
4992
|
+
* chat id.
|
|
4993
|
+
*
|
|
4994
|
+
* Worded as "dispatched", not "forwarded": the base channel still runs its
|
|
4995
|
+
* own gates (e.g. `requireMention`) after this point, so a dispatched message
|
|
4996
|
+
* is not necessarily one the model saw.
|
|
4997
|
+
*/
|
|
4998
|
+
logForwardedBotMessage(chatId) {
|
|
4999
|
+
const now = Date.now();
|
|
5000
|
+
if (now - (this._lastForwardedBotLog.get(chatId) ?? 0) < 60_000)
|
|
5001
|
+
return;
|
|
5002
|
+
this._lastForwardedBotLog.set(chatId, now);
|
|
5003
|
+
process.stderr.write(`[QQ:${this.name}] forwardBotMessages: bot-authored message in ${sanitizeLogText(chatId, 64)} dispatched\n`);
|
|
5004
|
+
}
|
|
4940
5005
|
/**
|
|
4941
5006
|
* Extract common group-message fields shared by handleGroup and handleGroupAll.
|
|
4942
5007
|
* Returns null when the message has no meaningful text after @-tag stripping.
|
|
@@ -4977,18 +5042,24 @@ export class QQChannel extends ChannelBase {
|
|
|
4977
5042
|
return null;
|
|
4978
5043
|
const effectiveIsAtBot = forceAtMention ?? isAtBot;
|
|
4979
5044
|
const rawCommandText = safeCleanText.replace(/<@[^>]{1,64}>/g, '').trim();
|
|
4980
|
-
|
|
5045
|
+
// A forwarded bot message must reach the model instead of the channel's
|
|
5046
|
+
// local command table: a peer bot's `/clear` or `!cmd` is another bot
|
|
5047
|
+
// talking, not this channel being commanded.
|
|
5048
|
+
// Same truthiness predicate as the three drop guards above, so a malformed
|
|
5049
|
+
// non-boolean `author.bot` can never be forwarded untagged.
|
|
5050
|
+
const forwardedBot = Boolean(event.author?.bot) && this.qqConfig.forwardBotMessages === true;
|
|
5051
|
+
const isSlash = effectiveIsAtBot && !forwardedBot && rawCommandText.startsWith('/');
|
|
4981
5052
|
const commandText = sanitizePromptText(rawCommandText);
|
|
4982
|
-
//
|
|
4983
|
-
//
|
|
4984
|
-
//
|
|
4985
|
-
//
|
|
4986
|
-
//
|
|
4987
|
-
//
|
|
4988
|
-
//
|
|
4989
|
-
//
|
|
4990
|
-
//
|
|
4991
|
-
|
|
5053
|
+
// Bot-authored messages are a feature when the operator opts in, and the
|
|
5054
|
+
// switch is the whole tradeoff. This traffic is another bot talking in the
|
|
5055
|
+
// group: QQ delivers message events for user-authored messages only, and a
|
|
5056
|
+
// bot's own sends come back in the send API's response (a message the bot
|
|
5057
|
+
// itself sent is referenced through the response's ext_info.ref_idx, not
|
|
5058
|
+
// through a message event), so a self-echo cannot reach this handler. No
|
|
5059
|
+
// automatic rate cap follows the switch — the group's human members and the
|
|
5060
|
+
// model's own silence rules are the guard. Dropping them is the default. A
|
|
5061
|
+
// user-supplied `[bot]` is stripped above, so the tag cannot be forged.
|
|
5062
|
+
const botTag = forwardedBot ? QQ_BOT_TAG : '';
|
|
4992
5063
|
const groupBotOpenId = this.botOpenIdByGroup.get(chatId);
|
|
4993
5064
|
const openIdSuffix = this.qqConfig.allowMention !== false && groupBotOpenId
|
|
4994
5065
|
? ` [botOpenId:${groupBotOpenId}]`
|
|
@@ -5035,7 +5106,7 @@ export class QQChannel extends ChannelBase {
|
|
|
5035
5106
|
: senderIdentity
|
|
5036
5107
|
? `(${truncateCodePoints(sanitizeSenderName(senderIdentity), 8)}…)`
|
|
5037
5108
|
: '';
|
|
5038
|
-
const head = `[atMention=${effectiveIsAtBot}]${openIdSuffix} [${safeName}${senderTag}]: `;
|
|
5109
|
+
const head = `[atMention=${effectiveIsAtBot}]${openIdSuffix} ${botTag}[${safeName}${senderTag}]: `;
|
|
5039
5110
|
const body = sanitizePromptText(this.qqConfig.allowMention !== false ? safeDisplayText : safeCleanText);
|
|
5040
5111
|
const text = isSlash
|
|
5041
5112
|
? sanitizePromptText(safeCleanText)
|
|
@@ -5050,6 +5121,7 @@ export class QQChannel extends ChannelBase {
|
|
|
5050
5121
|
body,
|
|
5051
5122
|
text,
|
|
5052
5123
|
senderName,
|
|
5124
|
+
forwardedBot,
|
|
5053
5125
|
};
|
|
5054
5126
|
}
|
|
5055
5127
|
/** All supported attachments of a message, in event order. */
|
|
@@ -5148,7 +5220,7 @@ export class QQChannel extends ChannelBase {
|
|
|
5148
5220
|
process.stderr.write(`[QQ:${this.name}] C2C message dropped: missing author\n`);
|
|
5149
5221
|
return;
|
|
5150
5222
|
}
|
|
5151
|
-
if (event.author.bot) {
|
|
5223
|
+
if (event.author.bot && this.qqConfig.forwardBotMessages !== true) {
|
|
5152
5224
|
process.stderr.write(`[QQ:${this.name}] Bot C2C message dropped\n`);
|
|
5153
5225
|
return;
|
|
5154
5226
|
}
|
|
@@ -5168,35 +5240,46 @@ export class QQChannel extends ChannelBase {
|
|
|
5168
5240
|
// resolved and would consume the ring's shared 256-chat budget.
|
|
5169
5241
|
const senderName = event.author.username || event.author.id || 'QQ User';
|
|
5170
5242
|
const safeName = sanitizeSenderName(senderName);
|
|
5243
|
+
// Same truthiness predicate as the drop guard above (see prepareGroupMessage).
|
|
5244
|
+
const forwardedBot = Boolean(event.author.bot) && this.qqConfig.forwardBotMessages === true;
|
|
5245
|
+
const botTag = forwardedBot ? QQ_BOT_TAG : '';
|
|
5171
5246
|
const cleanText = rawContent.trim();
|
|
5172
5247
|
// Strip system-reserved tags that could be forged by users
|
|
5173
5248
|
const safeContent = cleanText
|
|
5174
5249
|
.replace(/\[atMention=[^\]]*]/g, '')
|
|
5175
5250
|
.replace(/\[botOpenId:[^\]]*]/g, '')
|
|
5176
5251
|
.replace(/\[bot]/g, '');
|
|
5177
|
-
|
|
5252
|
+
// Same rule as the group path: a forwarded bot's slash/bang text is a
|
|
5253
|
+
// model prompt, not a command for this channel to execute locally.
|
|
5254
|
+
const isSlash = !forwardedBot && safeContent.startsWith('/');
|
|
5178
5255
|
const body = sanitizePromptText(safeContent);
|
|
5179
5256
|
const mediaOnly = !body && media.length > 0;
|
|
5180
5257
|
const text = mediaOnly
|
|
5181
5258
|
? mediaPlaceholder(media)
|
|
5182
5259
|
: isSlash || this.config.messageRoutes
|
|
5183
5260
|
? body
|
|
5184
|
-
: `[atMention=true] [${safeName}]: ${body}`;
|
|
5261
|
+
: `[atMention=true] ${botTag}[${safeName}]: ${body}`;
|
|
5185
5262
|
const envelope = {
|
|
5186
5263
|
channelName: this.name,
|
|
5187
5264
|
senderId: chatId,
|
|
5188
5265
|
senderName,
|
|
5189
5266
|
chatId,
|
|
5190
5267
|
text,
|
|
5268
|
+
...(forwardedBot ? { senderTag: QQ_BOT_SENDER_TAG } : {}),
|
|
5191
5269
|
messageId: event.id,
|
|
5192
5270
|
isGroup: false,
|
|
5193
5271
|
isMentioned: true,
|
|
5194
5272
|
isReplyToBot: false,
|
|
5195
5273
|
...(mediaOnly ? { syntheticText: true } : {}),
|
|
5196
|
-
|
|
5274
|
+
// A forwarded bot's media-only text is a bare placeholder with no sender
|
|
5275
|
+
// line, so leave it unprefixed: ChannelBase then renders the senderTag
|
|
5276
|
+
// (and keeps it when a failed download replaces the placeholder).
|
|
5277
|
+
...(isSlash || this.config.messageRoutes || (forwardedBot && mediaOnly)
|
|
5197
5278
|
? {}
|
|
5198
5279
|
: { alreadyPrefixed: true }),
|
|
5199
5280
|
};
|
|
5281
|
+
if (forwardedBot)
|
|
5282
|
+
this.logForwardedBotMessage(chatId);
|
|
5200
5283
|
this.dispatchInbound(envelope, media).catch((e) => process.stderr.write(`[QQ:${this.name}] C2C handler error: ${sanitizeLogText(e instanceof Error ? e.message : String(e), 200)}\n`));
|
|
5201
5284
|
}
|
|
5202
5285
|
handleGroup(event) {
|
|
@@ -5208,7 +5291,7 @@ export class QQChannel extends ChannelBase {
|
|
|
5208
5291
|
process.stderr.write(`[QQ:${this.name}] Group message dropped: missing author\n`);
|
|
5209
5292
|
return;
|
|
5210
5293
|
}
|
|
5211
|
-
if (event.author.bot) {
|
|
5294
|
+
if (event.author.bot && this.qqConfig.forwardBotMessages !== true) {
|
|
5212
5295
|
process.stderr.write(`[QQ:${this.name}] Bot message dropped in group ${sanitizeLogText(event.group_openid, 64)}\n`);
|
|
5213
5296
|
return;
|
|
5214
5297
|
}
|
|
@@ -5231,7 +5314,7 @@ export class QQChannel extends ChannelBase {
|
|
|
5231
5314
|
});
|
|
5232
5315
|
if (!result)
|
|
5233
5316
|
return;
|
|
5234
|
-
const { isSlash, text, commandText, routeText, senderName, safeName } = result;
|
|
5317
|
+
const { isSlash, text, commandText, routeText, senderName, safeName, forwardedBot, } = result;
|
|
5235
5318
|
const media = this.inboundMedia(event);
|
|
5236
5319
|
const mediaOnly = result.body === '' && media.length > 0;
|
|
5237
5320
|
// Deduplicate before handleInbound — prepareGroupMessage already ran
|
|
@@ -5263,15 +5346,21 @@ export class QQChannel extends ChannelBase {
|
|
|
5263
5346
|
: this.config.messageRoutes
|
|
5264
5347
|
? routeText
|
|
5265
5348
|
: text,
|
|
5349
|
+
...(forwardedBot ? { senderTag: QQ_BOT_SENDER_TAG } : {}),
|
|
5266
5350
|
messageId: event.id,
|
|
5267
5351
|
isGroup: true,
|
|
5268
5352
|
isMentioned: true,
|
|
5269
5353
|
isReplyToBot: true,
|
|
5270
5354
|
...(mediaOnly ? { syntheticText: true } : {}),
|
|
5271
|
-
|
|
5355
|
+
// A forwarded bot's media-only text is a bare placeholder with no sender
|
|
5356
|
+
// line, so leave it unprefixed: ChannelBase then renders the senderTag
|
|
5357
|
+
// attribution. Every other self-prefixed path keeps the flag.
|
|
5358
|
+
...(isSlash || this.config.messageRoutes || (forwardedBot && mediaOnly)
|
|
5272
5359
|
? {}
|
|
5273
5360
|
: { alreadyPrefixed: true }),
|
|
5274
5361
|
};
|
|
5362
|
+
if (forwardedBot)
|
|
5363
|
+
this.logForwardedBotMessage(chatId);
|
|
5275
5364
|
this.dispatchInbound(envelope, media).catch((e) => process.stderr.write(`[QQ:${this.name}] Group handler error: ${sanitizeLogText(e instanceof Error ? e.message : String(e), 200)}\n`));
|
|
5276
5365
|
}
|
|
5277
5366
|
handleGroupAll(event) {
|
|
@@ -5283,7 +5372,7 @@ export class QQChannel extends ChannelBase {
|
|
|
5283
5372
|
process.stderr.write(`[QQ:${this.name}] Group all-message dropped: missing author\n`);
|
|
5284
5373
|
return;
|
|
5285
5374
|
}
|
|
5286
|
-
if (event.author.bot) {
|
|
5375
|
+
if (event.author.bot && this.qqConfig.forwardBotMessages !== true) {
|
|
5287
5376
|
process.stderr.write(`[QQ:${this.name}] Bot message dropped in group ${sanitizeLogText(event.group_openid, 64)}\n`);
|
|
5288
5377
|
return;
|
|
5289
5378
|
}
|
|
@@ -5302,7 +5391,7 @@ export class QQChannel extends ChannelBase {
|
|
|
5302
5391
|
const result = this.prepareGroupMessage(event, chatId);
|
|
5303
5392
|
if (!result)
|
|
5304
5393
|
return;
|
|
5305
|
-
const { isSlash, text, commandText, routeText, senderName, isAtBot, safeName, } = result;
|
|
5394
|
+
const { isSlash, text, commandText, routeText, senderName, isAtBot, safeName, forwardedBot, } = result;
|
|
5306
5395
|
const media = this.inboundMedia(event);
|
|
5307
5396
|
const mediaOnly = result.body === '' && media.length > 0;
|
|
5308
5397
|
// @-bot messages always pass through (passive reply).
|
|
@@ -5385,15 +5474,21 @@ export class QQChannel extends ChannelBase {
|
|
|
5385
5474
|
: text,
|
|
5386
5475
|
senderId,
|
|
5387
5476
|
senderName,
|
|
5477
|
+
...(forwardedBot ? { senderTag: QQ_BOT_SENDER_TAG } : {}),
|
|
5388
5478
|
messageId: event.id,
|
|
5389
5479
|
isGroup: true,
|
|
5390
5480
|
isMentioned: isAtBot,
|
|
5391
5481
|
isReplyToBot: isAtBot,
|
|
5392
5482
|
...(mediaOnly ? { syntheticText: true } : {}),
|
|
5393
|
-
|
|
5483
|
+
// A forwarded bot's media-only text is a bare placeholder with no sender
|
|
5484
|
+
// line, so leave it unprefixed: ChannelBase then renders the senderTag
|
|
5485
|
+
// attribution. Every other self-prefixed path keeps the flag.
|
|
5486
|
+
...(isSlash || this.config.messageRoutes || (forwardedBot && mediaOnly)
|
|
5394
5487
|
? {}
|
|
5395
5488
|
: { alreadyPrefixed: true }),
|
|
5396
5489
|
};
|
|
5490
|
+
if (forwardedBot)
|
|
5491
|
+
this.logForwardedBotMessage(chatId);
|
|
5397
5492
|
this.dispatchInbound(envelope, media).catch((e) => {
|
|
5398
5493
|
process.stderr.write(`[QQ:${this.name}] handleGroupAll error: ${sanitizeLogText(e instanceof Error ? e.message : String(e), 200)}\n`);
|
|
5399
5494
|
});
|
|
@@ -5447,6 +5542,7 @@ export class QQChannel extends ChannelBase {
|
|
|
5447
5542
|
}
|
|
5448
5543
|
this.botOpenIdByGroup.delete(groupId);
|
|
5449
5544
|
this._lastKeywordNoMatchLog.delete(groupId);
|
|
5545
|
+
this._lastForwardedBotLog.delete(groupId);
|
|
5450
5546
|
this.recentInbound.delete(groupId);
|
|
5451
5547
|
// Clean up cron buffers targeting this group (always, regardless of config flag)
|
|
5452
5548
|
let cleanedCron = 0;
|