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.mjs
CHANGED
|
@@ -832,7 +832,7 @@ function getLogFilePath(uin, platformName) {
|
|
|
832
832
|
|
|
833
833
|
//#endregion
|
|
834
834
|
//#region package.json
|
|
835
|
-
var version = "0.2.
|
|
835
|
+
var version = "0.2.4";
|
|
836
836
|
|
|
837
837
|
//#endregion
|
|
838
838
|
//#region src/actions.ts
|
|
@@ -1179,15 +1179,15 @@ async function enablePlugin(bot, plugin, type = "external") {
|
|
|
1179
1179
|
await Promise.all([...clears, ...userClears].map((fn) => fn?.()));
|
|
1180
1180
|
runtimePlugins.delete(name);
|
|
1181
1181
|
} catch (err) {
|
|
1182
|
-
throw new Error(
|
|
1182
|
+
throw new Error(`>>> 禁用插件 [${typeDesc}]${name}@${version$1} 失败: ${err?.message}`);
|
|
1183
1183
|
}
|
|
1184
1184
|
}
|
|
1185
1185
|
});
|
|
1186
1186
|
const end = hrtime.bigint();
|
|
1187
1187
|
const time = Math.round(Number(end - start$1)) / 1e6;
|
|
1188
|
-
bot.logger.info(
|
|
1188
|
+
bot.logger.info(`>>> 启用插件 [${typeDesc}]${name}@${version$1} => 耗时 ${time} ms`);
|
|
1189
1189
|
} catch (e) {
|
|
1190
|
-
throw new Error(
|
|
1190
|
+
throw new Error(`>>> 启用插件 [${typeDesc}]${name}@${version$1} 失败: ${e?.message}`);
|
|
1191
1191
|
}
|
|
1192
1192
|
return plugin;
|
|
1193
1193
|
}
|
|
@@ -1622,26 +1622,35 @@ async function start(options = {}) {
|
|
|
1622
1622
|
process.title = `mioki v${version}`;
|
|
1623
1623
|
const logger = getMiokiLogger(botConfig.log_level || "info");
|
|
1624
1624
|
const plugin_dir = getAbsPluginDir();
|
|
1625
|
-
logger.info(`>>> mioki v${version}
|
|
1625
|
+
logger.info(`>>> mioki v${version} 启动中`);
|
|
1626
|
+
logger.info(`>>> 工作目录: ${BOT_CWD.value}`);
|
|
1627
|
+
logger.info(`>>> 插件目录: ${plugin_dir}`);
|
|
1626
1628
|
const napcat = new NapCat({
|
|
1627
1629
|
...botConfig.napcat,
|
|
1628
1630
|
logger
|
|
1629
1631
|
});
|
|
1630
1632
|
napcat.on("napcat.connected", async ({ uin }) => {
|
|
1631
|
-
logger.info(`>>> 已连接到 NapCat
|
|
1633
|
+
logger.info(`>>> 已连接到 NapCat 服务器`);
|
|
1634
|
+
logger.info(`>>> 当前登录 QQ 账号: ${uin}`);
|
|
1632
1635
|
let lastNoticeTime = 0;
|
|
1633
1636
|
process.on("uncaughtException", async (err) => {
|
|
1634
|
-
|
|
1637
|
+
const msg = stringifyError(err);
|
|
1638
|
+
napcat.logger.error(`>>> uncaughtException, 出错了: ${msg}`);
|
|
1635
1639
|
if (Date.now() - lastNoticeTime < 1e3) return;
|
|
1636
1640
|
lastNoticeTime = Date.now();
|
|
1637
|
-
await noticeMainOwner(napcat, `mioki 发生未捕获异常:\n\n${
|
|
1641
|
+
await noticeMainOwner(napcat, `mioki 发生未捕获异常:\n\n${msg}`).catch(() => {
|
|
1642
|
+
napcat.logger.error(">>> 发送未捕获异常通知失败");
|
|
1643
|
+
});
|
|
1638
1644
|
});
|
|
1639
1645
|
process.on("unhandledRejection", async (err) => {
|
|
1640
|
-
|
|
1646
|
+
const msg = stringifyError(err);
|
|
1647
|
+
napcat.logger.error(`>>> unhandledRejection, 出错了: ${msg}`);
|
|
1641
1648
|
if (Date.now() - lastNoticeTime < 1e3) return;
|
|
1642
1649
|
lastNoticeTime = Date.now();
|
|
1643
1650
|
const date = (/* @__PURE__ */ new Date()).toLocaleString();
|
|
1644
|
-
await noticeMainOwner(napcat, `【${date}】\n\nmioki 发生未处理异常:\n\n${
|
|
1651
|
+
await noticeMainOwner(napcat, `【${date}】\n\nmioki 发生未处理异常:\n\n${msg}`).catch(() => {
|
|
1652
|
+
napcat.logger.error(">>> 发送未处理异常通知失败");
|
|
1653
|
+
});
|
|
1645
1654
|
});
|
|
1646
1655
|
ensurePluginDir();
|
|
1647
1656
|
const plugins = botConfig.plugins.map((p) => ({
|
|
@@ -1688,27 +1697,27 @@ async function start(options = {}) {
|
|
|
1688
1697
|
try {
|
|
1689
1698
|
napcat.logger.info(`>>> 加载内置插件: ${BUILTIN_PLUGINS.map((p) => p.name).join(", ")}`);
|
|
1690
1699
|
await Promise.all(BUILTIN_PLUGINS.map((p) => enablePlugin(napcat, p, "builtin")));
|
|
1691
|
-
for (const [
|
|
1692
|
-
|
|
1693
|
-
|
|
1694
|
-
|
|
1695
|
-
|
|
1696
|
-
|
|
1697
|
-
|
|
1698
|
-
failedEnablePlugins.push([p.name, err]);
|
|
1699
|
-
}
|
|
1700
|
-
}));
|
|
1701
|
-
}
|
|
1700
|
+
for (const [_, plugins$1] of sortedGroups) await Promise.all(plugins$1.map(async (p) => {
|
|
1701
|
+
try {
|
|
1702
|
+
await enablePlugin(napcat, p, "external");
|
|
1703
|
+
} catch (e) {
|
|
1704
|
+
failedEnablePlugins.push([p.name, stringifyError(e)]);
|
|
1705
|
+
}
|
|
1706
|
+
}));
|
|
1702
1707
|
} catch (e) {
|
|
1703
1708
|
napcat.logger.error(e?.message);
|
|
1704
|
-
noticeMainOwner(napcat, e?.message)
|
|
1709
|
+
await noticeMainOwner(napcat, e?.message).catch(() => {
|
|
1710
|
+
napcat.logger.error(">>> 发送插件启用失败通知失败");
|
|
1711
|
+
});
|
|
1705
1712
|
}
|
|
1706
1713
|
const end = hrtime.bigint();
|
|
1707
1714
|
const costTime = Math.round(Number(end - start$1)) / 1e6;
|
|
1708
1715
|
const failedCount = failedImportPlugins.length + failedEnablePlugins.length;
|
|
1709
1716
|
const failedInfo = failedCount > 0 ? `${failedCount} 个失败 (导入 ${failedImportPlugins.length},启用 ${failedImportPlugins.length})。` : "";
|
|
1710
1717
|
napcat.logger.info(`>>> 成功加载了 ${runtimePlugins.size} 个插件。${failedInfo ? failedInfo : ""}总耗时 ${costTime} ms`);
|
|
1711
|
-
if (botConfig.online_push) await noticeMainOwner(napcat, `✅ mioki v${version} 已就绪`)
|
|
1718
|
+
if (botConfig.online_push) await noticeMainOwner(napcat, `✅ mioki v${version} 已就绪`).catch((err) => {
|
|
1719
|
+
napcat.logger.error(`>>> 发送就绪通知失败: ${stringifyError(err)}`);
|
|
1720
|
+
});
|
|
1712
1721
|
});
|
|
1713
1722
|
await napcat.run();
|
|
1714
1723
|
}
|