koishi-plugin-cocoyyy-console 1.0.16-beta.9 → 1.0.17

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.
Files changed (2) hide show
  1. package/lib/index.js +61 -56
  2. package/package.json +1 -1
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: () => Config2,
33
+ Config: () => Config,
34
34
  apply: () => apply,
35
35
  dev_mode: () => dev_mode,
36
36
  logger: () => logger,
@@ -300,6 +300,11 @@ var menuList = [
300
300
  description: "*人功能,用于*人",
301
301
  command: "无"
302
302
  },
303
+ {
304
+ name: "son",
305
+ description: "shit_or_not功能,用于鉴别史消息",
306
+ command: "无"
307
+ },
303
308
  {
304
309
  name: "kuro",
305
310
  description: "库洛相关功能,用于鸣潮相关功能",
@@ -1491,19 +1496,17 @@ function extractImageAndText(content) {
1491
1496
  }
1492
1497
  return " ";
1493
1498
  });
1494
- const text = stripped.replace(/\s+/g, " ").trim();
1499
+ const withoutTags = stripped.replace(/<[^>]+>/g, " ");
1500
+ const text = withoutTags.replace(/\s+/g, " ").trim();
1495
1501
  return { imageUrls, text };
1496
1502
  }
1497
1503
  __name(extractImageAndText, "extractImageAndText");
