mioki 0.5.1 → 0.6.1

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 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?.join(" ") || "");
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 message = logObj.message || logObj.args?.join(" ") || "";
916
- 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}] `) : "")}${message}`;
917
- if (logObj.level <= consola_core.LogLevels["info"]) console.log(line);
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.5.1";
940
+ var version = "0.6.1";
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(`启用插件 ${consola_utils.colors.yellow(`[${typeDesc}]`)}${consola_utils.colors.yellow(`${name}@${version$1}`)} => 耗时 ${consola_utils.colors.green(time.toFixed(2))} ms`);
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
  }
@@ -1330,10 +1339,12 @@ async function getMiokiStatus(bot) {
1330
1339
  const osArch = node_os.default.arch();
1331
1340
  const isInUnix = ["Linux", "Darwin"].includes(osType);
1332
1341
  const arch = ArchMap[osArch] || osArch;
1333
- const [osInfo, localPlugins, versionInfo] = await Promise.all([
1342
+ const [osInfo, localPlugins, versionInfo, friendList, groupList] = await Promise.all([
1334
1343
  systeminformation.default.osInfo(),
1335
1344
  findLocalPlugins(),
1336
- bot.getVersionInfo()
1345
+ bot.getVersionInfo(),
1346
+ bot.getFriendList(),
1347
+ bot.getGroupList()
1337
1348
  ]);
1338
1349
  const pluginCount = localPlugins.length + BUILTIN_PLUGINS.length;
1339
1350
  const system = isInUnix ? {
@@ -1351,13 +1362,19 @@ async function getMiokiStatus(bot) {
1351
1362
  return {
1352
1363
  bot: {
1353
1364
  uin: bot.uin,
1354
- nickname: bot.nickname
1365
+ nickname: bot.nickname,
1366
+ friends: friendList.length,
1367
+ groups: groupList.length
1355
1368
  },
1356
1369
  plugins: {
1357
1370
  enabled: runtimePlugins.size,
1358
1371
  total: pluginCount
1359
1372
  },
1360
- stats: { uptime: process.uptime() * 1e3 },
1373
+ stats: {
1374
+ uptime: process.uptime() * 1e3,
1375
+ send: bot.stat.send.group + bot.stat.send.private,
1376
+ receive: bot.stat.recv.group + bot.stat.recv.private
1377
+ },
1361
1378
  versions: {
1362
1379
  node: nodeVersion,
1363
1380
  mioki: version,
@@ -1398,7 +1415,9 @@ async function getMiokiStatusStr(client) {
1398
1415
  return `
1399
1416
  👤 ${bot.nickname}
1400
1417
  🆔 ${bot.uin}
1418
+ 📋 ${localNum(bot.friends)} 好友 / ${localNum(bot.groups)} 群
1401
1419
  🧩 启用了 ${localNum(plugins.enabled)} 个插件,共 ${localNum(plugins.total)} 个
1420
+ 📮 收 ${localNum(stats.receive)} 条,发 ${localNum(stats.send)} 条
1402
1421
  🚀 ${(0, filesize.filesize)(memory.rss.used, { round: 1 })}/${memory.percent}%
1403
1422
  ⏳ 已运行 ${(0, pretty_ms.default)(stats.uptime, {
1404
1423
  hideYear: true,
@@ -1732,7 +1751,7 @@ const BUILTIN_PLUGINS = [core_default];
1732
1751
  //#region src/start.ts
1733
1752
  async function start(options = {}) {
1734
1753
  const { cwd = process.cwd() } = options;
1735
- if (cwd !== BOT_CWD.value) updateBotCWD(cwd);
1754
+ if (cwd !== BOT_CWD.value) updateBotCWD(node_path.default.resolve(cwd));
1736
1755
  process.title = `mioki v${version}`;
1737
1756
  const plugin_dir = getAbsPluginDir();
1738
1757
  logger.info(consola_utils.colors.dim("=".repeat(40)));
@@ -1749,7 +1768,7 @@ async function start(options = {}) {
1749
1768
  logger.info(`${consola_utils.colors.dim("配置文件: ")}${consola_utils.colors.blue(`${BOT_CWD.value}/package.json`)}`);
1750
1769
  logger.info(consola_utils.colors.dim("=".repeat(40)));
1751
1770
  const { protocol = "ws", port = 6700, host = "localhost", token } = botConfig.napcat || {};
1752
- logger.info(`开始连接 NapCat 实例: ${consola_utils.colors.green(`${protocol}://${host}:${port}`)}`);
1771
+ logger.info(`>>> 正在连接 NapCat 实例: ${consola_utils.colors.green(`${protocol}://${host}:${port}`)}`);
1753
1772
  const napcat = new napcat_sdk.NapCat({
1754
1773
  token,
1755
1774
  protocol,
@@ -1759,9 +1778,11 @@ async function start(options = {}) {
1759
1778
  });
1760
1779
  napcat.on("ws.close", () => {
1761
1780
  logger.error("连接已关闭,请确保 NapCat 实例正常运行及 token 配置正确");
1781
+ process.exit(1);
1762
1782
  });
1763
1783
  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}-${nickname}(${user_id})`)}`);
1784
+ logger.info(`已连接到 NapCat 实例: ${consola_utils.colors.green(`${app_name}-v${app_version} ${nickname}(${user_id})`)}`);
1785
+ process.title = `mioki v${version} ${app_name}-v${app_version}-${user_id}`;
1765
1786
  let lastNoticeTime = 0;
1766
1787
  process.on("uncaughtException", async (err) => {
1767
1788
  const msg = stringifyError(err);
@@ -1825,7 +1846,7 @@ async function start(options = {}) {
1825
1846
  const sortedGroups = Array.from(pluginGroups.entries()).toSorted(([a], [b]) => a - b);
1826
1847
  const failedEnablePlugins = [];
1827
1848
  try {
1828
- napcat.logger.info(`加载内置插件: ${BUILTIN_PLUGINS.map((p) => consola_utils.colors.cyan(p.name)).join(", ")}`);
1849
+ napcat.logger.info(`>>> 加载 mioki 内置插件: ${BUILTIN_PLUGINS.map((p) => consola_utils.colors.cyan(p.name)).join(", ")}`);
1829
1850
  await Promise.all(BUILTIN_PLUGINS.map((p) => enablePlugin(napcat, p, "builtin")));
1830
1851
  for (const [_, plugins$1] of sortedGroups) await Promise.all(plugins$1.map(async (p) => {
1831
1852
  try {