mioki 0.9.1 → 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-CbQDT4KP.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,27 +1478,31 @@ 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
+ const statusAdminOnly = ctx.botConfig.status_permission === "admin-only";
1487
+ const getStatusStr = () => ctx.isFunction(ctx.services.customMiokiStatusStr) ? ctx.services.customMiokiStatusStr() : getMiokiStatusStr(ctx.bot);
1486
1488
  ctx.addService("miokiStatus", () => getMiokiStatus(ctx.bot));
1489
+ ctx.addService("miokiStatusStr", () => getMiokiStatusStr(ctx.bot));
1487
1490
  ctx.handle("message", (e) => ctx.runWithErrorHandler(async () => {
1488
1491
  const text$1 = ctx.text(e);
1489
1492
  if (!cmdPrefix.test(text$1)) return;
1493
+ if (statusAdminOnly && !ctx.hasRight(e)) return;
1490
1494
  if (text$1.replace(cmdPrefix, "") === "状态") {
1491
- const status = await getMiokiStatusStr(ctx.bot);
1495
+ const status = await getStatusStr();
1492
1496
  await e.reply(`〓 🟢 mioki 状态 〓\n${status}`.trim());
1493
1497
  return;
1494
1498
  }
1495
1499
  if (!ctx.isOwner(e)) return;
1496
- const { _: params, ..._options } = mri$1(string2argv$1(text$1));
1497
- const cmd = params.shift()?.replace(cmdPrefix, "") ?? "";
1500
+ const { cmd, params, ..._options } = ctx.createCmd(text$1);
1501
+ if (!cmd) return;
1498
1502
  const [subCmd, target, ..._subParams] = params;
1499
- switch (cmd) {
1503
+ switch (cmd?.replace(/\s+/g, "")) {
1500
1504
  case "帮助":
1501
- await e.reply(dedent$1(`
1505
+ await e.reply(ctx.dedent(`
1502
1506
  〓 💡 mioki 帮助 〓
1503
1507
  ${displayPrefix}插件 👉 框架插件管理
1504
1508
  ${displayPrefix}状态 👉 显示框架状态
@@ -1514,7 +1518,8 @@ const core = definePlugin({
1514
1518
  }
1515
1519
  switch (subCmd) {
1516
1520
  case "列表": {
1517
- 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) => {
1518
1523
  const isEnable = runtimePlugins.get(name);
1519
1524
  return `${isEnable ? "🟢" : "🔴"} ${isEnable && isEnable?.type === "builtin" ? "[内置]" : "[用户]"} ${name}`;
1520
1525
  }).toSorted((pre, next) => {
@@ -1527,7 +1532,7 @@ const core = definePlugin({
1527
1532
  const preWeight = weight(pre);
1528
1533
  return weight(next) - preWeight || pre.localeCompare(next);
1529
1534
  });
1530
- await e.reply(dedent$1(`
1535
+ await e.reply(ctx.dedent(`
1531
1536
  〓 插件列表 〓
1532
1537
  ${plugins.join("\n")}
1533
1538
  共 ${plugins.length} 个,启用 ${runtimePlugins.size} 个
@@ -1543,13 +1548,13 @@ const core = definePlugin({
1543
1548
  await e.reply(`插件 ${target} 已经是启用状态`, true);
1544
1549
  return;
1545
1550
  }
1546
- const pluginPath = path$1.join(getAbsPluginDir(), target);
1547
- if (!fs$1.existsSync(pluginPath)) {
1551
+ const pluginPath = ctx.path.join(getAbsPluginDir(), target);
1552
+ if (!ctx.fs.existsSync(pluginPath)) {
1548
1553
  await e.reply(`插件 ${target} 不存在`, true);
1549
1554
  return;
1550
1555
  }
1551
1556
  try {
1552
- const plugin = await jiti.import(pluginPath, { default: true });
1557
+ const plugin = await ctx.jiti.import(pluginPath, { default: true });
1553
1558
  if (plugin.name !== target) {
1554
1559
  const tip = `[插件目录名称: ${target}] 和插件代码中设置的 [name: ${plugin.name}] 不一致,可能导致重载异常,请修改后重启。`;
1555
1560
  ctx.bot.logger.warn(tip);
@@ -1560,7 +1565,7 @@ const core = definePlugin({
1560
1565
  await e.reply(`插件 ${target} 启用失败:${err?.message || "未知错误"}`, true);
1561
1566
  return;
1562
1567
  }
1563
- await updateBotConfig((c) => c.plugins = [...botConfig.plugins, target]);
1568
+ await ctx.updateBotConfig((c) => c.plugins = [...ctx.botConfig.plugins, target]);
1564
1569
  await e.reply(`插件 ${target} 启用成功`, true);
1565
1570
  break;
1566
1571
  }
@@ -1580,7 +1585,7 @@ const core = definePlugin({
1580
1585
  await e.reply(err?.message, true);
1581
1586
  break;
1582
1587
  }
1583
- 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));
1584
1589
  ctx.bot.logger.info(`禁用插件 => ${target}`);
1585
1590
  await e.reply(`插件 ${target} 已禁用`, true);
1586
1591
  break;
@@ -1594,13 +1599,13 @@ const core = definePlugin({
1594
1599
  const plugin = runtimePlugins.get(target);
1595
1600
  try {
1596
1601
  if (plugin) await plugin.disable();
1597
- const pluginPath = path$1.join(getAbsPluginDir(), target);
1598
- if (!fs$1.existsSync(pluginPath)) {
1602
+ const pluginPath = ctx.path.join(getAbsPluginDir(), target);
1603
+ if (!ctx.fs.existsSync(pluginPath)) {
1599
1604
  await e.reply(`插件 ${target} 不存在`, true);
1600
1605
  return;
1601
1606
  }
1602
1607
  if (!plugin) isOff = true;
1603
- const importedPlugin = await jiti.import(pluginPath, { default: true });
1608
+ const importedPlugin = await ctx.jiti.import(pluginPath, { default: true });
1604
1609
  if (importedPlugin.name !== target) {
1605
1610
  const tip = `插件目录名称: ${target} 和插件代码中设置的 name: ${importedPlugin.name} 不一致,可能导致重载异常,请修改后重启。`;
1606
1611
  ctx.bot.logger.warn(tip);
@@ -1609,15 +1614,15 @@ const core = definePlugin({
1609
1614
  await enablePlugin(ctx.bot, importedPlugin);
1610
1615
  } catch (err) {
1611
1616
  await e.reply(err?.message, true);
1612
- await updateBotConfig((c) => c.plugins = c.plugins.filter((name) => name !== target));
1617
+ await ctx.updateBotConfig((c) => c.plugins = c.plugins.filter((name) => name !== target));
1613
1618
  break;
1614
1619
  }
1615
- await updateBotConfig((c) => c.plugins = [...c.plugins, target]);
1620
+ await ctx.updateBotConfig((c) => c.plugins = [...c.plugins, target]);
1616
1621
  await e.reply(`插件 ${target} 已${isOff ? "直接启用" : "重载"}`, true);
1617
1622
  break;
1618
1623
  }
1619
1624
  default:
1620
- await e.reply(dedent$1(`
1625
+ await e.reply(ctx.dedent(`
1621
1626
  〓 🧩 mioki 插件 〓
1622
1627
  ${displayPrefix}插件 列表
1623
1628
  ${displayPrefix}插件 启用 <插件 ID>
@@ -1630,11 +1635,11 @@ const core = definePlugin({
1630
1635
  case "设置":
1631
1636
  switch (subCmd) {
1632
1637
  case "详情":
1633
- await e.reply(dedent$1(`
1638
+ await e.reply(ctx.dedent(`
1634
1639
  〓 设置详情 〓
1635
- 主人: ${botConfig.owners.join(", ")}
1636
- 管理: ${botConfig.admins.join(", ").trim()}
1637
- 启用插件: ${botConfig.plugins.join(", ").trim()}
1640
+ 主人: ${ctx.botConfig.owners.join(", ")}
1641
+ 管理: ${ctx.botConfig.admins.join(", ").trim()}
1642
+ 启用插件: ${ctx.botConfig.plugins.join(", ").trim()}
1638
1643
  `).trim());
1639
1644
  break;
1640
1645
  case "加主人":
@@ -1645,11 +1650,11 @@ const core = definePlugin({
1645
1650
  await e.reply("请指定主人 QQ/AT", true);
1646
1651
  return;
1647
1652
  }
1648
- if (botConfig.owners.includes(uid)) {
1653
+ if (ctx.botConfig.owners.includes(uid)) {
1649
1654
  await e.reply(`主人 ${uid} 已存在`, true);
1650
1655
  return;
1651
1656
  }
1652
- await updateBotConfig((c) => c.owners = [...c.owners, uid]);
1657
+ await ctx.updateBotConfig((c) => c.owners = [...c.owners, uid]);
1653
1658
  await e.reply(`已添加主人 ${uid}`, true);
1654
1659
  break;
1655
1660
  }
@@ -1665,12 +1670,12 @@ const core = definePlugin({
1665
1670
  await e.reply("不能删除第一主人", true);
1666
1671
  return;
1667
1672
  }
1668
- const idx = botConfig.owners.indexOf(uid);
1673
+ const idx = ctx.botConfig.owners.indexOf(uid);
1669
1674
  if (idx === -1) {
1670
1675
  await e.reply(`主人 ${uid} 不存在`, true);
1671
1676
  return;
1672
1677
  }
1673
- await updateBotConfig((c) => c.owners.splice(idx, 1));
1678
+ await ctx.updateBotConfig((c) => c.owners.splice(idx, 1));
1674
1679
  await e.reply(`已删除主人 ${uid}`, true);
1675
1680
  break;
1676
1681
  }
@@ -1682,11 +1687,11 @@ const core = definePlugin({
1682
1687
  await e.reply("请指定管理 QQ/AT", true);
1683
1688
  return;
1684
1689
  }
1685
- if (botConfig.admins.includes(uid)) {
1690
+ if (ctx.botConfig.admins.includes(uid)) {
1686
1691
  await e.reply(`管理 ${uid} 已存在`, true);
1687
1692
  return;
1688
1693
  }
1689
- await updateBotConfig((c) => c.admins = [...c.admins, uid]);
1694
+ await ctx.updateBotConfig((c) => c.admins = [...c.admins, uid]);
1690
1695
  await e.reply(`已添加管理 ${uid}`, true);
1691
1696
  break;
1692
1697
  }
@@ -1698,17 +1703,17 @@ const core = definePlugin({
1698
1703
  await e.reply("请指定管理 QQ/AT", true);
1699
1704
  return;
1700
1705
  }
1701
- const idx = botConfig.admins.indexOf(uid);
1706
+ const idx = ctx.botConfig.admins.indexOf(uid);
1702
1707
  if (idx === -1) {
1703
1708
  await e.reply(`管理 ${uid} 不存在`, true);
1704
1709
  return;
1705
1710
  }
1706
- await updateBotConfig((c) => c.admins.splice(idx, 1));
1711
+ await ctx.updateBotConfig((c) => c.admins.splice(idx, 1));
1707
1712
  await e.reply(`已删除管理 ${uid}`, true);
1708
1713
  break;
1709
1714
  }
1710
1715
  default:
1711
- await e.reply(dedent$1(`
1716
+ await e.reply(ctx.dedent(`
1712
1717
  〓 ⚙️ mioki 设置 〓
1713
1718
  ${displayPrefix}设置 详情
1714
1719
  ${displayPrefix}设置 [加/删]主人 <QQ/AT>