koishi-plugin-cocoyyy-console 1.1.3-alpha.6 → 1.1.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/index.js +62 -27
- package/package.json +1 -1
package/lib/index.js
CHANGED
|
@@ -333,70 +333,71 @@ __name(loadYamlConfig, "loadYamlConfig");
|
|
|
333
333
|
var menuList = [
|
|
334
334
|
{
|
|
335
335
|
name: "tag",
|
|
336
|
-
description: "标签功能,用于记录黑历史"
|
|
337
|
-
command: "maketag [标签]"
|
|
336
|
+
description: "标签功能,用于记录黑历史"
|
|
338
337
|
},
|
|
339
338
|
{
|
|
340
339
|
name: "repeat",
|
|
341
|
-
description: "复读功能,用于复读"
|
|
342
|
-
command: "无"
|
|
340
|
+
description: "复读功能,用于复读"
|
|
343
341
|
},
|
|
344
342
|
{
|
|
345
343
|
name: "rbq",
|
|
346
|
-
description: "*人功能,用于*人"
|
|
347
|
-
command: "无"
|
|
344
|
+
description: "*人功能,用于*人"
|
|
348
345
|
},
|
|
349
346
|
{
|
|
350
347
|
name: "son",
|
|
351
|
-
description: "shit_or_not功能,用于鉴别史消息"
|
|
352
|
-
command: "无"
|
|
348
|
+
description: "shit_or_not功能,用于鉴别史消息"
|
|
353
349
|
},
|
|
354
350
|
{
|
|
355
351
|
name: "setu",
|
|
356
|
-
description: "随机涩图功能,用于获取涩图"
|
|
357
|
-
|
|
352
|
+
description: "随机涩图功能,用于获取涩图"
|
|
353
|
+
},
|
|
354
|
+
{
|
|
355
|
+
name: "wish",
|
|
356
|
+
description: "许愿功能,用于许愿"
|
|
358
357
|
},
|
|
359
358
|
{
|
|
360
359
|
name: "game",
|
|
361
|
-
description: "游戏功能,用于游玩游戏"
|
|
362
|
-
command: "无"
|
|
360
|
+
description: "游戏功能,用于游玩游戏"
|
|
363
361
|
},
|
|
364
362
|
{
|
|
365
363
|
name: "kuro",
|
|
366
|
-
description: "库洛相关功能,用于鸣潮相关功能"
|
|
367
|
-
command: "无"
|
|
364
|
+
description: "库洛相关功能,用于鸣潮相关功能"
|
|
368
365
|
}
|
|
369
366
|
];
|
|
370
367
|
function getMenuList(command = null, functionConfig) {
|
|
371
368
|
switch (command) {
|
|
372
|
-
case
|
|
369
|
+
case menuList[0].name:
|
|
373
370
|
if (!functionConfig.tag_flag)
|
|
374
371
|
return "标签功能已关闭";
|
|
375
372
|
return getTagFuncMenu(command);
|
|
376
|
-
case
|
|
373
|
+
case menuList[1].name:
|
|
377
374
|
if (!functionConfig.repeat_flag)
|
|
378
375
|
return "复读功能已关闭";
|
|
379
376
|
return `[所有命令都需要@bot]
|
|
380
377
|
复读功能菜单:
|
|
381
378
|
群内重复一定次数的消息会进行复读
|
|
382
379
|
如果遇到问题请联系开发人员。`;
|
|
383
|
-
case
|
|
380
|
+
case menuList[2].name:
|
|
384
381
|
if (!functionConfig.rbq_flag)
|
|
385
382
|
return "*人功能已关闭";
|
|
386
383
|
return getRbqFuncMenu(command);
|
|
387
|
-
case
|
|
384
|
+
case menuList[3].name:
|
|
388
385
|
if (!functionConfig.son_flag)
|
|
389
386
|
return "son功能已关闭";
|
|
390
387
|
return getSonFuncMenu(command);
|
|
391
|
-
case
|
|
388
|
+
case menuList[4].name:
|
|
392
389
|
if (!functionConfig.setu_flag)
|
|
393
390
|
return "son功能已关闭";
|
|
394
391
|
return getSetuFuncMenu(command);
|
|
395
|
-
case
|
|
392
|
+
case menuList[5].name:
|
|
393
|
+
if (!functionConfig.wish_flag)
|
|
394
|
+
return "许愿功能已关闭";
|
|
395
|
+
return getWishFuncMenu(command);
|
|
396
|
+
case menuList[6].name:
|
|
396
397
|
if (!functionConfig.game_flag)
|
|
397
398
|
return "游戏功能已关闭";
|
|
398
399
|
return getGameFuncMenu(command);
|
|
399
|
-
case
|
|
400
|
+
case menuList[7].name:
|
|
400
401
|
if (!functionConfig.kuro_flag)
|
|
401
402
|
return "库洛相关功能已关闭";
|
|
402
403
|
return getKuroFuncMenu(command);
|
|
@@ -524,6 +525,20 @@ setu功能菜单:
|
|
|
524
525
|
输入对应指令使用setu功能,如果遇到问题请联系开发人员。`;
|
|
525
526
|
}
|
|
526
527
|
__name(getSetuFuncMenu, "getSetuFuncMenu");
|
|
528
|
+
var wishFuncMenuList = [
|
|
529
|
+
{
|
|
530
|
+
name: "wish",
|
|
531
|
+
description: "许愿功能",
|
|
532
|
+
command: "wish [愿望消息(不要超过80字)]"
|
|
533
|
+
}
|
|
534
|
+
];
|
|
535
|
+
function getWishFuncMenu(command = null) {
|
|
536
|
+
return `[所有命令都需要@bot]
|
|
537
|
+
许愿功能菜单:
|
|
538
|
+
${wishFuncMenuList.map((item) => item.command + ": " + item.description).join("\n ")}
|
|
539
|
+
输入对应指令使用许愿功能,如果遇到问题请联系开发人员。`;
|
|
540
|
+
}
|
|
541
|
+
__name(getWishFuncMenu, "getWishFuncMenu");
|
|
527
542
|
var gameFuncMenuList = [
|
|
528
543
|
{
|
|
529
544
|
name: "gamelist",
|
|
@@ -1749,13 +1764,14 @@ async function randomHImg(keywords, ...args) {
|
|
|
1749
1764
|
const params = new URLSearchParams();
|
|
1750
1765
|
params.append("excludeAI", "true");
|
|
1751
1766
|
params.append("size", "regular");
|
|
1752
|
-
|
|
1767
|
+
let r18_flag = 0;
|
|
1753
1768
|
if (r18) {
|
|
1754
1769
|
if (r18.toLowerCase() === "r18") {
|
|
1755
|
-
|
|
1770
|
+
r18_flag = 1;
|
|
1756
1771
|
tags = keywords?.slice(1);
|
|
1757
1772
|
}
|
|
1758
1773
|
}
|
|
1774
|
+
params.append("r18", r18_flag.toString());
|
|
1759
1775
|
if (args[0]) {
|
|
1760
1776
|
params.append("num", args[0].toString());
|
|
1761
1777
|
}
|
|
@@ -1878,6 +1894,22 @@ var tools = [
|
|
|
1878
1894
|
}
|
|
1879
1895
|
}
|
|
1880
1896
|
];
|
|
1897
|
+
function safeParseJSON(jsonString) {
|
|
1898
|
+
if (!jsonString || typeof jsonString !== "string") {
|
|
1899
|
+
throw new Error("输入不是有效的字符串");
|
|
1900
|
+
}
|
|
1901
|
+
let cleaned = jsonString.trim();
|
|
1902
|
+
cleaned = cleaned.replace(/^```(?:json)?\s*\n?/i, "");
|
|
1903
|
+
cleaned = cleaned.replace(/\n?```\s*$/i, "");
|
|
1904
|
+
cleaned = cleaned.trim();
|
|
1905
|
+
try {
|
|
1906
|
+
return JSON.parse(cleaned);
|
|
1907
|
+
} catch (error) {
|
|
1908
|
+
logger.error(`[safeParseJSON Error]: 无法解析 JSON,原始内容: ${jsonString.substring(0, 200)}...`);
|
|
1909
|
+
throw error;
|
|
1910
|
+
}
|
|
1911
|
+
}
|
|
1912
|
+
__name(safeParseJSON, "safeParseJSON");
|
|
1881
1913
|
async function checkAudit(local_config4, wish_content, config, wish_config) {
|
|
1882
1914
|
let prompt_msg = "";
|
|
1883
1915
|
if (!local_config4) return { result: false, reason: "未加载配置文件,请查看日志" };
|
|
@@ -1904,7 +1936,7 @@ async function checkAudit(local_config4, wish_content, config, wish_config) {
|
|
|
1904
1936
|
logger.error("[checkAudit Error]: API返回为空");
|
|
1905
1937
|
return { result: false, reason: "API返回为空" };
|
|
1906
1938
|
}
|
|
1907
|
-
const json =
|
|
1939
|
+
const json = safeParseJSON(resp);
|
|
1908
1940
|
if (json.category == "block") {
|
|
1909
1941
|
logger.info("[checkAudit Info]: 愿望被拒绝,原因: " + json.reason);
|
|
1910
1942
|
return { result: false, reason: json.reason };
|
|
@@ -1942,7 +1974,11 @@ async function gernerationSoluation(local_config4, wish_content, config, wish_co
|
|
|
1942
1974
|
logger.error("[gernerationSoluation Error]: " + err);
|
|
1943
1975
|
return null;
|
|
1944
1976
|
}
|
|
1945
|
-
|
|
1977
|
+
if (!resp) {
|
|
1978
|
+
logger.error("[gernerationSoluation Error]: API返回为空");
|
|
1979
|
+
return null;
|
|
1980
|
+
}
|
|
1981
|
+
const json = safeParseJSON(resp);
|
|
1946
1982
|
const scenario = json.scenario;
|
|
1947
1983
|
if (!scenario) {
|
|
1948
1984
|
logger.info("[gernerationSoluation Info]: API返回有误: " + resp);
|
|
@@ -1974,7 +2010,6 @@ function registerWishCommands(ctx, ai_config, wish_config) {
|
|
|
1974
2010
|
if (!dev_mode) {
|
|
1975
2011
|
if (!is_at_bot(session)) return "请提供正确格式,如: @bot wish [愿望消息(不要超过80字)]";
|
|
1976
2012
|
}
|
|
1977
|
-
if (think_flag2) return "请等待上一位的祈祷结果";
|
|
1978
2013
|
const wish_content = args?.[0];
|
|
1979
2014
|
if (!wish_content) return "输入愿望消息,不要超过80字";
|
|
1980
2015
|
await session.send("已收到,正在祈祷中...");
|
|
@@ -1984,7 +2019,7 @@ function registerWishCommands(ctx, ai_config, wish_config) {
|
|
|
1984
2019
|
if (!exec) return "愿望不合规被拒绝,请重新许愿";
|
|
1985
2020
|
let exec_generation = await gernerationSoluation(local_config2, wish_content, ai_config, wish_config);
|
|
1986
2021
|
if (!exec_generation) return "愿望实现失败,请重新许愿";
|
|
1987
|
-
return (0, import_koishi14.h)("at", { id: session.userId }) + "
|
|
2022
|
+
return (0, import_koishi14.h)("at", { id: session.userId }) + " 祈祷成功,愿梦想成真!\n" + exec_generation;
|
|
1988
2023
|
} finally {
|
|
1989
2024
|
think_flag2 = false;
|
|
1990
2025
|
}
|