koishi-plugin-cocoyyy-console 1.0.16-beta.3 → 1.0.16-beta.5
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 +241 -42
- 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,30 +1386,21 @@ __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;
|
|
1377
1400
|
const quoteUserId = session.quote.user.id;
|
|
1378
|
-
logger.error(`quoteContent: ${quoteContent}, quoteUserId: ${quoteUserId},content: ${content} userId: ${userId}`);
|
|
1401
|
+
logger.error(`command: quoteContent: ${quoteContent}, quoteUserId: ${quoteUserId},content: ${content} userId: ${userId}`);
|
|
1379
1402
|
} else {
|
|
1380
|
-
logger.error(`content: ${content} userId: ${userId}`);
|
|
1403
|
+
logger.error(`command: content: ${content} userId: ${userId}`);
|
|
1381
1404
|
}
|
|
1382
1405
|
});
|
|
1383
1406
|
ctx.middleware((session, next) => {
|
|
@@ -1396,8 +1419,181 @@ 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
|
+
function loadYamlConfig(configPath) {
|
|
1525
|
+
if (!configPath) {
|
|
1526
|
+
logger.error("[loadYamlConfig Error]: SON 配置文件路径未配置");
|
|
1527
|
+
return null;
|
|
1528
|
+
}
|
|
1529
|
+
try {
|
|
1530
|
+
const trimmedPath = configPath.trim();
|
|
1531
|
+
const fullPath = import_path3.default.isAbsolute(trimmedPath) ? trimmedPath : import_path3.default.resolve(process.cwd(), trimmedPath);
|
|
1532
|
+
if (!(0, import_fs3.existsSync)(fullPath)) {
|
|
1533
|
+
logger.error(`[loadYamlConfig Error]: SON 配置文件不存在: ${fullPath}`);
|
|
1534
|
+
return null;
|
|
1535
|
+
}
|
|
1536
|
+
const fileContent = (0, import_fs3.readFileSync)(fullPath, "utf-8");
|
|
1537
|
+
const config = yaml.load(fileContent);
|
|
1538
|
+
return config;
|
|
1539
|
+
} catch (error) {
|
|
1540
|
+
logger.error(`[loadYamlConfig Error]: SON 读取配置文件失败: ${configPath}`, error);
|
|
1541
|
+
return null;
|
|
1542
|
+
}
|
|
1543
|
+
}
|
|
1544
|
+
__name(loadYamlConfig, "loadYamlConfig");
|
|
1545
|
+
function registerShitOrNotCommands(ctx, config) {
|
|
1546
|
+
if (config?.config_path) {
|
|
1547
|
+
local_config = loadYamlConfig(config.config_path);
|
|
1548
|
+
if (local_config) {
|
|
1549
|
+
logger.info("[loadYamlConfig Info]: SON 成功加载配置文件");
|
|
1550
|
+
} else {
|
|
1551
|
+
logger.error("[loadYamlConfig Error]: SON 配置文件加载失败,将使用默认配置");
|
|
1552
|
+
}
|
|
1553
|
+
} else {
|
|
1554
|
+
logger.error("[loadYamlConfig Error]: 未配置 SON 配置文件路径");
|
|
1555
|
+
}
|
|
1556
|
+
ctx.command("son <参数>", "判定是否为史").action(async ({ session }, ...args) => {
|
|
1557
|
+
if (!dev_mode) {
|
|
1558
|
+
if (!is_at_bot_quote(session)) return "请提供正确格式,如:[引用消息] @bot son [判断模式]";
|
|
1559
|
+
} else {
|
|
1560
|
+
if (!session.quote) return "请提供正确格式,如:[引用消息] @bot son [判断模式]";
|
|
1561
|
+
}
|
|
1562
|
+
const parttern = args?.[0];
|
|
1563
|
+
if (!parttern) return "请提供正确格式,如:[引用消息] @bot son [判断模式]";
|
|
1564
|
+
if (!local_config) return "未加载配置文件,请查看日志";
|
|
1565
|
+
const parttern_msg = local_config.shit_or_not?.prompts[parttern];
|
|
1566
|
+
if (!parttern_msg) return "未找到判断模式,请查看日志";
|
|
1567
|
+
let exec = await checkShitOrNot(session, parttern_msg, config);
|
|
1568
|
+
return exec;
|
|
1569
|
+
});
|
|
1570
|
+
}
|
|
1571
|
+
__name(registerShitOrNotCommands, "registerShitOrNotCommands");
|
|
1572
|
+
function is_at_bot_quote(session) {
|
|
1573
|
+
if (!session.quote)
|
|
1574
|
+
return false;
|
|
1575
|
+
const { content, userId } = session;
|
|
1576
|
+
const quote = session.quote;
|
|
1577
|
+
const quoteUserId = quote.user.id;
|
|
1578
|
+
const quoteContent = quote.content;
|
|
1579
|
+
const botId = session?.bot?.selfId ?? session?.selfId;
|
|
1580
|
+
if (dev_mode)
|
|
1581
|
+
logger.info(`command: quoteContent: ${quoteContent}, quoteUserId: ${quoteUserId},content: ${content} userId: ${userId}`);
|
|
1582
|
+
const elements = quote.elements || [];
|
|
1583
|
+
for (const elem of elements) {
|
|
1584
|
+
if (elem.type === "at") {
|
|
1585
|
+
const atId = elem.attrs.id;
|
|
1586
|
+
if (String(atId) === String(botId)) {
|
|
1587
|
+
return true;
|
|
1588
|
+
}
|
|
1589
|
+
}
|
|
1590
|
+
}
|
|
1591
|
+
return false;
|
|
1592
|
+
}
|
|
1593
|
+
__name(is_at_bot_quote, "is_at_bot_quote");
|
|
1594
|
+
|
|
1595
|
+
// src/services/kuro_func/kuro_service.ts
|
|
1596
|
+
var import_axios2 = __toESM(require("axios"));
|
|
1401
1597
|
var import_qs = __toESM(require("qs"));
|
|
1402
1598
|
|
|
1403
1599
|
// src/models/kuro_user.ts
|
|
@@ -1506,7 +1702,7 @@ __name(createUpdateUser, "createUpdateUser");
|
|
|
1506
1702
|
|
|
1507
1703
|
// src/services/kuro_func/kuro_service.ts
|
|
1508
1704
|
var userTokenMap = /* @__PURE__ */ new Map();
|
|
1509
|
-
var
|
|
1705
|
+
var CONSTANTS = {
|
|
1510
1706
|
BASE_URL: "https://api.kurobbs.com",
|
|
1511
1707
|
LOGIN_URL: "/user/sdkLogin",
|
|
1512
1708
|
GAME_DATA_URL: "/gamer/role/list",
|
|
@@ -1530,11 +1726,11 @@ var CONSTANTS2 = {
|
|
|
1530
1726
|
"source": "ios"
|
|
1531
1727
|
}
|
|
1532
1728
|
};
|
|
1533
|
-
var wavesApi =
|
|
1729
|
+
var wavesApi = import_axios2.default.create();
|
|
1534
1730
|
wavesApi.interceptors.request.use(
|
|
1535
1731
|
async (config) => {
|
|
1536
1732
|
if (config.url.startsWith("/")) {
|
|
1537
|
-
config.url =
|
|
1733
|
+
config.url = CONSTANTS.BASE_URL + config.url;
|
|
1538
1734
|
}
|
|
1539
1735
|
return config;
|
|
1540
1736
|
},
|
|
@@ -1588,7 +1784,7 @@ async function getToken(session, mobile, code) {
|
|
|
1588
1784
|
code
|
|
1589
1785
|
});
|
|
1590
1786
|
try {
|
|
1591
|
-
const user_response = await wavesApi.post(
|
|
1787
|
+
const user_response = await wavesApi.post(CONSTANTS.LOGIN_URL, data, { headers: { ...CONSTANTS.REQUEST_HEADERS_BASE, devCode } });
|
|
1592
1788
|
if (user_response.data.code != 200) {
|
|
1593
1789
|
logger.error(`验证码登录失败: ${user_response.data.msg}`);
|
|
1594
1790
|
return { status: false, msg: user_response.data.msg };
|
|
@@ -1628,7 +1824,7 @@ async function getGameData(token) {
|
|
|
1628
1824
|
let data = import_qs.default.stringify({
|
|
1629
1825
|
"gameId": 3
|
|
1630
1826
|
});
|
|
1631
|
-
const response = await wavesApi.post(
|
|
1827
|
+
const response = await wavesApi.post(CONSTANTS.GAME_DATA_URL, data, { headers: { ...CONSTANTS.REQUEST_HEADERS_BASE, "token": token } });
|
|
1632
1828
|
if (response.data.code === 200) {
|
|
1633
1829
|
return { status: true, data: response.data.data[0] };
|
|
1634
1830
|
} else {
|
|
@@ -1647,7 +1843,7 @@ async function isAvailable(serverId, roleId, token) {
|
|
|
1647
1843
|
"roleId": roleId
|
|
1648
1844
|
});
|
|
1649
1845
|
try {
|
|
1650
|
-
const response = await wavesApi.post(
|
|
1846
|
+
const response = await wavesApi.post(CONSTANTS.TOKEN_REFRESH_URL, data, { headers: { ...CONSTANTS.REQUEST_HEADERS_BASE, "token": token } });
|
|
1651
1847
|
if (response.data.code === 220) {
|
|
1652
1848
|
logger.info(`${roleId} 获取可用性成功,账号已过期`);
|
|
1653
1849
|
return { status: false, msg: "账号已过期" };
|
|
@@ -1668,7 +1864,7 @@ async function refreshData(bat, serverId, roleId, token) {
|
|
|
1668
1864
|
"roleId": roleId
|
|
1669
1865
|
});
|
|
1670
1866
|
try {
|
|
1671
|
-
const response = await wavesApi.post(
|
|
1867
|
+
const response = await wavesApi.post(CONSTANTS.REFRESH_URL, data, { headers: { ...CONSTANTS.REQUEST_HEADERS_BASE, "token": token, "b-at": bat } });
|
|
1672
1868
|
if (response.data.code === 10902 || response.data.code === 200) {
|
|
1673
1869
|
return { status: true, data: response.data.data };
|
|
1674
1870
|
} else {
|
|
@@ -1695,7 +1891,7 @@ async function signIn(qq_uid) {
|
|
|
1695
1891
|
"reqMonth": ((/* @__PURE__ */ new Date()).getMonth() + 1).toString().padStart(2, "0")
|
|
1696
1892
|
});
|
|
1697
1893
|
try {
|
|
1698
|
-
const response = await wavesApi.post(
|
|
1894
|
+
const response = await wavesApi.post(CONSTANTS.SIGNIN_URL, data, { headers: { ...CONSTANTS.REQUEST_HEADERS_BASE, "token": userInfo.token, devcode: "", "b-at": userInfo.bat } });
|
|
1699
1895
|
if (response.data.code === 200) {
|
|
1700
1896
|
if (response.data.data === null) {
|
|
1701
1897
|
logger.info(`[signIn Info]: ${qq_uid} 签到失败,返回空数据`);
|
|
@@ -1724,7 +1920,7 @@ async function getRoleData(qq_uid) {
|
|
|
1724
1920
|
"roleId": userInfo.role_id
|
|
1725
1921
|
});
|
|
1726
1922
|
try {
|
|
1727
|
-
const response = await wavesApi.post(
|
|
1923
|
+
const response = await wavesApi.post(CONSTANTS.ROLE_DATA_URL, data, { headers: { ...CONSTANTS.REQUEST_HEADERS_BASE, "token": userInfo.token, "b-at": userInfo.bat } });
|
|
1728
1924
|
if (response.data.code === 10902 || response.data.code === 200) {
|
|
1729
1925
|
response.data.data = JSON.parse(response.data.data);
|
|
1730
1926
|
if (response.data.data === null || !response.data.data.showToGuest) {
|
|
@@ -1807,15 +2003,16 @@ __name(registerKuroCommands, "registerKuroCommands");
|
|
|
1807
2003
|
// src/index.ts
|
|
1808
2004
|
var name = "cocoyyy-console";
|
|
1809
2005
|
var dev_mode;
|
|
1810
|
-
var
|
|
2006
|
+
var Config2 = import_koishi10.Schema.object({
|
|
1811
2007
|
function_config: FunctionConfigSchema.description("功能开关配置"),
|
|
1812
2008
|
redis_config: RedisConfigSchema.description("Redis配置"),
|
|
1813
2009
|
mysql_config: MysqlConfigSchema.description("MySQL 数据库配置"),
|
|
1814
2010
|
tag_config: SaveConfigSchema.description("tag图片保存配置"),
|
|
1815
2011
|
repeat_config: RepeatConfigSchema.description("复读配置"),
|
|
1816
|
-
|
|
2012
|
+
son_config: ShitOrNotConfigSchema.description("SON配置"),
|
|
2013
|
+
test: import_koishi10.Schema.string().description("测试")
|
|
1817
2014
|
});
|
|
1818
|
-
var logger = new
|
|
2015
|
+
var logger = new import_koishi10.Logger(name);
|
|
1819
2016
|
var savePath = null;
|
|
1820
2017
|
async function apply(ctx, config) {
|
|
1821
2018
|
ctx = ctx.guild();
|
|
@@ -1835,6 +2032,8 @@ async function apply(ctx, config) {
|
|
|
1835
2032
|
registerTagCommands(ctx, connected, savePath);
|
|
1836
2033
|
if (config.function_config.repeat_flag)
|
|
1837
2034
|
registerRepeatMiddleware(ctx, config?.repeat_config);
|
|
2035
|
+
if (config.function_config.son_flag)
|
|
2036
|
+
registerShitOrNotCommands(ctx, config?.son_config);
|
|
1838
2037
|
if (config.function_config.rbq_flag)
|
|
1839
2038
|
registerRbqCommands(ctx, connected);
|
|
1840
2039
|
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.5",
|
|
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
|
+
}
|