@nestim/koishi-plugin-qq-group-manager 0.1.10 → 0.1.12
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 +6 -1
- package/lib/service.js +100 -3
- package/package.json +1 -1
- package/readme.md +22 -0
package/lib/index.js
CHANGED
|
@@ -72,8 +72,13 @@ exports.Config = koishi_1.Schema.intersect([
|
|
|
72
72
|
blacklistFileName: koishi_1.Schema.string().default('banMember.md').description('黑名单文件名(保存在 Koishi 数据目录,可用控制台左侧「探索器 Explorer」查看/编辑)。'),
|
|
73
73
|
banCommand: koishi_1.Schema.string().default('[ban]').description('(兼容字段)黑名单指令前缀,等同 cmdBan。'),
|
|
74
74
|
banKickOnJoin: koishi_1.Schema.boolean().default(true).description('有人入群时是否自动比对黑名单,命中则立即踢出并提示。'),
|
|
75
|
-
banRecordOnKick: koishi_1.Schema.boolean().default(true).description('
|
|
75
|
+
banRecordOnKick: koishi_1.Schema.boolean().default(true).description('有人被移出群聊时是否自动把被踢者加入黑名单。只处理明确判定为「被踢」的事件(subtype=passive/kick),主动退群(leave/quit)与 subtype 缺失一律不记录;bot 自己永不记入。设为 false 则关闭该自动拉黑,只保留手动 [ban]。'),
|
|
76
76
|
}).description('黑名单'),
|
|
77
|
+
koishi_1.Schema.object({
|
|
78
|
+
eyeSelfId: koishi_1.Schema.string().default('').description('耳目号(小号)的 QQ。填写后,本插件会接收 nestim-eye 上报的「拉人事件 + QQ 号」,并由**主号**执行拉黑 + 踢人。'),
|
|
79
|
+
eyePunishGroups: koishi_1.Schema.array(String).role('table').default([]).description('耳目上报后,对拉人者执行处罚的群号列表(主号必须在这些群里有管理员/群主权限才能踢人;无权限时仍会拉黑)。留空 = 只记日志,不处罚。'),
|
|
80
|
+
eyePunishCooldownMinutes: koishi_1.Schema.natural().default(10).description('同一个人被处罚的冷却时间(分钟),避免重复踢同一个人。'),
|
|
81
|
+
}).description('耳目联动'),
|
|
77
82
|
koishi_1.Schema.object({
|
|
78
83
|
enableSelfGag: koishi_1.Schema.boolean().default(true).description('启用口球娱乐:普通成员对自己使用 mute/gag 时随机 1~60 分钟禁言。'),
|
|
79
84
|
enableUnauthorizedMutePunish: koishi_1.Schema.boolean().default(true).description('启用违规惩罚:普通成员反复尝试禁言他人时禁言本人。'),
|
package/lib/service.js
CHANGED
|
@@ -118,9 +118,18 @@ class QQGroupManagerService extends koishi_1.Service {
|
|
|
118
118
|
return;
|
|
119
119
|
if (!session.guildId)
|
|
120
120
|
return;
|
|
121
|
-
//
|
|
122
|
-
|
|
123
|
-
|
|
121
|
+
// 需求:只对「被踢」拉黑,主动退群永远不拉黑。
|
|
122
|
+
// 判定采用白名单:subtype 必须是明确的被动踢出语义。
|
|
123
|
+
// 主动退群(leave/quit)与缺失/未知值一律不记录——
|
|
124
|
+
// 宁可漏记被踢者(可由 [ban] 手动补),也绝不误拉黑主动退群的人。
|
|
125
|
+
const subtype = String(session.subtype ?? '').toLowerCase();
|
|
126
|
+
const kicked = subtype === 'passive' || subtype === 'kick';
|
|
127
|
+
if (!kicked) {
|
|
128
|
+
const who = this.normalizeQqForCompare(session.targetId || session.userId) || '未知';
|
|
129
|
+
const reason = subtype === 'leave' || subtype === 'quit'
|
|
130
|
+
? '主动退群'
|
|
131
|
+
: `subtype=${subtype || '缺失'},无法确证为被踢`;
|
|
132
|
+
this._logger.info(`[ban] 不拉黑:${reason} qq=${who} | ${this.sessionTag(session)}`);
|
|
124
133
|
return;
|
|
125
134
|
}
|
|
126
135
|
const self = this.selfQqForCompare(session);
|
|
@@ -195,6 +204,94 @@ class QQGroupManagerService extends koishi_1.Service {
|
|
|
195
204
|
catch (error) {
|
|
196
205
|
this._logger.warn(`[join-review] 恢复待审单失败: ${String(error)}`);
|
|
197
206
|
}
|
|
207
|
+
// 接收耳目号(nestim-eye)上报的拉人事件 → 由主号执行拉黑 + 踢人
|
|
208
|
+
ctx.on('nestim-eye/report', (payload) => {
|
|
209
|
+
this.punishReportedUser(payload).catch((e) => this._logger.warn(`[eye] 处罚失败: ${String(e)}`));
|
|
210
|
+
});
|
|
211
|
+
}
|
|
212
|
+
/** 处罚去重记录:qq -> 上次处罚时间戳 */
|
|
213
|
+
_eyePunishAt = new Map();
|
|
214
|
+
/** 本次插件实例的主号 QQ(用于构造伪 session) */
|
|
215
|
+
resolveMainBot() {
|
|
216
|
+
const eye = String(this.config.eyeSelfId || '').replace(/\D/g, '');
|
|
217
|
+
const bots = Array.from(this.ctx.bots || []);
|
|
218
|
+
const onebotBots = bots.filter((b) => b.platform === 'onebot');
|
|
219
|
+
return onebotBots.find((b) => String(b.selfId || '').replace(/\D/g, '') !== eye)
|
|
220
|
+
|| onebotBots[0]
|
|
221
|
+
|| bots[0]
|
|
222
|
+
|| null;
|
|
223
|
+
}
|
|
224
|
+
/** 耳目上报的处罚生效群列表(留空则不处罚) */
|
|
225
|
+
resolveEyePunishGroups() {
|
|
226
|
+
const list = Array.isArray(this.config.eyePunishGroups) ? this.config.eyePunishGroups : [];
|
|
227
|
+
const out = [];
|
|
228
|
+
for (const item of list) {
|
|
229
|
+
const g = String(item ?? '').replace(/\D/g, '');
|
|
230
|
+
if (g && !out.includes(g))
|
|
231
|
+
out.push(g);
|
|
232
|
+
}
|
|
233
|
+
return out;
|
|
234
|
+
}
|
|
235
|
+
/**
|
|
236
|
+
* 处理耳目号上报的拉人事件:对拉人者执行「拉黑 + 踢人」。
|
|
237
|
+
* 只由主号执行(耳目自身不需要任何群权限);主号若无管理权限,踢人会失败但拉黑仍成立。
|
|
238
|
+
* payload: { type: 'private'|'group-invite', qq: string, guildId?: string, evidence?: string, name?: string }
|
|
239
|
+
*/
|
|
240
|
+
async punishReportedUser(payload) {
|
|
241
|
+
const qq = String((payload && payload.qq) || '').replace(/\D/g, '');
|
|
242
|
+
if (!/^\d{5,12}$/.test(qq)) {
|
|
243
|
+
this._logger.warn(`[eye] 上报的 QQ 号无效,已忽略: ${JSON.stringify(payload)}`);
|
|
244
|
+
return;
|
|
245
|
+
}
|
|
246
|
+
const groups = this.resolveEyePunishGroups();
|
|
247
|
+
const kind = (payload && payload.type) || 'unknown';
|
|
248
|
+
const evidence = String((payload && payload.evidence) || '').slice(0, 120);
|
|
249
|
+
if (!groups.length) {
|
|
250
|
+
this._logger.info(`[eye] 收到上报 type=${kind} qq=${qq} 目标群=${(payload && payload.guildId) || '-'} 证据="${evidence}",但 eyePunishGroups 为空,仅记录不处罚`);
|
|
251
|
+
return;
|
|
252
|
+
}
|
|
253
|
+
// 冷却:同一个人短时间内不重复处罚
|
|
254
|
+
const cooldownMs = Math.max(0, Number(this.config.eyePunishCooldownMinutes ?? 10)) * 60 * 1000;
|
|
255
|
+
const last = this._eyePunishAt.get(qq) || 0;
|
|
256
|
+
if (cooldownMs > 0 && Date.now() - last < cooldownMs) {
|
|
257
|
+
this._logger.info(`[eye] qq=${qq} 在冷却期内(${Math.round((Date.now() - last) / 1000)}s 前处理过),跳过处罚`);
|
|
258
|
+
return;
|
|
259
|
+
}
|
|
260
|
+
const bot = this.resolveMainBot();
|
|
261
|
+
if (!bot) {
|
|
262
|
+
this._logger.warn('[eye] 找不到主号 bot,无法执行处罚');
|
|
263
|
+
return;
|
|
264
|
+
}
|
|
265
|
+
const banned = [];
|
|
266
|
+
const kicked = [];
|
|
267
|
+
const failed = [];
|
|
268
|
+
for (const guildId of groups) {
|
|
269
|
+
const fake = { guildId, platform: 'onebot', userId: qq, bot, send: async () => { } };
|
|
270
|
+
try {
|
|
271
|
+
const r = await this.addToBlacklist(fake, qq, '');
|
|
272
|
+
if (r && r.ok)
|
|
273
|
+
banned.push(guildId);
|
|
274
|
+
else if (/已在/.test(String((r && r.message) || '')))
|
|
275
|
+
banned.push(guildId);
|
|
276
|
+
else
|
|
277
|
+
failed.push(`${guildId}(拉黑:${(r && r.message) || '未知'})`);
|
|
278
|
+
}
|
|
279
|
+
catch (e) {
|
|
280
|
+
failed.push(`${guildId}(拉黑异常)`);
|
|
281
|
+
}
|
|
282
|
+
try {
|
|
283
|
+
const r = await this.kick(fake, qq, true, `拉人(${kind})`);
|
|
284
|
+
if (r && r.ok)
|
|
285
|
+
kicked.push(guildId);
|
|
286
|
+
else
|
|
287
|
+
failed.push(`${guildId}(踢人:${(r && r.message) || '未知'})`);
|
|
288
|
+
}
|
|
289
|
+
catch (e) {
|
|
290
|
+
failed.push(`${guildId}(踢人异常)`);
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
this._eyePunishAt.set(qq, Date.now());
|
|
294
|
+
this._logger.info(`[eye] 已处罚 qq=${qq} 来源=${kind} 拉黑=[${banned.join(',')}] 踢出=[${kicked.join(',')}] 失败=[${failed.join('; ')}] 证据="${evidence}"`);
|
|
198
295
|
}
|
|
199
296
|
isPlatformAllowed(platform) {
|
|
200
297
|
if (!platform)
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nestim/koishi-plugin-qq-group-manager",
|
|
3
3
|
"description": "Koishi QQ群管理插件(OneBot/LLOneBot):群管命令、权限校验、文本菜单、复读、AI群聊回复、记忆库、识图与自动管控(禁言/踢人)。",
|
|
4
|
-
"version": "0.1.
|
|
4
|
+
"version": "0.1.12",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"typings": "lib/index.d.ts",
|
|
7
7
|
"files": [
|
package/readme.md
CHANGED
|
@@ -4,6 +4,28 @@
|
|
|
4
4
|
|
|
5
5
|
QQ群管理插件(OneBot/LLOneBot):群管命令、权限校验、文本菜单、复读、AI群聊回复、记忆库、识图与自动管控(禁言/踢人)。
|
|
6
6
|
|
|
7
|
+
## v0.1.11 重点更新
|
|
8
|
+
|
|
9
|
+
### 退群拉黑规则明确化:主动退群永不拉黑,被踢保留
|
|
10
|
+
|
|
11
|
+
需求是「bot 踢人和他人移除可以保留拉黑,但**自己退群的不要拉黑**」。判定改为白名单式:
|
|
12
|
+
|
|
13
|
+
| 事件 | 是否拉黑 |
|
|
14
|
+
| --- | --- |
|
|
15
|
+
| 主动退群(`leave`/`quit`) | **否** |
|
|
16
|
+
| 主动退群(事件不带 subtype) | **否** |
|
|
17
|
+
| subtype 为未知值 | **否**(宁可漏记,绝不误拉黑) |
|
|
18
|
+
| 被群主/管理员踢(`passive`) | 是 |
|
|
19
|
+
| 被踢(适配器写作 `kick`) | 是 |
|
|
20
|
+
| bot 自己踢人 | 是(记录被踢者) |
|
|
21
|
+
| bot 自己被踢 | 否 |
|
|
22
|
+
|
|
23
|
+
被踢者优先取 `targetId`;只有 `userId` 且它等于操作者时不记;bot 自身永不入黑名单。
|
|
24
|
+
每次跳过都会写 `[ban] 不拉黑:<原因>` 日志,方便你在日志里核对是谁、为什么。
|
|
25
|
+
|
|
26
|
+
**历史误封不会自动清除**,请检查 `banMember_<群号>.md` 删掉误封条目,或用 `[unban] QQ号` 解除。
|
|
27
|
+
若你的适配器把主动退群错标成被踢,可设 `banRecordOnKick: false` 彻底关闭「移出事件自动拉黑」。
|
|
28
|
+
|
|
7
29
|
## v0.1.10 重点更新
|
|
8
30
|
|
|
9
31
|
### 修复:没发过消息的成员被误加入黑名单
|