mioki 0.4.0 → 0.4.2

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.mjs CHANGED
@@ -866,7 +866,7 @@ const getMiokiLogger = (level) => {
866
866
  fs$1.appendFileSync(logFile, line + "\n");
867
867
  } }, { log: (logObj) => {
868
868
  const message = logObj.message || logObj.args?.join(" ") || "";
869
- const line = `${colors.gray(`[${logObj.date.toLocaleTimeString("zh-CN")}]`) + " " + colors.bold(colors[LEVEL_MAP[logObj.level].color](LEVEL_MAP[logObj.level].name)) + " " + (logObj.tag ? colors.bold(colors.dim(`[${logObj.tag}] `)) : "")}${message}`;
869
+ const line = `${colors.gray(`[${logObj.date.toLocaleTimeString("zh-CN")}]`) + " " + colors.bold(colors[LEVEL_MAP[logObj.level].color](LEVEL_MAP[logObj.level].name)) + " " + (logObj.tag ? colors.dim(`[${logObj.tag}] `) : "")}${message}`;
870
870
  if (logObj.level <= LogLevels["info"]) console.log(line);
871
871
  else if (logObj.level === LogLevels["warn"]) console.warn(line);
872
872
  else console.debug(line);
@@ -881,7 +881,7 @@ const getMiokiLogger = (level) => {
881
881
 
882
882
  //#endregion
883
883
  //#region package.json
884
- var version = "0.4.0";
884
+ var version = "0.4.2";
885
885
 
886
886
  //#endregion
887
887
  //#region src/actions.ts
@@ -1246,15 +1246,15 @@ async function enablePlugin(bot, plugin, type = "external") {
1246
1246
  await Promise.all([...clears, ...userClears].map((fn) => fn?.()));
1247
1247
  runtimePlugins.delete(name);
1248
1248
  } catch (err) {
1249
- throw new Error(`>>> 禁用插件 [${typeDesc}]${name}@${version$1} 失败: ${err?.message}`);
1249
+ throw new Error(`>>> 禁用插件 [${colors.bold(colors.yellow(typeDesc))}]${colors.bold(colors.yellow(name))}@${colors.bold(colors.yellow(version$1))} 失败: ${err?.message}`);
1250
1250
  }
1251
1251
  }
1252
1252
  });
1253
1253
  const end = hrtime.bigint();
1254
1254
  const time = Math.round(Number(end - start$1)) / 1e6;
1255
- bot.logger.info(`>>> 启用插件 [${typeDesc}]${name}@${version$1} => 耗时 ${time} ms`);
1255
+ bot.logger.info(`>>> 启用插件 ${colors.bold(colors.yellow(`[${typeDesc}]`))}${colors.bold(colors.yellow(`${name}@${version$1}`))} => 耗时 ${colors.bold(colors.green(time.toFixed(2)))} ms`);
1256
1256
  } catch (e) {
1257
- throw new Error(`>>> 启用插件 [${typeDesc}]${name}@${version$1} 失败: ${e?.message}`);
1257
+ throw new Error(`>>> 启用插件 ${colors.bold(colors.yellow(`[${typeDesc}]`))}${colors.bold(colors.yellow(`${name}@${version$1}`))} 失败: ${e?.message}`);
1258
1258
  }
1259
1259
  return plugin;
1260
1260
  }
