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.d.mts CHANGED
@@ -368,6 +368,7 @@ interface MiokiConfig {
368
368
  plugins: string[];
369
369
  online_push?: boolean;
370
370
  log_level?: string;
371
+ plugin_dir?: string;
371
372
  napcat: {
372
373
  protocol?: "ws" | "wss";
373
374
  port?: number;
@@ -625,6 +626,8 @@ interface MiokiPlugin {
625
626
  priority?: number;
626
627
  /** 插件描述,额外提示信息,暂没有被使用到的地方 */
627
628
  description?: string;
629
+ /** 插件额外依赖,框架不处理,仅做参考提醒用途 */
630
+ dependencies?: string[];
628
631
  /** 插件初始化,返回一个清理函数,用于在插件卸载时清理资源,比如定时器、数据库连接等 */
629
632
  setup?: (ctx: MiokiContext) => any;
630
633
  }
@@ -634,11 +637,19 @@ interface MiokiPlugin {
634
637
  * @returns Mioki 插件对象
635
638
  */
636
639
  declare function definePlugin(plugin: MiokiPlugin): MiokiPlugin;
640
+ /**
641
+ * 确保插件目录存在
642
+ */
643
+ declare function ensurePluginDir(): void;
644
+ /**
645
+ * 获取插件目录的绝对路径
646
+ */
647
+ declare function getAbsPluginDir(defaultDir?: string): string;
637
648
  declare function enablePlugin(bot: NapCat, plugin: MiokiPlugin, type?: "builtin" | "external"): Promise<MiokiPlugin>;
638
649
  declare function findLocalPlugins(): Promise<{
639
650
  name: string;
640
651
  absPath: string;
641
652
  }[]>;
642
653
  //#endregion
643
- export { AnyFunc, Arrayable, BOT_CWD, ChromeUA, CreateCmdOptions, Gettable, HasMessage, MiokiConfig, MiokiContext, MiokiPlugin, MiokiServices, Noop, PureObject, START_TIME, StartOptions, addService, base64Decode, base64Encode, botConfig, clamp, createCmd, createDB, createForwardMsg, createStore, dayjs, dedent, definePlugin, enablePlugin, ensureBuffer, filesize, filter, find, findLocalPlugins, formatDuration, formatQQLevel, fs, getAuthCodeViaTicket, getBfaceUrl, getGroupAvatarLink, getImage, getImageUrl, getLogFilePath, getMentionedImage, getMentionedImageUrl, getMentionedUserId, getMinicoTokenViaAuthCode, getMiokiLogger, getQQAvatarLink, getQuoteImage, getQuoteImageUrl, getQuoteMessage, getQuoteText, getTerminalInput, getViolationRecords, hasRight, isAdmin, isBoolean, isDefined, isFunction, isGroupMsg, isInPm2, isNumber, isObject, isOwner, isOwnerOrAdmin, isPrivateMsg, isString, jiti, localNum, localeDate, localeTime, match, md5, mri, noNullish, noticeAdmins, noticeFriends, noticeGroups, noticeMainOwner, noticeOwners, path, prettyMs, qs, queryDevToolsLoginStatus, randomId, randomInt, randomItem, randomItems, readMiokiConfig, readPackageJson, requestLoginViaDevTools, runWithErrorHandler, runWithReaction, runtimePlugins, services, signArk, start, string2argv, stringifyError, systemInfo, text, toArray, toMsgId, unique, updateBotCWD, updateBotConfig, uploadImageToCollection, uploadImageToGroupHomework, uploadImageToGroupNotice, uuid, wait, writePackageJson };
654
+ export { AnyFunc, Arrayable, BOT_CWD, ChromeUA, CreateCmdOptions, Gettable, HasMessage, MiokiConfig, MiokiContext, MiokiPlugin, MiokiServices, Noop, PureObject, START_TIME, StartOptions, addService, base64Decode, base64Encode, botConfig, clamp, createCmd, createDB, createForwardMsg, createStore, dayjs, dedent, definePlugin, enablePlugin, ensureBuffer, ensurePluginDir, filesize, filter, find, findLocalPlugins, formatDuration, formatQQLevel, fs, getAbsPluginDir, getAuthCodeViaTicket, getBfaceUrl, getGroupAvatarLink, getImage, getImageUrl, getLogFilePath, getMentionedImage, getMentionedImageUrl, getMentionedUserId, getMinicoTokenViaAuthCode, getMiokiLogger, getQQAvatarLink, getQuoteImage, getQuoteImageUrl, getQuoteMessage, getQuoteText, getTerminalInput, getViolationRecords, hasRight, isAdmin, isBoolean, isDefined, isFunction, isGroupMsg, isInPm2, isNumber, isObject, isOwner, isOwnerOrAdmin, isPrivateMsg, isString, jiti, localNum, localeDate, localeTime, match, md5, mri, noNullish, noticeAdmins, noticeFriends, noticeGroups, noticeMainOwner, noticeOwners, path, prettyMs, qs, queryDevToolsLoginStatus, randomId, randomInt, randomItem, randomItems, readMiokiConfig, readPackageJson, requestLoginViaDevTools, runWithErrorHandler, runWithReaction, runtimePlugins, services, signArk, start, string2argv, stringifyError, systemInfo, text, toArray, toMsgId, unique, updateBotCWD, updateBotConfig, uploadImageToCollection, uploadImageToGroupHomework, uploadImageToGroupNotice, uuid, wait, writePackageJson };
644
655
  //# sourceMappingURL=index.d.mts.map
package/dist/index.mjs CHANGED
@@ -16,9 +16,9 @@ import { filesize } from "filesize";
16
16
  import dayjs from "dayjs";
17
17
  import dedent, { default as dedent$1 } from "dedent";
18
18
  import systemInfo from "systeminformation";
19
- import nodeCron from "node-cron";
20
19
  import os from "node:os";
21
20
  import cp from "node:child_process";
21
+ import nodeCron from "node-cron";
22
22
 
23
23
  //#region src/logger.ts
24
24
  const getMiokiLogger = (level) => {
@@ -836,7 +836,7 @@ function getLogFilePath(uin, platformName) {
836
836
 
837
837
  //#endregion
838
838
  //#region package.json
839
- var version = "0.2.0";
839
+ var version = "0.2.1";
840
840
 
841
841
  //#endregion
842
842
  //#region src/actions.ts
@@ -908,7 +908,7 @@ async function noticeOwners(bot, message, delay = 1e3) {
908
908
  * 群发通知给第一个主人
909
909
  */
910
910
  async function noticeMainOwner(bot, message) {
911
- if (!bot.isOnline) {
911
+ if (!bot.isOnline()) {
912
912
  bot.logger.error("发送失败,Bot 不在线");
913
913
  return;
914
914
  }
@@ -1119,6 +1119,20 @@ const buildRemovedActions = (bot) => Object.fromEntries(Object.entries(actions_e
1119
1119
  function definePlugin(plugin) {
1120
1120
  return plugin;
1121
1121
  }
1122
+ /**
1123
+ * 确保插件目录存在
1124
+ */
1125
+ function ensurePluginDir() {
1126
+ const dir = getAbsPluginDir();
1127
+ if (!fs$1.existsSync(dir)) fs$1.mkdirSync(dir, { recursive: true });
1128
+ }
1129
+ /**
1130
+ * 获取插件目录的绝对路径
1131
+ */
1132
+ function getAbsPluginDir(defaultDir = "plugin") {
1133
+ const cwd = BOT_CWD.value;
1134
+ return path$1.resolve(cwd, botConfig.plugin_dir || defaultDir);
1135
+ }
1122
1136
  async function enablePlugin(bot, plugin, type = "external") {
1123
1137
  const typeDesc = type === "builtin" ? "内置" : "用户";
1124
1138
  const pluginName = plugin.name || "null";
@@ -1178,9 +1192,9 @@ async function enablePlugin(bot, plugin, type = "external") {
1178
1192
  return plugin;
1179
1193
  }
1180
1194
  async function findLocalPlugins() {
1181
- return (await fs$1.promises.readdir(path$1.join(BOT_CWD.value, "plugins"), { withFileTypes: true })).filter((e) => e.isDirectory() && !!e.name && !e.name.startsWith("_")).map((e) => ({
1195
+ return (await fs$1.promises.readdir(getAbsPluginDir(), { withFileTypes: true })).filter((e) => e.isDirectory() && !!e.name && !e.name.startsWith("_")).map((e) => ({
1182
1196
  name: e.name,
1183
- absPath: path$1.join(BOT_CWD.value, "plugins", e.name)
1197
+ absPath: path$1.join(getAbsPluginDir(), e.name)
1184
1198
  }));
1185
1199
  }
1186
1200
 
@@ -1607,13 +1621,14 @@ async function start(options = {}) {
1607
1621
  if (cwd !== BOT_CWD.value) updateBotCWD(cwd);
1608
1622
  process.title = `mioki v${version}`;
1609
1623
  const logger = getMiokiLogger(botConfig.log_level || "info");
1610
- logger.info(`>>> mioki v${version} 启动中,工作目录: ${BOT_CWD.value}`);
1624
+ const plugin_dir = getAbsPluginDir();
1625
+ logger.info(`>>> mioki v${version} 启动中,工作目录: ${BOT_CWD.value},插件目录: ${plugin_dir}`);
1611
1626
  const napcat = new NapCat({
1612
1627
  ...botConfig.napcat,
1613
1628
  logger
1614
1629
  });
1615
1630
  napcat.on("napcat.connected", async ({ uin }) => {
1616
- logger.info(`>>> 已连接到 NapCat 服务器,账号: ${uin}`);
1631
+ logger.info(`>>> 已连接到 NapCat 服务器,当前登录 QQ 账号: ${uin}`);
1617
1632
  let lastNoticeTime = 0;
1618
1633
  process.on("uncaughtException", async (err) => {
1619
1634
  napcat.logger.error(">>> uncaughtException, 出错了", err);
@@ -1628,9 +1643,10 @@ async function start(options = {}) {
1628
1643
  const date = (/* @__PURE__ */ new Date()).toLocaleString();
1629
1644
  await noticeMainOwner(napcat, `【${date}】\n\nmioki 发生未处理异常:\n\n${err?.message || "未知错误"}`);
1630
1645
  });
1646
+ ensurePluginDir();
1631
1647
  const plugins = botConfig.plugins.map((p) => ({
1632
1648
  dirName: p,
1633
- absPath: path$1.resolve(BOT_CWD.value, "plugins", p)
1649
+ absPath: path$1.resolve(plugin_dir, p)
1634
1650
  })).filter((p) => {
1635
1651
  if (!fs$1.existsSync(p.absPath)) {
1636
1652
  napcat.logger.warn(`>>> 插件 ${p.dirName} 不存在,已忽略`);
@@ -1698,5 +1714,5 @@ async function start(options = {}) {
1698
1714
  }
1699
1715
 
1700
1716
  //#endregion
1701
- export { BOT_CWD, ChromeUA, START_TIME, addService, base64Decode, base64Encode, botConfig, clamp, createCmd, createDB, createForwardMsg, createStore, dayjs, dedent, definePlugin, enablePlugin, ensureBuffer, filesize, filter, find, findLocalPlugins, formatDuration, formatQQLevel, fs, getAuthCodeViaTicket, getBfaceUrl, getGroupAvatarLink, getImage, getImageUrl, getLogFilePath, getMentionedImage, getMentionedImageUrl, getMentionedUserId, getMinicoTokenViaAuthCode, getMiokiLogger, getQQAvatarLink, getQuoteImage, getQuoteImageUrl, getQuoteMessage, getQuoteText, getTerminalInput, getViolationRecords, hasRight, isAdmin, isBoolean, isDefined, isFunction, isGroupMsg, isInPm2, isNumber, isObject, isOwner, isOwnerOrAdmin, isPrivateMsg, isString, jiti, localNum, localeDate, localeTime, match, md5, mri, noNullish, noticeAdmins, noticeFriends, noticeGroups, noticeMainOwner, noticeOwners, path, prettyMs, qs, queryDevToolsLoginStatus, randomId, randomInt, randomItem, randomItems, readMiokiConfig, readPackageJson, requestLoginViaDevTools, runWithErrorHandler, runWithReaction, runtimePlugins, services, signArk, start, string2argv, stringifyError, systemInfo, text, toArray, toMsgId, unique, updateBotCWD, updateBotConfig, uploadImageToCollection, uploadImageToGroupHomework, uploadImageToGroupNotice, uuid, wait, writePackageJson };
1717
+ export { BOT_CWD, ChromeUA, START_TIME, addService, base64Decode, base64Encode, botConfig, clamp, createCmd, createDB, createForwardMsg, createStore, dayjs, dedent, definePlugin, enablePlugin, ensureBuffer, ensurePluginDir, filesize, filter, find, findLocalPlugins, formatDuration, formatQQLevel, fs, getAbsPluginDir, getAuthCodeViaTicket, getBfaceUrl, getGroupAvatarLink, getImage, getImageUrl, getLogFilePath, getMentionedImage, getMentionedImageUrl, getMentionedUserId, getMinicoTokenViaAuthCode, getMiokiLogger, getQQAvatarLink, getQuoteImage, getQuoteImageUrl, getQuoteMessage, getQuoteText, getTerminalInput, getViolationRecords, hasRight, isAdmin, isBoolean, isDefined, isFunction, isGroupMsg, isInPm2, isNumber, isObject, isOwner, isOwnerOrAdmin, isPrivateMsg, isString, jiti, localNum, localeDate, localeTime, match, md5, mri, noNullish, noticeAdmins, noticeFriends, noticeGroups, noticeMainOwner, noticeOwners, path, prettyMs, qs, queryDevToolsLoginStatus, randomId, randomInt, randomItem, randomItems, readMiokiConfig, readPackageJson, requestLoginViaDevTools, runWithErrorHandler, runWithReaction, runtimePlugins, services, signArk, start, string2argv, stringifyError, systemInfo, text, toArray, toMsgId, unique, updateBotCWD, updateBotConfig, uploadImageToCollection, uploadImageToGroupHomework, uploadImageToGroupNotice, uuid, wait, writePackageJson };
1702
1718
  //# sourceMappingURL=index.mjs.map