mioki 0.2.2 → 0.2.4
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 +32 -23
- package/dist/index.cjs.map +1 -1
- package/dist/index.mjs +32 -23
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -2
package/dist/index.cjs
CHANGED
|
@@ -883,7 +883,7 @@ function getLogFilePath(uin, platformName) {
|
|
|
883
883
|
|
|
884
884
|
//#endregion
|
|
885
885
|
//#region package.json
|
|
886
|
-
var version = "0.2.
|
|
886
|
+
var version = "0.2.4";
|
|
887
887
|
|
|
888
888
|
//#endregion
|
|
889
889
|
//#region src/actions.ts
|
|
@@ -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
|
}
|
|
@@ -1673,26 +1673,35 @@ 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
|
+
const msg = stringifyError(err);
|
|
1689
|
+
napcat.logger.error(`>>> uncaughtException, 出错了: ${msg}`);
|
|
1686
1690
|
if (Date.now() - lastNoticeTime < 1e3) return;
|
|
1687
1691
|
lastNoticeTime = Date.now();
|
|
1688
|
-
await noticeMainOwner(napcat, `mioki 发生未捕获异常:\n\n${
|
|
1692
|
+
await noticeMainOwner(napcat, `mioki 发生未捕获异常:\n\n${msg}`).catch(() => {
|
|
1693
|
+
napcat.logger.error(">>> 发送未捕获异常通知失败");
|
|
1694
|
+
});
|
|
1689
1695
|
});
|
|
1690
1696
|
process.on("unhandledRejection", async (err) => {
|
|
1691
|
-
|
|
1697
|
+
const msg = stringifyError(err);
|
|
1698
|
+
napcat.logger.error(`>>> unhandledRejection, 出错了: ${msg}`);
|
|
1692
1699
|
if (Date.now() - lastNoticeTime < 1e3) return;
|
|
1693
1700
|
lastNoticeTime = Date.now();
|
|
1694
1701
|
const date = (/* @__PURE__ */ new Date()).toLocaleString();
|
|
1695
|
-
await noticeMainOwner(napcat, `【${date}】\n\nmioki 发生未处理异常:\n\n${
|
|
1702
|
+
await noticeMainOwner(napcat, `【${date}】\n\nmioki 发生未处理异常:\n\n${msg}`).catch(() => {
|
|
1703
|
+
napcat.logger.error(">>> 发送未处理异常通知失败");
|
|
1704
|
+
});
|
|
1696
1705
|
});
|
|
1697
1706
|
ensurePluginDir();
|
|
1698
1707
|
const plugins = botConfig.plugins.map((p) => ({
|
|
@@ -1739,27 +1748,27 @@ async function start(options = {}) {
|
|
|
1739
1748
|
try {
|
|
1740
1749
|
napcat.logger.info(`>>> 加载内置插件: ${BUILTIN_PLUGINS.map((p) => p.name).join(", ")}`);
|
|
1741
1750
|
await Promise.all(BUILTIN_PLUGINS.map((p) => enablePlugin(napcat, p, "builtin")));
|
|
1742
|
-
for (const [
|
|
1743
|
-
|
|
1744
|
-
|
|
1745
|
-
|
|
1746
|
-
|
|
1747
|
-
|
|
1748
|
-
|
|
1749
|
-
failedEnablePlugins.push([p.name, err]);
|
|
1750
|
-
}
|
|
1751
|
-
}));
|
|
1752
|
-
}
|
|
1751
|
+
for (const [_, plugins$1] of sortedGroups) await Promise.all(plugins$1.map(async (p) => {
|
|
1752
|
+
try {
|
|
1753
|
+
await enablePlugin(napcat, p, "external");
|
|
1754
|
+
} catch (e) {
|
|
1755
|
+
failedEnablePlugins.push([p.name, stringifyError(e)]);
|
|
1756
|
+
}
|
|
1757
|
+
}));
|
|
1753
1758
|
} catch (e) {
|
|
1754
1759
|
napcat.logger.error(e?.message);
|
|
1755
|
-
noticeMainOwner(napcat, e?.message)
|
|
1760
|
+
await noticeMainOwner(napcat, e?.message).catch(() => {
|
|
1761
|
+
napcat.logger.error(">>> 发送插件启用失败通知失败");
|
|
1762
|
+
});
|
|
1756
1763
|
}
|
|
1757
1764
|
const end = node_process.hrtime.bigint();
|
|
1758
1765
|
const costTime = Math.round(Number(end - start$1)) / 1e6;
|
|
1759
1766
|
const failedCount = failedImportPlugins.length + failedEnablePlugins.length;
|
|
1760
1767
|
const failedInfo = failedCount > 0 ? `${failedCount} 个失败 (导入 ${failedImportPlugins.length},启用 ${failedImportPlugins.length})。` : "";
|
|
1761
1768
|
napcat.logger.info(`>>> 成功加载了 ${runtimePlugins.size} 个插件。${failedInfo ? failedInfo : ""}总耗时 ${costTime} ms`);
|
|
1762
|
-
if (botConfig.online_push) await noticeMainOwner(napcat, `✅ mioki v${version} 已就绪`)
|
|
1769
|
+
if (botConfig.online_push) await noticeMainOwner(napcat, `✅ mioki v${version} 已就绪`).catch((err) => {
|
|
1770
|
+
napcat.logger.error(`>>> 发送就绪通知失败: ${stringifyError(err)}`);
|
|
1771
|
+
});
|
|
1763
1772
|
});
|
|
1764
1773
|
await napcat.run();
|
|
1765
1774
|
}
|