koishi-plugin-cocoyyy-console 1.0.17 → 1.1.0-beta.1
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 -1
- package/lib/index.js +225 -62
- package/lib/services/game_func/game_command.d.ts +6 -0
- package/lib/services/game_func/game_service.d.ts +6 -0
- package/lib/services/son_func/shit_or_not_command.d.ts +2 -1
- package/lib/services/son_func/shit_or_not_service.d.ts +2 -2
- package/lib/utils/common.d.ts +2 -1
- package/lib/utils/config.d.ts +2 -0
- package/lib/utils/configs/ai_config.d.ts +8 -0
- package/lib/utils/configs/function_config.d.ts +1 -0
- package/lib/utils/configs/game_config.d.ts +6 -0
- package/lib/utils/configs/son_config.d.ts +0 -3
- package/package.json +1 -1
package/lib/index.d.ts
CHANGED
|
@@ -4,11 +4,12 @@ export declare const name = "cocoyyy-console";
|
|
|
4
4
|
export declare let dev_mode: boolean;
|
|
5
5
|
export interface Config {
|
|
6
6
|
function_config?: my_config.FunctionConfig;
|
|
7
|
-
|
|
7
|
+
ai_config?: my_config.AiAPIConfig;
|
|
8
8
|
mysql_config?: my_config.MysqlConfig;
|
|
9
9
|
tag_config?: my_config.SaveConfig;
|
|
10
10
|
repeat_config?: my_config.RepeatConfig;
|
|
11
11
|
son_config?: my_config.ShitOrNotConfig;
|
|
12
|
+
game_config?: my_config.GameConfig;
|
|
12
13
|
test?: string;
|
|
13
14
|
}
|
|
14
15
|
export declare const Config: Schema<Config>;
|
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_koishi12 = require("koishi");
|
|
42
42
|
|
|
43
43
|
// src/utils/configs/function_config.ts
|
|
44
44
|
var import_koishi = require("koishi");
|
|
@@ -48,6 +48,7 @@ var FunctionConfigSchema = import_koishi.Schema.object({
|
|
|
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
|
+
game_flag: import_koishi.Schema.boolean().default(true).description("游戏功能是否启用"),
|
|
51
52
|
kuro_flag: import_koishi.Schema.boolean().default(true).description("鸣潮功能是否启用")
|
|
52
53
|
});
|
|
53
54
|
|
|
@@ -90,12 +91,23 @@ var RedisConfigSchema = import_koishi5.Schema.object({
|
|
|
90
91
|
// src/utils/configs/son_config.ts
|
|
91
92
|
var import_koishi6 = require("koishi");
|
|
92
93
|
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
94
|
config_path: import_koishi6.Schema.string().default("").description("配置文件路径")
|
|
97
95
|
});
|
|
98
96
|
|
|
97
|
+
// src/utils/configs/game_config.ts
|
|
98
|
+
var import_koishi7 = require("koishi");
|
|
99
|
+
var GameConfigSchema = import_koishi7.Schema.object({
|
|
100
|
+
config_path: import_koishi7.Schema.string().default("").description("配置文件路径")
|
|
101
|
+
});
|
|
102
|
+
|
|
103
|
+
// src/utils/configs/ai_config.ts
|
|
104
|
+
var import_koishi8 = require("koishi");
|
|
105
|
+
var AiAPIConfigSchema = import_koishi8.Schema.object({
|
|
106
|
+
api_url: import_koishi8.Schema.string().default("").description("Api接口Url"),
|
|
107
|
+
api_model: import_koishi8.Schema.string().default("").description("AI模型"),
|
|
108
|
+
api_key: import_koishi8.Schema.string().default("").description("API Key")
|
|
109
|
+
});
|
|
110
|
+
|
|
99
111
|
// src/infra/mysql_init.ts
|
|
100
112
|
var import_sequelize = require("sequelize");
|
|
101
113
|
var sequelize = null;
|
|
@@ -259,6 +271,9 @@ function getImgsModel() {
|
|
|
259
271
|
__name(getImgsModel, "getImgsModel");
|
|
260
272
|
|
|
261
273
|
// src/utils/common.ts
|
|
274
|
+
var import_fs = require("fs");
|
|
275
|
+
var yaml = __toESM(require("js-yaml"));
|
|
276
|
+
var import_path = __toESM(require("path"));
|
|
262
277
|
function is_at_bot(session) {
|
|
263
278
|
const elements = Array.isArray(session?.elements) ? session.elements : [];
|
|
264
279
|
const atElement = elements.find((element) => element?.type === "at");
|
|
@@ -282,6 +297,27 @@ function decodeHtmlEntities(text) {
|
|
|
282
297
|
});
|
|
283
298
|
}
|
|
284
299
|
__name(decodeHtmlEntities, "decodeHtmlEntities");
|
|
300
|
+
function loadYamlConfig(configPath) {
|
|
301
|
+
if (!configPath) {
|
|
302
|
+
logger.error("[loadYamlConfig Error]: SON 配置文件路径未配置");
|
|
303
|
+
return null;
|
|
304
|
+
}
|
|
305
|
+
try {
|
|
306
|
+
const trimmedPath = configPath.trim();
|
|
307
|
+
const fullPath = import_path.default.isAbsolute(trimmedPath) ? trimmedPath : import_path.default.resolve(process.cwd(), trimmedPath);
|
|
308
|
+
if (!(0, import_fs.existsSync)(fullPath)) {
|
|
309
|
+
logger.error(`[loadYamlConfig Error]: SON 配置文件不存在: ${fullPath}`);
|
|
310
|
+
return null;
|
|
311
|
+
}
|
|
312
|
+
const fileContent = (0, import_fs.readFileSync)(fullPath, "utf-8");
|
|
313
|
+
const config = yaml.load(fileContent);
|
|
314
|
+
return config;
|
|
315
|
+
} catch (error) {
|
|
316
|
+
logger.error(`[loadYamlConfig Error]: SON 读取配置文件失败: ${configPath}`, error);
|
|
317
|
+
return null;
|
|
318
|
+
}
|
|
319
|
+
}
|
|
320
|
+
__name(loadYamlConfig, "loadYamlConfig");
|
|
285
321
|
|
|
286
322
|
// src/services/menu_service.ts
|
|
287
323
|
var menuList = [
|
|
@@ -305,6 +341,11 @@ var menuList = [
|
|
|
305
341
|
description: "shit_or_not功能,用于鉴别史消息",
|
|
306
342
|
command: "无"
|
|
307
343
|
},
|
|
344
|
+
{
|
|
345
|
+
name: "game",
|
|
346
|
+
description: "游戏功能,用于游玩游戏",
|
|
347
|
+
command: "无"
|
|
348
|
+
},
|
|
308
349
|
{
|
|
309
350
|
name: "kuro",
|
|
310
351
|
description: "库洛相关功能,用于鸣潮相关功能",
|
|
@@ -332,6 +373,10 @@ function getMenuList(command = null, functionConfig) {
|
|
|
332
373
|
if (!functionConfig.son_flag)
|
|
333
374
|
return "son功能已关闭";
|
|
334
375
|
return getSonFuncMenu(command);
|
|
376
|
+
case "game":
|
|
377
|
+
if (!functionConfig.game_flag)
|
|
378
|
+
return "游戏功能已关闭";
|
|
379
|
+
return getGameFuncMenu(command);
|
|
335
380
|
case "kuro":
|
|
336
381
|
if (!functionConfig.kuro_flag)
|
|
337
382
|
return "库洛相关功能已关闭";
|
|
@@ -441,6 +486,30 @@ son功能菜单:
|
|
|
441
486
|
输入对应指令使用son功能,如果遇到问题请联系开发人员。`;
|
|
442
487
|
}
|
|
443
488
|
__name(getSonFuncMenu, "getSonFuncMenu");
|
|
489
|
+
var gameFuncMenuList = [
|
|
490
|
+
{
|
|
491
|
+
name: "gamelist",
|
|
492
|
+
description: "查看游戏列表",
|
|
493
|
+
command: "gamelist"
|
|
494
|
+
},
|
|
495
|
+
{
|
|
496
|
+
name: "startgame",
|
|
497
|
+
description: "开始游戏",
|
|
498
|
+
command: "startgame [游戏]"
|
|
499
|
+
},
|
|
500
|
+
{
|
|
501
|
+
name: "endgame",
|
|
502
|
+
description: "结束游戏",
|
|
503
|
+
command: "endgame"
|
|
504
|
+
}
|
|
505
|
+
];
|
|
506
|
+
function getGameFuncMenu(command = null) {
|
|
507
|
+
return `[所有命令都需要@bot]
|
|
508
|
+
游戏功能菜单:
|
|
509
|
+
${gameFuncMenuList.map((item) => item.command + ": " + item.description).join("\n ")}
|
|
510
|
+
输入对应指令使用游戏功能,如果遇到问题请联系开发人员。`;
|
|
511
|
+
}
|
|
512
|
+
__name(getGameFuncMenu, "getGameFuncMenu");
|
|
444
513
|
var kuroFuncMenuList = [
|
|
445
514
|
{
|
|
446
515
|
name: "login",
|
|
@@ -473,17 +542,17 @@ function registerMenuCommands(ctx, connected, functionConfig) {
|
|
|
473
542
|
__name(registerMenuCommands, "registerMenuCommands");
|
|
474
543
|
|
|
475
544
|
// src/services/tag_func/tag_commands.ts
|
|
476
|
-
var
|
|
545
|
+
var import_koishi10 = require("koishi");
|
|
477
546
|
|
|
478
547
|
// src/services/tag_func/tag_service.ts
|
|
479
548
|
var import_sequelize4 = require("sequelize");
|
|
480
|
-
var
|
|
481
|
-
var
|
|
549
|
+
var import_fs3 = require("fs");
|
|
550
|
+
var import_path3 = require("path");
|
|
482
551
|
|
|
483
552
|
// src/services/tag_func/img_service.ts
|
|
484
|
-
var
|
|
485
|
-
var
|
|
486
|
-
var
|
|
553
|
+
var import_koishi9 = require("koishi");
|
|
554
|
+
var import_path2 = require("path");
|
|
555
|
+
var import_fs2 = require("fs");
|
|
487
556
|
async function loadImageFromUrl(ctx, url) {
|
|
488
557
|
try {
|
|
489
558
|
const responseArrayBuffer = await ctx.http.get(url, {
|
|
@@ -512,7 +581,7 @@ async function saveImg(ctx, tag_name, guild_id, imgurl, savePath2) {
|
|
|
512
581
|
if (savePath2 == null) {
|
|
513
582
|
throw new Error("saving path config wrong!");
|
|
514
583
|
}
|
|
515
|
-
let dir = (0,
|
|
584
|
+
let dir = (0, import_path2.join)(savePath2, String(tag.get("id")));
|
|
516
585
|
const now = new Date(Date.now() + 8 * 60 * 60 * 1e3);
|
|
517
586
|
const srcMatch = imgurl.match(/src="([^"]+)"/);
|
|
518
587
|
if (!srcMatch) throw new Error("invalid img tag, no src found!");
|
|
@@ -526,8 +595,8 @@ async function saveImg(ctx, tag_name, guild_id, imgurl, savePath2) {
|
|
|
526
595
|
const fileNameMatch = imgurl.match(/file="([^"]+)"/);
|
|
527
596
|
if (!fileNameMatch) throw new Error("invalid img tag, no file name found!");
|
|
528
597
|
const fileName = fileNameMatch[1];
|
|
529
|
-
const filePath = (0,
|
|
530
|
-
await
|
|
598
|
+
const filePath = (0, import_path2.join)(dir, fileName);
|
|
599
|
+
await import_fs2.promises.writeFile(filePath, imageBuffer);
|
|
531
600
|
const saveImg2 = await Img.create({ tag_id: tag.get("id"), img_url: filePath, createtime: now });
|
|
532
601
|
logger.info("[saveImg Info]: save image to '" + tag_name + "' success");
|
|
533
602
|
return { result: true, error: null };
|
|
@@ -556,7 +625,7 @@ async function randomImgByTag(tag_name, guild_id) {
|
|
|
556
625
|
if (ImgList.length <= 0) {
|
|
557
626
|
throw new Error("Don't have image!");
|
|
558
627
|
}
|
|
559
|
-
const random = new
|
|
628
|
+
const random = new import_koishi9.Random(() => Math.random());
|
|
560
629
|
let result = ImgList[random.int(0, ImgList.length)];
|
|
561
630
|
const filePath = result.get("img_url");
|
|
562
631
|
return filePath;
|
|
@@ -665,8 +734,8 @@ async function createorUpdateTag(tag_name, guild_id, savePath2) {
|
|
|
665
734
|
}
|
|
666
735
|
const now = new Date(Date.now() + 8 * 60 * 60 * 1e3);
|
|
667
736
|
const tag = await Tag.create({ tags: tag_name, alias: null, guild_id, createtime: now });
|
|
668
|
-
const dir = (0,
|
|
669
|
-
(0,
|
|
737
|
+
const dir = (0, import_path3.join)(savePath2, String(tag.id));
|
|
738
|
+
(0, import_fs3.mkdirSync)(dir, { recursive: true });
|
|
670
739
|
return { result: true, error: null };
|
|
671
740
|
} catch (e) {
|
|
672
741
|
logger.error("[createorUpdateTag Error]: " + e?.message || String(e));
|
|
@@ -801,7 +870,7 @@ function registerTagCommands(ctx, connected, savePath2) {
|
|
|
801
870
|
if (!exec)
|
|
802
871
|
return `获取图片失败`;
|
|
803
872
|
let path2 = (0, import_url.pathToFileURL)(exec).href;
|
|
804
|
-
return
|
|
873
|
+
return import_koishi10.h.image(path2);
|
|
805
874
|
});
|
|
806
875
|
ctx.command("bind <参数>", "标签绑定别名").action(async ({ session }, ...args) => {
|
|
807
876
|
if (!dev_mode) {
|
|
@@ -944,7 +1013,7 @@ function registerRepeatMiddleware(ctx, config) {
|
|
|
944
1013
|
__name(registerRepeatMiddleware, "registerRepeatMiddleware");
|
|
945
1014
|
|
|
946
1015
|
// src/services/rbq_func/rbq_command.ts
|
|
947
|
-
var
|
|
1016
|
+
var import_koishi11 = require("koishi");
|
|
948
1017
|
|
|
949
1018
|
// src/models/rbq_persons.ts
|
|
950
1019
|
var import_sequelize5 = require("sequelize");
|
|
@@ -1269,7 +1338,7 @@ function registerRbqCommands(ctx, connected) {
|
|
|
1269
1338
|
if (!list || list.length === 0) {
|
|
1270
1339
|
return "当前群聊还没有设置任何rbq";
|
|
1271
1340
|
}
|
|
1272
|
-
return "当前群聊rbq列表:\n" + list.map((item) => (0,
|
|
1341
|
+
return "当前群聊rbq列表:\n" + list.map((item) => (0, import_koishi11.h)("at", { id: item })).join(",");
|
|
1273
1342
|
});
|
|
1274
1343
|
ctx.command("rbqadd <参数>", "添加rbq").action(async ({ session }, ...args) => {
|
|
1275
1344
|
if (!dev_mode) {
|
|
@@ -1287,7 +1356,7 @@ function registerRbqCommands(ctx, connected) {
|
|
|
1287
1356
|
exec = await create_person(session.guildId, uid);
|
|
1288
1357
|
if (!exec.result)
|
|
1289
1358
|
return `添加rbq失败: ${exec.error}`;
|
|
1290
|
-
return "已添加rbq:" + (0,
|
|
1359
|
+
return "已添加rbq:" + (0, import_koishi11.h)("at", { id: uid });
|
|
1291
1360
|
});
|
|
1292
1361
|
ctx.command("rbqinstead <参数>", "替换rbq").action(async ({ session }, ...args) => {
|
|
1293
1362
|
if (!dev_mode) {
|
|
@@ -1312,12 +1381,12 @@ function registerRbqCommands(ctx, connected) {
|
|
|
1312
1381
|
exec = await instead_person(session.guildId, source_uid, new_target);
|
|
1313
1382
|
if (!exec.result)
|
|
1314
1383
|
return `替换rbq失败:${exec.error}`;
|
|
1315
|
-
return "倒反天罡!进去吧你,已替换rbq:\n" + (0,
|
|
1384
|
+
return "倒反天罡!进去吧你,已替换rbq:\n" + (0, import_koishi11.h)("at", { id: source_uid }) + " -> " + (0, import_koishi11.h)("at", { id: new_target });
|
|
1316
1385
|
}
|
|
1317
1386
|
exec = await instead_person(session.guildId, source_uid, target_uid);
|
|
1318
1387
|
if (!exec.result)
|
|
1319
1388
|
return `替换rbq失败:${exec.error}`;
|
|
1320
|
-
return (0,
|
|
1389
|
+
return (0, import_koishi11.h)("p", "已替换rbq:", (0, import_koishi11.h)("at", { id: source_uid }), " -> ", (0, import_koishi11.h)("at", { id: target_uid }));
|
|
1321
1390
|
});
|
|
1322
1391
|
ctx.command("rbqadd_txt <参数>", "添加自定义文本").action(async ({ session }, ...args) => {
|
|
1323
1392
|
if (!dev_mode) {
|
|
@@ -1344,10 +1413,10 @@ function registerRbqCommands(ctx, connected) {
|
|
|
1344
1413
|
const contents = await get_content_list(session.guildId, target_uid);
|
|
1345
1414
|
let content2 = "*死你";
|
|
1346
1415
|
if (contents && contents.length > 0) {
|
|
1347
|
-
const random = new
|
|
1416
|
+
const random = new import_koishi11.Random(() => Math.random());
|
|
1348
1417
|
content2 = contents[random.int(0, contents.length)];
|
|
1349
1418
|
}
|
|
1350
|
-
return (0,
|
|
1419
|
+
return (0, import_koishi11.h)("at", { id: target_uid }) + "还想自己加文本?!\n" + content2;
|
|
1351
1420
|
} catch (error) {
|
|
1352
1421
|
logger.error("[rbq rbqadd_txt] Error:", error);
|
|
1353
1422
|
return "不能给自己设置文本,请输入其他qq号";
|
|
@@ -1377,10 +1446,10 @@ function registerRbqCommands(ctx, connected) {
|
|
|
1377
1446
|
const contents = await get_content_list(guildId, matchedUid);
|
|
1378
1447
|
let content = "*死你";
|
|
1379
1448
|
if (contents && contents.length > 0) {
|
|
1380
|
-
const random = new
|
|
1449
|
+
const random = new import_koishi11.Random(() => Math.random());
|
|
1381
1450
|
content = contents[random.int(0, contents.length)];
|
|
1382
1451
|
}
|
|
1383
|
-
return (0,
|
|
1452
|
+
return (0, import_koishi11.h)("at", { id: matchedUid }) + " " + content;
|
|
1384
1453
|
} catch (error) {
|
|
1385
1454
|
logger.error("[rbq middleware] Error:", error);
|
|
1386
1455
|
return next();
|
|
@@ -1424,11 +1493,6 @@ function registerTestCommands(ctx, config) {
|
|
|
1424
1493
|
}
|
|
1425
1494
|
__name(registerTestCommands, "registerTestCommands");
|
|
1426
1495
|
|
|
1427
|
-
// src/services/son_func/shit_or_not_command.ts
|
|
1428
|
-
var import_fs3 = require("fs");
|
|
1429
|
-
var yaml = __toESM(require("js-yaml"));
|
|
1430
|
-
var import_path3 = __toESM(require("path"));
|
|
1431
|
-
|
|
1432
1496
|
// src/services/son_func/shit_or_not_service.ts
|
|
1433
1497
|
var import_tesseract2 = require("tesseract.js");
|
|
1434
1498
|
|
|
@@ -1503,7 +1567,7 @@ function extractImageAndText(content) {
|
|
|
1503
1567
|
__name(extractImageAndText, "extractImageAndText");
|
|
1504
1568
|
async function checkShitOrNot(session, parttern_msg, config) {
|
|
1505
1569
|
chatHistory = [];
|
|
1506
|
-
chatHistory.push({ role: "
|
|
1570
|
+
chatHistory.push({ role: "system", content: [{ type: "text", text: parttern_msg }] });
|
|
1507
1571
|
const { err, resp } = await callOpenRouter(config.api_url, config.api_key, config.api_model, chatHistory);
|
|
1508
1572
|
if (err != null) {
|
|
1509
1573
|
logger.error("[callOpenRouter Error 1]: " + err);
|
|
@@ -1533,9 +1597,9 @@ __name(checkShitOrNot, "checkShitOrNot");
|
|
|
1533
1597
|
// src/services/son_func/shit_or_not_command.ts
|
|
1534
1598
|
var local_config = null;
|
|
1535
1599
|
var think_flag = false;
|
|
1536
|
-
function registerShitOrNotCommands(ctx,
|
|
1537
|
-
if (
|
|
1538
|
-
local_config = loadYamlConfig(
|
|
1600
|
+
function registerShitOrNotCommands(ctx, ai_config, son_config) {
|
|
1601
|
+
if (son_config?.config_path) {
|
|
1602
|
+
local_config = loadYamlConfig(son_config.config_path);
|
|
1539
1603
|
if (local_config) {
|
|
1540
1604
|
logger.info("[loadYamlConfig Info]: SON 成功加载配置文件");
|
|
1541
1605
|
} else {
|
|
@@ -1570,7 +1634,7 @@ son判断模式列表:
|
|
|
1570
1634
|
await session.send("已收到,正在品鉴中...");
|
|
1571
1635
|
think_flag = true;
|
|
1572
1636
|
try {
|
|
1573
|
-
let exec = await checkShitOrNot(session, parttern_msg,
|
|
1637
|
+
let exec = await checkShitOrNot(session, parttern_msg, ai_config);
|
|
1574
1638
|
if (exec == null) return "品鉴失败,请查看日志";
|
|
1575
1639
|
return exec;
|
|
1576
1640
|
} finally {
|
|
@@ -1579,27 +1643,6 @@ son判断模式列表:
|
|
|
1579
1643
|
});
|
|
1580
1644
|
}
|
|
1581
1645
|
__name(registerShitOrNotCommands, "registerShitOrNotCommands");
|
|
1582
|
-
function loadYamlConfig(configPath) {
|
|
1583
|
-
if (!configPath) {
|
|
1584
|
-
logger.error("[loadYamlConfig Error]: SON 配置文件路径未配置");
|
|
1585
|
-
return null;
|
|
1586
|
-
}
|
|
1587
|
-
try {
|
|
1588
|
-
const trimmedPath = configPath.trim();
|
|
1589
|
-
const fullPath = import_path3.default.isAbsolute(trimmedPath) ? trimmedPath : import_path3.default.resolve(process.cwd(), trimmedPath);
|
|
1590
|
-
if (!(0, import_fs3.existsSync)(fullPath)) {
|
|
1591
|
-
logger.error(`[loadYamlConfig Error]: SON 配置文件不存在: ${fullPath}`);
|
|
1592
|
-
return null;
|
|
1593
|
-
}
|
|
1594
|
-
const fileContent = (0, import_fs3.readFileSync)(fullPath, "utf-8");
|
|
1595
|
-
const config = yaml.load(fileContent);
|
|
1596
|
-
return config;
|
|
1597
|
-
} catch (error) {
|
|
1598
|
-
logger.error(`[loadYamlConfig Error]: SON 读取配置文件失败: ${configPath}`, error);
|
|
1599
|
-
return null;
|
|
1600
|
-
}
|
|
1601
|
-
}
|
|
1602
|
-
__name(loadYamlConfig, "loadYamlConfig");
|
|
1603
1646
|
function extractAtId(content) {
|
|
1604
1647
|
const match = content.match(/<at\b[^>]*id=["']?(\d+)["']?[^>]*>/i);
|
|
1605
1648
|
return match ? match[1] : null;
|
|
@@ -2029,19 +2072,135 @@ function registerKuroCommands(ctx, connected) {
|
|
|
2029
2072
|
}
|
|
2030
2073
|
__name(registerKuroCommands, "registerKuroCommands");
|
|
2031
2074
|
|
|
2075
|
+
// src/services/game_func/game_service.ts
|
|
2076
|
+
var is_gaming = false;
|
|
2077
|
+
var chatHistory2 = [];
|
|
2078
|
+
async function startSituationPuzzle(config) {
|
|
2079
|
+
if (is_gaming)
|
|
2080
|
+
return "海龟汤正在进行中,请先结束游戏";
|
|
2081
|
+
chatHistory2 = [];
|
|
2082
|
+
const prompt_start = `你是一个海龟汤游戏主持人,现在开始游戏。
|
|
2083
|
+
请生成一个海龟汤谜题,要求如下:
|
|
2084
|
+
1. 谜题是中文问句且内容简洁,包含一个看似矛盾或难以理解的情境
|
|
2085
|
+
2. 谜题长度不超过100字
|
|
2086
|
+
3. 谜题答案需要符合逻辑但出人意料
|
|
2087
|
+
`;
|
|
2088
|
+
chatHistory2.push({ role: "system", content: [{ type: "text", text: prompt_start }] });
|
|
2089
|
+
const { err, resp } = await callOpenRouter(config.api_url, config.api_key, config.api_model, chatHistory2);
|
|
2090
|
+
if (err != null) {
|
|
2091
|
+
logger.error("[startSituationPuzzle Error]: " + err);
|
|
2092
|
+
return null;
|
|
2093
|
+
}
|
|
2094
|
+
chatHistory2.push({ role: "assistant", content: [{ type: "text", text: resp }] });
|
|
2095
|
+
is_gaming = true;
|
|
2096
|
+
return resp;
|
|
2097
|
+
}
|
|
2098
|
+
__name(startSituationPuzzle, "startSituationPuzzle");
|
|
2099
|
+
async function questSituationPuzzle(content, config) {
|
|
2100
|
+
chatHistory2.push({ role: "user", content: [{ type: "text", text: content }] });
|
|
2101
|
+
const { err, resp } = await callOpenRouter(config.api_url, config.api_key, config.api_model, chatHistory2);
|
|
2102
|
+
if (err != null) {
|
|
2103
|
+
logger.error("[questSituationPuzzle Error]: " + err);
|
|
2104
|
+
return null;
|
|
2105
|
+
}
|
|
2106
|
+
chatHistory2.push({ role: "assistant", content: [{ type: "text", text: resp }] });
|
|
2107
|
+
}
|
|
2108
|
+
__name(questSituationPuzzle, "questSituationPuzzle");
|
|
2109
|
+
async function endSituationPuzzle(config) {
|
|
2110
|
+
is_gaming = false;
|
|
2111
|
+
chatHistory2.push({ role: "user", content: [{ type: "text", text: "结束游戏,请给出答案" }] });
|
|
2112
|
+
const { err, resp } = await callOpenRouter(config.api_url, config.api_key, config.api_model, chatHistory2);
|
|
2113
|
+
if (err != null) {
|
|
2114
|
+
logger.error("[endSituationPuzzle Error]: " + err);
|
|
2115
|
+
return null;
|
|
2116
|
+
}
|
|
2117
|
+
return resp;
|
|
2118
|
+
}
|
|
2119
|
+
__name(endSituationPuzzle, "endSituationPuzzle");
|
|
2120
|
+
|
|
2121
|
+
// src/services/game_func/game_command.ts
|
|
2122
|
+
var local_config2 = null;
|
|
2123
|
+
var gameList = [
|
|
2124
|
+
{
|
|
2125
|
+
name: "AI海龟汤",
|
|
2126
|
+
description: "AI海龟汤游戏,通过AI回答问题,猜测答案",
|
|
2127
|
+
command: "puzzle"
|
|
2128
|
+
}
|
|
2129
|
+
];
|
|
2130
|
+
function registerGameCommands(ctx, game_config, ai_config) {
|
|
2131
|
+
if (game_config?.config_path) {
|
|
2132
|
+
local_config2 = loadYamlConfig(game_config.config_path);
|
|
2133
|
+
if (local_config2) {
|
|
2134
|
+
logger.info("[loadYamlConfig Info]: SON 成功加载配置文件");
|
|
2135
|
+
} else {
|
|
2136
|
+
logger.error("[loadYamlConfig Error]: SON 配置文件加载失败,将使用默认配置");
|
|
2137
|
+
}
|
|
2138
|
+
} else {
|
|
2139
|
+
logger.error("[loadYamlConfig Error]: 未配置 SON 配置文件路径");
|
|
2140
|
+
}
|
|
2141
|
+
ctx.command("gamelist", "查看所有游戏").action(async ({ session }) => {
|
|
2142
|
+
return `[所有命令都需要@bot]
|
|
2143
|
+
游戏列表:
|
|
2144
|
+
${gameList.map((item) => item.command + ": " + item.name).join("\n ")}
|
|
2145
|
+
输入对应指令开始游戏,如果遇到问题请联系开发人员。`;
|
|
2146
|
+
});
|
|
2147
|
+
ctx.command("startgame <参数>", "开始游戏,参数为游戏名称").action(async ({ session }, ...args) => {
|
|
2148
|
+
if (!dev_mode) {
|
|
2149
|
+
if (!is_at_bot(session)) return;
|
|
2150
|
+
}
|
|
2151
|
+
const game = args?.[0];
|
|
2152
|
+
if (!game) return "请提供正确格式,如:@bot start game [游戏]";
|
|
2153
|
+
switch (game) {
|
|
2154
|
+
case gameList[0].command:
|
|
2155
|
+
await session.send("正在开始游戏,后续问答请参照格式:@bot [问题]");
|
|
2156
|
+
const resp = await startSituationPuzzle(ai_config);
|
|
2157
|
+
return checkResp(resp);
|
|
2158
|
+
default:
|
|
2159
|
+
return `游戏不存在,请输入gamelist查看所有游戏`;
|
|
2160
|
+
}
|
|
2161
|
+
});
|
|
2162
|
+
ctx.command("endgame", "结束游戏").action(async ({ session }, ...args) => {
|
|
2163
|
+
if (!dev_mode) {
|
|
2164
|
+
if (!is_at_bot(session)) return;
|
|
2165
|
+
}
|
|
2166
|
+
const resp = await endSituationPuzzle(ai_config);
|
|
2167
|
+
return checkResp(resp);
|
|
2168
|
+
});
|
|
2169
|
+
}
|
|
2170
|
+
__name(registerGameCommands, "registerGameCommands");
|
|
2171
|
+
function registerGameMiddleware(ctx, ai_config) {
|
|
2172
|
+
ctx.middleware(async (session, next) => {
|
|
2173
|
+
if (!is_gaming) return next();
|
|
2174
|
+
const { content, uid, userId } = session;
|
|
2175
|
+
if (ctx.bots[uid]) return next();
|
|
2176
|
+
if (!is_at_bot(session)) return next();
|
|
2177
|
+
const resp = await questSituationPuzzle(session.content, ai_config);
|
|
2178
|
+
return checkResp(resp);
|
|
2179
|
+
});
|
|
2180
|
+
}
|
|
2181
|
+
__name(registerGameMiddleware, "registerGameMiddleware");
|
|
2182
|
+
function checkResp(resp) {
|
|
2183
|
+
if (!resp) {
|
|
2184
|
+
return "返回有误,请检查日志";
|
|
2185
|
+
}
|
|
2186
|
+
return resp;
|
|
2187
|
+
}
|
|
2188
|
+
__name(checkResp, "checkResp");
|
|
2189
|
+
|
|
2032
2190
|
// src/index.ts
|
|
2033
2191
|
var name = "cocoyyy-console";
|
|
2034
2192
|
var dev_mode;
|
|
2035
|
-
var Config =
|
|
2193
|
+
var Config = import_koishi12.Schema.object({
|
|
2036
2194
|
function_config: FunctionConfigSchema.description("功能开关配置"),
|
|
2037
|
-
|
|
2195
|
+
ai_config: AiAPIConfigSchema.description("AI API配置"),
|
|
2038
2196
|
mysql_config: MysqlConfigSchema.description("MySQL 数据库配置"),
|
|
2039
2197
|
tag_config: SaveConfigSchema.description("tag图片保存配置"),
|
|
2040
2198
|
repeat_config: RepeatConfigSchema.description("复读配置"),
|
|
2041
2199
|
son_config: ShitOrNotConfigSchema.description("SON配置"),
|
|
2042
|
-
|
|
2200
|
+
game_config: GameConfigSchema.description("游戏配置"),
|
|
2201
|
+
test: import_koishi12.Schema.string().description("测试")
|
|
2043
2202
|
});
|
|
2044
|
-
var logger = new
|
|
2203
|
+
var logger = new import_koishi12.Logger(name);
|
|
2045
2204
|
var savePath = null;
|
|
2046
2205
|
async function apply(ctx, config) {
|
|
2047
2206
|
ctx = ctx.guild();
|
|
@@ -2062,7 +2221,11 @@ async function apply(ctx, config) {
|
|
|
2062
2221
|
if (config.function_config.repeat_flag)
|
|
2063
2222
|
registerRepeatMiddleware(ctx, config?.repeat_config);
|
|
2064
2223
|
if (config.function_config.son_flag)
|
|
2065
|
-
registerShitOrNotCommands(ctx, config?.son_config);
|
|
2224
|
+
registerShitOrNotCommands(ctx, config?.ai_config, config?.son_config);
|
|
2225
|
+
if (config.function_config.game_flag) {
|
|
2226
|
+
registerGameCommands(ctx, config?.game_config, config?.ai_config);
|
|
2227
|
+
registerGameMiddleware(ctx, config?.ai_config);
|
|
2228
|
+
}
|
|
2066
2229
|
if (config.function_config.rbq_flag)
|
|
2067
2230
|
registerRbqCommands(ctx, connected);
|
|
2068
2231
|
if (config.function_config)
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { Context } from 'koishi';
|
|
2
|
+
import { GameConfig } from '../../utils/configs/game_config';
|
|
3
|
+
import { AiAPIConfig } from '../../utils/config';
|
|
4
|
+
declare function registerGameCommands(ctx: Context, game_config: GameConfig, ai_config: AiAPIConfig): void;
|
|
5
|
+
declare function registerGameMiddleware(ctx: Context, ai_config: AiAPIConfig): void;
|
|
6
|
+
export { registerGameCommands, registerGameMiddleware, };
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { AiAPIConfig } from "../../utils/config";
|
|
2
|
+
declare let is_gaming: boolean;
|
|
3
|
+
declare function startSituationPuzzle(config: AiAPIConfig): Promise<string>;
|
|
4
|
+
declare function questSituationPuzzle(content: string, config: AiAPIConfig): Promise<any>;
|
|
5
|
+
declare function endSituationPuzzle(config: AiAPIConfig): Promise<string>;
|
|
6
|
+
export { is_gaming, startSituationPuzzle, questSituationPuzzle, endSituationPuzzle };
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { Context } from 'koishi';
|
|
2
2
|
import { ShitOrNotConfig } from '../../utils/config';
|
|
3
|
-
|
|
3
|
+
import { AiAPIConfig } from '../../utils/configs/ai_config';
|
|
4
|
+
declare function registerShitOrNotCommands(ctx: Context, ai_config: AiAPIConfig, son_config: ShitOrNotConfig): void;
|
|
4
5
|
export { registerShitOrNotCommands };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Session } from 'koishi';
|
|
2
|
-
import {
|
|
2
|
+
import { AiAPIConfig } from '../../utils/configs/ai_config';
|
|
3
3
|
declare function ocrImage(buffer: Buffer): Promise<string>;
|
|
4
|
-
declare function checkShitOrNot(session: Session, parttern_msg: string, config:
|
|
4
|
+
declare function checkShitOrNot(session: Session, parttern_msg: string, config: AiAPIConfig): Promise<string>;
|
|
5
5
|
export { checkShitOrNot, ocrImage };
|
package/lib/utils/common.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
1
|
declare function is_at_bot(session: any): boolean;
|
|
2
2
|
declare function decodeHtmlEntities(text: string): string;
|
|
3
|
-
|
|
3
|
+
declare function loadYamlConfig(configPath: string): any;
|
|
4
|
+
export { is_at_bot, decodeHtmlEntities, loadYamlConfig };
|
package/lib/utils/config.d.ts
CHANGED