mioki 0.2.1 → 0.2.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.cjs +41 -40
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +10 -9
- package/dist/index.d.mts +10 -9
- package/dist/index.mjs +41 -41
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -2
package/dist/index.cjs
CHANGED
|
@@ -90,7 +90,6 @@ var utils_exports = /* @__PURE__ */ __export({
|
|
|
90
90
|
START_TIME: () => START_TIME,
|
|
91
91
|
base64Decode: () => base64Decode,
|
|
92
92
|
base64Encode: () => base64Encode,
|
|
93
|
-
bindBot: () => bindBot,
|
|
94
93
|
clamp: () => clamp,
|
|
95
94
|
createCmd: () => createCmd,
|
|
96
95
|
createDB: () => createDB,
|
|
@@ -188,9 +187,9 @@ const jiti$1 = (0, jiti.createJiti)(__dirname, {
|
|
|
188
187
|
function createCmd(cmdStr, options = {}) {
|
|
189
188
|
const { prefix = "", onPrefix = () => {} } = options;
|
|
190
189
|
const { _, ...cmdOptions } = (0, mri.default)((0, string2argv.string2argv)(cmdStr));
|
|
191
|
-
const [cmd
|
|
190
|
+
const [cmd, ...params] = _;
|
|
192
191
|
if (prefix) {
|
|
193
|
-
if (cmd
|
|
192
|
+
if (cmd !== prefix) return {
|
|
194
193
|
cmd: void 0,
|
|
195
194
|
params: [],
|
|
196
195
|
options: cmdOptions
|
|
@@ -203,7 +202,7 @@ function createCmd(cmdStr, options = {}) {
|
|
|
203
202
|
};
|
|
204
203
|
}
|
|
205
204
|
return {
|
|
206
|
-
cmd
|
|
205
|
+
cmd,
|
|
207
206
|
params,
|
|
208
207
|
options: cmdOptions
|
|
209
208
|
};
|
|
@@ -782,9 +781,6 @@ async function getTerminalInput(inputTip = "请输入") {
|
|
|
782
781
|
getInput();
|
|
783
782
|
});
|
|
784
783
|
}
|
|
785
|
-
function bindBot(bot, func) {
|
|
786
|
-
return (...args) => func(bot, ...args);
|
|
787
|
-
}
|
|
788
784
|
/**
|
|
789
785
|
* 当前 Node.js 进程的启动时间,常量,Date 类型
|
|
790
786
|
*/
|
|
@@ -887,7 +883,7 @@ function getLogFilePath(uin, platformName) {
|
|
|
887
883
|
|
|
888
884
|
//#endregion
|
|
889
885
|
//#region package.json
|
|
890
|
-
var version = "0.2.
|
|
886
|
+
var version = "0.2.3";
|
|
891
887
|
|
|
892
888
|
//#endregion
|
|
893
889
|
//#region src/actions.ts
|
|
@@ -1160,6 +1156,9 @@ function addService(name, service, cover = true) {
|
|
|
1160
1156
|
|
|
1161
1157
|
//#endregion
|
|
1162
1158
|
//#region src/plugin.ts
|
|
1159
|
+
function bindBot(bot, func) {
|
|
1160
|
+
return (...args) => func(bot, ...args);
|
|
1161
|
+
}
|
|
1163
1162
|
const runtimePlugins = /* @__PURE__ */ new Map();
|
|
1164
1163
|
const buildRemovedActions = (bot) => Object.fromEntries(Object.entries(actions_exports).map(([k, v]) => [k, bindBot(bot, v)]));
|
|
1165
1164
|
/**
|
|
@@ -1180,9 +1179,9 @@ function ensurePluginDir() {
|
|
|
1180
1179
|
/**
|
|
1181
1180
|
* 获取插件目录的绝对路径
|
|
1182
1181
|
*/
|
|
1183
|
-
function getAbsPluginDir(defaultDir = "
|
|
1182
|
+
function getAbsPluginDir(defaultDir = "plugins") {
|
|
1184
1183
|
const cwd = BOT_CWD.value;
|
|
1185
|
-
return node_path.default.
|
|
1184
|
+
return node_path.default.join(cwd, botConfig.plugins_dir || defaultDir);
|
|
1186
1185
|
}
|
|
1187
1186
|
async function enablePlugin(bot, plugin, type = "external") {
|
|
1188
1187
|
const typeDesc = type === "builtin" ? "内置" : "用户";
|
|
@@ -1195,6 +1194,7 @@ async function enablePlugin(bot, plugin, type = "external") {
|
|
|
1195
1194
|
const context = {
|
|
1196
1195
|
bot,
|
|
1197
1196
|
segment: bot.segment,
|
|
1197
|
+
getCookie: bot.getCookie,
|
|
1198
1198
|
...utils_exports,
|
|
1199
1199
|
...config_exports,
|
|
1200
1200
|
...buildRemovedActions(bot),
|
|
@@ -1230,15 +1230,15 @@ async function enablePlugin(bot, plugin, type = "external") {
|
|
|
1230
1230
|
await Promise.all([...clears, ...userClears].map((fn) => fn?.()));
|
|
1231
1231
|
runtimePlugins.delete(name);
|
|
1232
1232
|
} catch (err) {
|
|
1233
|
-
throw new Error(
|
|
1233
|
+
throw new Error(`>>> 禁用插件 [${typeDesc}]${name}@${version$1} 失败: ${err?.message}`);
|
|
1234
1234
|
}
|
|
1235
1235
|
}
|
|
1236
1236
|
});
|
|
1237
1237
|
const end = node_process.hrtime.bigint();
|
|
1238
1238
|
const time = Math.round(Number(end - start$1)) / 1e6;
|
|
1239
|
-
bot.logger.info(
|
|
1239
|
+
bot.logger.info(`>>> 启用插件 [${typeDesc}]${name}@${version$1} => 耗时 ${time} ms`);
|
|
1240
1240
|
} catch (e) {
|
|
1241
|
-
throw new Error(
|
|
1241
|
+
throw new Error(`>>> 启用插件 [${typeDesc}]${name}@${version$1} 失败: ${e?.message}`);
|
|
1242
1242
|
}
|
|
1243
1243
|
return plugin;
|
|
1244
1244
|
}
|
|
@@ -1250,7 +1250,7 @@ async function findLocalPlugins() {
|
|
|
1250
1250
|
}
|
|
1251
1251
|
|
|
1252
1252
|
//#endregion
|
|
1253
|
-
//#region src/builtins/
|
|
1253
|
+
//#region src/builtins/core/status.ts
|
|
1254
1254
|
const SystemMap = {
|
|
1255
1255
|
Linux: "Linux",
|
|
1256
1256
|
Darwin: "macOS",
|
|
@@ -1302,8 +1302,8 @@ async function getMiokiStatus(bot) {
|
|
|
1302
1302
|
protocol: versionInfo.protocol_version
|
|
1303
1303
|
},
|
|
1304
1304
|
system: {
|
|
1305
|
-
name: system.name,
|
|
1306
|
-
version: system.version,
|
|
1305
|
+
name: system.name || "N/A",
|
|
1306
|
+
version: system.version || "N/A",
|
|
1307
1307
|
arch
|
|
1308
1308
|
},
|
|
1309
1309
|
memory: {
|
|
@@ -1322,7 +1322,7 @@ async function getMiokiStatus(bot) {
|
|
|
1322
1322
|
percent: 0
|
|
1323
1323
|
},
|
|
1324
1324
|
cpu: {
|
|
1325
|
-
name: cpu.name,
|
|
1325
|
+
name: cpu.name.trim(),
|
|
1326
1326
|
count: cpu.count,
|
|
1327
1327
|
percent: Number((await measureCpuUsage()).toFixed(1))
|
|
1328
1328
|
}
|
|
@@ -1341,7 +1341,7 @@ async function getMiokiStatusStr(client) {
|
|
|
1341
1341
|
hideYear: true,
|
|
1342
1342
|
secondsDecimalDigits: 0
|
|
1343
1343
|
})}
|
|
1344
|
-
🤖
|
|
1344
|
+
🤖 mioki/${versions.mioki}-NapCat/${versions.napcat}
|
|
1345
1345
|
🖥️ ${system.name.split(" ")[0]}/${system.version.split(".")[0]}-${system.name}-node/${versions.node.split(".")[0]}
|
|
1346
1346
|
📊 ${memory.percent}%-${(0, filesize.filesize)(memory.used, {
|
|
1347
1347
|
base: 2,
|
|
@@ -1351,7 +1351,7 @@ async function getMiokiStatusStr(client) {
|
|
|
1351
1351
|
round: 1
|
|
1352
1352
|
})}
|
|
1353
1353
|
🧮 ${cpu.percent}%-${cpu.name}-${cpu.count}核
|
|
1354
|
-
|
|
1354
|
+
${diskValid ? `💾 ${diskDesc}` : ""}
|
|
1355
1355
|
`.trim();
|
|
1356
1356
|
}
|
|
1357
1357
|
async function getDiskUsageInUnix(path$6 = "/") {
|
|
@@ -1407,10 +1407,10 @@ function getCpuInfo() {
|
|
|
1407
1407
|
}
|
|
1408
1408
|
|
|
1409
1409
|
//#endregion
|
|
1410
|
-
//#region src/builtins/
|
|
1411
|
-
const corePlugins = ["mioki-
|
|
1412
|
-
const
|
|
1413
|
-
name: "
|
|
1410
|
+
//#region src/builtins/core/index.ts
|
|
1411
|
+
const corePlugins = ["mioki-core"];
|
|
1412
|
+
const core = definePlugin({
|
|
1413
|
+
name: "mioki-core",
|
|
1414
1414
|
version,
|
|
1415
1415
|
priority: 1,
|
|
1416
1416
|
setup(ctx) {
|
|
@@ -1428,9 +1428,9 @@ const cmd = definePlugin({
|
|
|
1428
1428
|
}
|
|
1429
1429
|
if (!ctx.isOwner(e)) return;
|
|
1430
1430
|
const { _: params, ..._options } = (0, mri.default)((0, string2argv.string2argv)(text$1));
|
|
1431
|
-
const cmd
|
|
1431
|
+
const cmd = params.shift()?.replace(cmdPrefix, "") ?? "";
|
|
1432
1432
|
const [subCmd, target, ..._subParams] = params;
|
|
1433
|
-
switch (cmd
|
|
1433
|
+
switch (cmd) {
|
|
1434
1434
|
case "帮助":
|
|
1435
1435
|
await e.reply((0, dedent.default)(`
|
|
1436
1436
|
〓 💡 mioki 帮助 〓
|
|
@@ -1659,11 +1659,11 @@ const cmd = definePlugin({
|
|
|
1659
1659
|
}, e));
|
|
1660
1660
|
}
|
|
1661
1661
|
});
|
|
1662
|
-
var
|
|
1662
|
+
var core_default = core;
|
|
1663
1663
|
|
|
1664
1664
|
//#endregion
|
|
1665
1665
|
//#region src/builtins/index.ts
|
|
1666
|
-
const BUILTIN_PLUGINS = [
|
|
1666
|
+
const BUILTIN_PLUGINS = [core_default];
|
|
1667
1667
|
|
|
1668
1668
|
//#endregion
|
|
1669
1669
|
//#region src/start.ts
|
|
@@ -1673,13 +1673,16 @@ async function start(options = {}) {
|
|
|
1673
1673
|
process.title = `mioki v${version}`;
|
|
1674
1674
|
const logger = getMiokiLogger(botConfig.log_level || "info");
|
|
1675
1675
|
const plugin_dir = getAbsPluginDir();
|
|
1676
|
-
logger.info(`>>> mioki v${version}
|
|
1676
|
+
logger.info(`>>> mioki v${version} 启动中`);
|
|
1677
|
+
logger.info(`>>> 工作目录: ${BOT_CWD.value}`);
|
|
1678
|
+
logger.info(`>>> 插件目录: ${plugin_dir}`);
|
|
1677
1679
|
const napcat = new napcat_sdk.NapCat({
|
|
1678
1680
|
...botConfig.napcat,
|
|
1679
1681
|
logger
|
|
1680
1682
|
});
|
|
1681
1683
|
napcat.on("napcat.connected", async ({ uin }) => {
|
|
1682
|
-
logger.info(`>>> 已连接到 NapCat
|
|
1684
|
+
logger.info(`>>> 已连接到 NapCat 服务器`);
|
|
1685
|
+
logger.info(`>>> 当前登录 QQ 账号: ${uin}`);
|
|
1683
1686
|
let lastNoticeTime = 0;
|
|
1684
1687
|
process.on("uncaughtException", async (err) => {
|
|
1685
1688
|
napcat.logger.error(">>> uncaughtException, 出错了", err);
|
|
@@ -1739,17 +1742,14 @@ async function start(options = {}) {
|
|
|
1739
1742
|
try {
|
|
1740
1743
|
napcat.logger.info(`>>> 加载内置插件: ${BUILTIN_PLUGINS.map((p) => p.name).join(", ")}`);
|
|
1741
1744
|
await Promise.all(BUILTIN_PLUGINS.map((p) => enablePlugin(napcat, p, "builtin")));
|
|
1742
|
-
for (const [
|
|
1743
|
-
|
|
1744
|
-
|
|
1745
|
-
|
|
1746
|
-
|
|
1747
|
-
|
|
1748
|
-
|
|
1749
|
-
|
|
1750
|
-
}
|
|
1751
|
-
}));
|
|
1752
|
-
}
|
|
1745
|
+
for (const [_, plugins$1] of sortedGroups) await Promise.all(plugins$1.map(async (p) => {
|
|
1746
|
+
try {
|
|
1747
|
+
await enablePlugin(napcat, p, "external");
|
|
1748
|
+
} catch (e) {
|
|
1749
|
+
const err = stringifyError(e);
|
|
1750
|
+
failedEnablePlugins.push([p.name, err]);
|
|
1751
|
+
}
|
|
1752
|
+
}));
|
|
1753
1753
|
} catch (e) {
|
|
1754
1754
|
napcat.logger.error(e?.message);
|
|
1755
1755
|
noticeMainOwner(napcat, e?.message);
|
|
@@ -1771,6 +1771,7 @@ exports.START_TIME = START_TIME;
|
|
|
1771
1771
|
exports.addService = addService;
|
|
1772
1772
|
exports.base64Decode = base64Decode;
|
|
1773
1773
|
exports.base64Encode = base64Encode;
|
|
1774
|
+
exports.bindBot = bindBot;
|
|
1774
1775
|
exports.botConfig = botConfig;
|
|
1775
1776
|
exports.clamp = clamp;
|
|
1776
1777
|
exports.createCmd = createCmd;
|