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 +1 -1
- package/dist/cli.mjs +1 -1
- package/dist/index.cjs +44 -39
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +247 -245
- package/dist/index.d.mts +247 -245
- package/dist/index.mjs +45 -40
- package/dist/index.mjs.map +1 -1
- package/dist/{package-hrAht8He.cjs → package-C9ZLKmlF.cjs} +2 -2
- package/dist/package-C9ZLKmlF.cjs.map +1 -0
- package/dist/package-HADFnNFP.mjs +6 -0
- package/dist/package-HADFnNFP.mjs.map +1 -0
- package/package.json +2 -2
- package/dist/package-BUreTxqg.mjs +0 -6
- package/dist/package-BUreTxqg.mjs.map +0 -1
- package/dist/package-hrAht8He.cjs.map +0 -1
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-
|
|
2
|
+
import { t as version } from "./package-HADFnNFP.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";
|
|
@@ -11,10 +11,10 @@ import { createJiti } from "jiti";
|
|
|
11
11
|
import { string2argv, string2argv as string2argv$1 } from "string2argv";
|
|
12
12
|
import { fileURLToPath } from "node:url";
|
|
13
13
|
import { NapCat, segment } from "napcat-sdk";
|
|
14
|
-
import
|
|
14
|
+
import prettyMs from "pretty-ms";
|
|
15
15
|
import { filesize } from "filesize";
|
|
16
16
|
import dayjs from "dayjs";
|
|
17
|
-
import 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";
|
|
@@ -1392,8 +1392,8 @@ async function getMiokiStatus(bot) {
|
|
|
1392
1392
|
}
|
|
1393
1393
|
};
|
|
1394
1394
|
}
|
|
1395
|
-
async function
|
|
1396
|
-
const { bot, plugins, stats, system, disk, cpu, memory, versions } =
|
|
1395
|
+
async function formatMiokiStatus(status) {
|
|
1396
|
+
const { bot, plugins, stats, system, disk, cpu, memory, versions } = status;
|
|
1397
1397
|
const diskValid = disk.total > 0 && disk.free >= 0;
|
|
1398
1398
|
const diskDesc = `${disk.percent}%-${filesize(disk.used, { round: 1 })}/${filesize(disk.total, { round: 1 })}`;
|
|
1399
1399
|
return `
|
|
@@ -1403,7 +1403,7 @@ async function getMiokiStatusStr(client) {
|
|
|
1403
1403
|
🧩 启用了 ${localNum(plugins.enabled)} 个插件,共 ${localNum(plugins.total)} 个
|
|
1404
1404
|
📮 收 ${localNum(stats.receive)} 条,发 ${localNum(stats.send)} 条
|
|
1405
1405
|
🚀 ${filesize(memory.rss.used, { round: 1 })}/${memory.percent}%
|
|
1406
|
-
⏳ 已运行 ${
|
|
1406
|
+
⏳ 已运行 ${prettyMs(stats.uptime, {
|
|
1407
1407
|
hideYear: true,
|
|
1408
1408
|
secondsDecimalDigits: 0
|
|
1409
1409
|
})}
|
|
@@ -1478,30 +1478,34 @@ const corePlugins = ["mioki-core"];
|
|
|
1478
1478
|
const core = definePlugin({
|
|
1479
1479
|
name: "mioki-core",
|
|
1480
1480
|
version,
|
|
1481
|
-
priority:
|
|
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
|
-
|
|
1488
|
-
ctx.addService("
|
|
1487
|
+
let statusFormatter = (status) => formatMiokiStatus(status);
|
|
1488
|
+
ctx.addService("getMiokiStatus", () => getMiokiStatus(ctx.bot));
|
|
1489
|
+
ctx.addService("formatMiokiStatus", formatMiokiStatus);
|
|
1490
|
+
ctx.addService("customFormatMiokiStatus", (formatter) => {
|
|
1491
|
+
statusFormatter = formatter;
|
|
1492
|
+
});
|
|
1489
1493
|
ctx.handle("message", (e) => ctx.runWithErrorHandler(async () => {
|
|
1490
1494
|
const text$1 = ctx.text(e);
|
|
1491
1495
|
if (!cmdPrefix.test(text$1)) return;
|
|
1492
1496
|
if (statusAdminOnly && !ctx.hasRight(e)) return;
|
|
1493
1497
|
if (text$1.replace(cmdPrefix, "") === "状态") {
|
|
1494
|
-
const status = await
|
|
1498
|
+
const status = await statusFormatter(await getMiokiStatus(ctx.bot));
|
|
1495
1499
|
await e.reply(`〓 🟢 mioki 状态 〓\n${status}`.trim());
|
|
1496
1500
|
return;
|
|
1497
1501
|
}
|
|
1498
1502
|
if (!ctx.isOwner(e)) return;
|
|
1499
|
-
const {
|
|
1500
|
-
|
|
1503
|
+
const { cmd, params, ..._options } = ctx.createCmd(text$1);
|
|
1504
|
+
if (!cmd) return;
|
|
1501
1505
|
const [subCmd, target, ..._subParams] = params;
|
|
1502
|
-
switch (cmd) {
|
|
1506
|
+
switch (cmd?.replace(/\s+/g, "")) {
|
|
1503
1507
|
case "帮助":
|
|
1504
|
-
await e.reply(dedent
|
|
1508
|
+
await e.reply(ctx.dedent(`
|
|
1505
1509
|
〓 💡 mioki 帮助 〓
|
|
1506
1510
|
${displayPrefix}插件 👉 框架插件管理
|
|
1507
1511
|
${displayPrefix}状态 👉 显示框架状态
|
|
@@ -1517,7 +1521,8 @@ const core = definePlugin({
|
|
|
1517
1521
|
}
|
|
1518
1522
|
switch (subCmd) {
|
|
1519
1523
|
case "列表": {
|
|
1520
|
-
const
|
|
1524
|
+
const localPlugins = await findLocalPlugins();
|
|
1525
|
+
const plugins = ctx.unique([...localPlugins.map((e$1) => e$1.name), ...runtimePlugins.keys()]).map((name) => {
|
|
1521
1526
|
const isEnable = runtimePlugins.get(name);
|
|
1522
1527
|
return `${isEnable ? "🟢" : "🔴"} ${isEnable && isEnable?.type === "builtin" ? "[内置]" : "[用户]"} ${name}`;
|
|
1523
1528
|
}).toSorted((pre, next) => {
|
|
@@ -1530,7 +1535,7 @@ const core = definePlugin({
|
|
|
1530
1535
|
const preWeight = weight(pre);
|
|
1531
1536
|
return weight(next) - preWeight || pre.localeCompare(next);
|
|
1532
1537
|
});
|
|
1533
|
-
await e.reply(dedent
|
|
1538
|
+
await e.reply(ctx.dedent(`
|
|
1534
1539
|
〓 插件列表 〓
|
|
1535
1540
|
${plugins.join("\n")}
|
|
1536
1541
|
共 ${plugins.length} 个,启用 ${runtimePlugins.size} 个
|
|
@@ -1546,13 +1551,13 @@ const core = definePlugin({
|
|
|
1546
1551
|
await e.reply(`插件 ${target} 已经是启用状态`, true);
|
|
1547
1552
|
return;
|
|
1548
1553
|
}
|
|
1549
|
-
const pluginPath = path
|
|
1550
|
-
if (!fs
|
|
1554
|
+
const pluginPath = ctx.path.join(getAbsPluginDir(), target);
|
|
1555
|
+
if (!ctx.fs.existsSync(pluginPath)) {
|
|
1551
1556
|
await e.reply(`插件 ${target} 不存在`, true);
|
|
1552
1557
|
return;
|
|
1553
1558
|
}
|
|
1554
1559
|
try {
|
|
1555
|
-
const plugin = await jiti.import(pluginPath, { default: true });
|
|
1560
|
+
const plugin = await ctx.jiti.import(pluginPath, { default: true });
|
|
1556
1561
|
if (plugin.name !== target) {
|
|
1557
1562
|
const tip = `[插件目录名称: ${target}] 和插件代码中设置的 [name: ${plugin.name}] 不一致,可能导致重载异常,请修改后重启。`;
|
|
1558
1563
|
ctx.bot.logger.warn(tip);
|
|
@@ -1563,7 +1568,7 @@ const core = definePlugin({
|
|
|
1563
1568
|
await e.reply(`插件 ${target} 启用失败:${err?.message || "未知错误"}`, true);
|
|
1564
1569
|
return;
|
|
1565
1570
|
}
|
|
1566
|
-
await updateBotConfig((c) => c.plugins = [...botConfig.plugins, target]);
|
|
1571
|
+
await ctx.updateBotConfig((c) => c.plugins = [...ctx.botConfig.plugins, target]);
|
|
1567
1572
|
await e.reply(`插件 ${target} 启用成功`, true);
|
|
1568
1573
|
break;
|
|
1569
1574
|
}
|
|
@@ -1583,7 +1588,7 @@ const core = definePlugin({
|
|
|
1583
1588
|
await e.reply(err?.message, true);
|
|
1584
1589
|
break;
|
|
1585
1590
|
}
|
|
1586
|
-
await updateBotConfig((c) => c.plugins = botConfig.plugins.filter((name) => name !== target));
|
|
1591
|
+
await ctx.updateBotConfig((c) => c.plugins = ctx.botConfig.plugins.filter((name) => name !== target));
|
|
1587
1592
|
ctx.bot.logger.info(`禁用插件 => ${target}`);
|
|
1588
1593
|
await e.reply(`插件 ${target} 已禁用`, true);
|
|
1589
1594
|
break;
|
|
@@ -1597,13 +1602,13 @@ const core = definePlugin({
|
|
|
1597
1602
|
const plugin = runtimePlugins.get(target);
|
|
1598
1603
|
try {
|
|
1599
1604
|
if (plugin) await plugin.disable();
|
|
1600
|
-
const pluginPath = path
|
|
1601
|
-
if (!fs
|
|
1605
|
+
const pluginPath = ctx.path.join(getAbsPluginDir(), target);
|
|
1606
|
+
if (!ctx.fs.existsSync(pluginPath)) {
|
|
1602
1607
|
await e.reply(`插件 ${target} 不存在`, true);
|
|
1603
1608
|
return;
|
|
1604
1609
|
}
|
|
1605
1610
|
if (!plugin) isOff = true;
|
|
1606
|
-
const importedPlugin = await jiti.import(pluginPath, { default: true });
|
|
1611
|
+
const importedPlugin = await ctx.jiti.import(pluginPath, { default: true });
|
|
1607
1612
|
if (importedPlugin.name !== target) {
|
|
1608
1613
|
const tip = `插件目录名称: ${target} 和插件代码中设置的 name: ${importedPlugin.name} 不一致,可能导致重载异常,请修改后重启。`;
|
|
1609
1614
|
ctx.bot.logger.warn(tip);
|
|
@@ -1612,15 +1617,15 @@ const core = definePlugin({
|
|
|
1612
1617
|
await enablePlugin(ctx.bot, importedPlugin);
|
|
1613
1618
|
} catch (err) {
|
|
1614
1619
|
await e.reply(err?.message, true);
|
|
1615
|
-
await updateBotConfig((c) => c.plugins = c.plugins.filter((name) => name !== target));
|
|
1620
|
+
await ctx.updateBotConfig((c) => c.plugins = c.plugins.filter((name) => name !== target));
|
|
1616
1621
|
break;
|
|
1617
1622
|
}
|
|
1618
|
-
await updateBotConfig((c) => c.plugins = [...c.plugins, target]);
|
|
1623
|
+
await ctx.updateBotConfig((c) => c.plugins = [...c.plugins, target]);
|
|
1619
1624
|
await e.reply(`插件 ${target} 已${isOff ? "直接启用" : "重载"}`, true);
|
|
1620
1625
|
break;
|
|
1621
1626
|
}
|
|
1622
1627
|
default:
|
|
1623
|
-
await e.reply(dedent
|
|
1628
|
+
await e.reply(ctx.dedent(`
|
|
1624
1629
|
〓 🧩 mioki 插件 〓
|
|
1625
1630
|
${displayPrefix}插件 列表
|
|
1626
1631
|
${displayPrefix}插件 启用 <插件 ID>
|
|
@@ -1633,11 +1638,11 @@ const core = definePlugin({
|
|
|
1633
1638
|
case "设置":
|
|
1634
1639
|
switch (subCmd) {
|
|
1635
1640
|
case "详情":
|
|
1636
|
-
await e.reply(dedent
|
|
1641
|
+
await e.reply(ctx.dedent(`
|
|
1637
1642
|
〓 设置详情 〓
|
|
1638
|
-
主人: ${botConfig.owners.join(", ")}
|
|
1639
|
-
管理: ${botConfig.admins.join(", ").trim()}
|
|
1640
|
-
启用插件: ${botConfig.plugins.join(", ").trim()}
|
|
1643
|
+
主人: ${ctx.botConfig.owners.join(", ")}
|
|
1644
|
+
管理: ${ctx.botConfig.admins.join(", ").trim()}
|
|
1645
|
+
启用插件: ${ctx.botConfig.plugins.join(", ").trim()}
|
|
1641
1646
|
`).trim());
|
|
1642
1647
|
break;
|
|
1643
1648
|
case "加主人":
|
|
@@ -1648,11 +1653,11 @@ const core = definePlugin({
|
|
|
1648
1653
|
await e.reply("请指定主人 QQ/AT", true);
|
|
1649
1654
|
return;
|
|
1650
1655
|
}
|
|
1651
|
-
if (botConfig.owners.includes(uid)) {
|
|
1656
|
+
if (ctx.botConfig.owners.includes(uid)) {
|
|
1652
1657
|
await e.reply(`主人 ${uid} 已存在`, true);
|
|
1653
1658
|
return;
|
|
1654
1659
|
}
|
|
1655
|
-
await updateBotConfig((c) => c.owners = [...c.owners, uid]);
|
|
1660
|
+
await ctx.updateBotConfig((c) => c.owners = [...c.owners, uid]);
|
|
1656
1661
|
await e.reply(`已添加主人 ${uid}`, true);
|
|
1657
1662
|
break;
|
|
1658
1663
|
}
|
|
@@ -1668,12 +1673,12 @@ const core = definePlugin({
|
|
|
1668
1673
|
await e.reply("不能删除第一主人", true);
|
|
1669
1674
|
return;
|
|
1670
1675
|
}
|
|
1671
|
-
const idx = botConfig.owners.indexOf(uid);
|
|
1676
|
+
const idx = ctx.botConfig.owners.indexOf(uid);
|
|
1672
1677
|
if (idx === -1) {
|
|
1673
1678
|
await e.reply(`主人 ${uid} 不存在`, true);
|
|
1674
1679
|
return;
|
|
1675
1680
|
}
|
|
1676
|
-
await updateBotConfig((c) => c.owners.splice(idx, 1));
|
|
1681
|
+
await ctx.updateBotConfig((c) => c.owners.splice(idx, 1));
|
|
1677
1682
|
await e.reply(`已删除主人 ${uid}`, true);
|
|
1678
1683
|
break;
|
|
1679
1684
|
}
|
|
@@ -1685,11 +1690,11 @@ const core = definePlugin({
|
|
|
1685
1690
|
await e.reply("请指定管理 QQ/AT", true);
|
|
1686
1691
|
return;
|
|
1687
1692
|
}
|
|
1688
|
-
if (botConfig.admins.includes(uid)) {
|
|
1693
|
+
if (ctx.botConfig.admins.includes(uid)) {
|
|
1689
1694
|
await e.reply(`管理 ${uid} 已存在`, true);
|
|
1690
1695
|
return;
|
|
1691
1696
|
}
|
|
1692
|
-
await updateBotConfig((c) => c.admins = [...c.admins, uid]);
|
|
1697
|
+
await ctx.updateBotConfig((c) => c.admins = [...c.admins, uid]);
|
|
1693
1698
|
await e.reply(`已添加管理 ${uid}`, true);
|
|
1694
1699
|
break;
|
|
1695
1700
|
}
|
|
@@ -1701,17 +1706,17 @@ const core = definePlugin({
|
|
|
1701
1706
|
await e.reply("请指定管理 QQ/AT", true);
|
|
1702
1707
|
return;
|
|
1703
1708
|
}
|
|
1704
|
-
const idx = botConfig.admins.indexOf(uid);
|
|
1709
|
+
const idx = ctx.botConfig.admins.indexOf(uid);
|
|
1705
1710
|
if (idx === -1) {
|
|
1706
1711
|
await e.reply(`管理 ${uid} 不存在`, true);
|
|
1707
1712
|
return;
|
|
1708
1713
|
}
|
|
1709
|
-
await updateBotConfig((c) => c.admins.splice(idx, 1));
|
|
1714
|
+
await ctx.updateBotConfig((c) => c.admins.splice(idx, 1));
|
|
1710
1715
|
await e.reply(`已删除管理 ${uid}`, true);
|
|
1711
1716
|
break;
|
|
1712
1717
|
}
|
|
1713
1718
|
default:
|
|
1714
|
-
await e.reply(dedent
|
|
1719
|
+
await e.reply(ctx.dedent(`
|
|
1715
1720
|
〓 ⚙️ mioki 设置 〓
|
|
1716
1721
|
${displayPrefix}设置 详情
|
|
1717
1722
|
${displayPrefix}设置 [加/删]主人 <QQ/AT>
|