@@ -1493,7 +1493,7 @@ const core = definePlugin({
1493
1493
  await e.reply(`插件 ${target} 已经是启用状态`, true);
1494
1494
  return;
1495
1495
  }
1496
- const pluginPath = path$1.join(BOT_CWD.value, "plugins", target);
1496
+ const pluginPath = path$1.join(getAbsPluginDir(), target);
1497
1497
  if (!fs$1.existsSync(pluginPath)) {
1498
1498
  await e.reply(`插件 ${target} 不存在`, true);
1499
1499
  return;
@@ -1544,7 +1544,7 @@ const core = definePlugin({
1544
1544
  const plugin = runtimePlugins.get(target);
1545
1545
  try {
1546
1546
  if (plugin) await plugin.disable();
1547
- const pluginPath = path$1.join(BOT_CWD.value, "plugins", target);
1547
+ const pluginPath = path$1.join(getAbsPluginDir(), target);
1548
1548
  if (!fs$1.existsSync(pluginPath)) {
1549
1549
  await e.reply(`插件 ${target} 不存在`, true);
1550
1550
  return;
@@ -1689,11 +1689,12 @@ async function start(options = {}) {
1689
1689
  process.title = `mioki v${version}`;
1690
1690
  const logger = getMiokiLogger(botConfig.log_level || "info");
1691
1691
  const plugin_dir = getAbsPluginDir();
1692
- logger.info(`>>> ${colors.bold(colors.cyan("mioki"))} ${colors.bold(colors.green(`v${version}`))} 〓`);
1692
+ logger.info(`>>> -> ${colors.bold(colors.cyan("mioki"))} ${colors.bold(colors.green(`v${version}`))} <-`);
1693
1693
  logger.info(`>>> ${colors.yellow(colors.underline(`基于 NapCat 的 TypeScript 🤖️ 机器人框架。`))}`);
1694
- logger.info(`>>> ${colors.yellow(colors.underline(`作者: Viki <hi@viki.moe> (https://github.com/vikiboss)`))}`);
1695
- logger.info(`>>> ${colors.yellow(colors.underline(`协议: Licensed under MIT License.`))}`);
1696
- logger.info(`>>> ${colors.cyan(colors.underline(`GitHub: http://github.com/vikiboss/mioki`))}`);
1694
+ logger.info(`>>> ${colors.italic(`作者: Viki <hi@viki.moe> (https://github.com/vikiboss)`)}`);
1695
+ logger.info(`>>> ${colors.italic(`协议: Licensed under MIT License.`)}`);
1696
+ logger.info(`>>> ${colors.cyan(`GitHub: https://github.com/vikiboss/mioki`)}`);
1697
+ logger.info(">>> ----------------------------------------");
1697
1698
  logger.info(`>>> 工作目录: ${colors.bold(colors.blue(BOT_CWD.value))}`);
1698
1699
  logger.info(`>>> 插件目录: ${colors.bold(colors.blue(plugin_dir))}`);
1699
1700
  const napcat = new NapCat({
@@ -1701,7 +1702,7 @@ async function start(options = {}) {
1701
1702
  logger
1702
1703
  });
1703
1704
  napcat.on("napcat.connected", async ({ user_id, nickname }) => {
1704
- logger.info(`>>> 已连接到 NapCat: ${colors.bold(colors.green(nickname))} (${colors.bold(colors.green(user_id))})`);
1705
+ logger.info(`>>> 已连接到 NapCat: ${colors.bold(colors.green(nickname))}(${colors.bold(colors.green(user_id))})`);
1705
1706
  let lastNoticeTime = 0;
1706
1707
  process.on("uncaughtException", async (err) => {
1707
1708
  const msg = stringifyError(err);
@@ -1728,7 +1729,7 @@ async function start(options = {}) {
1728
1729
  absPath: path$1.resolve(plugin_dir, p)
1729
1730
  })).filter((p) => {
1730
1731
  if (!fs$1.existsSync(p.absPath)) {
1731
- napcat.logger.warn(`>>> 插件 ${p.dirName} 不存在,已忽略`);
1732
+ napcat.logger.warn(`>>> 插件 ${colors.bold(colors.red(p.dirName))} 不存在,已忽略`);
1732
1733
  return false;
1733
1734
  }
1734
1735
  return true;
@@ -1738,7 +1739,7 @@ async function start(options = {}) {
1738
1739
  try {
1739
1740
  const plugin = await jiti.import(absPath, { default: true });
1740
1741
  if (plugin.name !== dirName) {
1741
- const tip = `>>> 插件目录名 [${dirName}] 和插件声明的 name [${plugin.name}] 不一致,可能导致重载异常,请修改一致后重启。`;
1742
+ const tip = `>>> 插件目录名 [${colors.bold(colors.yellow(dirName))}] 和插件声明的 name [${colors.bold(colors.yellow(plugin.name))}] 不一致,可能导致重载异常,请修改一致后重启。`;
1742
1743
  napcat.logger.warn(tip);
1743
1744
  noticeMainOwner(napcat, tip);
1744
1745
  }
@@ -1752,7 +1753,7 @@ async function start(options = {}) {
1752
1753
  const start$1 = hrtime.bigint();
1753
1754
  const sortedUserPlugins = (await Promise.all(promises)).filter(Boolean).toSorted((prev, next) => (prev.priority ?? 100) - (next.priority ?? 100));
1754
1755
  if (failedImportPlugins.length) {
1755
- const tip = `>>> ${failedImportPlugins.length} 个插件加载失败: \n\n${failedImportPlugins.map(([dirName, err]) => `${dirName}: ${err}`).join("\n\n")}`;
1756
+ const tip = `>>> ${colors.bold(colors.red(failedImportPlugins.length))} 个插件加载失败: \n\n${failedImportPlugins.map(([dirName, err]) => `${dirName}: ${err}`).join("\n\n")}`;
1756
1757
  napcat.logger.warn(tip);
1757
1758
  noticeMainOwner(napcat, tip);
1758
1759
  }
@@ -1765,7 +1766,7 @@ async function start(options = {}) {
1765
1766
  const sortedGroups = Array.from(pluginGroups.entries()).toSorted(([a], [b]) => a - b);
1766
1767
  const failedEnablePlugins = [];
1767
1768
  try {
1768
- napcat.logger.info(`>>> 加载内置插件: ${BUILTIN_PLUGINS.map((p) => p.name).join(", ")}`);
1769
+ napcat.logger.info(`>>> 加载内置插件: ${BUILTIN_PLUGINS.map((p) => colors.bold(colors.cyan(p.name))).join(", ")}`);
1769
1770
  await Promise.all(BUILTIN_PLUGINS.map((p) => enablePlugin(napcat, p, "builtin")));
1770
1771
  for (const [_, plugins$1] of sortedGroups) await Promise.all(plugins$1.map(async (p) => {
1771
1772
  try {
@@ -1783,9 +1784,9 @@ async function start(options = {}) {
1783
1784
  const end = hrtime.bigint();
1784
1785
  const costTime = Math.round(Number(end - start$1)) / 1e6;
1785
1786
  const failedCount = failedImportPlugins.length + failedEnablePlugins.length;
1786
- const failedInfo = failedCount > 0 ? `${failedCount} 个失败 (导入 ${failedImportPlugins.length},启用 ${failedImportPlugins.length})。` : "";
1787
- napcat.logger.info(`>>> 成功加载了 ${runtimePlugins.size} 个插件。${failedInfo ? failedInfo : ""}总耗时 ${costTime} ms`);
1788
- napcat.logger.info(`>>> mioki 启动完成!祝您使用愉快!🎉️`);
1787
+ const failedInfo = failedCount > 0 ? `${colors.bold(colors.red(failedCount))} 个失败 (导入 ${colors.bold(colors.red(failedImportPlugins.length))},启用 ${colors.bold(colors.red(failedEnablePlugins.length))})。` : "";
1788
+ napcat.logger.info(`>>> 成功加载了 ${colors.bold(colors.green(runtimePlugins.size))} 个插件。${failedInfo ? failedInfo : ""}总耗时 ${colors.bold(colors.green(costTime.toFixed(2)))} ms`);
1789
+ napcat.logger.info(colors.bold(colors.green(`>>> mioki v${version} 启动完成!祝您使用愉快!🎉️`)));
1789
1790
  if (botConfig.online_push) await noticeMainOwner(napcat, `✅ mioki v${version} 已就绪`).catch((err) => {
1790
1791
  napcat.logger.error(`>>> 发送就绪通知失败: ${stringifyError(err)}`);
1791
1792
  });