mioki 0.3.0 → 0.4.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
@@ -871,12 +871,30 @@ function getLogFilePath$1(uin, platformName) {
871
871
  //#endregion
872
872
  //#region src/logger.ts
873
873
  const LEVEL_MAP = {
874
- 0: "FATAL",
875
- 1: "ERROR",
876
- 2: "WARN",
877
- 3: "INFO",
878
- 4: "DEBUG",
879
- 5: "TRACE"
874
+ 0: {
875
+ name: "ERROR",
876
+ color: "red"
877
+ },
878
+ 1: {
879
+ name: "WARN",
880
+ color: "yellow"
881
+ },
882
+ 2: {
883
+ name: "LOG",
884
+ color: "white"
885
+ },
886
+ 3: {
887
+ name: "INFO",
888
+ color: "green"
889
+ },
890
+ 4: {
891
+ name: "DEBUG",
892
+ color: "blue"
893
+ },
894
+ 5: {
895
+ name: "TRACE",
896
+ color: "gray"
897
+ }
880
898
  };
881
899
  /**
882
900
  * 获取日志文件名
@@ -894,11 +912,11 @@ const getMiokiLogger = (level) => {
894
912
  defaults: { tag: "mioki" },
895
913
  reporters: [{ log: (logObj) => {
896
914
  const message = (0, consola_utils.stripAnsi)(logObj.message || logObj.args?.join(" ") || "");
897
- const line = `${`[${logObj.date.toISOString()}] [${LEVEL_MAP[logObj.level]}] ${logObj.tag ? `[${logObj.tag}] ` : ""}`}${message}`;
915
+ const line = `${`[${logObj.date.toISOString()}] [${LEVEL_MAP[logObj.level].name}] ${logObj.tag ? `[${logObj.tag}] ` : ""}`}${message}`;
898
916
  node_fs.default.appendFileSync(logFile, line + "\n");
899
917
  } }, { log: (logObj) => {
900
918
  const message = logObj.message || logObj.args?.join(" ") || "";
901
- const line = `${consola_utils.colors.gray(`[${logObj.date.toLocaleTimeString("zh-CN")}]`) + " " + consola_utils.colors.bold(consola_utils.colors.blue(LEVEL_MAP[logObj.level])) + " " + (logObj.tag ? consola_utils.colors.bold(consola_utils.colors.green(`[${logObj.tag}] `)) : "")}${message}`;
919
+ 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}`;
902
920
  if (logObj.level <= consola_core.LogLevels["info"]) console.log(line);
903
921
  else if (logObj.level === consola_core.LogLevels["warn"]) console.warn(line);
904
922
  else console.debug(line);
@@ -913,7 +931,7 @@ const getMiokiLogger = (level) => {
913
931
 
914
932
  //#endregion
915
933
  //#region package.json
916
- var version = "0.3.0";
934
+ var version = "0.4.1";
917
935
 
918
936
  //#endregion
919
937
  //#region src/actions.ts
@@ -1278,15 +1296,15 @@ async function enablePlugin(bot, plugin, type = "external") {
1278
1296
  await Promise.all([...clears, ...userClears].map((fn) => fn?.()));
1279
1297
  runtimePlugins.delete(name);
1280
1298
  } catch (err) {
1281
- throw new Error(`>>> 禁用插件 [${typeDesc}]${name}@${version$1} 失败: ${err?.message}`);
1299
+ throw new Error(`>>> 禁用插件 [${consola_utils.colors.bold(consola_utils.colors.yellow(typeDesc))}]${consola_utils.colors.bold(consola_utils.colors.yellow(name))}@${consola_utils.colors.bold(consola_utils.colors.yellow(version$1))} 失败: ${err?.message}`);
1282
1300
  }
1283
1301
  }
1284
1302
  });
1285
1303
  const end = node_process.hrtime.bigint();
1286
1304
  const time = Math.round(Number(end - start$1)) / 1e6;
1287
- bot.logger.info(`>>> 启用插件 [${typeDesc}]${name}@${version$1} => 耗时 ${time} ms`);
1305
+ bot.logger.info(`>>> 启用插件 ${consola_utils.colors.bold(consola_utils.colors.yellow(`[${typeDesc}]`))}${consola_utils.colors.bold(consola_utils.colors.yellow(`${name}@${version$1}`))} => 耗时 ${consola_utils.colors.bold(consola_utils.colors.green(time.toFixed(2)))} ms`);
1288
1306
  } catch (e) {
1289
- throw new Error(`>>> 启用插件 [${typeDesc}]${name}@${version$1} 失败: ${e?.message}`);
1307
+ throw new Error(`>>> 启用插件 ${consola_utils.colors.bold(consola_utils.colors.yellow(`[${typeDesc}]`))}${consola_utils.colors.bold(consola_utils.colors.yellow(`${name}@${version$1}`))} 失败: ${e?.message}`);
1290
1308
  }
1291
1309
  return plugin;
1292
1310
  }
@@ -1721,15 +1739,20 @@ async function start(options = {}) {
1721
1739
  process.title = `mioki v${version}`;
1722
1740
  const logger = getMiokiLogger(botConfig.log_level || "info");
1723
1741
  const plugin_dir = getAbsPluginDir();
1724
- logger.info(`>>> mioki v${version} 启动中`);
1725
- logger.info(`>>> 工作目录: ${BOT_CWD.value}`);
1726
- logger.info(`>>> 插件目录: ${plugin_dir}`);
1742
+ logger.info(`>>> -> ${consola_utils.colors.bold(consola_utils.colors.cyan("mioki"))} ${consola_utils.colors.bold(consola_utils.colors.green(`v${version}`))} <-`);
1743
+ logger.info(`>>> ${consola_utils.colors.yellow(consola_utils.colors.underline(`基于 NapCat 的 TypeScript 🤖️ 机器人框架。`))}`);
1744
+ logger.info(`>>> ${consola_utils.colors.italic(`作者: Viki <hi@viki.moe> (https://github.com/vikiboss)`)}`);
1745
+ logger.info(`>>> ${consola_utils.colors.italic(`协议: Licensed under MIT License.`)}`);
1746
+ logger.info(`>>> ${consola_utils.colors.cyan(`GitHub: https://github.com/vikiboss/mioki`)}`);
1747
+ logger.info(">>> ----------------------------------------");
1748
+ logger.info(`>>> 工作目录: ${consola_utils.colors.bold(consola_utils.colors.blue(BOT_CWD.value))}`);
1749
+ logger.info(`>>> 插件目录: ${consola_utils.colors.bold(consola_utils.colors.blue(plugin_dir))}`);
1727
1750
  const napcat = new napcat_sdk.NapCat({
1728
1751
  ...botConfig.napcat,
1729
1752
  logger
1730
1753
  });
1731
1754
  napcat.on("napcat.connected", async ({ user_id, nickname }) => {
1732
- logger.info(`>>> 已连接到 NapCat: ${nickname} (${user_id})`);
1755
+ logger.info(`>>> 已连接到 NapCat: ${consola_utils.colors.bold(consola_utils.colors.green(nickname))}(${consola_utils.colors.bold(consola_utils.colors.green(user_id))})`);
1733
1756
  let lastNoticeTime = 0;
1734
1757
  process.on("uncaughtException", async (err) => {
1735
1758
  const msg = stringifyError(err);
@@ -1756,7 +1779,7 @@ async function start(options = {}) {
1756
1779
  absPath: node_path.default.resolve(plugin_dir, p)
1757
1780
  })).filter((p) => {
1758
1781
  if (!node_fs.default.existsSync(p.absPath)) {
1759
- napcat.logger.warn(`>>> 插件 ${p.dirName} 不存在,已忽略`);
1782
+ napcat.logger.warn(`>>> 插件 ${consola_utils.colors.bold(consola_utils.colors.red(p.dirName))} 不存在,已忽略`);
1760
1783
  return false;
1761
1784
  }
1762
1785
  return true;
@@ -1766,7 +1789,7 @@ async function start(options = {}) {
1766
1789
  try {
1767
1790
  const plugin = await jiti$1.import(absPath, { default: true });
1768
1791
  if (plugin.name !== dirName) {
1769
- const tip = `>>> 插件目录名 [${dirName}] 和插件声明的 name [${plugin.name}] 不一致,可能导致重载异常,请修改一致后重启。`;
1792
+ const tip = `>>> 插件目录名 [${consola_utils.colors.bold(consola_utils.colors.yellow(dirName))}] 和插件声明的 name [${consola_utils.colors.bold(consola_utils.colors.yellow(plugin.name))}] 不一致,可能导致重载异常,请修改一致后重启。`;
1770
1793
  napcat.logger.warn(tip);
1771
1794
  noticeMainOwner(napcat, tip);
1772
1795
  }
@@ -1780,7 +1803,7 @@ async function start(options = {}) {
1780
1803
  const start$1 = node_process.hrtime.bigint();
1781
1804
  const sortedUserPlugins = (await Promise.all(promises)).filter(Boolean).toSorted((prev, next) => (prev.priority ?? 100) - (next.priority ?? 100));
1782
1805
  if (failedImportPlugins.length) {
1783
- const tip = `>>> ${failedImportPlugins.length} 个插件加载失败: \n\n${failedImportPlugins.map(([dirName, err]) => `${dirName}: ${err}`).join("\n\n")}`;
1806
+ const tip = `>>> ${consola_utils.colors.bold(consola_utils.colors.red(failedImportPlugins.length))} 个插件加载失败: \n\n${failedImportPlugins.map(([dirName, err]) => `${dirName}: ${err}`).join("\n\n")}`;
1784
1807
  napcat.logger.warn(tip);
1785
1808
  noticeMainOwner(napcat, tip);
1786
1809
  }
@@ -1793,7 +1816,7 @@ async function start(options = {}) {
1793
1816
  const sortedGroups = Array.from(pluginGroups.entries()).toSorted(([a], [b]) => a - b);
1794
1817
  const failedEnablePlugins = [];
1795
1818
  try {
1796
- napcat.logger.info(`>>> 加载内置插件: ${BUILTIN_PLUGINS.map((p) => p.name).join(", ")}`);
1819
+ napcat.logger.info(`>>> 加载内置插件: ${BUILTIN_PLUGINS.map((p) => consola_utils.colors.bold(consola_utils.colors.cyan(p.name))).join(", ")}`);
1797
1820
  await Promise.all(BUILTIN_PLUGINS.map((p) => enablePlugin(napcat, p, "builtin")));
1798
1821
  for (const [_, plugins$1] of sortedGroups) await Promise.all(plugins$1.map(async (p) => {
1799
1822
  try {
@@ -1811,8 +1834,9 @@ async function start(options = {}) {
1811
1834
  const end = node_process.hrtime.bigint();
1812
1835
  const costTime = Math.round(Number(end - start$1)) / 1e6;
1813
1836
  const failedCount = failedImportPlugins.length + failedEnablePlugins.length;
1814
- const failedInfo = failedCount > 0 ? `${failedCount} 个失败 (导入 ${failedImportPlugins.length},启用 ${failedImportPlugins.length})。` : "";
1815
- napcat.logger.info(`>>> 成功加载了 ${runtimePlugins.size} 个插件。${failedInfo ? failedInfo : ""}总耗时 ${costTime} ms`);
1837
+ const failedInfo = failedCount > 0 ? `${consola_utils.colors.bold(consola_utils.colors.red(failedCount))} 个失败 (导入 ${consola_utils.colors.bold(consola_utils.colors.red(failedImportPlugins.length))},启用 ${consola_utils.colors.bold(consola_utils.colors.red(failedEnablePlugins.length))})。` : "";
1838
+ napcat.logger.info(`>>> 成功加载了 ${consola_utils.colors.bold(consola_utils.colors.green(runtimePlugins.size))} 个插件。${failedInfo ? failedInfo : ""}总耗时 ${consola_utils.colors.bold(consola_utils.colors.green(costTime.toFixed(2)))} ms`);
1839
+ napcat.logger.info(consola_utils.colors.bold(consola_utils.colors.green(`>>> mioki v${version} 启动完成!祝您使用愉快!🎉️`)));
1816
1840
  if (botConfig.online_push) await noticeMainOwner(napcat, `✅ mioki v${version} 已就绪`).catch((err) => {
1817
1841
  napcat.logger.error(`>>> 发送就绪通知失败: ${stringifyError(err)}`);
1818
1842
  });