mioki 0.4.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
@@ -916,7 +916,7 @@ const getMiokiLogger = (level) => {
916
916
  node_fs.default.appendFileSync(logFile, line + "\n");
917
917
  } }, { log: (logObj) => {
918
918
  const message = logObj.message || logObj.args?.join(" ") || "";
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.bold(consola_utils.colors.dim(`[${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}`;
920
920
  if (logObj.level <= consola_core.LogLevels["info"]) console.log(line);
921
921
  else if (logObj.level === consola_core.LogLevels["warn"]) console.warn(line);
922
922
  else console.debug(line);
@@ -931,7 +931,7 @@ const getMiokiLogger = (level) => {
931
931
 
932
932
  //#endregion
933
933
  //#region package.json
934
- var version = "0.4.0";
934
+ var version = "0.4.1";
935
935
 
936
936
  //#endregion
937
937
  //#region src/actions.ts
@@ -1296,15 +1296,15 @@ async function enablePlugin(bot, plugin, type = "external") {
1296
1296
  await Promise.all([...clears, ...userClears].map((fn) => fn?.()));
1297
1297
  runtimePlugins.delete(name);
1298
1298
  } catch (err) {
1299
- 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}`);
1300
1300
  }
1301
1301
  }
1302
1302
  });
1303
1303
  const end = node_process.hrtime.bigint();
1304
1304
  const time = Math.round(Number(end - start$1)) / 1e6;
1305
- 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`);
1306
1306
  } catch (e) {
1307
- 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}`);
1308
1308
  }
1309
1309
  return plugin;
1310
1310
  }
@@ -1739,11 +1739,12 @@ async function start(options = {}) {
1739
1739
  process.title = `mioki v${version}`;
1740
1740
  const logger = getMiokiLogger(botConfig.log_level || "info");
1741
1741
  const plugin_dir = getAbsPluginDir();
1742
- logger.info(`>>> ${consola_utils.colors.bold(consola_utils.colors.cyan("mioki"))} ${consola_utils.colors.bold(consola_utils.colors.green(`v${version}`))} 〓`);
1742
+ logger.info(`>>> -> ${consola_utils.colors.bold(consola_utils.colors.cyan("mioki"))} ${consola_utils.colors.bold(consola_utils.colors.green(`v${version}`))} <-`);
1743
1743
  logger.info(`>>> ${consola_utils.colors.yellow(consola_utils.colors.underline(`基于 NapCat 的 TypeScript 🤖️ 机器人框架。`))}`);
1744
- logger.info(`>>> ${consola_utils.colors.yellow(consola_utils.colors.underline(`作者: Viki <hi@viki.moe> (https://github.com/vikiboss)`))}`);
1745
- logger.info(`>>> ${consola_utils.colors.yellow(consola_utils.colors.underline(`协议: Licensed under MIT License.`))}`);
1746
- logger.info(`>>> ${consola_utils.colors.cyan(consola_utils.colors.underline(`GitHub: http://github.com/vikiboss/mioki`))}`);
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(">>> ----------------------------------------");
1747
1748
  logger.info(`>>> 工作目录: ${consola_utils.colors.bold(consola_utils.colors.blue(BOT_CWD.value))}`);
1748
1749
  logger.info(`>>> 插件目录: ${consola_utils.colors.bold(consola_utils.colors.blue(plugin_dir))}`);
1749
1750
  const napcat = new napcat_sdk.NapCat({
@@ -1751,7 +1752,7 @@ async function start(options = {}) {
1751
1752
  logger
1752
1753
  });
1753
1754
  napcat.on("napcat.connected", async ({ user_id, nickname }) => {
1754
- logger.info(`>>> 已连接到 NapCat: ${consola_utils.colors.bold(consola_utils.colors.green(nickname))} (${consola_utils.colors.bold(consola_utils.colors.green(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))})`);
1755
1756
  let lastNoticeTime = 0;
1756
1757
  process.on("uncaughtException", async (err) => {
1757
1758
  const msg = stringifyError(err);
@@ -1778,7 +1779,7 @@ async function start(options = {}) {
1778
1779
  absPath: node_path.default.resolve(plugin_dir, p)
1779
1780
  })).filter((p) => {
1780
1781
  if (!node_fs.default.existsSync(p.absPath)) {
1781
- napcat.logger.warn(`>>> 插件 ${p.dirName} 不存在,已忽略`);
1782
+ napcat.logger.warn(`>>> 插件 ${consola_utils.colors.bold(consola_utils.colors.red(p.dirName))} 不存在,已忽略`);
1782
1783
  return false;
1783
1784
  }
1784
1785
  return true;
@@ -1788,7 +1789,7 @@ async function start(options = {}) {
1788
1789
  try {
1789
1790
  const plugin = await jiti$1.import(absPath, { default: true });
1790
1791
  if (plugin.name !== dirName) {
1791
- 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))}] 不一致,可能导致重载异常,请修改一致后重启。`;
1792
1793
  napcat.logger.warn(tip);
1793
1794
  noticeMainOwner(napcat, tip);
1794
1795
  }
@@ -1802,7 +1803,7 @@ async function start(options = {}) {
1802
1803
  const start$1 = node_process.hrtime.bigint();
1803
1804
  const sortedUserPlugins = (await Promise.all(promises)).filter(Boolean).toSorted((prev, next) => (prev.priority ?? 100) - (next.priority ?? 100));
1804
1805
  if (failedImportPlugins.length) {
1805
- 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")}`;
1806
1807
  napcat.logger.warn(tip);
1807
1808
  noticeMainOwner(napcat, tip);
1808
1809
  }
@@ -1815,7 +1816,7 @@ async function start(options = {}) {
1815
1816
  const sortedGroups = Array.from(pluginGroups.entries()).toSorted(([a], [b]) => a - b);
1816
1817
  const failedEnablePlugins = [];
1817
1818
  try {
1818
- 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(", ")}`);
1819
1820
  await Promise.all(BUILTIN_PLUGINS.map((p) => enablePlugin(napcat, p, "builtin")));
1820
1821
  for (const [_, plugins$1] of sortedGroups) await Promise.all(plugins$1.map(async (p) => {
1821
1822
  try {
@@ -1833,9 +1834,9 @@ async function start(options = {}) {
1833
1834
  const end = node_process.hrtime.bigint();
1834
1835
  const costTime = Math.round(Number(end - start$1)) / 1e6;
1835
1836
  const failedCount = failedImportPlugins.length + failedEnablePlugins.length;
1836
- const failedInfo = failedCount > 0 ? `${failedCount} 个失败 (导入 ${failedImportPlugins.length},启用 ${failedImportPlugins.length})。` : "";
1837
- napcat.logger.info(`>>> 成功加载了 ${runtimePlugins.size} 个插件。${failedInfo ? failedInfo : ""}总耗时 ${costTime} ms`);
1838
- napcat.logger.info(`>>> mioki 启动完成!祝您使用愉快!🎉️`);
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} 启动完成!祝您使用愉快!🎉️`)));
1839
1840
  if (botConfig.online_push) await noticeMainOwner(napcat, `✅ mioki v${version} 已就绪`).catch((err) => {
1840
1841
  napcat.logger.error(`>>> 发送就绪通知失败: ${stringifyError(err)}`);
1841
1842
  });