koishi-plugin-808ps-qunmax 0.0.2 → 0.0.4
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 +29 -19
- package/package.json +1 -1
package/lib/index.js
CHANGED
|
@@ -41,9 +41,14 @@ module.exports = __toCommonJS(src_exports);
|
|
|
41
41
|
var import_koishi = require("koishi");
|
|
42
42
|
var import_promise = require("mysql2/promise");
|
|
43
43
|
var import_dayjs = __toESM(require("dayjs"));
|
|
44
|
+
var import_utc = __toESM(require("dayjs/plugin/utc"));
|
|
45
|
+
var import_timezone = __toESM(require("dayjs/plugin/timezone"));
|
|
44
46
|
var crypto = __toESM(require("crypto"));
|
|
45
47
|
var fs = __toESM(require("fs"));
|
|
46
48
|
var path = __toESM(require("path"));
|
|
49
|
+
import_dayjs.default.extend(import_utc.default);
|
|
50
|
+
import_dayjs.default.extend(import_timezone.default);
|
|
51
|
+
import_dayjs.default.tz.setDefault("Asia/Shanghai");
|
|
47
52
|
var name = "808ps-bot";
|
|
48
53
|
var logger = new import_koishi.Logger(name);
|
|
49
54
|
var using = ["http"];
|
|
@@ -144,7 +149,7 @@ var utils = {
|
|
|
144
149
|
fileLog: /* @__PURE__ */ __name((msg) => {
|
|
145
150
|
const logPath = path.join(process.cwd(), "data", "808ps-bot.log");
|
|
146
151
|
const stream = fs.createWriteStream(logPath, { flags: "a" });
|
|
147
|
-
const now =
|
|
152
|
+
const now = import_dayjs.default.tz().format("YYYY-MM-DD HH:mm:ss");
|
|
148
153
|
stream.write(`[${now}] ${msg}
|
|
149
154
|
`);
|
|
150
155
|
stream.end();
|
|
@@ -260,7 +265,7 @@ var Config = import_koishi.Schema.object({
|
|
|
260
265
|
温度值: import_koishi.Schema.number().default(0.7).min(0).max(1).description("AI回复的随机性(0-1,值越高越随机)"),
|
|
261
266
|
系统提示语: import_koishi.Schema.string().default("你是 QQ 机器人,请用中文回答。").description("AI的系统角色提示")
|
|
262
267
|
}).description("AI聊天功能的配置"),
|
|
263
|
-
重复推送限制小时: import_koishi.Schema.number().default(24).description("
|
|
268
|
+
重复推送限制小时: import_koishi.Schema.number().default(24).description("同一用户的资料重复推送限制小时(0=无限制)"),
|
|
264
269
|
进退群延迟秒: import_koishi.Schema.number().default(3).description("成员进退群后延迟同步数据的时间"),
|
|
265
270
|
定时同步分钟: import_koishi.Schema.number().default(60).min(1).description("定时同步群成员数据的间隔(分钟)"),
|
|
266
271
|
渠道配置: import_koishi.Schema.array(import_koishi.Schema.object({
|
|
@@ -308,7 +313,8 @@ async function initDatabase(config) {
|
|
|
308
313
|
port: config.数据库配置.端口,
|
|
309
314
|
user: config.数据库配置.用户名,
|
|
310
315
|
password: config.数据库配置.密码,
|
|
311
|
-
connectionLimit: 1
|
|
316
|
+
connectionLimit: 1,
|
|
317
|
+
timezone: "+08:00"
|
|
312
318
|
});
|
|
313
319
|
try {
|
|
314
320
|
await rootPool.execute(`CREATE DATABASE IF NOT EXISTS ${config.数据库配置["808ps数据库名"]} DEFAULT CHARSET utf8mb4`);
|
|
@@ -319,7 +325,8 @@ async function initDatabase(config) {
|
|
|
319
325
|
user: config.数据库配置.用户名,
|
|
320
326
|
password: config.数据库配置.密码,
|
|
321
327
|
database: config.数据库配置["808ps数据库名"],
|
|
322
|
-
connectionLimit: 50
|
|
328
|
+
connectionLimit: 50,
|
|
329
|
+
timezone: "+08:00"
|
|
323
330
|
});
|
|
324
331
|
await mainPool.execute(`
|
|
325
332
|
CREATE TABLE IF NOT EXISTS our_group_members (
|
|
@@ -374,7 +381,8 @@ async function initDatabase(config) {
|
|
|
374
381
|
user: config.数据库配置.用户名,
|
|
375
382
|
password: config.数据库配置.密码,
|
|
376
383
|
database: config.数据库配置.游戏数据库名,
|
|
377
|
-
connectionLimit: 20
|
|
384
|
+
connectionLimit: 20,
|
|
385
|
+
timezone: "+08:00"
|
|
378
386
|
});
|
|
379
387
|
logger.info("所有数据表创建/检测完成");
|
|
380
388
|
await rootPool.end();
|
|
@@ -433,15 +441,15 @@ async function saveGroupMember(ctx, botSet, pool, groupId, config) {
|
|
|
433
441
|
}
|
|
434
442
|
}
|
|
435
443
|
__name(saveGroupMember, "saveGroupMember");
|
|
436
|
-
async function checkRepeatPushLimit(mainPool, userId,
|
|
444
|
+
async function checkRepeatPushLimit(mainPool, userId, limitHours) {
|
|
437
445
|
const [logRows] = await mainPool.execute(`
|
|
438
|
-
SELECT MAX(capture_time) AS latest_time FROM drain_log WHERE monitor_qq = ?
|
|
439
|
-
`, [userId
|
|
446
|
+
SELECT MAX(capture_time) AS latest_time FROM drain_log WHERE monitor_qq = ?
|
|
447
|
+
`, [userId]);
|
|
440
448
|
const latestTimeStr = logRows[0].latest_time;
|
|
441
449
|
if (latestTimeStr && limitHours > 0) {
|
|
442
|
-
const hoursDiff =
|
|
450
|
+
const hoursDiff = import_dayjs.default.tz().diff(import_dayjs.default.tz(latestTimeStr), "hour");
|
|
443
451
|
if (hoursDiff < limitHours) {
|
|
444
|
-
logger.info(`[引流监控]
|
|
452
|
+
logger.info(`[引流监控] 用户${userId} 资料在${hoursDiff}小时内已推送,跳过重复推送`);
|
|
445
453
|
return true;
|
|
446
454
|
}
|
|
447
455
|
}
|
|
@@ -491,7 +499,7 @@ async function pushDrainData(mainPool, ctx, userId, groupId, subType, eventText,
|
|
|
491
499
|
📌 捕获资料
|
|
492
500
|
捕获QQ:${userId}
|
|
493
501
|
事件类型:${eventText}
|
|
494
|
-
捕获时间:${
|
|
502
|
+
捕获时间:${import_dayjs.default.tz().format("YYYY-MM-DD HH:mm:ss")}
|
|
495
503
|
捕获来源:外群${groupId}
|
|
496
504
|
`.trim()).catch(() => {
|
|
497
505
|
});
|
|
@@ -625,7 +633,7 @@ async function apply(ctx, config) {
|
|
|
625
633
|
原注册渠道:${existChannelConfig.渠道名称}
|
|
626
634
|
当前加入渠道:${currentChannelConfig.渠道名称}
|
|
627
635
|
当前群号:${groupId}
|
|
628
|
-
检测时间:${
|
|
636
|
+
检测时间:${import_dayjs.default.tz().format("YYYY-MM-DD HH:mm:ss")}
|
|
629
637
|
处理结果:仅通知,未执行踢人
|
|
630
638
|
`.trim();
|
|
631
639
|
await sendNotification(ctx, botQQs, notifyList, message);
|
|
@@ -658,7 +666,7 @@ async function apply(ctx, config) {
|
|
|
658
666
|
渠道:${channelConfig.渠道名称}
|
|
659
667
|
群名:${groupName}(${groupId})
|
|
660
668
|
用户QQ:${userId}
|
|
661
|
-
入群时间:${
|
|
669
|
+
入群时间:${import_dayjs.default.tz().format("YYYY-MM-DD HH:mm:ss")}
|
|
662
670
|
`.trim();
|
|
663
671
|
await sendNotification(ctx, botQQs, notifyList, message);
|
|
664
672
|
}
|
|
@@ -687,7 +695,7 @@ async function apply(ctx, config) {
|
|
|
687
695
|
群名:${groupName}(${groupId})
|
|
688
696
|
用户QQ:${userId}
|
|
689
697
|
事件类型:${actionText}
|
|
690
|
-
退群时间:${
|
|
698
|
+
退群时间:${import_dayjs.default.tz().format("YYYY-MM-DD HH:mm:ss")}
|
|
691
699
|
`.trim();
|
|
692
700
|
await sendNotification(ctx, botQQs, notifyList, message);
|
|
693
701
|
}
|
|
@@ -859,8 +867,8 @@ async function apply(ctx, config) {
|
|
|
859
867
|
拉人值班:${inviterQQ || "无人/主动加入"}
|
|
860
868
|
注册来源:${registerChannelName}
|
|
861
869
|
来源群号:${registerGroupId || "未知"}
|
|
862
|
-
进群时间:${joinTime ?
|
|
863
|
-
注册时间:${
|
|
870
|
+
进群时间:${joinTime ? import_dayjs.default.tz(joinTime).format("YYYY-MM-DD HH:mm:ss") : "未知"}
|
|
871
|
+
注册时间:${import_dayjs.default.tz(registerTime).format("YYYY-MM-DD HH:mm:ss")}
|
|
864
872
|
转化时长:${durationText}
|
|
865
873
|
`.trim();
|
|
866
874
|
await sendNotification(ctx, botQQs, notifyList, adminMessage);
|
|
@@ -889,7 +897,7 @@ async function apply(ctx, config) {
|
|
|
889
897
|
}
|
|
890
898
|
if (content === config.值班配置.上岗密码) {
|
|
891
899
|
try {
|
|
892
|
-
const expireTime =
|
|
900
|
+
const expireTime = import_dayjs.default.tz().add(config.值班配置.有效期小时, "hour").format("YYYY-MM-DD HH:mm:ss");
|
|
893
901
|
await mainPool.execute(`
|
|
894
902
|
INSERT INTO duty_user (qq, login_time, expire_time, today_get_count)
|
|
895
903
|
VALUES (?, NOW(), ?, 0) ON DUPLICATE KEY UPDATE
|
|
@@ -974,7 +982,7 @@ async function apply(ctx, config) {
|
|
|
974
982
|
logger.info(`[外群监控] 群${groupId} 用户${userId} 是自身群成员,跳过推送`);
|
|
975
983
|
return;
|
|
976
984
|
}
|
|
977
|
-
if (await checkRepeatPushLimit(mainPool, userId,
|
|
985
|
+
if (await checkRepeatPushLimit(mainPool, userId, config.重复推送限制小时)) return;
|
|
978
986
|
await pushDrainData(mainPool, ctx, userId, groupId, subType, eventExtractor.getActionText(subType), config);
|
|
979
987
|
});
|
|
980
988
|
ctx.on("guild-member-removed", async (session) => {
|
|
@@ -995,7 +1003,7 @@ async function apply(ctx, config) {
|
|
|
995
1003
|
logger.info(`[外群监控] 群${groupId} 用户${userId} 是自身群成员,跳过推送`);
|
|
996
1004
|
return;
|
|
997
1005
|
}
|
|
998
|
-
if (await checkRepeatPushLimit(mainPool, userId,
|
|
1006
|
+
if (await checkRepeatPushLimit(mainPool, userId, config.重复推送限制小时)) return;
|
|
999
1007
|
await pushDrainData(mainPool, ctx, userId, groupId, subType, eventText, config);
|
|
1000
1008
|
});
|
|
1001
1009
|
ctx.setInterval(async () => await mainPool.execute("DELETE FROM duty_user WHERE expire_time < NOW()"), 5 * 60 * 1e3);
|
|
@@ -1020,6 +1028,8 @@ async function apply(ctx, config) {
|
|
|
1020
1028
|
logger.info("✅ 已恢复:注册+修改密码+注册送点券代币功能");
|
|
1021
1029
|
logger.info("✅ 渠道精确绑定:一个渠道绑定多个精确群号");
|
|
1022
1030
|
logger.info("✅ 渠道级防串群:同一渠道多个群不算串群");
|
|
1031
|
+
logger.info("✅ 已修复:重复推送限制(按用户全局去重)");
|
|
1032
|
+
logger.info("✅ 已修复:全局时间统一为北京时间");
|
|
1023
1033
|
}
|
|
1024
1034
|
__name(apply, "apply");
|
|
1025
1035
|
var src_default = { name, Config, apply, using, description: "808ps游戏引流插件(全链路引流追踪+渠道绑定+渠道级防串群)" };
|