koishi-plugin-cocoyyy-console 1.0.16-beta.8 → 1.0.16

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 +51 -55
  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: "库洛相关功能,用于鸣潮相关功能",
@@ -1434,7 +1439,7 @@ async function callOpenRouter(api_url, api_key, api_model = "gpt-4o-mini", messa
1434
1439
  const { data } = await import_axios.default.post(
1435
1440
  api_url,
1436
1441
  {
1437
- api_model,
1442
+ model: api_model,
1438
1443
  messages
1439
1444
  },
1440
1445
  {
@@ -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,6 @@ __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");
1564
1535
  function registerShitOrNotCommands(ctx, config) {
1565
1536
  if (config?.config_path) {
1566
1537
  local_config = loadYamlConfig(config.config_path);
@@ -1572,19 +1543,25 @@ function registerShitOrNotCommands(ctx, config) {
1572
1543
  } else {
1573
1544
  logger.error("[loadYamlConfig Error]: 未配置 SON 配置文件路径");
1574
1545
  }
1575
- ctx.command("sonlist <参数>", "查看son判断模式列表").action(() => {
1546
+ ctx.command("sonlist <参数>", "查看son判断模式列表").action(async ({ session }) => {
1547
+ if (!dev_mode) {
1548
+ if (!is_at_bot(session)) return;
1549
+ }
1550
+ if (!local_config) return "未加载配置文件,请查看日志";
1551
+ const mode_intro = local_config?.shit_or_not?.menu;
1552
+ if (!mode_intro) return "未找到判断模式列表,请查看日志";
1576
1553
  return `[所有命令都需要@bot]
1577
1554
  son判断模式列表:
1578
1555
  ${Object.keys(mode_intro).map((item) => item + ": " + mode_intro[item]).join("\n ")}`;
1579
1556
  });
1580
1557
  ctx.command("son <参数>", "判定是否为史").action(async ({ session }, ...args) => {
1581
1558
  if (!dev_mode) {
1582
- if (!is_at_bot_quote(session)) return "请提供正确格式1,如: [引用消息] @bot son [判断模式]";
1559
+ if (!is_at_bot_quote(session)) return "请提供正确格式,如: [引用消息] @bot son [判断模式]";
1583
1560
  } else {
1584
- if (!session.quote) return "请提供正确格式2,如: [引用消息] @bot son [判断模式]";
1561
+ if (!session.quote) return "请引用消息后使用功能";
1585
1562
  }
1586
1563
  const parttern = args?.[0];
1587
- if (!parttern) return "请提供正确格式3,如: [引用消息] @bot son [判断模式]";
1564
+ if (!parttern) return "请提供正确判断模式,如: [引用消息] @bot son [判断模式]";
1588
1565
  if (!local_config) return "未加载配置文件,请查看日志";
1589
1566
  const parttern_msg = local_config.shit_or_not?.prompts[parttern];
1590
1567
  if (!parttern_msg) return "未找到判断模式,请查看日志";
@@ -1593,6 +1570,32 @@ son判断模式列表:
1593
1570
  });
1594
1571
  }
1595
1572
  __name(registerShitOrNotCommands, "registerShitOrNotCommands");
1573
+ function loadYamlConfig(configPath) {
1574
+ if (!configPath) {
1575
+ logger.error("[loadYamlConfig Error]: SON 配置文件路径未配置");
1576
+ return null;
1577
+ }
1578
+ try {
1579
+ const trimmedPath = configPath.trim();
1580
+ const fullPath = import_path3.default.isAbsolute(trimmedPath) ? trimmedPath : import_path3.default.resolve(process.cwd(), trimmedPath);
1581
+ if (!(0, import_fs3.existsSync)(fullPath)) {
1582
+ logger.error(`[loadYamlConfig Error]: SON 配置文件不存在: ${fullPath}`);
1583
+ return null;
1584
+ }
1585
+ const fileContent = (0, import_fs3.readFileSync)(fullPath, "utf-8");
1586
+ const config = yaml.load(fileContent);
1587
+ return config;
1588
+ } catch (error) {
1589
+ logger.error(`[loadYamlConfig Error]: SON 读取配置文件失败: ${configPath}`, error);
1590
+ return null;
1591
+ }
1592
+ }
1593
+ __name(loadYamlConfig, "loadYamlConfig");
1594
+ function extractAtId(content) {
1595
+ const match = content.match(/<at\b[^>]*id=["']?(\d+)["']?[^>]*>/i);
1596
+ return match ? match[1] : null;
1597
+ }
1598
+ __name(extractAtId, "extractAtId");
1596
1599
  function is_at_bot_quote(session) {
1597
1600
  if (!session.quote)
1598
1601
  return false;
@@ -1601,17 +1604,10 @@ function is_at_bot_quote(session) {
1601
1604
  const quoteUserId = quote.user.id;
1602
1605
  const quoteContent = quote.content;
1603
1606
  const botId = session?.bot?.selfId ?? session?.selfId;
1604
- if (dev_mode)
1605
- logger.info(`command: quoteContent: ${quoteContent}, quoteUserId: ${quoteUserId},content: ${content} userId: ${userId}`);
1606
1607
  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
- }
1608
+ const atId = extractAtId(session.content);
1609
+ if (atId === botId)
1610
+ return true;
1615
1611
  return false;
1616
1612
  }
1617
1613
  __name(is_at_bot_quote, "is_at_bot_quote");
@@ -2027,7 +2023,7 @@ __name(registerKuroCommands, "registerKuroCommands");
2027
2023
  // src/index.ts
2028
2024
  var name = "cocoyyy-console";
2029
2025
  var dev_mode;
2030
- var Config2 = import_koishi10.Schema.object({
2026
+ var Config = import_koishi10.Schema.object({
2031
2027
  function_config: FunctionConfigSchema.description("功能开关配置"),
2032
2028
  redis_config: RedisConfigSchema.description("Redis配置"),
2033
2029
  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.8",
4
+ "version": "1.0.16",
5
5
  "main": "lib/index.js",
6
6
  "typings": "lib/index.d.ts",
7
7
  "contributors": [