mioki 0.2.0 → 0.2.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.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) => {
@@ -90,7 +90,6 @@ var utils_exports = /* @__PURE__ */ __export({
90
90
  START_TIME: () => START_TIME,
91
91
  base64Decode: () => base64Decode,
92
92
  base64Encode: () => base64Encode,
93
- bindBot: () => bindBot,
94
93
  clamp: () => clamp,
95
94
  createCmd: () => createCmd,
96
95
  createDB: () => createDB,
@@ -188,9 +187,9 @@ const jiti$1 = (0, jiti.createJiti)(__dirname, {
188
187
  function createCmd(cmdStr, options = {}) {
189
188
  const { prefix = "", onPrefix = () => {} } = options;
190
189
  const { _, ...cmdOptions } = (0, mri.default)((0, string2argv.string2argv)(cmdStr));
191
- const [cmd$1, ...params] = _;
190
+ const [cmd, ...params] = _;
192
191
  if (prefix) {
193
- if (cmd$1 !== prefix) return {
192
+ if (cmd !== prefix) return {
194
193
  cmd: void 0,
195
194
  params: [],
196
195
  options: cmdOptions
@@ -203,7 +202,7 @@ function createCmd(cmdStr, options = {}) {
203
202
  };
204
203
  }
205
204
  return {
206
- cmd: cmd$1,
205
+ cmd,
207
206
  params,
208
207
  options: cmdOptions
209
208
  };
@@ -782,9 +781,6 @@ async function getTerminalInput(inputTip = "请输入") {
782
781
  getInput();
783
782
  });
784
783
  }
785
- function bindBot(bot, func) {
786
- return (...args) => func(bot, ...args);
787
- }
788
784
  /**
789
785
  * 当前 Node.js 进程的启动时间,常量,Date 类型
790
786
  */
@@ -887,7 +883,7 @@ function getLogFilePath(uin, platformName) {
887
883
 
888
884
  //#endregion
889
885
  //#region package.json
890
- var version = "0.2.0";
886
+ var version = "0.2.2";
891
887
 
892
888
  //#endregion
893
889
  //#region src/actions.ts
@@ -959,7 +955,7 @@ async function noticeOwners(bot, message, delay = 1e3) {
959
955
  * 群发通知给第一个主人
960
956
  */
961
957
  async function noticeMainOwner(bot, message) {
962
- if (!bot.isOnline) {
958
+ if (!bot.isOnline()) {
963
959
  bot.logger.error("发送失败,Bot 不在线");
964
960
  return;
965
961
  }
@@ -1160,6 +1156,9 @@ function addService(name, service, cover = true) {
1160
1156
 
1161
1157
  //#endregion
1162
1158
  //#region src/plugin.ts
1159
+ function bindBot(bot, func) {
1160
+ return (...args) => func(bot, ...args);
1161
+ }
1163
1162
  const runtimePlugins = /* @__PURE__ */ new Map();
1164
1163
  const buildRemovedActions = (bot) => Object.fromEntries(Object.entries(actions_exports).map(([k, v]) => [k, bindBot(bot, v)]));
1165
1164
  /**
@@ -1170,6 +1169,20 @@ const buildRemovedActions = (bot) => Object.fromEntries(Object.entries(actions_e
1170
1169
  function definePlugin(plugin) {
1171
1170
  return plugin;
1172
1171
  }
1172
+ /**
1173
+ * 确保插件目录存在
1174
+ */
1175
+ function ensurePluginDir() {
1176
+ const dir = getAbsPluginDir();
1177
+ if (!node_fs.default.existsSync(dir)) node_fs.default.mkdirSync(dir, { recursive: true });
1178
+ }
1179
+ /**
1180
+ * 获取插件目录的绝对路径
1181
+ */
1182
+ function getAbsPluginDir(defaultDir = "plugins") {
1183
+ const cwd = BOT_CWD.value;
1184
+ return node_path.default.join(cwd, botConfig.plugins_dir || defaultDir);
1185
+ }
1173
1186
  async function enablePlugin(bot, plugin, type = "external") {
1174
1187
  const typeDesc = type === "builtin" ? "内置" : "用户";
1175
1188
  const pluginName = plugin.name || "null";
@@ -1181,6 +1194,7 @@ async function enablePlugin(bot, plugin, type = "external") {
1181
1194
  const context = {
1182
1195
  bot,
1183
1196
  segment: bot.segment,
1197
+ getCookie: bot.getCookie,
1184
1198
  ...utils_exports,
1185
1199
  ...config_exports,
1186
1200
  ...buildRemovedActions(bot),
@@ -1229,14 +1243,14 @@ 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
 
1238
1252
  //#endregion
1239
- //#region src/builtins/cmd/status.ts
1253
+ //#region src/builtins/core/status.ts
1240
1254
  const SystemMap = {
1241
1255
  Linux: "Linux",
1242
1256
  Darwin: "macOS",
@@ -1288,8 +1302,8 @@ async function getMiokiStatus(bot) {
1288
1302
  protocol: versionInfo.protocol_version
1289
1303
  },
1290
1304
  system: {
1291
- name: system.name,
1292
- version: system.version,
1305
+ name: system.name || "N/A",
1306
+ version: system.version || "N/A",
1293
1307
  arch
1294
1308
  },
1295
1309
  memory: {
@@ -1308,7 +1322,7 @@ async function getMiokiStatus(bot) {
1308
1322
  percent: 0
1309
1323
  },
1310
1324
  cpu: {
1311
- name: cpu.name,
1325
+ name: cpu.name.trim(),
1312
1326
  count: cpu.count,
1313
1327
  percent: Number((await measureCpuUsage()).toFixed(1))
1314
1328
  }
@@ -1327,7 +1341,7 @@ async function getMiokiStatusStr(client) {
1327
1341
  hideYear: true,
1328
1342
  secondsDecimalDigits: 0
1329
1343
  })}
1330
- 🤖 NapCat/${versions.napcat}-mioki/${versions.mioki}
1344
+ 🤖 mioki/${versions.mioki}-NapCat/${versions.napcat}
1331
1345
  🖥️ ${system.name.split(" ")[0]}/${system.version.split(".")[0]}-${system.name}-node/${versions.node.split(".")[0]}
1332
1346
  📊 ${memory.percent}%-${(0, filesize.filesize)(memory.used, {
1333
1347
  base: 2,
@@ -1337,7 +1351,7 @@ async function getMiokiStatusStr(client) {
1337
1351
  round: 1
1338
1352
  })}
1339
1353
  🧮 ${cpu.percent}%-${cpu.name}-${cpu.count}核
1340
- 💾 ${diskValid ? diskDesc : "N/A (不适用)"}
1354
+ ${diskValid ? `💾 ${diskDesc}` : ""}
1341
1355
  `.trim();
1342
1356
  }
1343
1357
  async function getDiskUsageInUnix(path$6 = "/") {
@@ -1393,10 +1407,10 @@ function getCpuInfo() {
1393
1407
  }
1394
1408
 
1395
1409
  //#endregion
1396
- //#region src/builtins/cmd/index.ts
1397
- const corePlugins = ["mioki-cmd"];
1398
- const cmd = definePlugin({
1399
- name: "kivi-cmd",
1410
+ //#region src/builtins/core/index.ts
1411
+ const corePlugins = ["mioki-core"];
1412
+ const core = definePlugin({
1413
+ name: "mioki-core",
1400
1414
  version,
1401
1415
  priority: 1,
1402
1416
  setup(ctx) {
@@ -1414,9 +1428,9 @@ const cmd = definePlugin({
1414
1428
  }
1415
1429
  if (!ctx.isOwner(e)) return;
1416
1430
  const { _: params, ..._options } = (0, mri.default)((0, string2argv.string2argv)(text$1));
1417
- const cmd$1 = params.shift()?.replace(cmdPrefix, "") ?? "";
1431
+ const cmd = params.shift()?.replace(cmdPrefix, "") ?? "";
1418
1432
  const [subCmd, target, ..._subParams] = params;
1419
- switch (cmd$1) {
1433
+ switch (cmd) {
1420
1434
  case "帮助":
1421
1435
  await e.reply((0, dedent.default)(`
1422
1436
  〓 💡 mioki 帮助 〓
@@ -1645,11 +1659,11 @@ const cmd = definePlugin({
1645
1659
  }, e));
1646
1660
  }
1647
1661
  });
1648
- var cmd_default = cmd;
1662
+ var core_default = core;
1649
1663
 
1650
1664
  //#endregion
1651
1665
  //#region src/builtins/index.ts
1652
- const BUILTIN_PLUGINS = [cmd_default];
1666
+ const BUILTIN_PLUGINS = [core_default];
1653
1667
 
1654
1668
  //#endregion
1655
1669
  //#region src/start.ts
@@ -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} 不存在,已忽略`);
@@ -1755,6 +1771,7 @@ exports.START_TIME = START_TIME;
1755
1771
  exports.addService = addService;
1756
1772
  exports.base64Decode = base64Decode;
1757
1773
  exports.base64Encode = base64Encode;
1774
+ exports.bindBot = bindBot;
1758
1775
  exports.botConfig = botConfig;
1759
1776
  exports.clamp = clamp;
1760
1777
  exports.createCmd = createCmd;
@@ -1776,6 +1793,7 @@ Object.defineProperty(exports, 'dedent', {
1776
1793
  exports.definePlugin = definePlugin;
1777
1794
  exports.enablePlugin = enablePlugin;
1778
1795
  exports.ensureBuffer = ensureBuffer;
1796
+ exports.ensurePluginDir = ensurePluginDir;
1779
1797
  Object.defineProperty(exports, 'filesize', {
1780
1798
  enumerable: true,
1781
1799
  get: function () {
@@ -1793,6 +1811,7 @@ Object.defineProperty(exports, 'fs', {
1793
1811
  return node_fs.default;
1794
1812
  }
1795
1813
  });
1814
+ exports.getAbsPluginDir = getAbsPluginDir;
1796
1815
  exports.getAuthCodeViaTicket = getAuthCodeViaTicket;
1797
1816
  exports.getBfaceUrl = getBfaceUrl;
1798
1817
  exports.getGroupAvatarLink = getGroupAvatarLink;