koishi-plugin-cocoyyy-console 1.0.16-beta.4 → 1.0.16-beta.6
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.d.ts +1 -0
- package/lib/index.js +255 -40
- package/lib/services/son_func/shit_or_not_command.d.ts +4 -1
- package/lib/services/son_func/shit_or_not_service.d.ts +2 -2
- package/lib/utils/ai_axios.d.ts +7 -9
- package/lib/utils/config.d.ts +1 -0
- package/lib/utils/configs/function_config.d.ts +1 -1
- package/lib/utils/configs/son_config.d.ts +1 -0
- package/package.json +4 -3
package/lib/index.d.ts
CHANGED
package/lib/index.js
CHANGED
|
@@ -30,7 +30,7 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
30
30
|
// src/index.ts
|
|
31
31
|
var src_exports = {};
|
|
32
32
|
__export(src_exports, {
|
|
33
|
-
Config: () =>
|
|
33
|
+
Config: () => Config2,
|
|
34
34
|
apply: () => apply,
|
|
35
35
|
dev_mode: () => dev_mode,
|
|
36
36
|
logger: () => logger,
|
|
@@ -38,7 +38,7 @@ __export(src_exports, {
|
|
|
38
38
|
savePath: () => savePath
|
|
39
39
|
});
|
|
40
40
|
module.exports = __toCommonJS(src_exports);
|
|
41
|
-
var
|
|
41
|
+
var import_koishi10 = require("koishi");
|
|
42
42
|
|
|
43
43
|
// src/utils/configs/function_config.ts
|
|
44
44
|
var import_koishi = require("koishi");
|
|
@@ -47,7 +47,7 @@ var FunctionConfigSchema = import_koishi.Schema.object({
|
|
|
47
47
|
tag_flag: import_koishi.Schema.boolean().default(true).description("标签功能是否启用"),
|
|
48
48
|
repeat_flag: import_koishi.Schema.boolean().default(true).description("复读功能是否启用"),
|
|
49
49
|
rbq_flag: import_koishi.Schema.boolean().default(true).description("*人功能是否启用"),
|
|
50
|
-
|
|
50
|
+
son_flag: import_koishi.Schema.boolean().default(true).description("鉴别史消息功能是否启用"),
|
|
51
51
|
kuro_flag: import_koishi.Schema.boolean().default(true).description("鸣潮功能是否启用")
|
|
52
52
|
});
|
|
53
53
|
|
|
@@ -87,6 +87,15 @@ var RedisConfigSchema = import_koishi5.Schema.object({
|
|
|
87
87
|
redis_url: import_koishi5.Schema.string().default("127.0.0.1:6379").description("Redis连接字符串")
|
|
88
88
|
});
|
|
89
89
|
|
|
90
|
+
// src/utils/configs/son_config.ts
|
|
91
|
+
var import_koishi6 = require("koishi");
|
|
92
|
+
var ShitOrNotConfigSchema = import_koishi6.Schema.object({
|
|
93
|
+
api_url: import_koishi6.Schema.string().default("").description("Api接口Url"),
|
|
94
|
+
api_model: import_koishi6.Schema.string().default("").description("AI模型"),
|
|
95
|
+
api_key: import_koishi6.Schema.string().default("").description("API Key"),
|
|
96
|
+
config_path: import_koishi6.Schema.string().default("").description("配置文件路径")
|
|
97
|
+
});
|
|
98
|
+
|
|
90
99
|
// src/infra/mysql_init.ts
|
|
91
100
|
var import_sequelize = require("sequelize");
|
|
92
101
|
var sequelize = null;
|
|
@@ -314,6 +323,10 @@ function getMenuList(command = null, functionConfig) {
|
|
|
314
323
|
if (!functionConfig.rbq_flag)
|
|
315
324
|
return "*人功能已关闭";
|
|
316
325
|
return getRbqFuncMenu(command);
|
|
326
|
+
case "son":
|
|
327
|
+
if (!functionConfig.son_flag)
|
|
328
|
+
return "son功能已关闭";
|
|
329
|
+
return getSonFuncMenu(command);
|
|
317
330
|
case "kuro":
|
|
318
331
|
if (!functionConfig.kuro_flag)
|
|
319
332
|
return "库洛相关功能已关闭";
|
|
@@ -404,6 +417,25 @@ function getRbqFuncMenu(command = null) {
|
|
|
404
417
|
输入对应指令使用*人功能,如果遇到问题请联系开发人员。`;
|
|
405
418
|
}
|
|
406
419
|
__name(getRbqFuncMenu, "getRbqFuncMenu");
|
|
420
|
+
var sonFuncMenuList = [
|
|
421
|
+
{
|
|
422
|
+
name: "sonlist",
|
|
423
|
+
description: "查看son判断模式列表",
|
|
424
|
+
command: "sonlist"
|
|
425
|
+
},
|
|
426
|
+
{
|
|
427
|
+
name: "son",
|
|
428
|
+
description: "判断是否为史",
|
|
429
|
+
command: "son [判断模式]"
|
|
430
|
+
}
|
|
431
|
+
];
|
|
432
|
+
function getSonFuncMenu(command = null) {
|
|
433
|
+
return `[所有命令都需要@bot]
|
|
434
|
+
son功能菜单:
|
|
435
|
+
${sonFuncMenuList.map((item) => item.command + ": " + item.description).join("\n ")}
|
|
436
|
+
输入对应指令使用son功能,如果遇到问题请联系开发人员。`;
|
|
437
|
+
}
|
|
438
|
+
__name(getSonFuncMenu, "getSonFuncMenu");
|
|
407
439
|
var kuroFuncMenuList = [
|
|
408
440
|
{
|
|
409
441
|
name: "login",
|
|
@@ -436,7 +468,7 @@ function registerMenuCommands(ctx, connected, functionConfig) {
|
|
|
436
468
|
__name(registerMenuCommands, "registerMenuCommands");
|
|
437
469
|
|
|
438
470
|
// src/services/tag_func/tag_commands.ts
|
|
439
|
-
var
|
|
471
|
+
var import_koishi8 = require("koishi");
|
|
440
472
|
|
|
441
473
|
// src/services/tag_func/tag_service.ts
|
|
442
474
|
var import_sequelize4 = require("sequelize");
|
|
@@ -444,7 +476,7 @@ var import_fs2 = require("fs");
|
|
|
444
476
|
var import_path2 = require("path");
|
|
445
477
|
|
|
446
478
|
// src/services/tag_func/img_service.ts
|
|
447
|
-
var
|
|
479
|
+
var import_koishi7 = require("koishi");
|
|
448
480
|
var import_path = require("path");
|
|
449
481
|
var import_fs = require("fs");
|
|
450
482
|
async function loadImageFromUrl(ctx, url) {
|
|
@@ -519,7 +551,7 @@ async function randomImgByTag(tag_name, guild_id) {
|
|
|
519
551
|
if (ImgList.length <= 0) {
|
|
520
552
|
throw new Error("Don't have image!");
|
|
521
553
|
}
|
|
522
|
-
const random = new
|
|
554
|
+
const random = new import_koishi7.Random(() => Math.random());
|
|
523
555
|
let result = ImgList[random.int(0, ImgList.length)];
|
|
524
556
|
const filePath = result.get("img_url");
|
|
525
557
|
return filePath;
|
|
@@ -763,8 +795,8 @@ function registerTagCommands(ctx, connected, savePath2) {
|
|
|
763
795
|
let exec = await randomImgByTag(tag, session.guildId);
|
|
764
796
|
if (!exec)
|
|
765
797
|
return `获取图片失败`;
|
|
766
|
-
let
|
|
767
|
-
return
|
|
798
|
+
let path2 = (0, import_url.pathToFileURL)(exec).href;
|
|
799
|
+
return import_koishi8.h.image(path2);
|
|
768
800
|
});
|
|
769
801
|
ctx.command("bind <参数>", "标签绑定别名").action(async ({ session }, ...args) => {
|
|
770
802
|
if (!dev_mode) {
|
|
@@ -907,7 +939,7 @@ function registerRepeatMiddleware(ctx, config) {
|
|
|
907
939
|
__name(registerRepeatMiddleware, "registerRepeatMiddleware");
|
|
908
940
|
|
|
909
941
|
// src/services/rbq_func/rbq_command.ts
|
|
910
|
-
var
|
|
942
|
+
var import_koishi9 = require("koishi");
|
|
911
943
|
|
|
912
944
|
// src/models/rbq_persons.ts
|
|
913
945
|
var import_sequelize5 = require("sequelize");
|
|
@@ -1232,7 +1264,7 @@ function registerRbqCommands(ctx, connected) {
|
|
|
1232
1264
|
if (!list || list.length === 0) {
|
|
1233
1265
|
return "当前群聊还没有设置任何rbq";
|
|
1234
1266
|
}
|
|
1235
|
-
return "当前群聊rbq列表:\n" + list.map((item) => (0,
|
|
1267
|
+
return "当前群聊rbq列表:\n" + list.map((item) => (0, import_koishi9.h)("at", { id: item })).join(",");
|
|
1236
1268
|
});
|
|
1237
1269
|
ctx.command("rbqadd <参数>", "添加rbq").action(async ({ session }, ...args) => {
|
|
1238
1270
|
if (!dev_mode) {
|
|
@@ -1250,7 +1282,7 @@ function registerRbqCommands(ctx, connected) {
|
|
|
1250
1282
|
exec = await create_person(session.guildId, uid);
|
|
1251
1283
|
if (!exec.result)
|
|
1252
1284
|
return `添加rbq失败: ${exec.error}`;
|
|
1253
|
-
return "已添加rbq:" + (0,
|
|
1285
|
+
return "已添加rbq:" + (0, import_koishi9.h)("at", { id: uid });
|
|
1254
1286
|
});
|
|
1255
1287
|
ctx.command("rbqinstead <参数>", "替换rbq").action(async ({ session }, ...args) => {
|
|
1256
1288
|
if (!dev_mode) {
|
|
@@ -1275,12 +1307,12 @@ function registerRbqCommands(ctx, connected) {
|
|
|
1275
1307
|
exec = await instead_person(session.guildId, source_uid, new_target);
|
|
1276
1308
|
if (!exec.result)
|
|
1277
1309
|
return `替换rbq失败:${exec.error}`;
|
|
1278
|
-
return "倒反天罡!进去吧你,已替换rbq:\n" + (0,
|
|
1310
|
+
return "倒反天罡!进去吧你,已替换rbq:\n" + (0, import_koishi9.h)("at", { id: source_uid }) + " -> " + (0, import_koishi9.h)("at", { id: new_target });
|
|
1279
1311
|
}
|
|
1280
1312
|
exec = await instead_person(session.guildId, source_uid, target_uid);
|
|
1281
1313
|
if (!exec.result)
|
|
1282
1314
|
return `替换rbq失败:${exec.error}`;
|
|
1283
|
-
return (0,
|
|
1315
|
+
return (0, import_koishi9.h)("p", "已替换rbq:", (0, import_koishi9.h)("at", { id: source_uid }), " -> ", (0, import_koishi9.h)("at", { id: target_uid }));
|
|
1284
1316
|
});
|
|
1285
1317
|
ctx.command("rbqadd_txt <参数>", "添加自定义文本").action(async ({ session }, ...args) => {
|
|
1286
1318
|
if (!dev_mode) {
|
|
@@ -1307,10 +1339,10 @@ function registerRbqCommands(ctx, connected) {
|
|
|
1307
1339
|
const contents = await get_content_list(session.guildId, target_uid);
|
|
1308
1340
|
let content2 = "*死你";
|
|
1309
1341
|
if (contents && contents.length > 0) {
|
|
1310
|
-
const random = new
|
|
1342
|
+
const random = new import_koishi9.Random(() => Math.random());
|
|
1311
1343
|
content2 = contents[random.int(0, contents.length)];
|
|
1312
1344
|
}
|
|
1313
|
-
return (0,
|
|
1345
|
+
return (0, import_koishi9.h)("at", { id: target_uid }) + "还想自己加文本?!\n" + content2;
|
|
1314
1346
|
} catch (error) {
|
|
1315
1347
|
logger.error("[rbq rbqadd_txt] Error:", error);
|
|
1316
1348
|
return "不能给自己设置文本,请输入其他qq号";
|
|
@@ -1340,10 +1372,10 @@ function registerRbqCommands(ctx, connected) {
|
|
|
1340
1372
|
const contents = await get_content_list(guildId, matchedUid);
|
|
1341
1373
|
let content = "*死你";
|
|
1342
1374
|
if (contents && contents.length > 0) {
|
|
1343
|
-
const random = new
|
|
1375
|
+
const random = new import_koishi9.Random(() => Math.random());
|
|
1344
1376
|
content = contents[random.int(0, contents.length)];
|
|
1345
1377
|
}
|
|
1346
|
-
return (0,
|
|
1378
|
+
return (0, import_koishi9.h)("at", { id: matchedUid }) + " " + content;
|
|
1347
1379
|
} catch (error) {
|
|
1348
1380
|
logger.error("[rbq middleware] Error:", error);
|
|
1349
1381
|
return next();
|
|
@@ -1354,23 +1386,14 @@ __name(registerRbqCommands, "registerRbqCommands");
|
|
|
1354
1386
|
|
|
1355
1387
|
// src/services/test_command.ts
|
|
1356
1388
|
var import_tesseract = require("tesseract.js");
|
|
1357
|
-
var CONSTANTS = {
|
|
1358
|
-
ESU: "前提条件"
|
|
1359
|
-
};
|
|
1360
|
-
var chatHistory = [];
|
|
1361
1389
|
function registerTestCommands(ctx, config) {
|
|
1362
1390
|
ctx.command("test1 <prompt:text>", "调用 OpenRouter 模型进行测试").action(async ({ session }, prompt) => {
|
|
1363
1391
|
const apiKey = config?.test || process.env.OPENROUTER_API_KEY;
|
|
1364
1392
|
if (!apiKey) return "未配置 OpenRouter API Key(config.test 或环境变量 OPENROUTER_API_KEY)";
|
|
1365
1393
|
const content = prompt?.trim();
|
|
1366
1394
|
if (!content) return "请输入要测试的内容";
|
|
1367
|
-
chatHistory.push({ role: "user", content });
|
|
1368
|
-
const messages = [
|
|
1369
|
-
{ role: "system", content: CONSTANTS.ESU },
|
|
1370
|
-
...chatHistory
|
|
1371
|
-
];
|
|
1372
1395
|
});
|
|
1373
|
-
ctx.command("test <path>", "测试用").action(async ({ session },
|
|
1396
|
+
ctx.command("test <path>", "测试用").action(async ({ session }, path2) => {
|
|
1374
1397
|
const { content, uid, userId } = session;
|
|
1375
1398
|
if (session.quote) {
|
|
1376
1399
|
const quoteContent = session.quote.content;
|
|
@@ -1396,8 +1419,197 @@ function registerTestCommands(ctx, config) {
|
|
|
1396
1419
|
}
|
|
1397
1420
|
__name(registerTestCommands, "registerTestCommands");
|
|
1398
1421
|
|
|
1399
|
-
// src/services/
|
|
1422
|
+
// src/services/son_func/shit_or_not_command.ts
|
|
1423
|
+
var import_fs3 = require("fs");
|
|
1424
|
+
var yaml = __toESM(require("js-yaml"));
|
|
1425
|
+
var import_path3 = __toESM(require("path"));
|
|
1426
|
+
|
|
1427
|
+
// src/services/son_func/shit_or_not_service.ts
|
|
1428
|
+
var import_tesseract2 = require("tesseract.js");
|
|
1429
|
+
|
|
1430
|
+
// src/utils/ai_axios.ts
|
|
1400
1431
|
var import_axios = __toESM(require("axios"));
|
|
1432
|
+
async function callOpenRouter(api_url, api_key, api_model = "gpt-4o-mini", messages) {
|
|
1433
|
+
try {
|
|
1434
|
+
const { data } = await import_axios.default.post(
|
|
1435
|
+
api_url,
|
|
1436
|
+
{
|
|
1437
|
+
api_model,
|
|
1438
|
+
messages
|
|
1439
|
+
},
|
|
1440
|
+
{
|
|
1441
|
+
headers: {
|
|
1442
|
+
Authorization: `Bearer ${api_key}`,
|
|
1443
|
+
"Content-Type": "application/json"
|
|
1444
|
+
}
|
|
1445
|
+
}
|
|
1446
|
+
);
|
|
1447
|
+
const choices = data?.choices ?? [];
|
|
1448
|
+
const reply = choices[0]?.message?.content;
|
|
1449
|
+
let responseText;
|
|
1450
|
+
let err = null;
|
|
1451
|
+
if (typeof reply === "string") {
|
|
1452
|
+
responseText = reply.trim();
|
|
1453
|
+
} else if (Array.isArray(reply)) {
|
|
1454
|
+
responseText = reply.map((part) => part?.text ?? "").join("").trim();
|
|
1455
|
+
if (!responseText) {
|
|
1456
|
+
err = "OpenRouter 返回空内容";
|
|
1457
|
+
}
|
|
1458
|
+
} else {
|
|
1459
|
+
err = "OpenRouter 返回了未知格式,请检查日志";
|
|
1460
|
+
}
|
|
1461
|
+
return { err, resp: responseText };
|
|
1462
|
+
} catch (error) {
|
|
1463
|
+
const err = error;
|
|
1464
|
+
const status = err.response?.status;
|
|
1465
|
+
const detail = err.response?.data?.error || err.response?.data?.message || err.message;
|
|
1466
|
+
logger.error("[callOpenRouter Error]: OpenRouter 请求失败" + error);
|
|
1467
|
+
const errorMessage = `test error${status ? `(${status})` : ""}: ${detail}`;
|
|
1468
|
+
return { err: errorMessage, resp: null };
|
|
1469
|
+
}
|
|
1470
|
+
}
|
|
1471
|
+
__name(callOpenRouter, "callOpenRouter");
|
|
1472
|
+
|
|
1473
|
+
// src/services/son_func/shit_or_not_service.ts
|
|
1474
|
+
var chatHistory = [];
|
|
1475
|
+
function decodeHtmlEntities2(value) {
|
|
1476
|
+
return value.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, '"').replace(/'/g, "'");
|
|
1477
|
+
}
|
|
1478
|
+
__name(decodeHtmlEntities2, "decodeHtmlEntities");
|
|
1479
|
+
function extractImageAndText(content) {
|
|
1480
|
+
const imageUrls = [];
|
|
1481
|
+
const imgTagRegex = /<img\b[^>]*>/gi;
|
|
1482
|
+
const stripped = content.replace(imgTagRegex, (tag) => {
|
|
1483
|
+
const srcMatch = tag.match(/src=["']([^"']+)["']/i);
|
|
1484
|
+
if (srcMatch?.[1]) {
|
|
1485
|
+
imageUrls.push(decodeHtmlEntities2(srcMatch[1]));
|
|
1486
|
+
}
|
|
1487
|
+
return " ";
|
|
1488
|
+
});
|
|
1489
|
+
const text = stripped.replace(/\s+/g, " ").trim();
|
|
1490
|
+
return { imageUrls, text };
|
|
1491
|
+
}
|
|
1492
|
+
__name(extractImageAndText, "extractImageAndText");
|
|
1493
|
+
async function checkShitOrNot(session, parttern_msg, config) {
|
|
1494
|
+
chatHistory = [];
|
|
1495
|
+
chatHistory.push({ role: "user", content: [{ type: "text", text: parttern_msg }] });
|
|
1496
|
+
const { err, resp } = await callOpenRouter(config.api_url, config.api_key, config.api_model, chatHistory);
|
|
1497
|
+
if (err != null) {
|
|
1498
|
+
logger.error("[callOpenRouter Error]: " + err);
|
|
1499
|
+
return null;
|
|
1500
|
+
}
|
|
1501
|
+
chatHistory.push({ role: "assistant", content: [{ type: "text", text: resp }] });
|
|
1502
|
+
const quoteContent = session.quote.content;
|
|
1503
|
+
const { imageUrls, text } = extractImageAndText(quoteContent);
|
|
1504
|
+
if (!text && imageUrls.length === 0) {
|
|
1505
|
+
logger.warn("[checkShitOrNot Warn]: 引用消息中未发现文本或图片");
|
|
1506
|
+
return "引用消息中未发现文本或图片";
|
|
1507
|
+
}
|
|
1508
|
+
const targetContent = [
|
|
1509
|
+
...text ? [{ type: "text", text }] : [],
|
|
1510
|
+
...imageUrls.map((url) => ({ type: "image_url", image_url: { url } }))
|
|
1511
|
+
];
|
|
1512
|
+
chatHistory.push({ role: "user", content: targetContent });
|
|
1513
|
+
const secondCall = await callOpenRouter(config.api_url, config.api_key, config.api_model, chatHistory);
|
|
1514
|
+
if (secondCall.err != null) {
|
|
1515
|
+
logger.error("[callOpenRouter Error]: " + secondCall.err);
|
|
1516
|
+
return null;
|
|
1517
|
+
}
|
|
1518
|
+
return secondCall.resp;
|
|
1519
|
+
}
|
|
1520
|
+
__name(checkShitOrNot, "checkShitOrNot");
|
|
1521
|
+
|
|
1522
|
+
// src/services/son_func/shit_or_not_command.ts
|
|
1523
|
+
var local_config = null;
|
|
1524
|
+
var mode_intro = {
|
|
1525
|
+
"esu": "【图文】ohno妈咪饿素啊😨,恶俗慎用!🈲",
|
|
1526
|
+
"nov": "【图文】来段微小说📕",
|
|
1527
|
+
"lit": "【图文】文楠魅力时刻📕👨",
|
|
1528
|
+
"zhi": "【图文】分享你刚编的故事🤓",
|
|
1529
|
+
"boa": "【图文】《答案之书》🔮",
|
|
1530
|
+
"scp": "【图文】控制-收容-保护,献上你的异常👽",
|
|
1531
|
+
"phi": "【图文】我思,故我在🧠",
|
|
1532
|
+
"see": "【图像】让我康康怎么个事👀",
|
|
1533
|
+
"ccb": "【图像】压抑笑传之踩踩背🐘"
|
|
1534
|
+
};
|
|
1535
|
+
function loadYamlConfig(configPath) {
|
|
1536
|
+
if (!configPath) {
|
|
1537
|
+
logger.error("[loadYamlConfig Error]: SON 配置文件路径未配置");
|
|
1538
|
+
return null;
|
|
1539
|
+
}
|
|
1540
|
+
try {
|
|
1541
|
+
const trimmedPath = configPath.trim();
|
|
1542
|
+
const fullPath = import_path3.default.isAbsolute(trimmedPath) ? trimmedPath : import_path3.default.resolve(process.cwd(), trimmedPath);
|
|
1543
|
+
if (!(0, import_fs3.existsSync)(fullPath)) {
|
|
1544
|
+
logger.error(`[loadYamlConfig Error]: SON 配置文件不存在: ${fullPath}`);
|
|
1545
|
+
return null;
|
|
1546
|
+
}
|
|
1547
|
+
const fileContent = (0, import_fs3.readFileSync)(fullPath, "utf-8");
|
|
1548
|
+
const config = yaml.load(fileContent);
|
|
1549
|
+
return config;
|
|
1550
|
+
} catch (error) {
|
|
1551
|
+
logger.error(`[loadYamlConfig Error]: SON 读取配置文件失败: ${configPath}`, error);
|
|
1552
|
+
return null;
|
|
1553
|
+
}
|
|
1554
|
+
}
|
|
1555
|
+
__name(loadYamlConfig, "loadYamlConfig");
|
|
1556
|
+
function registerShitOrNotCommands(ctx, config) {
|
|
1557
|
+
if (config?.config_path) {
|
|
1558
|
+
local_config = loadYamlConfig(config.config_path);
|
|
1559
|
+
if (local_config) {
|
|
1560
|
+
logger.info("[loadYamlConfig Info]: SON 成功加载配置文件");
|
|
1561
|
+
} else {
|
|
1562
|
+
logger.error("[loadYamlConfig Error]: SON 配置文件加载失败,将使用默认配置");
|
|
1563
|
+
}
|
|
1564
|
+
} else {
|
|
1565
|
+
logger.error("[loadYamlConfig Error]: 未配置 SON 配置文件路径");
|
|
1566
|
+
}
|
|
1567
|
+
ctx.command("sonlist <参数>", "查看son判断模式列表").action(() => {
|
|
1568
|
+
return `[所有命令都需要@bot]
|
|
1569
|
+
son判断模式列表:
|
|
1570
|
+
${Object.keys(mode_intro).map((item) => item + ": " + mode_intro[item]).join("\n ")}`;
|
|
1571
|
+
});
|
|
1572
|
+
ctx.command("son <参数>", "判定是否为史").action(async ({ session }, ...args) => {
|
|
1573
|
+
if (!dev_mode) {
|
|
1574
|
+
if (!is_at_bot_quote(session)) return "请提供正确格式,如:1 [引用消息] @bot son [判断模式]";
|
|
1575
|
+
} else {
|
|
1576
|
+
if (!session.quote) return "请提供正确格式,如:2 [引用消息] @bot son [判断模式]";
|
|
1577
|
+
}
|
|
1578
|
+
const parttern = args?.[0];
|
|
1579
|
+
if (!parttern) return "请提供正确格式,如:3 [引用消息] @bot son [判断模式]";
|
|
1580
|
+
if (!local_config) return "未加载配置文件,请查看日志";
|
|
1581
|
+
const parttern_msg = local_config.shit_or_not?.prompts[parttern];
|
|
1582
|
+
if (!parttern_msg) return "未找到判断模式,请查看日志";
|
|
1583
|
+
let exec = await checkShitOrNot(session, parttern_msg, config);
|
|
1584
|
+
return exec;
|
|
1585
|
+
});
|
|
1586
|
+
}
|
|
1587
|
+
__name(registerShitOrNotCommands, "registerShitOrNotCommands");
|
|
1588
|
+
function is_at_bot_quote(session) {
|
|
1589
|
+
if (!session.quote)
|
|
1590
|
+
return false;
|
|
1591
|
+
const { content, userId } = session;
|
|
1592
|
+
const quote = session.quote;
|
|
1593
|
+
const quoteUserId = quote.user.id;
|
|
1594
|
+
const quoteContent = quote.content;
|
|
1595
|
+
const botId = session?.bot?.selfId ?? session?.selfId;
|
|
1596
|
+
if (dev_mode)
|
|
1597
|
+
logger.info(`command: quoteContent: ${quoteContent}, quoteUserId: ${quoteUserId},content: ${content} userId: ${userId}`);
|
|
1598
|
+
const elements = quote.elements || [];
|
|
1599
|
+
for (const elem of elements) {
|
|
1600
|
+
if (elem.type === "at") {
|
|
1601
|
+
const atId = elem.attrs.id;
|
|
1602
|
+
if (String(atId) === String(botId)) {
|
|
1603
|
+
return true;
|
|
1604
|
+
}
|
|
1605
|
+
}
|
|
1606
|
+
}
|
|
1607
|
+
return false;
|
|
1608
|
+
}
|
|
1609
|
+
__name(is_at_bot_quote, "is_at_bot_quote");
|
|
1610
|
+
|
|
1611
|
+
// src/services/kuro_func/kuro_service.ts
|
|
1612
|
+
var import_axios2 = __toESM(require("axios"));
|
|
1401
1613
|
var import_qs = __toESM(require("qs"));
|
|
1402
1614
|
|
|
1403
1615
|
// src/models/kuro_user.ts
|
|
@@ -1506,7 +1718,7 @@ __name(createUpdateUser, "createUpdateUser");
|
|
|
1506
1718
|
|
|
1507
1719
|
// src/services/kuro_func/kuro_service.ts
|
|
1508
1720
|
var userTokenMap = /* @__PURE__ */ new Map();
|
|
1509
|
-
var
|
|
1721
|
+
var CONSTANTS = {
|
|
1510
1722
|
BASE_URL: "https://api.kurobbs.com",
|
|
1511
1723
|
LOGIN_URL: "/user/sdkLogin",
|
|
1512
1724
|
GAME_DATA_URL: "/gamer/role/list",
|
|
@@ -1530,11 +1742,11 @@ var CONSTANTS2 = {
|
|
|
1530
1742
|
"source": "ios"
|
|
1531
1743
|
}
|
|
1532
1744
|
};
|
|
1533
|
-
var wavesApi =
|
|
1745
|
+
var wavesApi = import_axios2.default.create();
|
|
1534
1746
|
wavesApi.interceptors.request.use(
|
|
1535
1747
|
async (config) => {
|
|
1536
1748
|
if (config.url.startsWith("/")) {
|
|
1537
|
-
config.url =
|
|
1749
|
+
config.url = CONSTANTS.BASE_URL + config.url;
|
|
1538
1750
|
}
|
|
1539
1751
|
return config;
|
|
1540
1752
|
},
|
|
@@ -1588,7 +1800,7 @@ async function getToken(session, mobile, code) {
|
|
|
1588
1800
|
code
|
|
1589
1801
|
});
|
|
1590
1802
|
try {
|
|
1591
|
-
const user_response = await wavesApi.post(
|
|
1803
|
+
const user_response = await wavesApi.post(CONSTANTS.LOGIN_URL, data, { headers: { ...CONSTANTS.REQUEST_HEADERS_BASE, devCode } });
|
|
1592
1804
|
if (user_response.data.code != 200) {
|
|
1593
1805
|
logger.error(`验证码登录失败: ${user_response.data.msg}`);
|
|
1594
1806
|
return { status: false, msg: user_response.data.msg };
|
|
@@ -1628,7 +1840,7 @@ async function getGameData(token) {
|
|
|
1628
1840
|
let data = import_qs.default.stringify({
|
|
1629
1841
|
"gameId": 3
|
|
1630
1842
|
});
|
|
1631
|
-
const response = await wavesApi.post(
|
|
1843
|
+
const response = await wavesApi.post(CONSTANTS.GAME_DATA_URL, data, { headers: { ...CONSTANTS.REQUEST_HEADERS_BASE, "token": token } });
|
|
1632
1844
|
if (response.data.code === 200) {
|
|
1633
1845
|
return { status: true, data: response.data.data[0] };
|
|
1634
1846
|
} else {
|
|
@@ -1647,7 +1859,7 @@ async function isAvailable(serverId, roleId, token) {
|
|
|
1647
1859
|
"roleId": roleId
|
|
1648
1860
|
});
|
|
1649
1861
|
try {
|
|
1650
|
-
const response = await wavesApi.post(
|
|
1862
|
+
const response = await wavesApi.post(CONSTANTS.TOKEN_REFRESH_URL, data, { headers: { ...CONSTANTS.REQUEST_HEADERS_BASE, "token": token } });
|
|
1651
1863
|
if (response.data.code === 220) {
|
|
1652
1864
|
logger.info(`${roleId} 获取可用性成功,账号已过期`);
|
|
1653
1865
|
return { status: false, msg: "账号已过期" };
|
|
@@ -1668,7 +1880,7 @@ async function refreshData(bat, serverId, roleId, token) {
|
|
|
1668
1880
|
"roleId": roleId
|
|
1669
1881
|
});
|
|
1670
1882
|
try {
|
|
1671
|
-
const response = await wavesApi.post(
|
|
1883
|
+
const response = await wavesApi.post(CONSTANTS.REFRESH_URL, data, { headers: { ...CONSTANTS.REQUEST_HEADERS_BASE, "token": token, "b-at": bat } });
|
|
1672
1884
|
if (response.data.code === 10902 || response.data.code === 200) {
|
|
1673
1885
|
return { status: true, data: response.data.data };
|
|
1674
1886
|
} else {
|
|
@@ -1695,7 +1907,7 @@ async function signIn(qq_uid) {
|
|
|
1695
1907
|
"reqMonth": ((/* @__PURE__ */ new Date()).getMonth() + 1).toString().padStart(2, "0")
|
|
1696
1908
|
});
|
|
1697
1909
|
try {
|
|
1698
|
-
const response = await wavesApi.post(
|
|
1910
|
+
const response = await wavesApi.post(CONSTANTS.SIGNIN_URL, data, { headers: { ...CONSTANTS.REQUEST_HEADERS_BASE, "token": userInfo.token, devcode: "", "b-at": userInfo.bat } });
|
|
1699
1911
|
if (response.data.code === 200) {
|
|
1700
1912
|
if (response.data.data === null) {
|
|
1701
1913
|
logger.info(`[signIn Info]: ${qq_uid} 签到失败,返回空数据`);
|
|
@@ -1724,7 +1936,7 @@ async function getRoleData(qq_uid) {
|
|
|
1724
1936
|
"roleId": userInfo.role_id
|
|
1725
1937
|
});
|
|
1726
1938
|
try {
|
|
1727
|
-
const response = await wavesApi.post(
|
|
1939
|
+
const response = await wavesApi.post(CONSTANTS.ROLE_DATA_URL, data, { headers: { ...CONSTANTS.REQUEST_HEADERS_BASE, "token": userInfo.token, "b-at": userInfo.bat } });
|
|
1728
1940
|
if (response.data.code === 10902 || response.data.code === 200) {
|
|
1729
1941
|
response.data.data = JSON.parse(response.data.data);
|
|
1730
1942
|
if (response.data.data === null || !response.data.data.showToGuest) {
|
|
@@ -1807,15 +2019,16 @@ __name(registerKuroCommands, "registerKuroCommands");
|
|
|
1807
2019
|
// src/index.ts
|
|
1808
2020
|
var name = "cocoyyy-console";
|
|
1809
2021
|
var dev_mode;
|
|
1810
|
-
var
|
|
2022
|
+
var Config2 = import_koishi10.Schema.object({
|
|
1811
2023
|
function_config: FunctionConfigSchema.description("功能开关配置"),
|
|
1812
2024
|
redis_config: RedisConfigSchema.description("Redis配置"),
|
|
1813
2025
|
mysql_config: MysqlConfigSchema.description("MySQL 数据库配置"),
|
|
1814
2026
|
tag_config: SaveConfigSchema.description("tag图片保存配置"),
|
|
1815
2027
|
repeat_config: RepeatConfigSchema.description("复读配置"),
|
|
1816
|
-
|
|
2028
|
+
son_config: ShitOrNotConfigSchema.description("SON配置"),
|
|
2029
|
+
test: import_koishi10.Schema.string().description("测试")
|
|
1817
2030
|
});
|
|
1818
|
-
var logger = new
|
|
2031
|
+
var logger = new import_koishi10.Logger(name);
|
|
1819
2032
|
var savePath = null;
|
|
1820
2033
|
async function apply(ctx, config) {
|
|
1821
2034
|
ctx = ctx.guild();
|
|
@@ -1835,6 +2048,8 @@ async function apply(ctx, config) {
|
|
|
1835
2048
|
registerTagCommands(ctx, connected, savePath);
|
|
1836
2049
|
if (config.function_config.repeat_flag)
|
|
1837
2050
|
registerRepeatMiddleware(ctx, config?.repeat_config);
|
|
2051
|
+
if (config.function_config.son_flag)
|
|
2052
|
+
registerShitOrNotCommands(ctx, config?.son_config);
|
|
1838
2053
|
if (config.function_config.rbq_flag)
|
|
1839
2054
|
registerRbqCommands(ctx, connected);
|
|
1840
2055
|
if (config.function_config)
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { OpenRouterMessage } from '../../utils/ai_axios';
|
|
2
1
|
import { Session } from 'koishi';
|
|
2
|
+
import { ShitOrNotConfig } from '../../utils/config';
|
|
3
3
|
declare function ocrImage(buffer: Buffer): Promise<string>;
|
|
4
|
-
declare function checkShitOrNot(session: Session, parttern_msg: string): Promise<
|
|
4
|
+
declare function checkShitOrNot(session: Session, parttern_msg: string, config: ShitOrNotConfig): Promise<string>;
|
|
5
5
|
export { checkShitOrNot, ocrImage };
|
package/lib/utils/ai_axios.d.ts
CHANGED
|
@@ -1,17 +1,15 @@
|
|
|
1
1
|
export interface OpenRouterMessage {
|
|
2
2
|
role: 'system' | 'user' | 'assistant';
|
|
3
|
-
content:
|
|
3
|
+
content: Array<{
|
|
4
|
+
type: 'text' | 'image_url';
|
|
5
|
+
text?: string;
|
|
6
|
+
image_url?: {
|
|
7
|
+
url: string;
|
|
8
|
+
};
|
|
9
|
+
}>;
|
|
4
10
|
}
|
|
5
11
|
export interface OpenRouterResult {
|
|
6
12
|
err: string | null;
|
|
7
13
|
resp: string | null;
|
|
8
14
|
}
|
|
9
|
-
/**
|
|
10
|
-
* 调用 OpenRouter API 进行对话
|
|
11
|
-
* @param apiKey OpenRouter API Key
|
|
12
|
-
* @param messages 消息数组,包含系统消息和用户消息
|
|
13
|
-
* @param model 模型名称,默认为 gpt-4o-mini
|
|
14
|
-
* @returns 返回包含错误和响应的对象 { err: string | null, resp: string | null }
|
|
15
|
-
* err 不为 null 时表示出错,resp 不为 null 时表示成功
|
|
16
|
-
*/
|
|
17
15
|
export declare function callOpenRouter(api_url: string, api_key: string, api_model: string, messages: OpenRouterMessage[]): Promise<OpenRouterResult>;
|
package/lib/utils/config.d.ts
CHANGED
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "koishi-plugin-cocoyyy-console",
|
|
3
3
|
"description": "自用koishi插件,功能包含复读,记录黑历史,*人等",
|
|
4
|
-
"version": "1.0.16-beta.
|
|
4
|
+
"version": "1.0.16-beta.6",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"typings": "lib/index.d.ts",
|
|
7
7
|
"contributors": [
|
|
@@ -26,6 +26,7 @@
|
|
|
26
26
|
"qs": "^6.14.0",
|
|
27
27
|
"sequelize": "^6.37.3",
|
|
28
28
|
"ioredis": "^5.8.2",
|
|
29
|
-
"tesseract.js": "^5.1.0"
|
|
29
|
+
"tesseract.js": "^5.1.0",
|
|
30
|
+
"js-yaml": "^4.1.1"
|
|
30
31
|
}
|
|
31
|
-
}
|
|
32
|
+
}
|