1498
1504
  async function checkShitOrNot(session, parttern_msg, config) {
1499
1505
  chatHistory = [];
1500
1506
  chatHistory.push({ role: "user", content: [{ type: "text", text: parttern_msg }] });
1501
- if (dev_mode) {
1502
- logger.info("[checkShitOrNot Info]: chatHistory", { chatHistory });
1503
- }
1504
1507
  const { err, resp } = await callOpenRouter(config.api_url, config.api_key, config.api_model, chatHistory);
1505
1508
  if (err != null) {
1506
- logger.error("[callOpenRouter Error1]: " + err);
1509
+ logger.error("[callOpenRouter Error 1]: " + err);
1507
1510
  return null;
1508
1511
  }
1509
1512
  chatHistory.push({ role: "assistant", content: [{ type: "text", text: resp }] });
@@ -1520,7 +1523,7 @@ async function checkShitOrNot(session, parttern_msg, config) {
1520
1523
  chatHistory.push({ role: "user", content: targetContent });
1521
1524
  const { err: err2, resp: resp2 } = await callOpenRouter(config.api_url, config.api_key, config.api_model, chatHistory);
1522
1525
  if (err2 != null) {
1523
- logger.error("[callOpenRouter Error2]: " + err2);
1526
+ logger.error("[callOpenRouter Error 2]: " + err2);
1524
1527
  return null;
1525
1528
  }
1526
1529
  return resp2;
@@ -1529,38 +1532,7 @@ __name(checkShitOrNot, "checkShitOrNot");
1529
1532
 
1530
1533
  // src/services/son_func/shit_or_not_command.ts
1531
1534
  var local_config = null;
1532
- var mode_intro = {
1533
- "esu": "【图文】ohno妈咪饿素啊😨,恶俗慎用!🈲",
1534
- "nov": "【图文】来段微小说📕",
1535
- "lit": "【图文】文楠魅力时刻📕👨",
1536
- "zhi": "【图文】分享你刚编的故事🤓",
1537
- "boa": "【图文】《答案之书》🔮",
1538
- "scp": "【图文】控制-收容-保护,献上你的异常👽",
1539
- "phi": "【图文】我思,故我在🧠",
1540
- "see": "【图像】让我康康怎么个事👀",
1541
- "ccb": "【图像】压抑笑传之踩踩背🐘"
1542
- };
1543
- function loadYamlConfig(configPath) {
1544
- if (!configPath) {
1545
- logger.error("[loadYamlConfig Error]: SON 配置文件路径未配置");
1546
- return null;
1547
- }
1548
- try {
1549
- const trimmedPath = configPath.trim();
1550
- const fullPath = import_path3.default.isAbsolute(trimmedPath) ? trimmedPath : import_path3.default.resolve(process.cwd(), trimmedPath);
1551
- if (!(0, import_fs3.existsSync)(fullPath)) {
1552
- logger.error(`[loadYamlConfig Error]: SON 配置文件不存在: ${fullPath}`);
1553
- return null;
1554
- }
1555
- const fileContent = (0, import_fs3.readFileSync)(fullPath, "utf-8");
1556
- const config = yaml.load(fileContent);
1557
- return config;
1558
- } catch (error) {
1559
- logger.error(`[loadYamlConfig Error]: SON 读取配置文件失败: ${configPath}`, error);
1560
- return null;
1561
- }
1562
- }
1563
- __name(loadYamlConfig, "loadYamlConfig");
1535
+ var think_flag = false;
1564
1536
  function registerShitOrNotCommands(ctx, config) {
1565
1537
  if (config?.config_path) {
1566
1538
  local_config = loadYamlConfig(config.config_path);
@@ -1572,27 +1544,67 @@ function registerShitOrNotCommands(ctx, config) {
1572
1544
  } else {
1573
1545
  logger.error("[loadYamlConfig Error]: 未配置 SON 配置文件路径");
1574
1546
  }
1575
- ctx.command("sonlist <参数>", "查看son判断模式列表").action(() => {
1547
+ ctx.command("sonlist <参数>", "查看son判断模式列表").action(async ({ session }) => {
1548
+ if (!dev_mode) {
1549
+ if (!is_at_bot(session)) return;
1550
+ }
1551
+ if (!local_config) return "未加载配置文件,请查看日志";
1552
+ const mode_intro = local_config?.shit_or_not?.menu;
1553
+ if (!mode_intro) return "未找到判断模式列表,请查看日志";
1576
1554
  return `[所有命令都需要@bot]
1577
1555
  son判断模式列表:
1578
1556
  ${Object.keys(mode_intro).map((item) => item + ": " + mode_intro[item]).join("\n ")}`;
1579
1557
  });
1580
1558
  ctx.command("son <参数>", "判定是否为史").action(async ({ session }, ...args) => {
1581
1559
  if (!dev_mode) {
1582
- if (!is_at_bot_quote(session)) return "请提供正确格式1,如: [引用消息] @bot son [判断模式]";
1560
+ if (!is_at_bot_quote(session)) return "请提供正确格式,如: [引用消息] @bot son [判断模式]";
1583
1561
  } else {
1584
- if (!session.quote) return "请提供正确格式2,如: [引用消息] @bot son [判断模式]";
1562
+ if (!session.quote) return "请引用消息后使用功能";
1585
1563
  }
1564
+ if (think_flag) return "请等待思考结果";
1586
1565
  const parttern = args?.[0];
1587
- if (!parttern) return "请提供正确格式3,如: [引用消息] @bot son [判断模式]";
1566
+ if (!parttern) return "请提供正确判断模式,如: [引用消息] @bot son [判断模式]";
1588
1567
  if (!local_config) return "未加载配置文件,请查看日志";
1589
1568
  const parttern_msg = local_config.shit_or_not?.prompts[parttern];
1590
1569
  if (!parttern_msg) return "未找到判断模式,请查看日志";
1591
- let exec = await checkShitOrNot(session, parttern_msg, config);
1592
- return exec;
1570
+ await session.send("已收到,正在品鉴中...");
1571
+ think_flag = true;
1572
+ try {
1573
+ let exec = await checkShitOrNot(session, parttern_msg, config);
1574
+ if (exec == null) return "品鉴失败,请查看日志";
1575
+ return exec;
1576
+ } finally {
1577
+ think_flag = false;
1578
+ }
1593
1579
  });
1594
1580
  }
1595
1581
  __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
+ function extractAtId(content) {
1604
+ const match = content.match(/<at\b[^>]*id=["']?(\d+)["']?[^>]*>/i);
1605
+ return match ? match[1] : null;
1606
+ }
1607
+ __name(extractAtId, "extractAtId");
1596
1608
  function is_at_bot_quote(session) {
1597
1609
  if (!session.quote)
1598
1610
  return false;
@@ -1601,17 +1613,10 @@ function is_at_bot_quote(session) {
1601
1613
  const quoteUserId = quote.user.id;
1602
1614
  const quoteContent = quote.content;
1603
1615
  const botId = session?.bot?.selfId ?? session?.selfId;
1604
- if (dev_mode)
1605
- logger.info(`command: quoteContent: ${quoteContent}, quoteUserId: ${quoteUserId},content: ${content} userId: ${userId}`);
1606
1616
  const elements = quote.elements || [];
1607
- for (const elem of elements) {
1608
- if (elem.type === "at") {
1609
- const atId = elem.attrs.id;
1610
- if (String(atId) === String(botId)) {
1611
- return true;
1612
- }
1613
- }
1614
- }
1617
+ const atId = extractAtId(session.content);
1618
+ if (atId === botId)
1619
+ return true;
1615
1620
  return false;
1616
1621
  }
1617
1622
  __name(is_at_bot_quote, "is_at_bot_quote");
@@ -2027,7 +2032,7 @@ __name(registerKuroCommands, "registerKuroCommands");
2027
2032
  // src/index.ts
2028
2033
  var name = "cocoyyy-console";
2029
2034
  var dev_mode;
2030
- var Config2 = import_koishi10.Schema.object({
2035
+ var Config = import_koishi10.Schema.object({
2031
2036
  function_config: FunctionConfigSchema.description("功能开关配置"),
2032
2037
  redis_config: RedisConfigSchema.description("Redis配置"),
2033
2038
  mysql_config: MysqlConfigSchema.description("MySQL 数据库配置"),
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.9",
4
+ "version": "1.0.17",
5
5
  "main": "lib/index.js",
6
6
  "typings": "lib/index.d.ts",
7
7
  "contributors": [