mioki 0.9.2 → 0.9.3

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/dist/index.mjs CHANGED
@@ -1,5 +1,5 @@
1
1
  import { t as __export } from "./chunk-DYZpOiH0.mjs";
2
- import { t as version } from "./package-BUreTxqg.mjs";
2
+ import { t as version } from "./package-LmjT9AeF.mjs";
3
3
  import fs, { default as fs$1 } from "node:fs";
4
4
  import util from "node:util";
5
5
  import path, { default as path$1 } from "node:path";
@@ -14,7 +14,7 @@ import { NapCat, segment } from "napcat-sdk";
14
14
  import pm, { default as prettyMs } from "pretty-ms";
15
15
  import { filesize } from "filesize";
16
16
  import dayjs from "dayjs";
17
- import dedent, { default as dedent$1 } from "dedent";
17
+ import dedent from "dedent";
18
18
  import { box, colorize, colors, colors as colors$1, stripAnsi, stripAnsi as stripAnsi$1 } from "consola/utils";
19
19
  import systemInfo from "systeminformation";
20
20
  import { LogLevels, createConsola } from "consola/core";
@@ -1478,12 +1478,13 @@ const corePlugins = ["mioki-core"];
1478
1478
  const core = definePlugin({
1479
1479
  name: "mioki-core",
1480
1480
  version,
1481
- priority: 1,
1481
+ priority: 8,
1482
1482
  setup(ctx) {
1483
1483
  const prefix = (ctx.botConfig.prefix ?? "#").replace(/[-_.^$?[\]{}]/g, "\\$&");
1484
1484
  const cmdPrefix = /* @__PURE__ */ new RegExp(`^${prefix}`);
1485
1485
  const displayPrefix = prefix.replace(/\\\\/g, "\\");
1486
1486
  const statusAdminOnly = ctx.botConfig.status_permission === "admin-only";
1487
+ const getStatusStr = () => ctx.isFunction(ctx.services.customMiokiStatusStr) ? ctx.services.customMiokiStatusStr() : getMiokiStatusStr(ctx.bot);
1487
1488
  ctx.addService("miokiStatus", () => getMiokiStatus(ctx.bot));
1488
1489
  ctx.addService("miokiStatusStr", () => getMiokiStatusStr(ctx.bot));
1489
1490
  ctx.handle("message", (e) => ctx.runWithErrorHandler(async () => {
@@ -1491,17 +1492,17 @@ const core = definePlugin({
1491
1492
  if (!cmdPrefix.test(text$1)) return;
1492
1493
  if (statusAdminOnly && !ctx.hasRight(e)) return;
1493
1494
  if (text$1.replace(cmdPrefix, "") === "状态") {
1494
- const status = await getMiokiStatusStr(ctx.bot);
1495
+ const status = await getStatusStr();
1495
1496
  await e.reply(`〓 🟢 mioki 状态 〓\n${status}`.trim());
1496
1497
  return;
1497
1498
  }
1498
1499
  if (!ctx.isOwner(e)) return;
1499
- const { _: params, ..._options } = mri$1(string2argv$1(text$1));
1500
- const cmd = params.shift()?.replace(cmdPrefix, "") ?? "";
1500
+ const { cmd, params, ..._options } = ctx.createCmd(text$1);
1501
+ if (!cmd) return;
1501
1502
  const [subCmd, target, ..._subParams] = params;
1502
- switch (cmd) {
1503
+ switch (cmd?.replace(/\s+/g, "")) {
1503
1504
  case "帮助":
1504
- await e.reply(dedent$1(`
1505
+ await e.reply(ctx.dedent(`
1505
1506
  〓 💡 mioki 帮助 〓
1506
1507
  ${displayPrefix}插件 👉 框架插件管理
1507
1508
  ${displayPrefix}状态 👉 显示框架状态
@@ -1517,7 +1518,8 @@ const core = definePlugin({
1517
1518
  }
1518
1519
  switch (subCmd) {
1519
1520
  case "列表": {
1520
- const plugins = unique([...(await findLocalPlugins()).map((e$1) => e$1.name), ...runtimePlugins.keys()]).map((name) => {
1521
+ const localPlugins = await findLocalPlugins();
1522
+ const plugins = ctx.unique([...localPlugins.map((e$1) => e$1.name), ...runtimePlugins.keys()]).map((name) => {
1521
1523
  const isEnable = runtimePlugins.get(name);
1522
1524
  return `${isEnable ? "🟢" : "🔴"} ${isEnable && isEnable?.type === "builtin" ? "[内置]" : "[用户]"} ${name}`;
1523
1525
  }).toSorted((pre, next) => {
@@ -1530,7 +1532,7 @@ const core = definePlugin({
1530
1532
  const preWeight = weight(pre);
1531
1533
  return weight(next) - preWeight || pre.localeCompare(next);
1532
1534
  });
1533
- await e.reply(dedent$1(`
1535
+ await e.reply(ctx.dedent(`
1534
1536
  〓 插件列表 〓
1535
1537
  ${plugins.join("\n")}
1536
1538
  共 ${plugins.length} 个,启用 ${runtimePlugins.size} 个
@@ -1546,13 +1548,13 @@ const core = definePlugin({
1546
1548
  await e.reply(`插件 ${target} 已经是启用状态`, true);
1547
1549
  return;
1548
1550
  }
1549
- const pluginPath = path$1.join(getAbsPluginDir(), target);
1550
- if (!fs$1.existsSync(pluginPath)) {
1551
+ const pluginPath = ctx.path.join(getAbsPluginDir(), target);
1552
+ if (!ctx.fs.existsSync(pluginPath)) {
1551
1553
  await e.reply(`插件 ${target} 不存在`, true);
1552
1554
  return;
1553
1555
  }
1554
1556
  try {
1555
- const plugin = await jiti.import(pluginPath, { default: true });
1557
+ const plugin = await ctx.jiti.import(pluginPath, { default: true });
1556
1558
  if (plugin.name !== target) {
1557
1559
  const tip = `[插件目录名称: ${target}] 和插件代码中设置的 [name: ${plugin.name}] 不一致,可能导致重载异常,请修改后重启。`;
1558
1560
  ctx.bot.logger.warn(tip);
@@ -1563,7 +1565,7 @@ const core = definePlugin({
1563
1565
  await e.reply(`插件 ${target} 启用失败:${err?.message || "未知错误"}`, true);
1564
1566
  return;
1565
1567
  }
1566
- await updateBotConfig((c) => c.plugins = [...botConfig.plugins, target]);
1568
+ await ctx.updateBotConfig((c) => c.plugins = [...ctx.botConfig.plugins, target]);
1567
1569
  await e.reply(`插件 ${target} 启用成功`, true);
1568
1570
  break;
1569
1571
  }
@@ -1583,7 +1585,7 @@ const core = definePlugin({
1583
1585
  await e.reply(err?.message, true);
1584
1586
  break;
1585
1587
  }
1586
- await updateBotConfig((c) => c.plugins = botConfig.plugins.filter((name) => name !== target));
1588
+ await ctx.updateBotConfig((c) => c.plugins = ctx.botConfig.plugins.filter((name) => name !== target));
1587
1589
  ctx.bot.logger.info(`禁用插件 => ${target}`);
1588
1590
  await e.reply(`插件 ${target} 已禁用`, true);
1589
1591
  break;
@@ -1597,13 +1599,13 @@ const core = definePlugin({
1597
1599
  const plugin = runtimePlugins.get(target);
1598
1600
  try {
1599
1601
  if (plugin) await plugin.disable();
1600
- const pluginPath = path$1.join(getAbsPluginDir(), target);
1601
- if (!fs$1.existsSync(pluginPath)) {
1602
+ const pluginPath = ctx.path.join(getAbsPluginDir(), target);
1603
+ if (!ctx.fs.existsSync(pluginPath)) {
1602
1604
  await e.reply(`插件 ${target} 不存在`, true);
1603
1605
  return;
1604
1606
  }
1605
1607
  if (!plugin) isOff = true;
1606
- const importedPlugin = await jiti.import(pluginPath, { default: true });
1608
+ const importedPlugin = await ctx.jiti.import(pluginPath, { default: true });
1607
1609
  if (importedPlugin.name !== target) {
1608
1610
  const tip = `插件目录名称: ${target} 和插件代码中设置的 name: ${importedPlugin.name} 不一致,可能导致重载异常,请修改后重启。`;
1609
1611
  ctx.bot.logger.warn(tip);
@@ -1612,15 +1614,15 @@ const core = definePlugin({
1612
1614
  await enablePlugin(ctx.bot, importedPlugin);
1613
1615
  } catch (err) {
1614
1616
  await e.reply(err?.message, true);
1615
- await updateBotConfig((c) => c.plugins = c.plugins.filter((name) => name !== target));
1617
+ await ctx.updateBotConfig((c) => c.plugins = c.plugins.filter((name) => name !== target));
1616
1618
  break;
1617
1619
  }
1618
- await updateBotConfig((c) => c.plugins = [...c.plugins, target]);
1620
+ await ctx.updateBotConfig((c) => c.plugins = [...c.plugins, target]);
1619
1621
  await e.reply(`插件 ${target} 已${isOff ? "直接启用" : "重载"}`, true);
1620
1622
  break;
1621
1623
  }
1622
1624
  default:
1623
- await e.reply(dedent$1(`
1625
+ await e.reply(ctx.dedent(`
1624
1626
  〓 🧩 mioki 插件 〓
1625
1627
  ${displayPrefix}插件 列表
1626
1628
  ${displayPrefix}插件 启用 <插件 ID>
@@ -1633,11 +1635,11 @@ const core = definePlugin({
1633
1635
  case "设置":
1634
1636
  switch (subCmd) {
1635
1637
  case "详情":
1636
- await e.reply(dedent$1(`
1638
+ await e.reply(ctx.dedent(`
1637
1639
  〓 设置详情 〓
1638
- 主人: ${botConfig.owners.join(", ")}
1639
- 管理: ${botConfig.admins.join(", ").trim()}
1640
- 启用插件: ${botConfig.plugins.join(", ").trim()}
1640
+ 主人: ${ctx.botConfig.owners.join(", ")}
1641
+ 管理: ${ctx.botConfig.admins.join(", ").trim()}
1642
+ 启用插件: ${ctx.botConfig.plugins.join(", ").trim()}
1641
1643
  `).trim());
1642
1644
  break;
1643
1645
  case "加主人":
@@ -1648,11 +1650,11 @@ const core = definePlugin({
1648
1650
  await e.reply("请指定主人 QQ/AT", true);
1649
1651
  return;
1650
1652
  }
1651
- if (botConfig.owners.includes(uid)) {
1653
+ if (ctx.botConfig.owners.includes(uid)) {
1652
1654
  await e.reply(`主人 ${uid} 已存在`, true);
1653
1655
  return;
1654
1656
  }
1655
- await updateBotConfig((c) => c.owners = [...c.owners, uid]);
1657
+ await ctx.updateBotConfig((c) => c.owners = [...c.owners, uid]);
1656
1658
  await e.reply(`已添加主人 ${uid}`, true);
1657
1659
  break;
1658
1660
  }
@@ -1668,12 +1670,12 @@ const core = definePlugin({
1668
1670
  await e.reply("不能删除第一主人", true);
1669
1671
  return;
1670
1672
  }
1671
- const idx = botConfig.owners.indexOf(uid);
1673
+ const idx = ctx.botConfig.owners.indexOf(uid);
1672
1674
  if (idx === -1) {
1673
1675
  await e.reply(`主人 ${uid} 不存在`, true);
1674
1676
  return;
1675
1677
  }
1676
- await updateBotConfig((c) => c.owners.splice(idx, 1));
1678
+ await ctx.updateBotConfig((c) => c.owners.splice(idx, 1));
1677
1679
  await e.reply(`已删除主人 ${uid}`, true);
1678
1680
  break;
1679
1681
  }
@@ -1685,11 +1687,11 @@ const core = definePlugin({
1685
1687
  await e.reply("请指定管理 QQ/AT", true);
1686
1688
  return;
1687
1689
  }
1688
- if (botConfig.admins.includes(uid)) {
1690
+ if (ctx.botConfig.admins.includes(uid)) {
1689
1691
  await e.reply(`管理 ${uid} 已存在`, true);
1690
1692
  return;
1691
1693
  }
1692
- await updateBotConfig((c) => c.admins = [...c.admins, uid]);
1694
+ await ctx.updateBotConfig((c) => c.admins = [...c.admins, uid]);
1693
1695
  await e.reply(`已添加管理 ${uid}`, true);
1694
1696
  break;
1695
1697
  }
@@ -1701,17 +1703,17 @@ const core = definePlugin({
1701
1703
  await e.reply("请指定管理 QQ/AT", true);
1702
1704
  return;
1703
1705
  }
1704
- const idx = botConfig.admins.indexOf(uid);
1706
+ const idx = ctx.botConfig.admins.indexOf(uid);
1705
1707
  if (idx === -1) {
1706
1708
  await e.reply(`管理 ${uid} 不存在`, true);
1707
1709
  return;
1708
1710
  }
1709
- await updateBotConfig((c) => c.admins.splice(idx, 1));
1711
+ await ctx.updateBotConfig((c) => c.admins.splice(idx, 1));
1710
1712
  await e.reply(`已删除管理 ${uid}`, true);
1711
1713
  break;
1712
1714
  }
1713
1715
  default:
1714
- await e.reply(dedent$1(`
1716
+ await e.reply(ctx.dedent(`
1715
1717
  〓 ⚙️ mioki 设置 〓
1716
1718
  ${displayPrefix}设置 详情
1717
1719
  ${displayPrefix}设置 [加/删]主人 <QQ/AT>