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 +49 -30
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +20 -8
- package/dist/index.d.mts +20 -8
- package/dist/index.mjs +46 -30
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -2
package/dist/index.d.cts
CHANGED
|
@@ -25,7 +25,7 @@ interface StartOptions {
|
|
|
25
25
|
}
|
|
26
26
|
declare function start(options?: StartOptions): Promise<void>;
|
|
27
27
|
declare namespace utils_d_exports {
|
|
28
|
-
export { AnyFunc, Arrayable, ChromeUA, CreateCmdOptions, Gettable, HasMessage, Noop,
|
|
28
|
+
export { AnyFunc, Arrayable, ChromeUA, CreateCmdOptions, Gettable, HasMessage, Noop, PureObject, START_TIME, base64Decode, base64Encode, clamp, createCmd, createDB, createStore, dayjs, dedent, ensureBuffer, filesize, filter, find, formatDuration, formatQQLevel, fs, getAuthCodeViaTicket, getBfaceUrl, getGroupAvatarLink, getImage, getImageUrl, getMentionedImage, getMentionedImageUrl, getMentionedUserId, getMinicoTokenViaAuthCode, getQQAvatarLink, getQuoteImage, getQuoteImageUrl, getQuoteMessage, getQuoteText, getTerminalInput, isBoolean, isDefined, isFunction, isGroupMsg, isNumber, isObject, isPrivateMsg, isString, jiti, localNum, localeDate, localeTime, match, md5, mri, noNullish, path, prettyMs, qs, queryDevToolsLoginStatus, randomId, randomInt, randomItem, randomItems, requestLoginViaDevTools, runWithReaction, string2argv, stringifyError, systemInfo, text, toArray, toMsgId, unique, uuid, wait };
|
|
29
29
|
}
|
|
30
30
|
declare const ChromeUA = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) Chrome/131.0.0.0";
|
|
31
31
|
type Noop = () => void;
|
|
@@ -351,8 +351,6 @@ declare function getMinicoTokenViaAuthCode(authCode: string, appid: number): Pro
|
|
|
351
351
|
* 获取终端输入,返回 Promise,支持提示信息
|
|
352
352
|
*/
|
|
353
353
|
declare function getTerminalInput(inputTip?: string): Promise<string>;
|
|
354
|
-
type OmitBotParamFromFunc$1<Func extends (bot: NapCat, ...args: any[]) => any> = Func extends ((bot: NapCat, ...args: infer A) => infer Return) ? (...args: A) => Return : never;
|
|
355
|
-
declare function bindBot<Params extends Array<any> = any[], Return$1 = any>(bot: NapCat, func: (bot: NapCat, ...args: Params) => Return$1): OmitBotParamFromFunc$1<(bot: NapCat, ...args: Params) => Return$1>;
|
|
356
354
|
/**
|
|
357
355
|
* 当前 Node.js 进程的启动时间,常量,Date 类型
|
|
358
356
|
*/
|
|
@@ -370,6 +368,7 @@ interface MiokiConfig {
|
|
|
370
368
|
plugins: string[];
|
|
371
369
|
online_push?: boolean;
|
|
372
370
|
log_level?: string;
|
|
371
|
+
plugins_dir?: string;
|
|
373
372
|
napcat: {
|
|
374
373
|
protocol?: "ws" | "wss";
|
|
375
374
|
port?: number;
|
|
@@ -518,7 +517,7 @@ declare function getViolationRecords(bot: NapCat, authCode: string, appid: numbe
|
|
|
518
517
|
reason: number;
|
|
519
518
|
}[]>;
|
|
520
519
|
//#endregion
|
|
521
|
-
//#region src/builtins/
|
|
520
|
+
//#region src/builtins/core/status.d.ts
|
|
522
521
|
interface MiokiStatus {
|
|
523
522
|
bot: {
|
|
524
523
|
uin: number;
|
|
@@ -564,15 +563,15 @@ interface MiokiStatus {
|
|
|
564
563
|
};
|
|
565
564
|
}
|
|
566
565
|
//#endregion
|
|
567
|
-
//#region src/builtins/
|
|
568
|
-
interface
|
|
566
|
+
//#region src/builtins/core/index.d.ts
|
|
567
|
+
interface MiokiCoreServiceContrib {
|
|
569
568
|
/** 获取框架和系统的实时状态 */
|
|
570
569
|
getMiokiStatus(): Promise<MiokiStatus>;
|
|
571
570
|
}
|
|
572
571
|
declare namespace services_d_exports {
|
|
573
572
|
export { MiokiServices, addService, services };
|
|
574
573
|
}
|
|
575
|
-
interface MiokiServices extends Record<string, unknown>,
|
|
574
|
+
interface MiokiServices extends Record<string, unknown>, MiokiCoreServiceContrib {}
|
|
576
575
|
/**
|
|
577
576
|
* 服务,由其他插件贡献的方法、数据等
|
|
578
577
|
*/
|
|
@@ -595,6 +594,7 @@ type Services = typeof services_d_exports;
|
|
|
595
594
|
type StrictEqual<T, U> = (<G>() => G extends T ? 1 : 2) extends (<G>() => G extends U ? 1 : 2) ? true : false;
|
|
596
595
|
type RemoveBotParam<T> = { [K in keyof T]: T[K] extends ((...args: any[]) => any) ? StrictEqual<Parameters<T[K]>[0], NapCat> extends true ? OmitBotParamFromFunc<T[K]> : never : never };
|
|
597
596
|
type OmitBotParamFromFunc<Func extends (bot: NapCat, ...args: any[]) => any> = Func extends ((bot: NapCat, ...args: infer A) => infer Return) ? (...args: A) => Return : never;
|
|
597
|
+
declare function bindBot<Params extends Array<any> = any[], Return$1 = any>(bot: NapCat, func: (bot: NapCat, ...args: Params) => Return$1): OmitBotParamFromFunc<(bot: NapCat, ...args: Params) => Return$1>;
|
|
598
598
|
/**
|
|
599
599
|
* Mioki 上下文对象,包含 Mioki 运行时的信息和方法
|
|
600
600
|
*/
|
|
@@ -603,6 +603,8 @@ interface MiokiContext extends Services, Configs, Utils, RemoveBotParam<Actions>
|
|
|
603
603
|
bot: NapCat;
|
|
604
604
|
/** 消息构造器 */
|
|
605
605
|
segment: NapCat["segment"];
|
|
606
|
+
/** 通过域名获取 Cookies */
|
|
607
|
+
getCookie: NapCat["getCookie"];
|
|
606
608
|
/** 注册事件处理器 */
|
|
607
609
|
handle: <EventName extends keyof EventMap>(eventName: EventName, handler: (event: EventMap[EventName]) => any) => void;
|
|
608
610
|
/** 注册定时任务 */
|
|
@@ -627,6 +629,8 @@ interface MiokiPlugin {
|
|
|
627
629
|
priority?: number;
|
|
628
630
|
/** 插件描述,额外提示信息,暂没有被使用到的地方 */
|
|
629
631
|
description?: string;
|
|
632
|
+
/** 插件额外依赖,框架不处理,仅做参考提醒用途 */
|
|
633
|
+
dependencies?: string[];
|
|
630
634
|
/** 插件初始化,返回一个清理函数,用于在插件卸载时清理资源,比如定时器、数据库连接等 */
|
|
631
635
|
setup?: (ctx: MiokiContext) => any;
|
|
632
636
|
}
|
|
@@ -636,11 +640,19 @@ interface MiokiPlugin {
|
|
|
636
640
|
* @returns Mioki 插件对象
|
|
637
641
|
*/
|
|
638
642
|
declare function definePlugin(plugin: MiokiPlugin): MiokiPlugin;
|
|
643
|
+
/**
|
|
644
|
+
* 确保插件目录存在
|
|
645
|
+
*/
|
|
646
|
+
declare function ensurePluginDir(): void;
|
|
647
|
+
/**
|
|
648
|
+
* 获取插件目录的绝对路径
|
|
649
|
+
*/
|
|
650
|
+
declare function getAbsPluginDir(defaultDir?: string): string;
|
|
639
651
|
declare function enablePlugin(bot: NapCat, plugin: MiokiPlugin, type?: "builtin" | "external"): Promise<MiokiPlugin>;
|
|
640
652
|
declare function findLocalPlugins(): Promise<{
|
|
641
653
|
name: string;
|
|
642
654
|
absPath: string;
|
|
643
655
|
}[]>;
|
|
644
656
|
//#endregion
|
|
645
|
-
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 };
|
|
657
|
+
export { AnyFunc, Arrayable, BOT_CWD, ChromeUA, CreateCmdOptions, Gettable, HasMessage, MiokiConfig, MiokiContext, MiokiPlugin, MiokiServices, Noop, OmitBotParamFromFunc, PureObject, START_TIME, StartOptions, addService, base64Decode, base64Encode, bindBot, 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 };
|
|
646
658
|
//# sourceMappingURL=index.d.cts.map
|
package/dist/index.d.mts
CHANGED
|
@@ -23,7 +23,7 @@ interface StartOptions {
|
|
|
23
23
|
}
|
|
24
24
|
declare function start(options?: StartOptions): Promise<void>;
|
|
25
25
|
declare namespace utils_d_exports {
|
|
26
|
-
export { AnyFunc, Arrayable, ChromeUA, CreateCmdOptions, Gettable, HasMessage, Noop,
|
|
26
|
+
export { AnyFunc, Arrayable, ChromeUA, CreateCmdOptions, Gettable, HasMessage, Noop, PureObject, START_TIME, base64Decode, base64Encode, clamp, createCmd, createDB, createStore, dayjs, dedent, ensureBuffer, filesize, filter, find, formatDuration, formatQQLevel, fs, getAuthCodeViaTicket, getBfaceUrl, getGroupAvatarLink, getImage, getImageUrl, getMentionedImage, getMentionedImageUrl, getMentionedUserId, getMinicoTokenViaAuthCode, getQQAvatarLink, getQuoteImage, getQuoteImageUrl, getQuoteMessage, getQuoteText, getTerminalInput, isBoolean, isDefined, isFunction, isGroupMsg, isNumber, isObject, isPrivateMsg, isString, jiti, localNum, localeDate, localeTime, match, md5, mri, noNullish, path, prettyMs, qs, queryDevToolsLoginStatus, randomId, randomInt, randomItem, randomItems, requestLoginViaDevTools, runWithReaction, string2argv, stringifyError, systemInfo, text, toArray, toMsgId, unique, uuid, wait };
|
|
27
27
|
}
|
|
28
28
|
declare const ChromeUA = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) Chrome/131.0.0.0";
|
|
29
29
|
type Noop = () => void;
|
|
@@ -349,8 +349,6 @@ declare function getMinicoTokenViaAuthCode(authCode: string, appid: number): Pro
|
|
|
349
349
|
* 获取终端输入,返回 Promise,支持提示信息
|
|
350
350
|
*/
|
|
351
351
|
declare function getTerminalInput(inputTip?: string): Promise<string>;
|
|
352
|
-
type OmitBotParamFromFunc$1<Func extends (bot: NapCat, ...args: any[]) => any> = Func extends ((bot: NapCat, ...args: infer A) => infer Return) ? (...args: A) => Return : never;
|
|
353
|
-
declare function bindBot<Params extends Array<any> = any[], Return$1 = any>(bot: NapCat, func: (bot: NapCat, ...args: Params) => Return$1): OmitBotParamFromFunc$1<(bot: NapCat, ...args: Params) => Return$1>;
|
|
354
352
|
/**
|
|
355
353
|
* 当前 Node.js 进程的启动时间,常量,Date 类型
|
|
356
354
|
*/
|
|
@@ -368,6 +366,7 @@ interface MiokiConfig {
|
|
|
368
366
|
plugins: string[];
|
|
369
367
|
online_push?: boolean;
|
|
370
368
|
log_level?: string;
|
|
369
|
+
plugins_dir?: string;
|
|
371
370
|
napcat: {
|
|
372
371
|
protocol?: "ws" | "wss";
|
|
373
372
|
port?: number;
|
|
@@ -516,7 +515,7 @@ declare function getViolationRecords(bot: NapCat, authCode: string, appid: numbe
|
|
|
516
515
|
reason: number;
|
|
517
516
|
}[]>;
|
|
518
517
|
//#endregion
|
|
519
|
-
//#region src/builtins/
|
|
518
|
+
//#region src/builtins/core/status.d.ts
|
|
520
519
|
interface MiokiStatus {
|
|
521
520
|
bot: {
|
|
522
521
|
uin: number;
|
|
@@ -562,15 +561,15 @@ interface MiokiStatus {
|
|
|
562
561
|
};
|
|
563
562
|
}
|
|
564
563
|
//#endregion
|
|
565
|
-
//#region src/builtins/
|
|
566
|
-
interface
|
|
564
|
+
//#region src/builtins/core/index.d.ts
|
|
565
|
+
interface MiokiCoreServiceContrib {
|
|
567
566
|
/** 获取框架和系统的实时状态 */
|
|
568
567
|
getMiokiStatus(): Promise<MiokiStatus>;
|
|
569
568
|
}
|
|
570
569
|
declare namespace services_d_exports {
|
|
571
570
|
export { MiokiServices, addService, services };
|
|
572
571
|
}
|
|
573
|
-
interface MiokiServices extends Record<string, unknown>,
|
|
572
|
+
interface MiokiServices extends Record<string, unknown>, MiokiCoreServiceContrib {}
|
|
574
573
|
/**
|
|
575
574
|
* 服务,由其他插件贡献的方法、数据等
|
|
576
575
|
*/
|
|
@@ -593,6 +592,7 @@ type Services = typeof services_d_exports;
|
|
|
593
592
|
type StrictEqual<T, U> = (<G>() => G extends T ? 1 : 2) extends (<G>() => G extends U ? 1 : 2) ? true : false;
|
|
594
593
|
type RemoveBotParam<T> = { [K in keyof T]: T[K] extends ((...args: any[]) => any) ? StrictEqual<Parameters<T[K]>[0], NapCat> extends true ? OmitBotParamFromFunc<T[K]> : never : never };
|
|
595
594
|
type OmitBotParamFromFunc<Func extends (bot: NapCat, ...args: any[]) => any> = Func extends ((bot: NapCat, ...args: infer A) => infer Return) ? (...args: A) => Return : never;
|
|
595
|
+
declare function bindBot<Params extends Array<any> = any[], Return$1 = any>(bot: NapCat, func: (bot: NapCat, ...args: Params) => Return$1): OmitBotParamFromFunc<(bot: NapCat, ...args: Params) => Return$1>;
|
|
596
596
|
/**
|
|
597
597
|
* Mioki 上下文对象,包含 Mioki 运行时的信息和方法
|
|
598
598
|
*/
|
|
@@ -601,6 +601,8 @@ interface MiokiContext extends Services, Configs, Utils, RemoveBotParam<Actions>
|
|
|
601
601
|
bot: NapCat;
|
|
602
602
|
/** 消息构造器 */
|
|
603
603
|
segment: NapCat["segment"];
|
|
604
|
+
/** 通过域名获取 Cookies */
|
|
605
|
+
getCookie: NapCat["getCookie"];
|
|
604
606
|
/** 注册事件处理器 */
|
|
605
607
|
handle: <EventName extends keyof EventMap>(eventName: EventName, handler: (event: EventMap[EventName]) => any) => void;
|
|
606
608
|
/** 注册定时任务 */
|
|
@@ -625,6 +627,8 @@ interface MiokiPlugin {
|
|
|
625
627
|
priority?: number;
|
|
626
628
|
/** 插件描述,额外提示信息,暂没有被使用到的地方 */
|
|
627
629
|
description?: string;
|
|
630
|
+
/** 插件额外依赖,框架不处理,仅做参考提醒用途 */
|
|
631
|
+
dependencies?: string[];
|
|
628
632
|
/** 插件初始化,返回一个清理函数,用于在插件卸载时清理资源,比如定时器、数据库连接等 */
|
|
629
633
|
setup?: (ctx: MiokiContext) => any;
|
|
630
634
|
}
|
|
@@ -634,11 +638,19 @@ interface MiokiPlugin {
|
|
|
634
638
|
* @returns Mioki 插件对象
|
|
635
639
|
*/
|
|
636
640
|
declare function definePlugin(plugin: MiokiPlugin): MiokiPlugin;
|
|
641
|
+
/**
|
|
642
|
+
* 确保插件目录存在
|
|
643
|
+
*/
|
|
644
|
+
declare function ensurePluginDir(): void;
|
|
645
|
+
/**
|
|
646
|
+
* 获取插件目录的绝对路径
|
|
647
|
+
*/
|
|
648
|
+
declare function getAbsPluginDir(defaultDir?: string): string;
|
|
637
649
|
declare function enablePlugin(bot: NapCat, plugin: MiokiPlugin, type?: "builtin" | "external"): Promise<MiokiPlugin>;
|
|
638
650
|
declare function findLocalPlugins(): Promise<{
|
|
639
651
|
name: string;
|
|
640
652
|
absPath: string;
|
|
641
653
|
}[]>;
|
|
642
654
|
//#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 };
|
|
655
|
+
export { AnyFunc, Arrayable, BOT_CWD, ChromeUA, CreateCmdOptions, Gettable, HasMessage, MiokiConfig, MiokiContext, MiokiPlugin, MiokiServices, Noop, OmitBotParamFromFunc, PureObject, START_TIME, StartOptions, addService, base64Decode, base64Encode, bindBot, 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
656
|
//# 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) => {
|
|
@@ -39,7 +39,6 @@ var utils_exports = /* @__PURE__ */ __export({
|
|
|
39
39
|
START_TIME: () => START_TIME,
|
|
40
40
|
base64Decode: () => base64Decode,
|
|
41
41
|
base64Encode: () => base64Encode,
|
|
42
|
-
bindBot: () => bindBot,
|
|
43
42
|
clamp: () => clamp,
|
|
44
43
|
createCmd: () => createCmd,
|
|
45
44
|
createDB: () => createDB,
|
|
@@ -137,9 +136,9 @@ const jiti = createJiti(__dirname, {
|
|
|
137
136
|
function createCmd(cmdStr, options = {}) {
|
|
138
137
|
const { prefix = "", onPrefix = () => {} } = options;
|
|
139
138
|
const { _, ...cmdOptions } = mri$1(string2argv$1(cmdStr));
|
|
140
|
-
const [cmd
|
|
139
|
+
const [cmd, ...params] = _;
|
|
141
140
|
if (prefix) {
|
|
142
|
-
if (cmd
|
|
141
|
+
if (cmd !== prefix) return {
|
|
143
142
|
cmd: void 0,
|
|
144
143
|
params: [],
|
|
145
144
|
options: cmdOptions
|
|
@@ -152,7 +151,7 @@ function createCmd(cmdStr, options = {}) {
|
|
|
152
151
|
};
|
|
153
152
|
}
|
|
154
153
|
return {
|
|
155
|
-
cmd
|
|
154
|
+
cmd,
|
|
156
155
|
params,
|
|
157
156
|
options: cmdOptions
|
|
158
157
|
};
|
|
@@ -731,9 +730,6 @@ async function getTerminalInput(inputTip = "请输入") {
|
|
|
731
730
|
getInput();
|
|
732
731
|
});
|
|
733
732
|
}
|
|
734
|
-
function bindBot(bot, func) {
|
|
735
|
-
return (...args) => func(bot, ...args);
|
|
736
|
-
}
|
|
737
733
|
/**
|
|
738
734
|
* 当前 Node.js 进程的启动时间,常量,Date 类型
|
|
739
735
|
*/
|
|
@@ -836,7 +832,7 @@ function getLogFilePath(uin, platformName) {
|
|
|
836
832
|
|
|
837
833
|
//#endregion
|
|
838
834
|
//#region package.json
|
|
839
|
-
var version = "0.2.
|
|
835
|
+
var version = "0.2.2";
|
|
840
836
|
|
|
841
837
|
//#endregion
|
|
842
838
|
//#region src/actions.ts
|
|
@@ -908,7 +904,7 @@ async function noticeOwners(bot, message, delay = 1e3) {
|
|
|
908
904
|
* 群发通知给第一个主人
|
|
909
905
|
*/
|
|
910
906
|
async function noticeMainOwner(bot, message) {
|
|
911
|
-
if (!bot.isOnline) {
|
|
907
|
+
if (!bot.isOnline()) {
|
|
912
908
|
bot.logger.error("发送失败,Bot 不在线");
|
|
913
909
|
return;
|
|
914
910
|
}
|
|
@@ -1109,6 +1105,9 @@ function addService(name, service, cover = true) {
|
|
|
1109
1105
|
|
|
1110
1106
|
//#endregion
|
|
1111
1107
|
//#region src/plugin.ts
|
|
1108
|
+
function bindBot(bot, func) {
|
|
1109
|
+
return (...args) => func(bot, ...args);
|
|
1110
|
+
}
|
|
1112
1111
|
const runtimePlugins = /* @__PURE__ */ new Map();
|
|
1113
1112
|
const buildRemovedActions = (bot) => Object.fromEntries(Object.entries(actions_exports).map(([k, v]) => [k, bindBot(bot, v)]));
|
|
1114
1113
|
/**
|
|
@@ -1119,6 +1118,20 @@ const buildRemovedActions = (bot) => Object.fromEntries(Object.entries(actions_e
|
|
|
1119
1118
|
function definePlugin(plugin) {
|
|
1120
1119
|
return plugin;
|
|
1121
1120
|
}
|
|
1121
|
+
/**
|
|
1122
|
+
* 确保插件目录存在
|
|
1123
|
+
*/
|
|
1124
|
+
function ensurePluginDir() {
|
|
1125
|
+
const dir = getAbsPluginDir();
|
|
1126
|
+
if (!fs$1.existsSync(dir)) fs$1.mkdirSync(dir, { recursive: true });
|
|
1127
|
+
}
|
|
1128
|
+
/**
|
|
1129
|
+
* 获取插件目录的绝对路径
|
|
1130
|
+
*/
|
|
1131
|
+
function getAbsPluginDir(defaultDir = "plugins") {
|
|
1132
|
+
const cwd = BOT_CWD.value;
|
|
1133
|
+
return path$1.join(cwd, botConfig.plugins_dir || defaultDir);
|
|
1134
|
+
}
|
|
1122
1135
|
async function enablePlugin(bot, plugin, type = "external") {
|
|
1123
1136
|
const typeDesc = type === "builtin" ? "内置" : "用户";
|
|
1124
1137
|
const pluginName = plugin.name || "null";
|
|
@@ -1130,6 +1143,7 @@ async function enablePlugin(bot, plugin, type = "external") {
|
|
|
1130
1143
|
const context = {
|
|
1131
1144
|
bot,
|
|
1132
1145
|
segment: bot.segment,
|
|
1146
|
+
getCookie: bot.getCookie,
|
|
1133
1147
|
...utils_exports,
|
|
1134
1148
|
...config_exports,
|
|
1135
1149
|
...buildRemovedActions(bot),
|
|
@@ -1178,14 +1192,14 @@ 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(
|
|
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(
|
|
1197
|
+
absPath: path$1.join(getAbsPluginDir(), e.name)
|
|
1184
1198
|
}));
|
|
1185
1199
|
}
|
|
1186
1200
|
|
|
1187
1201
|
//#endregion
|
|
1188
|
-
//#region src/builtins/
|
|
1202
|
+
//#region src/builtins/core/status.ts
|
|
1189
1203
|
const SystemMap = {
|
|
1190
1204
|
Linux: "Linux",
|
|
1191
1205
|
Darwin: "macOS",
|
|
@@ -1237,8 +1251,8 @@ async function getMiokiStatus(bot) {
|
|
|
1237
1251
|
protocol: versionInfo.protocol_version
|
|
1238
1252
|
},
|
|
1239
1253
|
system: {
|
|
1240
|
-
name: system.name,
|
|
1241
|
-
version: system.version,
|
|
1254
|
+
name: system.name || "N/A",
|
|
1255
|
+
version: system.version || "N/A",
|
|
1242
1256
|
arch
|
|
1243
1257
|
},
|
|
1244
1258
|
memory: {
|
|
@@ -1257,7 +1271,7 @@ async function getMiokiStatus(bot) {
|
|
|
1257
1271
|
percent: 0
|
|
1258
1272
|
},
|
|
1259
1273
|
cpu: {
|
|
1260
|
-
name: cpu.name,
|
|
1274
|
+
name: cpu.name.trim(),
|
|
1261
1275
|
count: cpu.count,
|
|
1262
1276
|
percent: Number((await measureCpuUsage()).toFixed(1))
|
|
1263
1277
|
}
|
|
@@ -1276,7 +1290,7 @@ async function getMiokiStatusStr(client) {
|
|
|
1276
1290
|
hideYear: true,
|
|
1277
1291
|
secondsDecimalDigits: 0
|
|
1278
1292
|
})}
|
|
1279
|
-
🤖
|
|
1293
|
+
🤖 mioki/${versions.mioki}-NapCat/${versions.napcat}
|
|
1280
1294
|
🖥️ ${system.name.split(" ")[0]}/${system.version.split(".")[0]}-${system.name}-node/${versions.node.split(".")[0]}
|
|
1281
1295
|
📊 ${memory.percent}%-${filesize(memory.used, {
|
|
1282
1296
|
base: 2,
|
|
@@ -1286,7 +1300,7 @@ async function getMiokiStatusStr(client) {
|
|
|
1286
1300
|
round: 1
|
|
1287
1301
|
})}
|
|
1288
1302
|
🧮 ${cpu.percent}%-${cpu.name}-${cpu.count}核
|
|
1289
|
-
|
|
1303
|
+
${diskValid ? `💾 ${diskDesc}` : ""}
|
|
1290
1304
|
`.trim();
|
|
1291
1305
|
}
|
|
1292
1306
|
async function getDiskUsageInUnix(path$2 = "/") {
|
|
@@ -1342,10 +1356,10 @@ function getCpuInfo() {
|
|
|
1342
1356
|
}
|
|
1343
1357
|
|
|
1344
1358
|
//#endregion
|
|
1345
|
-
//#region src/builtins/
|
|
1346
|
-
const corePlugins = ["mioki-
|
|
1347
|
-
const
|
|
1348
|
-
name: "
|
|
1359
|
+
//#region src/builtins/core/index.ts
|
|
1360
|
+
const corePlugins = ["mioki-core"];
|
|
1361
|
+
const core = definePlugin({
|
|
1362
|
+
name: "mioki-core",
|
|
1349
1363
|
version,
|
|
1350
1364
|
priority: 1,
|
|
1351
1365
|
setup(ctx) {
|
|
@@ -1363,9 +1377,9 @@ const cmd = definePlugin({
|
|
|
1363
1377
|
}
|
|
1364
1378
|
if (!ctx.isOwner(e)) return;
|
|
1365
1379
|
const { _: params, ..._options } = mri$1(string2argv$1(text$1));
|
|
1366
|
-
const cmd
|
|
1380
|
+
const cmd = params.shift()?.replace(cmdPrefix, "") ?? "";
|
|
1367
1381
|
const [subCmd, target, ..._subParams] = params;
|
|
1368
|
-
switch (cmd
|
|
1382
|
+
switch (cmd) {
|
|
1369
1383
|
case "帮助":
|
|
1370
1384
|
await e.reply(dedent$1(`
|
|
1371
1385
|
〓 💡 mioki 帮助 〓
|
|
@@ -1594,11 +1608,11 @@ const cmd = definePlugin({
|
|
|
1594
1608
|
}, e));
|
|
1595
1609
|
}
|
|
1596
1610
|
});
|
|
1597
|
-
var
|
|
1611
|
+
var core_default = core;
|
|
1598
1612
|
|
|
1599
1613
|
//#endregion
|
|
1600
1614
|
//#region src/builtins/index.ts
|
|
1601
|
-
const BUILTIN_PLUGINS = [
|
|
1615
|
+
const BUILTIN_PLUGINS = [core_default];
|
|
1602
1616
|
|
|
1603
1617
|
//#endregion
|
|
1604
1618
|
//#region src/start.ts
|
|
@@ -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
|
-
|
|
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
|
|
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(
|
|
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, bindBot, 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
|