mioki 0.5.1 → 0.6.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/index.cjs +22 -11
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +4 -5
- package/dist/index.d.mts +4 -5
- package/dist/index.mjs +21 -11
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -2
package/dist/index.cjs
CHANGED
|
@@ -40,6 +40,8 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
40
40
|
//#endregion
|
|
41
41
|
let node_fs = require("node:fs");
|
|
42
42
|
node_fs = __toESM(node_fs);
|
|
43
|
+
let node_util = require("node:util");
|
|
44
|
+
node_util = __toESM(node_util);
|
|
43
45
|
let node_path = require("node:path");
|
|
44
46
|
node_path = __toESM(node_path);
|
|
45
47
|
let mri = require("mri");
|
|
@@ -908,14 +910,21 @@ function getMiokiLogger(level) {
|
|
|
908
910
|
level: consola_core.LogLevels[level],
|
|
909
911
|
defaults: { tag: "mioki" },
|
|
910
912
|
reporters: [{ log: (logObj) => {
|
|
911
|
-
const message = (0, consola_utils.stripAnsi)(logObj.message || logObj.args?.
|
|
913
|
+
const message = (0, consola_utils.stripAnsi)(logObj.message || logObj.args?.map((e) => typeof e === "string" ? e : node_util.default.inspect(e, {
|
|
914
|
+
colors: true,
|
|
915
|
+
depth: null
|
|
916
|
+
})).join(" ") || "");
|
|
912
917
|
const line = `${`[${logObj.date.toISOString()}] [${LEVEL_MAP[logObj.level].name}] ${logObj.tag ? `[${logObj.tag}] ` : ""}`}${message}`;
|
|
913
918
|
node_fs.default.appendFileSync(logFile, line + "\n");
|
|
914
919
|
} }, { log: (logObj) => {
|
|
915
|
-
const
|
|
916
|
-
|
|
917
|
-
|
|
920
|
+
const line = `${consola_utils.colors.gray(`[${logObj.date.toLocaleTimeString("zh-CN")}]`)} ${consola_utils.colors.bold(consola_utils.colors[LEVEL_MAP[logObj.level].color](LEVEL_MAP[logObj.level].name))} ${logObj.tag ? consola_utils.colors.dim(`[${logObj.tag}] `) : ""} ${logObj.message || logObj.args?.map((e) => typeof e === "string" ? e : node_util.default.inspect(e, {
|
|
921
|
+
colors: true,
|
|
922
|
+
depth: null
|
|
923
|
+
})).join(" ") || ""}`;
|
|
924
|
+
if (logObj.level <= consola_core.LogLevels["error"]) console.error(line);
|
|
918
925
|
else if (logObj.level === consola_core.LogLevels["warn"]) console.warn(line);
|
|
926
|
+
else if (logObj.level === consola_core.LogLevels["log"]) console.log(line);
|
|
927
|
+
else if (logObj.level === consola_core.LogLevels["info"]) console.info(line);
|
|
919
928
|
else console.debug(line);
|
|
920
929
|
} }],
|
|
921
930
|
formatOptions: {
|
|
@@ -928,7 +937,7 @@ function getMiokiLogger(level) {
|
|
|
928
937
|
|
|
929
938
|
//#endregion
|
|
930
939
|
//#region package.json
|
|
931
|
-
var version = "0.
|
|
940
|
+
var version = "0.6.0";
|
|
932
941
|
|
|
933
942
|
//#endregion
|
|
934
943
|
//#region src/actions.ts
|
|
@@ -1299,9 +1308,9 @@ async function enablePlugin(bot, plugin, type = "external") {
|
|
|
1299
1308
|
});
|
|
1300
1309
|
const end = node_process.hrtime.bigint();
|
|
1301
1310
|
const time = Math.round(Number(end - start$1)) / 1e6;
|
|
1302
|
-
bot.logger.info(
|
|
1311
|
+
bot.logger.info(`- 启用插件 ${consola_utils.colors.yellow(`[${typeDesc}]`)} ${consola_utils.colors.yellow(`${name}@${version$1}`)} => 耗时 ${consola_utils.colors.green(time.toFixed(2))} 毫秒`);
|
|
1303
1312
|
} catch (e) {
|
|
1304
|
-
throw new Error(`启用插件 ${consola_utils.colors.yellow(`[${typeDesc}]`)}${consola_utils.colors.yellow(`${name}@${version$1}`)} 失败: ${e?.message}`);
|
|
1313
|
+
throw new Error(`启用插件 ${consola_utils.colors.yellow(`[${typeDesc}]`)} ${consola_utils.colors.yellow(`${name}@${version$1}`)} 失败: ${e?.message}`);
|
|
1305
1314
|
}
|
|
1306
1315
|
return plugin;
|
|
1307
1316
|
}
|
|
@@ -1732,7 +1741,7 @@ const BUILTIN_PLUGINS = [core_default];
|
|
|
1732
1741
|
//#region src/start.ts
|
|
1733
1742
|
async function start(options = {}) {
|
|
1734
1743
|
const { cwd = process.cwd() } = options;
|
|
1735
|
-
if (cwd !== BOT_CWD.value) updateBotCWD(cwd);
|
|
1744
|
+
if (cwd !== BOT_CWD.value) updateBotCWD(node_path.default.resolve(cwd));
|
|
1736
1745
|
process.title = `mioki v${version}`;
|
|
1737
1746
|
const plugin_dir = getAbsPluginDir();
|
|
1738
1747
|
logger.info(consola_utils.colors.dim("=".repeat(40)));
|
|
@@ -1749,7 +1758,7 @@ async function start(options = {}) {
|
|
|
1749
1758
|
logger.info(`${consola_utils.colors.dim("配置文件: ")}${consola_utils.colors.blue(`${BOT_CWD.value}/package.json`)}`);
|
|
1750
1759
|
logger.info(consola_utils.colors.dim("=".repeat(40)));
|
|
1751
1760
|
const { protocol = "ws", port = 6700, host = "localhost", token } = botConfig.napcat || {};
|
|
1752
|
-
logger.info(
|
|
1761
|
+
logger.info(`>>> 正在连接 NapCat 实例: ${consola_utils.colors.green(`${protocol}://${host}:${port}`)}`);
|
|
1753
1762
|
const napcat = new napcat_sdk.NapCat({
|
|
1754
1763
|
token,
|
|
1755
1764
|
protocol,
|
|
@@ -1759,9 +1768,11 @@ async function start(options = {}) {
|
|
|
1759
1768
|
});
|
|
1760
1769
|
napcat.on("ws.close", () => {
|
|
1761
1770
|
logger.error("连接已关闭,请确保 NapCat 实例正常运行及 token 配置正确");
|
|
1771
|
+
process.exit(1);
|
|
1762
1772
|
});
|
|
1763
1773
|
napcat.on("napcat.connected", async ({ user_id, nickname, app_name, app_version }) => {
|
|
1764
|
-
logger.info(`已连接到 NapCat 实例: ${consola_utils.colors.green(`${app_name}-v${app_version}
|
|
1774
|
+
logger.info(`已连接到 NapCat 实例: ${consola_utils.colors.green(`${app_name}-v${app_version} ${nickname}(${user_id})`)}`);
|
|
1775
|
+
process.title = `mioki v${version} ${app_name}-v${app_version}-${user_id}`;
|
|
1765
1776
|
let lastNoticeTime = 0;
|
|
1766
1777
|
process.on("uncaughtException", async (err) => {
|
|
1767
1778
|
const msg = stringifyError(err);
|
|
@@ -1825,7 +1836,7 @@ async function start(options = {}) {
|
|
|
1825
1836
|
const sortedGroups = Array.from(pluginGroups.entries()).toSorted(([a], [b]) => a - b);
|
|
1826
1837
|
const failedEnablePlugins = [];
|
|
1827
1838
|
try {
|
|
1828
|
-
napcat.logger.info(
|
|
1839
|
+
napcat.logger.info(`>>> 加载 mioki 内置插件: ${BUILTIN_PLUGINS.map((p) => consola_utils.colors.cyan(p.name)).join(", ")}`);
|
|
1829
1840
|
await Promise.all(BUILTIN_PLUGINS.map((p) => enablePlugin(napcat, p, "builtin")));
|
|
1830
1841
|
for (const [_, plugins$1] of sortedGroups) await Promise.all(plugins$1.map(async (p) => {
|
|
1831
1842
|
try {
|