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/cli.cjs CHANGED
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env node
2
- const require_package = require('./package-hrAht8He.cjs');
2
+ const require_package = require('./package-BDo4MHDy.cjs');
3
3
  let node_fs = require("node:fs");
4
4
  node_fs = require_package.__toESM(node_fs);
5
5
  let node_path = require("node:path");
package/dist/cli.mjs CHANGED
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env node
2
- import { t as version } from "./package-BUreTxqg.mjs";
2
+ import { t as version } from "./package-LmjT9AeF.mjs";
3
3
  import fs from "node:fs";
4
4
  import path from "node:path";
5
5
  import mri from "mri";
package/dist/index.cjs CHANGED
@@ -1,4 +1,4 @@
1
- const require_package = require('./package-hrAht8He.cjs');
1
+ const require_package = require('./package-BDo4MHDy.cjs');
2
2
  let node_fs = require("node:fs");
3
3
  node_fs = require_package.__toESM(node_fs);
4
4
  let node_util = require("node:util");
@@ -1431,9 +1431,9 @@ async function getMiokiStatusStr(client) {
1431
1431
  ${diskValid ? `💾 ${diskDesc}` : ""}
1432
1432
  `.trim();
1433
1433
  }
1434
- async function getDiskUsageInUnix(path$7 = "/") {
1434
+ async function getDiskUsageInUnix(path$6 = "/") {
1435
1435
  return new Promise((resolve) => {
1436
- node_child_process.default.exec(`df -k ${path$7} | tail -1 | awk '{print $2,$4}'`, (err, stdout) => {
1436
+ node_child_process.default.exec(`df -k ${path$6} | tail -1 | awk '{print $2,$4}'`, (err, stdout) => {
1437
1437
  if (err) {
1438
1438
  console.error(err);
1439
1439
  return resolve({
@@ -1489,12 +1489,13 @@ const corePlugins = ["mioki-core"];
1489
1489
  const core = definePlugin({
1490
1490
  name: "mioki-core",
1491
1491
  version: require_package.version,
1492
- priority: 1,
1492
+ priority: 8,
1493
1493
  setup(ctx) {
1494
1494
  const prefix = (ctx.botConfig.prefix ?? "#").replace(/[-_.^$?[\]{}]/g, "\\$&");
1495
1495
  const cmdPrefix = /* @__PURE__ */ new RegExp(`^${prefix}`);
1496
1496
  const displayPrefix = prefix.replace(/\\\\/g, "\\");
1497
1497
  const statusAdminOnly = ctx.botConfig.status_permission === "admin-only";
1498
+ const getStatusStr = () => ctx.isFunction(ctx.services.customMiokiStatusStr) ? ctx.services.customMiokiStatusStr() : getMiokiStatusStr(ctx.bot);
1498
1499
  ctx.addService("miokiStatus", () => getMiokiStatus(ctx.bot));
1499
1500
  ctx.addService("miokiStatusStr", () => getMiokiStatusStr(ctx.bot));
1500
1501
  ctx.handle("message", (e) => ctx.runWithErrorHandler(async () => {
@@ -1502,17 +1503,17 @@ const core = definePlugin({
1502
1503
  if (!cmdPrefix.test(text$1)) return;
1503
1504
  if (statusAdminOnly && !ctx.hasRight(e)) return;
1504
1505
  if (text$1.replace(cmdPrefix, "") === "状态") {
1505
- const status = await getMiokiStatusStr(ctx.bot);
1506
+ const status = await getStatusStr();
1506
1507
  await e.reply(`〓 🟢 mioki 状态 〓\n${status}`.trim());
1507
1508
  return;
1508
1509
  }
1509
1510
  if (!ctx.isOwner(e)) return;
1510
- const { _: params, ..._options } = (0, mri.default)((0, string2argv.string2argv)(text$1));
1511
- const cmd = params.shift()?.replace(cmdPrefix, "") ?? "";
1511
+ const { cmd, params, ..._options } = ctx.createCmd(text$1);
1512
+ if (!cmd) return;
1512
1513
  const [subCmd, target, ..._subParams] = params;
1513
- switch (cmd) {
1514
+ switch (cmd?.replace(/\s+/g, "")) {
1514
1515
  case "帮助":
1515
- await e.reply((0, dedent.default)(`
1516
+ await e.reply(ctx.dedent(`
1516
1517
  〓 💡 mioki 帮助 〓
1517
1518
  ${displayPrefix}插件 👉 框架插件管理
1518
1519
  ${displayPrefix}状态 👉 显示框架状态
@@ -1528,7 +1529,8 @@ const core = definePlugin({
1528
1529
  }
1529
1530
  switch (subCmd) {
1530
1531
  case "列表": {
1531
- const plugins = unique([...(await findLocalPlugins()).map((e$1) => e$1.name), ...runtimePlugins.keys()]).map((name) => {
1532
+ const localPlugins = await findLocalPlugins();
1533
+ const plugins = ctx.unique([...localPlugins.map((e$1) => e$1.name), ...runtimePlugins.keys()]).map((name) => {
1532
1534
  const isEnable = runtimePlugins.get(name);
1533
1535
  return `${isEnable ? "🟢" : "🔴"} ${isEnable && isEnable?.type === "builtin" ? "[内置]" : "[用户]"} ${name}`;
1534
1536
  }).toSorted((pre, next) => {
@@ -1541,7 +1543,7 @@ const core = definePlugin({
1541
1543
  const preWeight = weight(pre);
1542
1544
  return weight(next) - preWeight || pre.localeCompare(next);
1543
1545
  });
1544
- await e.reply((0, dedent.default)(`
1546
+ await e.reply(ctx.dedent(`
1545
1547
  〓 插件列表 〓
1546
1548
  ${plugins.join("\n")}
1547
1549
  共 ${plugins.length} 个,启用 ${runtimePlugins.size} 个
@@ -1557,13 +1559,13 @@ const core = definePlugin({
1557
1559
  await e.reply(`插件 ${target} 已经是启用状态`, true);
1558
1560
  return;
1559
1561
  }
1560
- const pluginPath = node_path.default.join(getAbsPluginDir(), target);
1561
- if (!node_fs.default.existsSync(pluginPath)) {
1562
+ const pluginPath = ctx.path.join(getAbsPluginDir(), target);
1563
+ if (!ctx.fs.existsSync(pluginPath)) {
1562
1564
  await e.reply(`插件 ${target} 不存在`, true);
1563
1565
  return;
1564
1566
  }
1565
1567
  try {
1566
- const plugin = await jiti$1.import(pluginPath, { default: true });
1568
+ const plugin = await ctx.jiti.import(pluginPath, { default: true });
1567
1569
  if (plugin.name !== target) {
1568
1570
  const tip = `[插件目录名称: ${target}] 和插件代码中设置的 [name: ${plugin.name}] 不一致,可能导致重载异常,请修改后重启。`;
1569
1571
  ctx.bot.logger.warn(tip);
@@ -1574,7 +1576,7 @@ const core = definePlugin({
1574
1576
  await e.reply(`插件 ${target} 启用失败:${err?.message || "未知错误"}`, true);
1575
1577
  return;
1576
1578
  }
1577
- await updateBotConfig((c) => c.plugins = [...botConfig.plugins, target]);
1579
+ await ctx.updateBotConfig((c) => c.plugins = [...ctx.botConfig.plugins, target]);
1578
1580
  await e.reply(`插件 ${target} 启用成功`, true);
1579
1581
  break;
1580
1582
  }
@@ -1594,7 +1596,7 @@ const core = definePlugin({
1594
1596
  await e.reply(err?.message, true);
1595
1597
  break;
1596
1598
  }
1597
- await updateBotConfig((c) => c.plugins = botConfig.plugins.filter((name) => name !== target));
1599
+ await ctx.updateBotConfig((c) => c.plugins = ctx.botConfig.plugins.filter((name) => name !== target));
1598
1600
  ctx.bot.logger.info(`禁用插件 => ${target}`);
1599
1601
  await e.reply(`插件 ${target} 已禁用`, true);
1600
1602
  break;
@@ -1608,13 +1610,13 @@ const core = definePlugin({
1608
1610
  const plugin = runtimePlugins.get(target);
1609
1611
  try {
1610
1612
  if (plugin) await plugin.disable();
1611
- const pluginPath = node_path.default.join(getAbsPluginDir(), target);
1612
- if (!node_fs.default.existsSync(pluginPath)) {
1613
+ const pluginPath = ctx.path.join(getAbsPluginDir(), target);
1614
+ if (!ctx.fs.existsSync(pluginPath)) {
1613
1615
  await e.reply(`插件 ${target} 不存在`, true);
1614
1616
  return;
1615
1617
  }
1616
1618
  if (!plugin) isOff = true;
1617
- const importedPlugin = await jiti$1.import(pluginPath, { default: true });
1619
+ const importedPlugin = await ctx.jiti.import(pluginPath, { default: true });
1618
1620
  if (importedPlugin.name !== target) {
1619
1621
  const tip = `插件目录名称: ${target} 和插件代码中设置的 name: ${importedPlugin.name} 不一致,可能导致重载异常,请修改后重启。`;
1620
1622
  ctx.bot.logger.warn(tip);
@@ -1623,15 +1625,15 @@ const core = definePlugin({
1623
1625
  await enablePlugin(ctx.bot, importedPlugin);
1624
1626
  } catch (err) {
1625
1627
  await e.reply(err?.message, true);
1626
- await updateBotConfig((c) => c.plugins = c.plugins.filter((name) => name !== target));
1628
+ await ctx.updateBotConfig((c) => c.plugins = c.plugins.filter((name) => name !== target));
1627
1629
  break;
1628
1630
  }
1629
- await updateBotConfig((c) => c.plugins = [...c.plugins, target]);
1631
+ await ctx.updateBotConfig((c) => c.plugins = [...c.plugins, target]);
1630
1632
  await e.reply(`插件 ${target} 已${isOff ? "直接启用" : "重载"}`, true);
1631
1633
  break;
1632
1634
  }
1633
1635
  default:
1634
- await e.reply((0, dedent.default)(`
1636
+ await e.reply(ctx.dedent(`
1635
1637
  〓 🧩 mioki 插件 〓
1636
1638
  ${displayPrefix}插件 列表
1637
1639
  ${displayPrefix}插件 启用 <插件 ID>
@@ -1644,11 +1646,11 @@ const core = definePlugin({
1644
1646
  case "设置":
1645
1647
  switch (subCmd) {
1646
1648
  case "详情":
1647
- await e.reply((0, dedent.default)(`
1649
+ await e.reply(ctx.dedent(`
1648
1650
  〓 设置详情 〓
1649
- 主人: ${botConfig.owners.join(", ")}
1650
- 管理: ${botConfig.admins.join(", ").trim()}
1651
- 启用插件: ${botConfig.plugins.join(", ").trim()}
1651
+ 主人: ${ctx.botConfig.owners.join(", ")}
1652
+ 管理: ${ctx.botConfig.admins.join(", ").trim()}
1653
+ 启用插件: ${ctx.botConfig.plugins.join(", ").trim()}
1652
1654
  `).trim());
1653
1655
  break;
1654
1656
  case "加主人":
@@ -1659,11 +1661,11 @@ const core = definePlugin({
1659
1661
  await e.reply("请指定主人 QQ/AT", true);
1660
1662
  return;
1661
1663
  }
1662
- if (botConfig.owners.includes(uid)) {
1664
+ if (ctx.botConfig.owners.includes(uid)) {
1663
1665
  await e.reply(`主人 ${uid} 已存在`, true);
1664
1666
  return;
1665
1667
  }
1666
- await updateBotConfig((c) => c.owners = [...c.owners, uid]);
1668
+ await ctx.updateBotConfig((c) => c.owners = [...c.owners, uid]);
1667
1669
  await e.reply(`已添加主人 ${uid}`, true);
1668
1670
  break;
1669
1671
  }
@@ -1679,12 +1681,12 @@ const core = definePlugin({
1679
1681
  await e.reply("不能删除第一主人", true);
1680
1682
  return;
1681
1683
  }
1682
- const idx = botConfig.owners.indexOf(uid);
1684
+ const idx = ctx.botConfig.owners.indexOf(uid);
1683
1685
  if (idx === -1) {
1684
1686
  await e.reply(`主人 ${uid} 不存在`, true);
1685
1687
  return;
1686
1688
  }
1687
- await updateBotConfig((c) => c.owners.splice(idx, 1));
1689
+ await ctx.updateBotConfig((c) => c.owners.splice(idx, 1));
1688
1690
  await e.reply(`已删除主人 ${uid}`, true);
1689
1691
  break;
1690
1692
  }
@@ -1696,11 +1698,11 @@ const core = definePlugin({
1696
1698
  await e.reply("请指定管理 QQ/AT", true);
1697
1699
  return;
1698
1700
  }
1699
- if (botConfig.admins.includes(uid)) {
1701
+ if (ctx.botConfig.admins.includes(uid)) {
1700
1702
  await e.reply(`管理 ${uid} 已存在`, true);
1701
1703
  return;
1702
1704
  }
1703
- await updateBotConfig((c) => c.admins = [...c.admins, uid]);
1705
+ await ctx.updateBotConfig((c) => c.admins = [...c.admins, uid]);
1704
1706
  await e.reply(`已添加管理 ${uid}`, true);
1705
1707
  break;
1706
1708
  }
@@ -1712,17 +1714,17 @@ const core = definePlugin({
1712
1714
  await e.reply("请指定管理 QQ/AT", true);
1713
1715
  return;
1714
1716
  }
1715
- const idx = botConfig.admins.indexOf(uid);
1717
+ const idx = ctx.botConfig.admins.indexOf(uid);
1716
1718
  if (idx === -1) {
1717
1719
  await e.reply(`管理 ${uid} 不存在`, true);
1718
1720
  return;
1719
1721
  }
1720
- await updateBotConfig((c) => c.admins.splice(idx, 1));
1722
+ await ctx.updateBotConfig((c) => c.admins.splice(idx, 1));
1721
1723
  await e.reply(`已删除管理 ${uid}`, true);
1722
1724
  break;
1723
1725
  }
1724
1726
  default:
1725
- await e.reply((0, dedent.default)(`
1727
+ await e.reply(ctx.dedent(`
1726
1728
  〓 ⚙️ mioki 设置 〓
1727
1729
  ${displayPrefix}设置 详情
1728
1730
  ${displayPrefix}设置 [加/删]主人 <QQ/AT>