koishi-plugin-group-verification 1.0.22 → 1.0.24
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/lib/index.js +18 -1
- package/package.json +1 -1
- package/readme.md +7 -1
- package/src/index.ts +23 -1
package/lib/index.js
CHANGED
|
@@ -291,6 +291,10 @@ __name(verifyApplication, "verifyApplication");
|
|
|
291
291
|
async function handleFailedVerification(ctx, session, config, matchedCount, requiredThreshold) {
|
|
292
292
|
const guildId = (session.guildId || session.channelId || "").toString().trim();
|
|
293
293
|
const userId = session.userId;
|
|
294
|
+
if (!guildId) {
|
|
295
|
+
logger.warn("handleFailedVerification invoked without guildId, aborting");
|
|
296
|
+
return;
|
|
297
|
+
}
|
|
294
298
|
const username = session.username || "未知用户";
|
|
295
299
|
const message = session.content || "";
|
|
296
300
|
logger.info(`处理失败验证 guild=${guildId} user=${userId} msg="${message}" matched=${matchedCount} threshold=${requiredThreshold}`);
|
|
@@ -318,7 +322,20 @@ async function handleFailedVerification(ctx, session, config, matchedCount, requ
|
|
|
318
322
|
}
|
|
319
323
|
let reminderMsg = config.reminderMessage;
|
|
320
324
|
reminderMsg = reminderMsg.replace(/{user}/g, username).replace(/{id}/g, userId).replace(/{group}/g, guildId).replace(/{gname}/g, groupName).replace(/{question}/g, message).replace(/{answer}/g, matchedCount.toString()).replace(/{threshold}/g, requiredThreshold);
|
|
321
|
-
|
|
325
|
+
const rawChannel = (session.channelId || "").toString().trim();
|
|
326
|
+
const channel = rawChannel || guildId;
|
|
327
|
+
const target = rawChannel ? [channel, guildId] : guildId;
|
|
328
|
+
logger.debug("broadcast target", { channel, guildId, target });
|
|
329
|
+
if (session.bot && typeof session.bot.broadcast === "function") {
|
|
330
|
+
try {
|
|
331
|
+
await session.bot.broadcast([target], reminderMsg);
|
|
332
|
+
} catch (err) {
|
|
333
|
+
logger.warn("bot.broadcast failed, fallback to ctx.broadcast", err);
|
|
334
|
+
await ctx.broadcast([target], reminderMsg);
|
|
335
|
+
}
|
|
336
|
+
} else {
|
|
337
|
+
await ctx.broadcast([target], reminderMsg);
|
|
338
|
+
}
|
|
322
339
|
}
|
|
323
340
|
__name(handleFailedVerification, "handleFailedVerification");
|
|
324
341
|
function apply(ctx, config) {
|
package/package.json
CHANGED
package/readme.md
CHANGED
|
@@ -146,7 +146,13 @@ group-verify.stats total
|
|
|
146
146
|
- **手动批准**:管理员手动同意的用户数
|
|
147
147
|
- **拒绝**:被拒绝的申请数
|
|
148
148
|
- **手动入群**:管理员直接邀请入群的用户数
|
|
149
|
-
|
|
149
|
+
### ⚠️ OneBot/QQ 适配器注意
|
|
150
|
+
默认情况下插件会使用 `ctx.broadcast` 发送提醒消息,
|
|
151
|
+
为了兼容 OneBot、QQ 等需要同时指定频道和群号的协议,
|
|
152
|
+
插件会自动将 `session.channelId` 与 `session.guildId` 一起
|
|
153
|
+
传给 `broadcast`。如果你使用的适配器出现无法发送消息的
|
|
154
|
+
情况,请确保群号与频道 ID 正确无空格,或者手动在配置
|
|
155
|
+
中补充 channelId(目前是自动处理)。
|
|
150
156
|
## 🛠️ 开发配置
|
|
151
157
|
|
|
152
158
|
### 全局配置
|
package/src/index.ts
CHANGED
|
@@ -415,6 +415,11 @@ export async function handleFailedVerification(
|
|
|
415
415
|
) {
|
|
416
416
|
const guildId = (session.guildId || session.channelId || '').toString().trim();
|
|
417
417
|
const userId = session.userId
|
|
418
|
+
// 如果没有可用的群号,直接退出(防止错误插入数据库)
|
|
419
|
+
if (!guildId) {
|
|
420
|
+
logger.warn('handleFailedVerification invoked without guildId, aborting')
|
|
421
|
+
return
|
|
422
|
+
}
|
|
418
423
|
const username = session.username || '未知用户'
|
|
419
424
|
const message = session.content || ''
|
|
420
425
|
logger.info(`处理失败验证 guild=${guildId} user=${userId} msg="${message}" matched=${matchedCount} threshold=${requiredThreshold}`)
|
|
@@ -460,7 +465,24 @@ export async function handleFailedVerification(
|
|
|
460
465
|
.replace(/{threshold}/g, requiredThreshold!)
|
|
461
466
|
|
|
462
467
|
// 发送提醒消息到群内
|
|
463
|
-
|
|
468
|
+
// OneBot 等适配器需要同时指定 channelId 与 guildId,否则会无法定位到具体频道
|
|
469
|
+
// ctx.broadcast 接收的元素可以是字符串、[channel, guild] 或者 session
|
|
470
|
+
const rawChannel = (session.channelId || '').toString().trim()
|
|
471
|
+
const channel = rawChannel || guildId
|
|
472
|
+
const target: string | [string, string] = rawChannel ? [channel, guildId] : guildId
|
|
473
|
+
logger.debug('broadcast target', { channel, guildId, target })
|
|
474
|
+
// prefer using bot.broadcast since ctx.broadcast may not support tuple
|
|
475
|
+
if (session.bot && typeof session.bot.broadcast === 'function') {
|
|
476
|
+
try {
|
|
477
|
+
await session.bot.broadcast([target], reminderMsg as any)
|
|
478
|
+
} catch (err) {
|
|
479
|
+
// fallback to ctx.broadcast if bot.broadcast fails for some reason
|
|
480
|
+
logger.warn('bot.broadcast failed, fallback to ctx.broadcast', err)
|
|
481
|
+
await (ctx.broadcast as any)([target], reminderMsg)
|
|
482
|
+
}
|
|
483
|
+
} else {
|
|
484
|
+
await (ctx.broadcast as any)([target], reminderMsg)
|
|
485
|
+
}
|
|
464
486
|
}
|
|
465
487
|
|
|
466
488
|
export function apply(ctx: Context, config: Config) {
|