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