@qwen-code/channel-qqbot 0.27.0 → 0.27.2-nightly.20261112.70a487be84
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 +15 -0
- package/dist/QQChannel.d.ts.map +1 -1
- package/dist/QQChannel.js +123 -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). */
|
|
@@ -329,6 +331,7 @@ export declare class QQChannel extends ChannelBase {
|
|
|
329
331
|
* after a full unattended turn was spent.
|
|
330
332
|
*/
|
|
331
333
|
protected supportsProactiveTarget(target: SessionTarget): boolean;
|
|
334
|
+
protected canDeliverBackgroundWorkflow(target: SessionTarget): boolean;
|
|
332
335
|
sendMessage(chatId: string, text: string): Promise<void>;
|
|
333
336
|
protected sendThreadMessage(chatId: string, _threadId: string | undefined, text: string, sourceLabel?: string): Promise<void>;
|
|
334
337
|
/**
|
|
@@ -942,6 +945,18 @@ export declare class QQChannel extends ChannelBase {
|
|
|
942
945
|
private extractBotOpenId;
|
|
943
946
|
/** Check if a message ID was already processed (reconnect replay dedup). */
|
|
944
947
|
private isDuplicate;
|
|
948
|
+
/**
|
|
949
|
+
* One rate-limited stderr line per chat per minute when a forwarded bot
|
|
950
|
+
* message is handed to the base channel. Forwarding is the one enabled path
|
|
951
|
+
* whose only brake is the model's own judgement, so an operator needs to see
|
|
952
|
+
* it is live; the line carries no sender name or payload, only the sanitized
|
|
953
|
+
* chat id.
|
|
954
|
+
*
|
|
955
|
+
* Worded as "dispatched", not "forwarded": the base channel still runs its
|
|
956
|
+
* own gates (e.g. `requireMention`) after this point, so a dispatched message
|
|
957
|
+
* is not necessarily one the model saw.
|
|
958
|
+
*/
|
|
959
|
+
private logForwardedBotMessage;
|
|
945
960
|
/**
|
|
946
961
|
* Extract common group-message fields shared by handleGroup and handleGroupAll.
|
|
947
962
|
* 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,iBA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GG;IACH,OAAO,CAAC,aAAa;IAUrB,OAAO,CAAC,oBAAoB;IA4M5B,OAAO,CAAC,YAAY;IAuCpB;;;;OAIG;YACW,kBAAkB;IA+DhC,OAAO,CAAC,KAAK;IAOb,OAAO,CAAC,cAAc;IAkBtB,OAAO,CAAC,aAAa;IASrB,OAAO,CAAC,gBAAgB;IAsBxB,4EAA4E;IAC5E,OAAO,CAAC,WAAW;IAmBnB;;;;;;;;;;OAUG;IACH,OAAO,CAAC,sBAAsB;IAS9B;;;OAGG;IACH,OAAO,CAAC,mBAAmB;IA2J3B,8DAA8D;IAC9D,OAAO,CAAC,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();
|
|
@@ -861,6 +894,9 @@ export class QQChannel extends ChannelBase {
|
|
|
861
894
|
const isGroup = target.isGroup === true || chatType === 'group';
|
|
862
895
|
return !isGroup || this.groupActiveMsgEnabled.get(target.chatId) !== false;
|
|
863
896
|
}
|
|
897
|
+
canDeliverBackgroundWorkflow(target) {
|
|
898
|
+
return this.supportsProactiveTarget(target);
|
|
899
|
+
}
|
|
864
900
|
async sendMessage(chatId, text) {
|
|
865
901
|
const inboundContext = this.inboundReplyContext.getStore();
|
|
866
902
|
const latest = this.replyMsgId.get(chatId);
|
|
@@ -1221,6 +1257,7 @@ export class QQChannel extends ChannelBase {
|
|
|
1221
1257
|
}
|
|
1222
1258
|
this.cronBuffer.clear();
|
|
1223
1259
|
this._lastKeywordNoMatchLog.clear();
|
|
1260
|
+
this._lastForwardedBotLog.clear();
|
|
1224
1261
|
this.flushQQState();
|
|
1225
1262
|
this.backupGlobalSessions();
|
|
1226
1263
|
if (this.readyTimeout) {
|
|
@@ -4430,9 +4467,19 @@ export class QQChannel extends ChannelBase {
|
|
|
4430
4467
|
async fetchToken() {
|
|
4431
4468
|
const safeName = this.name.replace(/[^A-Za-z0-9_-]/g, '_');
|
|
4432
4469
|
const credsFile = getCredsFilePath(safeName);
|
|
4470
|
+
// Only a daemon worker has no operator watching. A stream cannot tell
|
|
4471
|
+
// "piped to a human-visible tee" from "piped to a worker" — both are
|
|
4472
|
+
// pipes — so key on the explicit context the supervisor stamps on every
|
|
4473
|
+
// child it spawns (QWEN_CODE_SERVE=1, set in
|
|
4474
|
+
// cli/src/serve/channel-worker-supervisor.ts and not scrubbed).
|
|
4475
|
+
const daemonWorker = process.env['QWEN_CODE_SERVE'] === '1';
|
|
4433
4476
|
let appID = this.qqConfig.appID;
|
|
4434
4477
|
let appSecret = this.qqConfig.appSecret;
|
|
4435
|
-
|
|
4478
|
+
// The credentials file is keyed by channel name under one shared QWEN_HOME,
|
|
4479
|
+
// so in a daemon it can hold a bot bound by a different workspace. The
|
|
4480
|
+
// workspace channel config is the daemon's only source of truth; adopting
|
|
4481
|
+
// that file would connect this workspace to someone else's bot.
|
|
4482
|
+
if (!daemonWorker && (!appID || !appSecret)) {
|
|
4436
4483
|
const saved = loadCredentials(credsFile);
|
|
4437
4484
|
if (saved) {
|
|
4438
4485
|
appID = saved.appId;
|
|
@@ -4442,6 +4489,9 @@ export class QQChannel extends ChannelBase {
|
|
|
4442
4489
|
}
|
|
4443
4490
|
}
|
|
4444
4491
|
if (!appID || !appSecret) {
|
|
4492
|
+
if (daemonWorker) {
|
|
4493
|
+
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.`);
|
|
4494
|
+
}
|
|
4445
4495
|
process.stderr.write(`[QQ:${this.name}] No credentials, scan QR code with QQ...\n`);
|
|
4446
4496
|
const creds = await qrCodeLogin();
|
|
4447
4497
|
appID = creds.appId;
|
|
@@ -4937,6 +4987,24 @@ export class QQChannel extends ChannelBase {
|
|
|
4937
4987
|
}
|
|
4938
4988
|
return false;
|
|
4939
4989
|
}
|
|
4990
|
+
/**
|
|
4991
|
+
* One rate-limited stderr line per chat per minute when a forwarded bot
|
|
4992
|
+
* message is handed to the base channel. Forwarding is the one enabled path
|
|
4993
|
+
* whose only brake is the model's own judgement, so an operator needs to see
|
|
4994
|
+
* it is live; the line carries no sender name or payload, only the sanitized
|
|
4995
|
+
* chat id.
|
|
4996
|
+
*
|
|
4997
|
+
* Worded as "dispatched", not "forwarded": the base channel still runs its
|
|
4998
|
+
* own gates (e.g. `requireMention`) after this point, so a dispatched message
|
|
4999
|
+
* is not necessarily one the model saw.
|
|
5000
|
+
*/
|
|
5001
|
+
logForwardedBotMessage(chatId) {
|
|
5002
|
+
const now = Date.now();
|
|
5003
|
+
if (now - (this._lastForwardedBotLog.get(chatId) ?? 0) < 60_000)
|
|
5004
|
+
return;
|
|
5005
|
+
this._lastForwardedBotLog.set(chatId, now);
|
|
5006
|
+
process.stderr.write(`[QQ:${this.name}] forwardBotMessages: bot-authored message in ${sanitizeLogText(chatId, 64)} dispatched\n`);
|
|
5007
|
+
}
|
|
4940
5008
|
/**
|
|
4941
5009
|
* Extract common group-message fields shared by handleGroup and handleGroupAll.
|
|
4942
5010
|
* Returns null when the message has no meaningful text after @-tag stripping.
|
|
@@ -4977,18 +5045,24 @@ export class QQChannel extends ChannelBase {
|
|
|
4977
5045
|
return null;
|
|
4978
5046
|
const effectiveIsAtBot = forceAtMention ?? isAtBot;
|
|
4979
5047
|
const rawCommandText = safeCleanText.replace(/<@[^>]{1,64}>/g, '').trim();
|
|
4980
|
-
|
|
5048
|
+
// A forwarded bot message must reach the model instead of the channel's
|
|
5049
|
+
// local command table: a peer bot's `/clear` or `!cmd` is another bot
|
|
5050
|
+
// talking, not this channel being commanded.
|
|
5051
|
+
// Same truthiness predicate as the three drop guards above, so a malformed
|
|
5052
|
+
// non-boolean `author.bot` can never be forwarded untagged.
|
|
5053
|
+
const forwardedBot = Boolean(event.author?.bot) && this.qqConfig.forwardBotMessages === true;
|
|
5054
|
+
const isSlash = effectiveIsAtBot && !forwardedBot && rawCommandText.startsWith('/');
|
|
4981
5055
|
const commandText = sanitizePromptText(rawCommandText);
|
|
4982
|
-
//
|
|
4983
|
-
//
|
|
4984
|
-
//
|
|
4985
|
-
//
|
|
4986
|
-
//
|
|
4987
|
-
//
|
|
4988
|
-
//
|
|
4989
|
-
//
|
|
4990
|
-
//
|
|
4991
|
-
|
|
5056
|
+
// Bot-authored messages are a feature when the operator opts in, and the
|
|
5057
|
+
// switch is the whole tradeoff. This traffic is another bot talking in the
|
|
5058
|
+
// group: QQ delivers message events for user-authored messages only, and a
|
|
5059
|
+
// bot's own sends come back in the send API's response (a message the bot
|
|
5060
|
+
// itself sent is referenced through the response's ext_info.ref_idx, not
|
|
5061
|
+
// through a message event), so a self-echo cannot reach this handler. No
|
|
5062
|
+
// automatic rate cap follows the switch — the group's human members and the
|
|
5063
|
+
// model's own silence rules are the guard. Dropping them is the default. A
|
|
5064
|
+
// user-supplied `[bot]` is stripped above, so the tag cannot be forged.
|
|
5065
|
+
const botTag = forwardedBot ? QQ_BOT_TAG : '';
|
|
4992
5066
|
const groupBotOpenId = this.botOpenIdByGroup.get(chatId);
|
|
4993
5067
|
const openIdSuffix = this.qqConfig.allowMention !== false && groupBotOpenId
|
|
4994
5068
|
? ` [botOpenId:${groupBotOpenId}]`
|
|
@@ -5035,7 +5109,7 @@ export class QQChannel extends ChannelBase {
|
|
|
5035
5109
|
: senderIdentity
|
|
5036
5110
|
? `(${truncateCodePoints(sanitizeSenderName(senderIdentity), 8)}…)`
|
|
5037
5111
|
: '';
|
|
5038
|
-
const head = `[atMention=${effectiveIsAtBot}]${openIdSuffix} [${safeName}${senderTag}]: `;
|
|
5112
|
+
const head = `[atMention=${effectiveIsAtBot}]${openIdSuffix} ${botTag}[${safeName}${senderTag}]: `;
|
|
5039
5113
|
const body = sanitizePromptText(this.qqConfig.allowMention !== false ? safeDisplayText : safeCleanText);
|
|
5040
5114
|
const text = isSlash
|
|
5041
5115
|
? sanitizePromptText(safeCleanText)
|
|
@@ -5050,6 +5124,7 @@ export class QQChannel extends ChannelBase {
|
|
|
5050
5124
|
body,
|
|
5051
5125
|
text,
|
|
5052
5126
|
senderName,
|
|
5127
|
+
forwardedBot,
|
|
5053
5128
|
};
|
|
5054
5129
|
}
|
|
5055
5130
|
/** All supported attachments of a message, in event order. */
|
|
@@ -5148,7 +5223,7 @@ export class QQChannel extends ChannelBase {
|
|
|
5148
5223
|
process.stderr.write(`[QQ:${this.name}] C2C message dropped: missing author\n`);
|
|
5149
5224
|
return;
|
|
5150
5225
|
}
|
|
5151
|
-
if (event.author.bot) {
|
|
5226
|
+
if (event.author.bot && this.qqConfig.forwardBotMessages !== true) {
|
|
5152
5227
|
process.stderr.write(`[QQ:${this.name}] Bot C2C message dropped\n`);
|
|
5153
5228
|
return;
|
|
5154
5229
|
}
|
|
@@ -5168,35 +5243,46 @@ export class QQChannel extends ChannelBase {
|
|
|
5168
5243
|
// resolved and would consume the ring's shared 256-chat budget.
|
|
5169
5244
|
const senderName = event.author.username || event.author.id || 'QQ User';
|
|
5170
5245
|
const safeName = sanitizeSenderName(senderName);
|
|
5246
|
+
// Same truthiness predicate as the drop guard above (see prepareGroupMessage).
|
|
5247
|
+
const forwardedBot = Boolean(event.author.bot) && this.qqConfig.forwardBotMessages === true;
|
|
5248
|
+
const botTag = forwardedBot ? QQ_BOT_TAG : '';
|
|
5171
5249
|
const cleanText = rawContent.trim();
|
|
5172
5250
|
// Strip system-reserved tags that could be forged by users
|
|
5173
5251
|
const safeContent = cleanText
|
|
5174
5252
|
.replace(/\[atMention=[^\]]*]/g, '')
|
|
5175
5253
|
.replace(/\[botOpenId:[^\]]*]/g, '')
|
|
5176
5254
|
.replace(/\[bot]/g, '');
|
|
5177
|
-
|
|
5255
|
+
// Same rule as the group path: a forwarded bot's slash/bang text is a
|
|
5256
|
+
// model prompt, not a command for this channel to execute locally.
|
|
5257
|
+
const isSlash = !forwardedBot && safeContent.startsWith('/');
|
|
5178
5258
|
const body = sanitizePromptText(safeContent);
|
|
5179
5259
|
const mediaOnly = !body && media.length > 0;
|
|
5180
5260
|
const text = mediaOnly
|
|
5181
5261
|
? mediaPlaceholder(media)
|
|
5182
5262
|
: isSlash || this.config.messageRoutes
|
|
5183
5263
|
? body
|
|
5184
|
-
: `[atMention=true] [${safeName}]: ${body}`;
|
|
5264
|
+
: `[atMention=true] ${botTag}[${safeName}]: ${body}`;
|
|
5185
5265
|
const envelope = {
|
|
5186
5266
|
channelName: this.name,
|
|
5187
5267
|
senderId: chatId,
|
|
5188
5268
|
senderName,
|
|
5189
5269
|
chatId,
|
|
5190
5270
|
text,
|
|
5271
|
+
...(forwardedBot ? { senderTag: QQ_BOT_SENDER_TAG } : {}),
|
|
5191
5272
|
messageId: event.id,
|
|
5192
5273
|
isGroup: false,
|
|
5193
5274
|
isMentioned: true,
|
|
5194
5275
|
isReplyToBot: false,
|
|
5195
5276
|
...(mediaOnly ? { syntheticText: true } : {}),
|
|
5196
|
-
|
|
5277
|
+
// A forwarded bot's media-only text is a bare placeholder with no sender
|
|
5278
|
+
// line, so leave it unprefixed: ChannelBase then renders the senderTag
|
|
5279
|
+
// (and keeps it when a failed download replaces the placeholder).
|
|
5280
|
+
...(isSlash || this.config.messageRoutes || (forwardedBot && mediaOnly)
|
|
5197
5281
|
? {}
|
|
5198
5282
|
: { alreadyPrefixed: true }),
|
|
5199
5283
|
};
|
|
5284
|
+
if (forwardedBot)
|
|
5285
|
+
this.logForwardedBotMessage(chatId);
|
|
5200
5286
|
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
5287
|
}
|
|
5202
5288
|
handleGroup(event) {
|
|
@@ -5208,7 +5294,7 @@ export class QQChannel extends ChannelBase {
|
|
|
5208
5294
|
process.stderr.write(`[QQ:${this.name}] Group message dropped: missing author\n`);
|
|
5209
5295
|
return;
|
|
5210
5296
|
}
|
|
5211
|
-
if (event.author.bot) {
|
|
5297
|
+
if (event.author.bot && this.qqConfig.forwardBotMessages !== true) {
|
|
5212
5298
|
process.stderr.write(`[QQ:${this.name}] Bot message dropped in group ${sanitizeLogText(event.group_openid, 64)}\n`);
|
|
5213
5299
|
return;
|
|
5214
5300
|
}
|
|
@@ -5231,7 +5317,7 @@ export class QQChannel extends ChannelBase {
|
|
|
5231
5317
|
});
|
|
5232
5318
|
if (!result)
|
|
5233
5319
|
return;
|
|
5234
|
-
const { isSlash, text, commandText, routeText, senderName, safeName } = result;
|
|
5320
|
+
const { isSlash, text, commandText, routeText, senderName, safeName, forwardedBot, } = result;
|
|
5235
5321
|
const media = this.inboundMedia(event);
|
|
5236
5322
|
const mediaOnly = result.body === '' && media.length > 0;
|
|
5237
5323
|
// Deduplicate before handleInbound — prepareGroupMessage already ran
|
|
@@ -5263,15 +5349,21 @@ export class QQChannel extends ChannelBase {
|
|
|
5263
5349
|
: this.config.messageRoutes
|
|
5264
5350
|
? routeText
|
|
5265
5351
|
: text,
|
|
5352
|
+
...(forwardedBot ? { senderTag: QQ_BOT_SENDER_TAG } : {}),
|
|
5266
5353
|
messageId: event.id,
|
|
5267
5354
|
isGroup: true,
|
|
5268
5355
|
isMentioned: true,
|
|
5269
5356
|
isReplyToBot: true,
|
|
5270
5357
|
...(mediaOnly ? { syntheticText: true } : {}),
|
|
5271
|
-
|
|
5358
|
+
// A forwarded bot's media-only text is a bare placeholder with no sender
|
|
5359
|
+
// line, so leave it unprefixed: ChannelBase then renders the senderTag
|
|
5360
|
+
// attribution. Every other self-prefixed path keeps the flag.
|
|
5361
|
+
...(isSlash || this.config.messageRoutes || (forwardedBot && mediaOnly)
|
|
5272
5362
|
? {}
|
|
5273
5363
|
: { alreadyPrefixed: true }),
|
|
5274
5364
|
};
|
|
5365
|
+
if (forwardedBot)
|
|
5366
|
+
this.logForwardedBotMessage(chatId);
|
|
5275
5367
|
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
5368
|
}
|
|
5277
5369
|
handleGroupAll(event) {
|
|
@@ -5283,7 +5375,7 @@ export class QQChannel extends ChannelBase {
|
|
|
5283
5375
|
process.stderr.write(`[QQ:${this.name}] Group all-message dropped: missing author\n`);
|
|
5284
5376
|
return;
|
|
5285
5377
|
}
|
|
5286
|
-
if (event.author.bot) {
|
|
5378
|
+
if (event.author.bot && this.qqConfig.forwardBotMessages !== true) {
|
|
5287
5379
|
process.stderr.write(`[QQ:${this.name}] Bot message dropped in group ${sanitizeLogText(event.group_openid, 64)}\n`);
|
|
5288
5380
|
return;
|
|
5289
5381
|
}
|
|
@@ -5302,7 +5394,7 @@ export class QQChannel extends ChannelBase {
|
|
|
5302
5394
|
const result = this.prepareGroupMessage(event, chatId);
|
|
5303
5395
|
if (!result)
|
|
5304
5396
|
return;
|
|
5305
|
-
const { isSlash, text, commandText, routeText, senderName, isAtBot, safeName, } = result;
|
|
5397
|
+
const { isSlash, text, commandText, routeText, senderName, isAtBot, safeName, forwardedBot, } = result;
|
|
5306
5398
|
const media = this.inboundMedia(event);
|
|
5307
5399
|
const mediaOnly = result.body === '' && media.length > 0;
|
|
5308
5400
|
// @-bot messages always pass through (passive reply).
|
|
@@ -5385,15 +5477,21 @@ export class QQChannel extends ChannelBase {
|
|
|
5385
5477
|
: text,
|
|
5386
5478
|
senderId,
|
|
5387
5479
|
senderName,
|
|
5480
|
+
...(forwardedBot ? { senderTag: QQ_BOT_SENDER_TAG } : {}),
|
|
5388
5481
|
messageId: event.id,
|
|
5389
5482
|
isGroup: true,
|
|
5390
5483
|
isMentioned: isAtBot,
|
|
5391
5484
|
isReplyToBot: isAtBot,
|
|
5392
5485
|
...(mediaOnly ? { syntheticText: true } : {}),
|
|
5393
|
-
|
|
5486
|
+
// A forwarded bot's media-only text is a bare placeholder with no sender
|
|
5487
|
+
// line, so leave it unprefixed: ChannelBase then renders the senderTag
|
|
5488
|
+
// attribution. Every other self-prefixed path keeps the flag.
|
|
5489
|
+
...(isSlash || this.config.messageRoutes || (forwardedBot && mediaOnly)
|
|
5394
5490
|
? {}
|
|
5395
5491
|
: { alreadyPrefixed: true }),
|
|
5396
5492
|
};
|
|
5493
|
+
if (forwardedBot)
|
|
5494
|
+
this.logForwardedBotMessage(chatId);
|
|
5397
5495
|
this.dispatchInbound(envelope, media).catch((e) => {
|
|
5398
5496
|
process.stderr.write(`[QQ:${this.name}] handleGroupAll error: ${sanitizeLogText(e instanceof Error ? e.message : String(e), 200)}\n`);
|
|
5399
5497
|
});
|
|
@@ -5447,6 +5545,7 @@ export class QQChannel extends ChannelBase {
|
|
|
5447
5545
|
}
|
|
5448
5546
|
this.botOpenIdByGroup.delete(groupId);
|
|
5449
5547
|
this._lastKeywordNoMatchLog.delete(groupId);
|
|
5548
|
+
this._lastForwardedBotLog.delete(groupId);
|
|
5450
5549
|
this.recentInbound.delete(groupId);
|
|
5451
5550
|
// Clean up cron buffers targeting this group (always, regardless of config flag)
|
|
5452
5551
|
let cleanedCron = 0;
|