mioki 0.2.0 → 0.2.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
@@ -64,12 +64,12 @@ let dedent = require("dedent");
64
64
  dedent = __toESM(dedent);
65
65
  let systeminformation = require("systeminformation");
66
66
  systeminformation = __toESM(systeminformation);
67
- let node_cron = require("node-cron");
68
- node_cron = __toESM(node_cron);
69
67
  let node_os = require("node:os");
70
68
  node_os = __toESM(node_os);
71
69
  let node_child_process = require("node:child_process");
72
70
  node_child_process = __toESM(node_child_process);
71
+ let node_cron = require("node-cron");
72
+ node_cron = __toESM(node_cron);
73
73
 
74
74
  //#region src/logger.ts
75
75
  const getMiokiLogger = (level) => {
@@ -887,7 +887,7 @@ function getLogFilePath(uin, platformName) {
887
887
 
888
888
  //#endregion
889
889
  //#region package.json
890
- var version = "0.2.0";
890
+ var version = "0.2.1";
891
891
 
892
892
  //#endregion
893
893
  //#region src/actions.ts
@@ -959,7 +959,7 @@ async function noticeOwners(bot, message, delay = 1e3) {
959
959
  * 群发通知给第一个主人
960
960
  */
961
961
  async function noticeMainOwner(bot, message) {
962
- if (!bot.isOnline) {
962
+ if (!bot.isOnline()) {
963
963
  bot.logger.error("发送失败,Bot 不在线");
964
964
  return;
965
965
  }
@@ -1170,6 +1170,20 @@ const buildRemovedActions = (bot) => Object.fromEntries(Object.entries(actions_e
1170
1170
  function definePlugin(plugin) {
1171
1171
  return plugin;
1172
1172
  }
1173
+ /**
1174
+ * 确保插件目录存在
1175
+ */
1176
+ function ensurePluginDir() {
1177
+ const dir = getAbsPluginDir();
1178
+ if (!node_fs.default.existsSync(dir)) node_fs.default.mkdirSync(dir, { recursive: true });
1179
+ }
1180
+ /**
1181
+ * 获取插件目录的绝对路径
1182
+ */
1183
+ function getAbsPluginDir(defaultDir = "plugin") {
1184
+ const cwd = BOT_CWD.value;
1185
+ return node_path.default.resolve(cwd, botConfig.plugin_dir || defaultDir);
1186
+ }
1173
1187
  async function enablePlugin(bot, plugin, type = "external") {
1174
1188
  const typeDesc = type === "builtin" ? "内置" : "用户";
1175
1189
  const pluginName = plugin.name || "null";
@@ -1229,9 +1243,9 @@ async function enablePlugin(bot, plugin, type = "external") {
1229
1243
  return plugin;
1230
1244
  }
1231
1245
  async function findLocalPlugins() {
1232
- return (await node_fs.default.promises.readdir(node_path.default.join(BOT_CWD.value, "plugins"), { withFileTypes: true })).filter((e) => e.isDirectory() && !!e.name && !e.name.startsWith("_")).map((e) => ({
1246
+ return (await node_fs.default.promises.readdir(getAbsPluginDir(), { withFileTypes: true })).filter((e) => e.isDirectory() && !!e.name && !e.name.startsWith("_")).map((e) => ({
1233
1247
  name: e.name,
1234
- absPath: node_path.default.join(BOT_CWD.value, "plugins", e.name)
1248
+ absPath: node_path.default.join(getAbsPluginDir(), e.name)
1235
1249
  }));
1236
1250
  }
1237
1251
 
@@ -1658,13 +1672,14 @@ async function start(options = {}) {
1658
1672
  if (cwd !== BOT_CWD.value) updateBotCWD(cwd);
1659
1673
  process.title = `mioki v${version}`;
1660
1674
  const logger = getMiokiLogger(botConfig.log_level || "info");
1661
- logger.info(`>>> mioki v${version} 启动中,工作目录: ${BOT_CWD.value}`);
1675
+ const plugin_dir = getAbsPluginDir();
1676
+ logger.info(`>>> mioki v${version} 启动中,工作目录: ${BOT_CWD.value},插件目录: ${plugin_dir}`);
1662
1677
  const napcat = new napcat_sdk.NapCat({
1663
1678
  ...botConfig.napcat,
1664
1679
  logger
1665
1680
  });
1666
1681
  napcat.on("napcat.connected", async ({ uin }) => {
1667
- logger.info(`>>> 已连接到 NapCat 服务器,账号: ${uin}`);
1682
+ logger.info(`>>> 已连接到 NapCat 服务器,当前登录 QQ 账号: ${uin}`);
1668
1683
  let lastNoticeTime = 0;
1669
1684
  process.on("uncaughtException", async (err) => {
1670
1685
  napcat.logger.error(">>> uncaughtException, 出错了", err);
@@ -1679,9 +1694,10 @@ async function start(options = {}) {
1679
1694
  const date = (/* @__PURE__ */ new Date()).toLocaleString();
1680
1695
  await noticeMainOwner(napcat, `【${date}】\n\nmioki 发生未处理异常:\n\n${err?.message || "未知错误"}`);
1681
1696
  });
1697
+ ensurePluginDir();
1682
1698
  const plugins = botConfig.plugins.map((p) => ({
1683
1699
  dirName: p,
1684
- absPath: node_path.default.resolve(BOT_CWD.value, "plugins", p)
1700
+ absPath: node_path.default.resolve(plugin_dir, p)
1685
1701
  })).filter((p) => {
1686
1702
  if (!node_fs.default.existsSync(p.absPath)) {
1687
1703
  napcat.logger.warn(`>>> 插件 ${p.dirName} 不存在,已忽略`);
@@ -1776,6 +1792,7 @@ Object.defineProperty(exports, 'dedent', {
1776
1792
  exports.definePlugin = definePlugin;
1777
1793
  exports.enablePlugin = enablePlugin;
1778
1794
  exports.ensureBuffer = ensureBuffer;
1795
+ exports.ensurePluginDir = ensurePluginDir;
1779
1796
  Object.defineProperty(exports, 'filesize', {
1780
1797
  enumerable: true,
1781
1798
  get: function () {
@@ -1793,6 +1810,7 @@ Object.defineProperty(exports, 'fs', {
1793
1810
  return node_fs.default;
1794
1811
  }
1795
1812
  });
1813
+ exports.getAbsPluginDir = getAbsPluginDir;
1796
1814
  exports.getAuthCodeViaTicket = getAuthCodeViaTicket;
1797
1815
  exports.getBfaceUrl = getBfaceUrl;
1798
1816
  exports.getGroupAvatarLink = getGroupAvatarLink;