@nestim/koishi-plugin-qq-group-manager 0.1.11 → 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 +5 -0
- package/lib/service.js +88 -0
- package/package.json +1 -1
package/lib/index.js
CHANGED
|
@@ -74,6 +74,11 @@ exports.Config = koishi_1.Schema.intersect([
|
|
|
74
74
|
banKickOnJoin: koishi_1.Schema.boolean().default(true).description('有人入群时是否自动比对黑名单,命中则立即踢出并提示。'),
|
|
75
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
|
@@ -204,6 +204,94 @@ class QQGroupManagerService extends koishi_1.Service {
|
|
|
204
204
|
catch (error) {
|
|
205
205
|
this._logger.warn(`[join-review] 恢复待审单失败: ${String(error)}`);
|
|
206
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}"`);
|
|
207
295
|
}
|
|
208
296
|
isPlatformAllowed(platform) {
|
|
209
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": [
|