koishi-plugin-cocoyyy-console 1.0.16-beta.1 → 1.0.16-beta.10
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 +2 -0
- package/lib/index.js +278 -28
- package/lib/services/son_func/shit_or_not_command.d.ts +4 -0
- package/lib/services/son_func/shit_or_not_service.d.ts +5 -0
- package/lib/services/test_command.d.ts +3 -1
- package/lib/utils/ai_axios.d.ts +15 -0
- package/lib/utils/config.d.ts +1 -0
- package/lib/utils/configs/function_config.d.ts +1 -0
- package/lib/utils/configs/son_config.d.ts +9 -0
- package/package.json +5 -3
package/lib/index.d.ts
CHANGED
|
@@ -8,6 +8,8 @@ export interface Config {
|
|
|
8
8
|
mysql_config?: my_config.MysqlConfig;
|
|
9
9
|
tag_config?: my_config.SaveConfig;
|
|
10
10
|
repeat_config?: my_config.RepeatConfig;
|
|
11
|
+
son_config?: my_config.ShitOrNotConfig;
|
|
12
|
+
test?: string;
|
|
11
13
|
}
|
|
12
14
|
export declare const Config: Schema<Config>;
|
|
13
15
|
export declare let logger: Logger;
|
package/lib/index.js
CHANGED
|
@@ -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,6 +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
|
+
son_flag: import_koishi.Schema.boolean().default(true).description("鉴别史消息功能是否启用"),
|
|
50
51
|
kuro_flag: import_koishi.Schema.boolean().default(true).description("鸣潮功能是否启用")
|
|
51
52
|
});
|
|
52
53
|
|
|
@@ -86,6 +87,15 @@ var RedisConfigSchema = import_koishi5.Schema.object({
|
|
|
86
87
|
redis_url: import_koishi5.Schema.string().default("127.0.0.1:6379").description("Redis连接字符串")
|
|
87
88
|
});
|
|
88
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
|
+
|
|
89
99
|
// src/infra/mysql_init.ts
|
|
90
100
|
var import_sequelize = require("sequelize");
|
|
91
101
|
var sequelize = null;
|
|
@@ -313,6 +323,10 @@ function getMenuList(command = null, functionConfig) {
|
|
|
313
323
|
if (!functionConfig.rbq_flag)
|
|
314
324
|
return "*人功能已关闭";
|
|
315
325
|
return getRbqFuncMenu(command);
|
|
326
|
+
case "son":
|
|
327
|
+
if (!functionConfig.son_flag)
|
|
328
|
+
return "son功能已关闭";
|
|
329
|
+
return getSonFuncMenu(command);
|
|
316
330
|
case "kuro":
|
|
317
331
|
if (!functionConfig.kuro_flag)
|
|
318
332
|
return "库洛相关功能已关闭";
|
|
@@ -321,7 +335,7 @@ function getMenuList(command = null, functionConfig) {
|
|
|
321
335
|
return `[所有命令都需要@bot]
|
|
322
336
|
当前可用功能列表:
|
|
323
337
|
${menuList.map((item) => item.name + ": " + item.description).join("\n ")}
|
|
324
|
-
输入"help 功能名"查看特定功能的指令和使用示例。`;
|
|
338
|
+
输入"help [功能名]"查看特定功能的指令和使用示例。`;
|
|
325
339
|
}
|
|
326
340
|
}
|
|
327
341
|
__name(getMenuList, "getMenuList");
|
|
@@ -403,6 +417,25 @@ function getRbqFuncMenu(command = null) {
|
|
|
403
417
|
输入对应指令使用*人功能,如果遇到问题请联系开发人员。`;
|
|
404
418
|
}
|
|
405
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");
|
|
406
439
|
var kuroFuncMenuList = [
|
|
407
440
|
{
|
|
408
441
|
name: "login",
|
|
@@ -435,7 +468,7 @@ function registerMenuCommands(ctx, connected, functionConfig) {
|
|
|
435
468
|
__name(registerMenuCommands, "registerMenuCommands");
|
|
436
469
|
|
|
437
470
|
// src/services/tag_func/tag_commands.ts
|
|
438
|
-
var
|
|
471
|
+
var import_koishi8 = require("koishi");
|
|
439
472
|
|
|
440
473
|
// src/services/tag_func/tag_service.ts
|
|
441
474
|
var import_sequelize4 = require("sequelize");
|
|
@@ -443,7 +476,7 @@ var import_fs2 = require("fs");
|
|
|
443
476
|
var import_path2 = require("path");
|
|
444
477
|
|
|
445
478
|
// src/services/tag_func/img_service.ts
|
|
446
|
-
var
|
|
479
|
+
var import_koishi7 = require("koishi");
|
|
447
480
|
var import_path = require("path");
|
|
448
481
|
var import_fs = require("fs");
|
|
449
482
|
async function loadImageFromUrl(ctx, url) {
|
|
@@ -518,7 +551,7 @@ async function randomImgByTag(tag_name, guild_id) {
|
|
|
518
551
|
if (ImgList.length <= 0) {
|
|
519
552
|
throw new Error("Don't have image!");
|
|
520
553
|
}
|
|
521
|
-
const random = new
|
|
554
|
+
const random = new import_koishi7.Random(() => Math.random());
|
|
522
555
|
let result = ImgList[random.int(0, ImgList.length)];
|
|
523
556
|
const filePath = result.get("img_url");
|
|
524
557
|
return filePath;
|
|
@@ -762,8 +795,8 @@ function registerTagCommands(ctx, connected, savePath2) {
|
|
|
762
795
|
let exec = await randomImgByTag(tag, session.guildId);
|
|
763
796
|
if (!exec)
|
|
764
797
|
return `获取图片失败`;
|
|
765
|
-
let
|
|
766
|
-
return
|
|
798
|
+
let path2 = (0, import_url.pathToFileURL)(exec).href;
|
|
799
|
+
return import_koishi8.h.image(path2);
|
|
767
800
|
});
|
|
768
801
|
ctx.command("bind <参数>", "标签绑定别名").action(async ({ session }, ...args) => {
|
|
769
802
|
if (!dev_mode) {
|
|
@@ -906,7 +939,7 @@ function registerRepeatMiddleware(ctx, config) {
|
|
|
906
939
|
__name(registerRepeatMiddleware, "registerRepeatMiddleware");
|
|
907
940
|
|
|
908
941
|
// src/services/rbq_func/rbq_command.ts
|
|
909
|
-
var
|
|
942
|
+
var import_koishi9 = require("koishi");
|
|
910
943
|
|
|
911
944
|
// src/models/rbq_persons.ts
|
|
912
945
|
var import_sequelize5 = require("sequelize");
|
|
@@ -1231,7 +1264,7 @@ function registerRbqCommands(ctx, connected) {
|
|
|
1231
1264
|
if (!list || list.length === 0) {
|
|
1232
1265
|
return "当前群聊还没有设置任何rbq";
|
|
1233
1266
|
}
|
|
1234
|
-
return "当前群聊rbq列表:\n" + list.map((item) => (0,
|
|
1267
|
+
return "当前群聊rbq列表:\n" + list.map((item) => (0, import_koishi9.h)("at", { id: item })).join(",");
|
|
1235
1268
|
});
|
|
1236
1269
|
ctx.command("rbqadd <参数>", "添加rbq").action(async ({ session }, ...args) => {
|
|
1237
1270
|
if (!dev_mode) {
|
|
@@ -1249,7 +1282,7 @@ function registerRbqCommands(ctx, connected) {
|
|
|
1249
1282
|
exec = await create_person(session.guildId, uid);
|
|
1250
1283
|
if (!exec.result)
|
|
1251
1284
|
return `添加rbq失败: ${exec.error}`;
|
|
1252
|
-
return "已添加rbq:" + (0,
|
|
1285
|
+
return "已添加rbq:" + (0, import_koishi9.h)("at", { id: uid });
|
|
1253
1286
|
});
|
|
1254
1287
|
ctx.command("rbqinstead <参数>", "替换rbq").action(async ({ session }, ...args) => {
|
|
1255
1288
|
if (!dev_mode) {
|
|
@@ -1274,12 +1307,12 @@ function registerRbqCommands(ctx, connected) {
|
|
|
1274
1307
|
exec = await instead_person(session.guildId, source_uid, new_target);
|
|
1275
1308
|
if (!exec.result)
|
|
1276
1309
|
return `替换rbq失败:${exec.error}`;
|
|
1277
|
-
return "倒反天罡!进去吧你,已替换rbq:\n" + (0,
|
|
1310
|
+
return "倒反天罡!进去吧你,已替换rbq:\n" + (0, import_koishi9.h)("at", { id: source_uid }) + " -> " + (0, import_koishi9.h)("at", { id: new_target });
|
|
1278
1311
|
}
|
|
1279
1312
|
exec = await instead_person(session.guildId, source_uid, target_uid);
|
|
1280
1313
|
if (!exec.result)
|
|
1281
1314
|
return `替换rbq失败:${exec.error}`;
|
|
1282
|
-
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 }));
|
|
1283
1316
|
});
|
|
1284
1317
|
ctx.command("rbqadd_txt <参数>", "添加自定义文本").action(async ({ session }, ...args) => {
|
|
1285
1318
|
if (!dev_mode) {
|
|
@@ -1306,10 +1339,10 @@ function registerRbqCommands(ctx, connected) {
|
|
|
1306
1339
|
const contents = await get_content_list(session.guildId, target_uid);
|
|
1307
1340
|
let content2 = "*死你";
|
|
1308
1341
|
if (contents && contents.length > 0) {
|
|
1309
|
-
const random = new
|
|
1342
|
+
const random = new import_koishi9.Random(() => Math.random());
|
|
1310
1343
|
content2 = contents[random.int(0, contents.length)];
|
|
1311
1344
|
}
|
|
1312
|
-
return (0,
|
|
1345
|
+
return (0, import_koishi9.h)("at", { id: target_uid }) + "还想自己加文本?!\n" + content2;
|
|
1313
1346
|
} catch (error) {
|
|
1314
1347
|
logger.error("[rbq rbqadd_txt] Error:", error);
|
|
1315
1348
|
return "不能给自己设置文本,请输入其他qq号";
|
|
@@ -1339,10 +1372,10 @@ function registerRbqCommands(ctx, connected) {
|
|
|
1339
1372
|
const contents = await get_content_list(guildId, matchedUid);
|
|
1340
1373
|
let content = "*死你";
|
|
1341
1374
|
if (contents && contents.length > 0) {
|
|
1342
|
-
const random = new
|
|
1375
|
+
const random = new import_koishi9.Random(() => Math.random());
|
|
1343
1376
|
content = contents[random.int(0, contents.length)];
|
|
1344
1377
|
}
|
|
1345
|
-
return (0,
|
|
1378
|
+
return (0, import_koishi9.h)("at", { id: matchedUid }) + " " + content;
|
|
1346
1379
|
} catch (error) {
|
|
1347
1380
|
logger.error("[rbq middleware] Error:", error);
|
|
1348
1381
|
return next();
|
|
@@ -1352,19 +1385,232 @@ function registerRbqCommands(ctx, connected) {
|
|
|
1352
1385
|
__name(registerRbqCommands, "registerRbqCommands");
|
|
1353
1386
|
|
|
1354
1387
|
// src/services/test_command.ts
|
|
1355
|
-
|
|
1356
|
-
|
|
1357
|
-
|
|
1358
|
-
|
|
1359
|
-
|
|
1360
|
-
|
|
1388
|
+
var import_tesseract = require("tesseract.js");
|
|
1389
|
+
function registerTestCommands(ctx, config) {
|
|
1390
|
+
ctx.command("test1 <prompt:text>", "调用 OpenRouter 模型进行测试").action(async ({ session }, prompt) => {
|
|
1391
|
+
const apiKey = config?.test || process.env.OPENROUTER_API_KEY;
|
|
1392
|
+
if (!apiKey) return "未配置 OpenRouter API Key(config.test 或环境变量 OPENROUTER_API_KEY)";
|
|
1393
|
+
const content = prompt?.trim();
|
|
1394
|
+
if (!content) return "请输入要测试的内容";
|
|
1395
|
+
});
|
|
1396
|
+
ctx.command("test <path>", "测试用").action(async ({ session }, path2) => {
|
|
1397
|
+
const { content, uid, userId } = session;
|
|
1398
|
+
if (session.quote) {
|
|
1399
|
+
const quoteContent = session.quote.content;
|
|
1400
|
+
const quoteUserId = session.quote.user.id;
|
|
1401
|
+
logger.error(`command: quoteContent: ${quoteContent}, quoteUserId: ${quoteUserId},content: ${content} userId: ${userId}`);
|
|
1402
|
+
} else {
|
|
1403
|
+
logger.error(`command: content: ${content} userId: ${userId}`);
|
|
1404
|
+
}
|
|
1405
|
+
});
|
|
1406
|
+
ctx.middleware((session, next) => {
|
|
1407
|
+
const { content, uid, userId } = session;
|
|
1408
|
+
const cid = session.cid;
|
|
1409
|
+
if (session.guildId != "829263238") return next();
|
|
1410
|
+
if (ctx.bots[uid]) return next();
|
|
1411
|
+
if (session.quote) {
|
|
1412
|
+
const quoteContent = session.quote.content;
|
|
1413
|
+
const quoteUserId = session.quote.user.id;
|
|
1414
|
+
logger.error(`quoteContent: ${quoteContent}, quoteUserId: ${quoteUserId},content: ${content} userId: ${userId}`);
|
|
1415
|
+
} else {
|
|
1416
|
+
logger.error(`content: ${content} userId: ${userId}`);
|
|
1361
1417
|
}
|
|
1362
1418
|
});
|
|
1363
1419
|
}
|
|
1364
1420
|
__name(registerTestCommands, "registerTestCommands");
|
|
1365
1421
|
|
|
1366
|
-
// 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
|
|
1367
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
|
+
model: 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 请求失败", {
|
|
1467
|
+
status,
|
|
1468
|
+
detail,
|
|
1469
|
+
url: err.config?.url,
|
|
1470
|
+
payload: err.config?.data
|
|
1471
|
+
});
|
|
1472
|
+
const errorMessage = `test error${status ? `(${status})` : ""}: ${detail}`;
|
|
1473
|
+
return { err: errorMessage, resp: null };
|
|
1474
|
+
}
|
|
1475
|
+
}
|
|
1476
|
+
__name(callOpenRouter, "callOpenRouter");
|
|
1477
|
+
|
|
1478
|
+
// src/services/son_func/shit_or_not_service.ts
|
|
1479
|
+
var chatHistory = [];
|
|
1480
|
+
function decodeHtmlEntities2(value) {
|
|
1481
|
+
return value.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, '"').replace(/'/g, "'");
|
|
1482
|
+
}
|
|
1483
|
+
__name(decodeHtmlEntities2, "decodeHtmlEntities");
|
|
1484
|
+
function extractImageAndText(content) {
|
|
1485
|
+
const imageUrls = [];
|
|
1486
|
+
const imgTagRegex = /<img\b[^>]*>/gi;
|
|
1487
|
+
const stripped = content.replace(imgTagRegex, (tag) => {
|
|
1488
|
+
const srcMatch = tag.match(/src=["']([^"']+)["']/i);
|
|
1489
|
+
if (srcMatch?.[1]) {
|
|
1490
|
+
imageUrls.push(decodeHtmlEntities2(srcMatch[1]));
|
|
1491
|
+
}
|
|
1492
|
+
return " ";
|
|
1493
|
+
});
|
|
1494
|
+
const withoutTags = stripped.replace(/<[^>]+>/g, " ");
|
|
1495
|
+
const text = withoutTags.replace(/\s+/g, " ").trim();
|
|
1496
|
+
return { imageUrls, text };
|
|
1497
|
+
}
|
|
1498
|
+
__name(extractImageAndText, "extractImageAndText");
|
|
1499
|
+
async function checkShitOrNot(session, parttern_msg, config) {
|
|
1500
|
+
chatHistory = [];
|
|
1501
|
+
chatHistory.push({ role: "user", content: [{ type: "text", text: parttern_msg }] });
|
|
1502
|
+
const { err, resp } = await callOpenRouter(config.api_url, config.api_key, config.api_model, chatHistory);
|
|
1503
|
+
if (err != null) {
|
|
1504
|
+
logger.error("[callOpenRouter Error 1]: " + err);
|
|
1505
|
+
return null;
|
|
1506
|
+
}
|
|
1507
|
+
chatHistory.push({ role: "assistant", content: [{ type: "text", text: resp }] });
|
|
1508
|
+
const quoteContent = session.quote.content;
|
|
1509
|
+
const { imageUrls, text } = extractImageAndText(quoteContent);
|
|
1510
|
+
if (!text && imageUrls.length === 0) {
|
|
1511
|
+
logger.warn("[checkShitOrNot Warn]: 引用消息中未发现文本或图片");
|
|
1512
|
+
return "引用消息中未发现文本或图片";
|
|
1513
|
+
}
|
|
1514
|
+
const targetContent = [
|
|
1515
|
+
...text ? [{ type: "text", text }] : [],
|
|
1516
|
+
...imageUrls.map((url) => ({ type: "image_url", image_url: { url } }))
|
|
1517
|
+
];
|
|
1518
|
+
chatHistory.push({ role: "user", content: targetContent });
|
|
1519
|
+
const { err: err2, resp: resp2 } = await callOpenRouter(config.api_url, config.api_key, config.api_model, chatHistory);
|
|
1520
|
+
if (err2 != null) {
|
|
1521
|
+
logger.error("[callOpenRouter Error 2]: " + err2);
|
|
1522
|
+
return null;
|
|
1523
|
+
}
|
|
1524
|
+
return resp2;
|
|
1525
|
+
}
|
|
1526
|
+
__name(checkShitOrNot, "checkShitOrNot");
|
|
1527
|
+
|
|
1528
|
+
// src/services/son_func/shit_or_not_command.ts
|
|
1529
|
+
var local_config = null;
|
|
1530
|
+
function loadYamlConfig(configPath) {
|
|
1531
|
+
if (!configPath) {
|
|
1532
|
+
logger.error("[loadYamlConfig Error]: SON 配置文件路径未配置");
|
|
1533
|
+
return null;
|
|
1534
|
+
}
|
|
1535
|
+
try {
|
|
1536
|
+
const trimmedPath = configPath.trim();
|
|
1537
|
+
const fullPath = import_path3.default.isAbsolute(trimmedPath) ? trimmedPath : import_path3.default.resolve(process.cwd(), trimmedPath);
|
|
1538
|
+
if (!(0, import_fs3.existsSync)(fullPath)) {
|
|
1539
|
+
logger.error(`[loadYamlConfig Error]: SON 配置文件不存在: ${fullPath}`);
|
|
1540
|
+
return null;
|
|
1541
|
+
}
|
|
1542
|
+
const fileContent = (0, import_fs3.readFileSync)(fullPath, "utf-8");
|
|
1543
|
+
const config = yaml.load(fileContent);
|
|
1544
|
+
return config;
|
|
1545
|
+
} catch (error) {
|
|
1546
|
+
logger.error(`[loadYamlConfig Error]: SON 读取配置文件失败: ${configPath}`, error);
|
|
1547
|
+
return null;
|
|
1548
|
+
}
|
|
1549
|
+
}
|
|
1550
|
+
__name(loadYamlConfig, "loadYamlConfig");
|
|
1551
|
+
function registerShitOrNotCommands(ctx, config) {
|
|
1552
|
+
if (config?.config_path) {
|
|
1553
|
+
local_config = loadYamlConfig(config.config_path);
|
|
1554
|
+
if (local_config) {
|
|
1555
|
+
logger.info("[loadYamlConfig Info]: SON 成功加载配置文件");
|
|
1556
|
+
} else {
|
|
1557
|
+
logger.error("[loadYamlConfig Error]: SON 配置文件加载失败,将使用默认配置");
|
|
1558
|
+
}
|
|
1559
|
+
} else {
|
|
1560
|
+
logger.error("[loadYamlConfig Error]: 未配置 SON 配置文件路径");
|
|
1561
|
+
}
|
|
1562
|
+
ctx.command("sonlist <参数>", "查看son判断模式列表").action(async ({ session }) => {
|
|
1563
|
+
if (!dev_mode) {
|
|
1564
|
+
if (!is_at_bot(session)) return;
|
|
1565
|
+
}
|
|
1566
|
+
if (!local_config) return "未加载配置文件,请查看日志";
|
|
1567
|
+
const mode_intro = local_config?.menu;
|
|
1568
|
+
if (!mode_intro) return "未找到判断模式列表,请查看日志";
|
|
1569
|
+
return `[所有命令都需要@bot]
|
|
1570
|
+
son判断模式列表:
|
|
1571
|
+
${Object.keys(mode_intro).map((item) => item + ": " + mode_intro[item]).join("\n ")}`;
|
|
1572
|
+
});
|
|
1573
|
+
ctx.command("son <参数>", "判定是否为史").action(async ({ session }, ...args) => {
|
|
1574
|
+
if (!dev_mode) {
|
|
1575
|
+
if (!is_at_bot_quote(session)) return "请提供正确格式,如: [引用消息] @bot son [判断模式]";
|
|
1576
|
+
} else {
|
|
1577
|
+
if (!session.quote) return "请引用消息后使用功能";
|
|
1578
|
+
}
|
|
1579
|
+
const parttern = args?.[0];
|
|
1580
|
+
if (!parttern) return "请提供正确判断模式,如: [引用消息] @bot son [判断模式]";
|
|
1581
|
+
if (!local_config) return "未加载配置文件,请查看日志";
|
|
1582
|
+
const parttern_msg = local_config.shit_or_not?.prompts[parttern];
|
|
1583
|
+
if (!parttern_msg) return "未找到判断模式,请查看日志";
|
|
1584
|
+
let exec = await checkShitOrNot(session, parttern_msg, config);
|
|
1585
|
+
return exec;
|
|
1586
|
+
});
|
|
1587
|
+
}
|
|
1588
|
+
__name(registerShitOrNotCommands, "registerShitOrNotCommands");
|
|
1589
|
+
function is_at_bot_quote(session) {
|
|
1590
|
+
if (!session.quote)
|
|
1591
|
+
return false;
|
|
1592
|
+
const { content, userId } = session;
|
|
1593
|
+
const quote = session.quote;
|
|
1594
|
+
const quoteUserId = quote.user.id;
|
|
1595
|
+
const quoteContent = quote.content;
|
|
1596
|
+
const botId = session?.bot?.selfId ?? session?.selfId;
|
|
1597
|
+
logger.info(`command: quoteContent: ${quoteContent}, quoteUserId: ${quoteUserId},content: ${content} userId: ${userId}`);
|
|
1598
|
+
const elements = quote.elements || [];
|
|
1599
|
+
logger.info("quote elements: ", { elements });
|
|
1600
|
+
for (const elem of elements) {
|
|
1601
|
+
if (elem.type === "at") {
|
|
1602
|
+
const atId = elem.attrs.id;
|
|
1603
|
+
if (String(atId) === String(botId)) {
|
|
1604
|
+
return true;
|
|
1605
|
+
}
|
|
1606
|
+
}
|
|
1607
|
+
}
|
|
1608
|
+
return false;
|
|
1609
|
+
}
|
|
1610
|
+
__name(is_at_bot_quote, "is_at_bot_quote");
|
|
1611
|
+
|
|
1612
|
+
// src/services/kuro_func/kuro_service.ts
|
|
1613
|
+
var import_axios2 = __toESM(require("axios"));
|
|
1368
1614
|
var import_qs = __toESM(require("qs"));
|
|
1369
1615
|
|
|
1370
1616
|
// src/models/kuro_user.ts
|
|
@@ -1497,7 +1743,7 @@ var CONSTANTS = {
|
|
|
1497
1743
|
"source": "ios"
|
|
1498
1744
|
}
|
|
1499
1745
|
};
|
|
1500
|
-
var wavesApi =
|
|
1746
|
+
var wavesApi = import_axios2.default.create();
|
|
1501
1747
|
wavesApi.interceptors.request.use(
|
|
1502
1748
|
async (config) => {
|
|
1503
1749
|
if (config.url.startsWith("/")) {
|
|
@@ -1774,14 +2020,16 @@ __name(registerKuroCommands, "registerKuroCommands");
|
|
|
1774
2020
|
// src/index.ts
|
|
1775
2021
|
var name = "cocoyyy-console";
|
|
1776
2022
|
var dev_mode;
|
|
1777
|
-
var Config =
|
|
2023
|
+
var Config = import_koishi10.Schema.object({
|
|
1778
2024
|
function_config: FunctionConfigSchema.description("功能开关配置"),
|
|
1779
2025
|
redis_config: RedisConfigSchema.description("Redis配置"),
|
|
1780
2026
|
mysql_config: MysqlConfigSchema.description("MySQL 数据库配置"),
|
|
1781
2027
|
tag_config: SaveConfigSchema.description("tag图片保存配置"),
|
|
1782
|
-
repeat_config: RepeatConfigSchema.description("复读配置")
|
|
2028
|
+
repeat_config: RepeatConfigSchema.description("复读配置"),
|
|
2029
|
+
son_config: ShitOrNotConfigSchema.description("SON配置"),
|
|
2030
|
+
test: import_koishi10.Schema.string().description("测试")
|
|
1783
2031
|
});
|
|
1784
|
-
var logger = new
|
|
2032
|
+
var logger = new import_koishi10.Logger(name);
|
|
1785
2033
|
var savePath = null;
|
|
1786
2034
|
async function apply(ctx, config) {
|
|
1787
2035
|
ctx = ctx.guild();
|
|
@@ -1801,12 +2049,14 @@ async function apply(ctx, config) {
|
|
|
1801
2049
|
registerTagCommands(ctx, connected, savePath);
|
|
1802
2050
|
if (config.function_config.repeat_flag)
|
|
1803
2051
|
registerRepeatMiddleware(ctx, config?.repeat_config);
|
|
2052
|
+
if (config.function_config.son_flag)
|
|
2053
|
+
registerShitOrNotCommands(ctx, config?.son_config);
|
|
1804
2054
|
if (config.function_config.rbq_flag)
|
|
1805
2055
|
registerRbqCommands(ctx, connected);
|
|
1806
2056
|
if (config.function_config)
|
|
1807
2057
|
registerKuroCommands(ctx, connected);
|
|
1808
2058
|
if (dev_mode)
|
|
1809
|
-
registerTestCommands(ctx);
|
|
2059
|
+
registerTestCommands(ctx, config);
|
|
1810
2060
|
}
|
|
1811
2061
|
__name(apply, "apply");
|
|
1812
2062
|
// Annotate the CommonJS export names for ESM import in node:
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { Session } from 'koishi';
|
|
2
|
+
import { ShitOrNotConfig } from '../../utils/config';
|
|
3
|
+
declare function ocrImage(buffer: Buffer): Promise<string>;
|
|
4
|
+
declare function checkShitOrNot(session: Session, parttern_msg: string, config: ShitOrNotConfig): Promise<string>;
|
|
5
|
+
export { checkShitOrNot, ocrImage };
|
|
@@ -1,3 +1,5 @@
|
|
|
1
1
|
import { Context } from 'koishi';
|
|
2
|
-
|
|
2
|
+
import { Config } from '..';
|
|
3
|
+
declare function registerTestCommands(ctx: Context, config: Config): void;
|
|
4
|
+
export declare function ocrImage(buffer: Buffer): Promise<string>;
|
|
3
5
|
export { registerTestCommands };
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export interface OpenRouterMessage {
|
|
2
|
+
role: 'system' | 'user' | 'assistant';
|
|
3
|
+
content: Array<{
|
|
4
|
+
type: 'text' | 'image_url';
|
|
5
|
+
text?: string;
|
|
6
|
+
image_url?: {
|
|
7
|
+
url: string;
|
|
8
|
+
};
|
|
9
|
+
}>;
|
|
10
|
+
}
|
|
11
|
+
export interface OpenRouterResult {
|
|
12
|
+
err: string | null;
|
|
13
|
+
resp: string | null;
|
|
14
|
+
}
|
|
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
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { Schema } from 'koishi';
|
|
2
|
+
interface ShitOrNotConfig {
|
|
3
|
+
api_url?: string;
|
|
4
|
+
api_model?: string;
|
|
5
|
+
api_key?: string;
|
|
6
|
+
config_path?: string;
|
|
7
|
+
}
|
|
8
|
+
declare const ShitOrNotConfigSchema: Schema<ShitOrNotConfig>;
|
|
9
|
+
export { ShitOrNotConfig, ShitOrNotConfigSchema, };
|
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.10",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"typings": "lib/index.d.ts",
|
|
7
7
|
"contributors": [
|
|
@@ -25,6 +25,8 @@
|
|
|
25
25
|
"mysql2": "^3.11.0",
|
|
26
26
|
"qs": "^6.14.0",
|
|
27
27
|
"sequelize": "^6.37.3",
|
|
28
|
-
"ioredis": "^5.8.2"
|
|
28
|
+
"ioredis": "^5.8.2",
|
|
29
|
+
"tesseract.js": "^5.1.0",
|
|
30
|
+
"js-yaml": "^4.1.1"
|
|
29
31
|
}
|
|
30
|
-
}
|
|
32
|
+
}
|