mioki 0.9.2 → 0.10.0

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-C9ZLKmlF.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-HADFnNFP.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-C9ZLKmlF.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");
@@ -1403,8 +1403,8 @@ async function getMiokiStatus(bot) {
1403
1403
  }
1404
1404
  };
1405
1405
  }
1406
- async function getMiokiStatusStr(client) {
1407
- const { bot, plugins, stats, system, disk, cpu, memory, versions } = await getMiokiStatus(client);
1406
+ async function formatMiokiStatus(status) {
1407
+ const { bot, plugins, stats, system, disk, cpu, memory, versions } = status;
1408
1408
  const diskValid = disk.total > 0 && disk.free >= 0;
1409
1409
  const diskDesc = `${disk.percent}%-${(0, filesize.filesize)(disk.used, { round: 1 })}/${(0, filesize.filesize)(disk.total, { round: 1 })}`;
1410
1410
  return `
@@ -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,30 +1489,34 @@ 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
- ctx.addService("miokiStatus", () => getMiokiStatus(ctx.bot));
1499
- ctx.addService("miokiStatusStr", () => getMiokiStatusStr(ctx.bot));
1498
+ let statusFormatter = (status) => formatMiokiStatus(status);
1499
+ ctx.addService("getMiokiStatus", () => getMiokiStatus(ctx.bot));
1500
+ ctx.addService("formatMiokiStatus", formatMiokiStatus);
1501
+ ctx.addService("customFormatMiokiStatus", (formatter) => {
1502
+ statusFormatter = formatter;
1503
+ });
1500
1504
  ctx.handle("message", (e) => ctx.runWithErrorHandler(async () => {
1501
1505
  const text$1 = ctx.text(e);
1502
1506
  if (!cmdPrefix.test(text$1)) return;
1503
1507
  if (statusAdminOnly && !ctx.hasRight(e)) return;
1504
1508
  if (text$1.replace(cmdPrefix, "") === "状态") {
1505
- const status = await getMiokiStatusStr(ctx.bot);
1509
+ const status = await statusFormatter(await getMiokiStatus(ctx.bot));
1506
1510
  await e.reply(`〓 🟢 mioki 状态 〓\n${status}`.trim());
1507
1511
  return;
1508
1512
  }
1509
1513
  if (!ctx.isOwner(e)) return;
1510
- const { _: params, ..._options } = (0, mri.default)((0, string2argv.string2argv)(text$1));
1511
- const cmd = params.shift()?.replace(cmdPrefix, "") ?? "";
1514
+ const { cmd, params, ..._options } = ctx.createCmd(text$1);
1515
+ if (!cmd) return;
1512
1516
  const [subCmd, target, ..._subParams] = params;
1513
- switch (cmd) {
1517
+ switch (cmd?.replace(/\s+/g, "")) {
1514
1518
  case "帮助":
1515
- await e.reply((0, dedent.default)(`
1519
+ await e.reply(ctx.dedent(`
1516
1520
  〓 💡 mioki 帮助 〓
1517
1521
  ${displayPrefix}插件 👉 框架插件管理
1518
1522
  ${displayPrefix}状态 👉 显示框架状态
@@ -1528,7 +1532,8 @@ const core = definePlugin({
1528
1532
  }
1529
1533
  switch (subCmd) {
1530
1534
  case "列表": {
1531
- const plugins = unique([...(await findLocalPlugins()).map((e$1) => e$1.name), ...runtimePlugins.keys()]).map((name) => {
1535
+ const localPlugins = await findLocalPlugins();
1536
+ const plugins = ctx.unique([...localPlugins.map((e$1) => e$1.name), ...runtimePlugins.keys()]).map((name) => {
1532
1537
  const isEnable = runtimePlugins.get(name);
1533
1538
  return `${isEnable ? "🟢" : "🔴"} ${isEnable && isEnable?.type === "builtin" ? "[内置]" : "[用户]"} ${name}`;
1534
1539
  }).toSorted((pre, next) => {
@@ -1541,7 +1546,7 @@ const core = definePlugin({
1541
1546
  const preWeight = weight(pre);
1542
1547
  return weight(next) - preWeight || pre.localeCompare(next);
1543
1548
  });
1544
- await e.reply((0, dedent.default)(`
1549
+ await e.reply(ctx.dedent(`
1545
1550
  〓 插件列表 〓
1546
1551
  ${plugins.join("\n")}
1547
1552
  共 ${plugins.length} 个,启用 ${runtimePlugins.size} 个
@@ -1557,13 +1562,13 @@ const core = definePlugin({
1557
1562
  await e.reply(`插件 ${target} 已经是启用状态`, true);
1558
1563
  return;
1559
1564
  }
1560
- const pluginPath = node_path.default.join(getAbsPluginDir(), target);
1561
- if (!node_fs.default.existsSync(pluginPath)) {
1565
+ const pluginPath = ctx.path.join(getAbsPluginDir(), target);
1566
+ if (!ctx.fs.existsSync(pluginPath)) {
1562
1567
  await e.reply(`插件 ${target} 不存在`, true);
1563
1568
  return;
1564
1569
  }
1565
1570
  try {
1566
- const plugin = await jiti$1.import(pluginPath, { default: true });
1571
+ const plugin = await ctx.jiti.import(pluginPath, { default: true });
1567
1572
  if (plugin.name !== target) {
1568
1573
  const tip = `[插件目录名称: ${target}] 和插件代码中设置的 [name: ${plugin.name}] 不一致,可能导致重载异常,请修改后重启。`;
1569
1574
  ctx.bot.logger.warn(tip);
@@ -1574,7 +1579,7 @@ const core = definePlugin({
1574
1579
  await e.reply(`插件 ${target} 启用失败:${err?.message || "未知错误"}`, true);
1575
1580
  return;
1576
1581
  }
1577
- await updateBotConfig((c) => c.plugins = [...botConfig.plugins, target]);
1582
+ await ctx.updateBotConfig((c) => c.plugins = [...ctx.botConfig.plugins, target]);
1578
1583
  await e.reply(`插件 ${target} 启用成功`, true);
1579
1584
  break;
1580
1585
  }
@@ -1594,7 +1599,7 @@ const core = definePlugin({
1594
1599
  await e.reply(err?.message, true);
1595
1600
  break;
1596
1601
  }
1597
- await updateBotConfig((c) => c.plugins = botConfig.plugins.filter((name) => name !== target));
1602
+ await ctx.updateBotConfig((c) => c.plugins = ctx.botConfig.plugins.filter((name) => name !== target));
1598
1603
  ctx.bot.logger.info(`禁用插件 => ${target}`);
1599
1604
  await e.reply(`插件 ${target} 已禁用`, true);
1600
1605
  break;
@@ -1608,13 +1613,13 @@ const core = definePlugin({
1608
1613
  const plugin = runtimePlugins.get(target);
1609
1614
  try {
1610
1615
  if (plugin) await plugin.disable();
1611
- const pluginPath = node_path.default.join(getAbsPluginDir(), target);
1612
- if (!node_fs.default.existsSync(pluginPath)) {
1616
+ const pluginPath = ctx.path.join(getAbsPluginDir(), target);
1617
+ if (!ctx.fs.existsSync(pluginPath)) {
1613
1618
  await e.reply(`插件 ${target} 不存在`, true);
1614
1619
  return;
1615
1620
  }
1616
1621
  if (!plugin) isOff = true;
1617
- const importedPlugin = await jiti$1.import(pluginPath, { default: true });
1622
+ const importedPlugin = await ctx.jiti.import(pluginPath, { default: true });
1618
1623
  if (importedPlugin.name !== target) {
1619
1624
  const tip = `插件目录名称: ${target} 和插件代码中设置的 name: ${importedPlugin.name} 不一致,可能导致重载异常,请修改后重启。`;
1620
1625
  ctx.bot.logger.warn(tip);
@@ -1623,15 +1628,15 @@ const core = definePlugin({
1623
1628
  await enablePlugin(ctx.bot, importedPlugin);
1624
1629
  } catch (err) {
1625
1630
  await e.reply(err?.message, true);
1626
- await updateBotConfig((c) => c.plugins = c.plugins.filter((name) => name !== target));
1631
+ await ctx.updateBotConfig((c) => c.plugins = c.plugins.filter((name) => name !== target));
1627
1632
  break;
1628
1633
  }
1629
- await updateBotConfig((c) => c.plugins = [...c.plugins, target]);
1634
+ await ctx.updateBotConfig((c) => c.plugins = [...c.plugins, target]);
1630
1635
  await e.reply(`插件 ${target} 已${isOff ? "直接启用" : "重载"}`, true);
1631
1636
  break;
1632
1637
  }
1633
1638
  default:
1634
- await e.reply((0, dedent.default)(`
1639
+ await e.reply(ctx.dedent(`
1635
1640
  〓 🧩 mioki 插件 〓
1636
1641
  ${displayPrefix}插件 列表
1637
1642
  ${displayPrefix}插件 启用 <插件 ID>
@@ -1644,11 +1649,11 @@ const core = definePlugin({
1644
1649
  case "设置":
1645
1650
  switch (subCmd) {
1646
1651
  case "详情":
1647
- await e.reply((0, dedent.default)(`
1652
+ await e.reply(ctx.dedent(`
1648
1653
  〓 设置详情 〓
1649
- 主人: ${botConfig.owners.join(", ")}
1650
- 管理: ${botConfig.admins.join(", ").trim()}
1651
- 启用插件: ${botConfig.plugins.join(", ").trim()}
1654
+ 主人: ${ctx.botConfig.owners.join(", ")}
1655
+ 管理: ${ctx.botConfig.admins.join(", ").trim()}
1656
+ 启用插件: ${ctx.botConfig.plugins.join(", ").trim()}
1652
1657
  `).trim());
1653
1658
  break;
1654
1659
  case "加主人":
@@ -1659,11 +1664,11 @@ const core = definePlugin({
1659
1664
  await e.reply("请指定主人 QQ/AT", true);
1660
1665
  return;
1661
1666
  }
1662
- if (botConfig.owners.includes(uid)) {
1667
+ if (ctx.botConfig.owners.includes(uid)) {
1663
1668
  await e.reply(`主人 ${uid} 已存在`, true);
1664
1669
  return;
1665
1670
  }
1666
- await updateBotConfig((c) => c.owners = [...c.owners, uid]);
1671
+ await ctx.updateBotConfig((c) => c.owners = [...c.owners, uid]);
1667
1672
  await e.reply(`已添加主人 ${uid}`, true);
1668
1673
  break;
1669
1674
  }
@@ -1679,12 +1684,12 @@ const core = definePlugin({
1679
1684
  await e.reply("不能删除第一主人", true);
1680
1685
  return;
1681
1686
  }
1682
- const idx = botConfig.owners.indexOf(uid);
1687
+ const idx = ctx.botConfig.owners.indexOf(uid);
1683
1688
  if (idx === -1) {
1684
1689
  await e.reply(`主人 ${uid} 不存在`, true);
1685
1690
  return;
1686
1691
  }
1687
- await updateBotConfig((c) => c.owners.splice(idx, 1));
1692
+ await ctx.updateBotConfig((c) => c.owners.splice(idx, 1));
1688
1693
  await e.reply(`已删除主人 ${uid}`, true);
1689
1694
  break;
1690
1695
  }
@@ -1696,11 +1701,11 @@ const core = definePlugin({
1696
1701
  await e.reply("请指定管理 QQ/AT", true);
1697
1702
  return;
1698
1703
  }
1699
- if (botConfig.admins.includes(uid)) {
1704
+ if (ctx.botConfig.admins.includes(uid)) {
1700
1705
  await e.reply(`管理 ${uid} 已存在`, true);
1701
1706
  return;
1702
1707
  }
1703
- await updateBotConfig((c) => c.admins = [...c.admins, uid]);
1708
+ await ctx.updateBotConfig((c) => c.admins = [...c.admins, uid]);
1704
1709
  await e.reply(`已添加管理 ${uid}`, true);
1705
1710
  break;
1706
1711
  }
@@ -1712,17 +1717,17 @@ const core = definePlugin({
1712
1717
  await e.reply("请指定管理 QQ/AT", true);
1713
1718
  return;
1714
1719
  }
1715
- const idx = botConfig.admins.indexOf(uid);
1720
+ const idx = ctx.botConfig.admins.indexOf(uid);
1716
1721
  if (idx === -1) {
1717
1722
  await e.reply(`管理 ${uid} 不存在`, true);
1718
1723
  return;
1719
1724
  }
1720
- await updateBotConfig((c) => c.admins.splice(idx, 1));
1725
+ await ctx.updateBotConfig((c) => c.admins.splice(idx, 1));
1721
1726
  await e.reply(`已删除管理 ${uid}`, true);
1722
1727
  break;
1723
1728
  }
1724
1729
  default:
1725
- await e.reply((0, dedent.default)(`
1730
+ await e.reply(ctx.dedent(`
1726
1731
  〓 ⚙️ mioki 设置 〓
1727
1732
  ${displayPrefix}设置 详情
1728
1733
  ${displayPrefix}设置 [加/删]主人 <QQ/AT>