mioki 0.1.2 → 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.cts CHANGED
@@ -1,5 +1,657 @@
1
- //#region src/index.d.ts
2
- declare function start(): void;
1
+ import { LevelWithSilentOrString } from "pino";
2
+ import { EventMap, GroupMessageEvent, Logger, MessageEvent, NapCat, PrivateMessageEvent, RecvElement, RecvImageElement, Sendable } from "napcat-sdk";
3
+ import { Low } from "lowdb";
4
+ import { Jiti } from "jiti";
5
+ import prettyMs from "pretty-ms";
6
+ import { BinaryLike, BinaryToTextEncoding } from "node:crypto";
7
+ import { filesize } from "filesize";
8
+ import { string2argv } from "string2argv";
9
+ import fs from "node:fs";
10
+ import mri from "mri";
11
+ import path from "node:path";
12
+ import dayjs from "dayjs";
13
+ import dedent from "dedent";
14
+ import systemInfo from "systeminformation";
15
+ import { ScheduledTask, TaskContext } from "node-cron";
16
+
17
+ //#region rolldown:runtime
3
18
  //#endregion
4
- export { start };
19
+ //#region src/logger.d.ts
20
+ declare const getMiokiLogger: (level: LevelWithSilentOrString) => Logger;
21
+ //#endregion
22
+ //#region src/start.d.ts
23
+ interface StartOptions {
24
+ cwd?: string;
25
+ }
26
+ declare function start(options?: StartOptions): Promise<void>;
27
+ declare namespace utils_d_exports {
28
+ export { AnyFunc, Arrayable, ChromeUA, CreateCmdOptions, Gettable, HasMessage, Noop, OmitBotParamFromFunc$1 as OmitBotParamFromFunc, PureObject, START_TIME, base64Decode, base64Encode, bindBot, 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
+ }
30
+ declare const ChromeUA = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) Chrome/131.0.0.0";
31
+ type Noop = () => void;
32
+ type AnyFunc = (...args: any[]) => any;
33
+ type PureObject<T = any> = Record<PropertyKey, T>;
34
+ type Arrayable<T> = T | T[];
35
+ type Gettable<T> = T | (() => T);
36
+ type HasMessage = {
37
+ message: RecvElement[];
38
+ } | RecvElement[];
39
+ /**
40
+ * Jiti 实例
41
+ */
42
+ declare const jiti: Jiti;
43
+ interface CreateCmdOptions {
44
+ prefix?: string;
45
+ onPrefix?(): void;
46
+ }
47
+ /**
48
+ * 解析命令字符串,返回命令和参数
49
+ */
50
+ declare function createCmd(cmdStr: string, options?: CreateCmdOptions): {
51
+ cmd: string | undefined;
52
+ params: string[];
53
+ options: Record<string, any>;
54
+ };
55
+ /**
56
+ * 带有表情反应的函数执行包装器
57
+ */
58
+ declare function runWithReaction<T extends AnyFunc>(e: GroupMessageEvent, fn: T, id?: string): Promise<ReturnType<T>>;
59
+ /**
60
+ * 创建一个 LowDB 数据库实例
61
+ */
62
+ declare function createDB<T extends object = object>(filename: string, options?: {
63
+ defaultData?: T;
64
+ compress?: boolean;
65
+ }): Promise<Low<T>>;
66
+ /**
67
+ * 确保返回一个可用的图片元素
68
+ *
69
+ * @param buffer 图片缓冲区
70
+ * @param text 文本
71
+ * @returns 图片元素
72
+ */
73
+ declare function ensureBuffer(buffer?: Buffer | null | undefined, text?: null): null;
74
+ declare function ensureBuffer(buffer?: Buffer | null | undefined, text?: string): Sendable;
75
+ /**
76
+ * 格式化时间间隔为可读字符串
77
+ *
78
+ * @param ms 时间间隔(毫秒)
79
+ * @returns 可读字符串
80
+ */
81
+ declare function formatDuration(ms: number): string;
82
+ type MatchPatternItem = null | undefined | void | false | Sendable;
83
+ /**
84
+ * 匹配输入文本与匹配模式,如果匹配成功,则回复匹配结果
85
+ *
86
+ * @param event 消息事件
87
+ * @param pattern 匹配模式
88
+ * @param quote 是否引用回复
89
+ * @returns 匹配结果
90
+ */
91
+ declare function match(event: MessageEvent, pattern: Record<string, MatchPatternItem | (() => MatchPatternItem) | (() => Promise<MatchPatternItem>)>, quote?: boolean): Promise<{
92
+ message_id: number;
93
+ } | null>;
94
+ /**
95
+ * 创建一个持久化数据库,基于 createDB 封装
96
+ */
97
+ declare function createStore<T extends object = object>(defaultData: T, options?: {
98
+ __dirname?: string;
99
+ importMeta?: ImportMeta;
100
+ compress?: boolean;
101
+ filename?: string;
102
+ }): Promise<Low<T>>;
103
+ /**
104
+ * MD5 加密
105
+ */
106
+ declare function md5(text: BinaryLike, encoding: "buffer"): Buffer;
107
+ declare function md5(text: BinaryLike, encoding?: BinaryToTextEncoding): string;
108
+ /**
109
+ * 数组去重
110
+ */
111
+ declare function unique<T>(array: T[]): T[];
112
+ /**
113
+ * 确保值为数组
114
+ *
115
+ */
116
+ declare function toArray<T>(value: T | T[]): T[];
117
+ /**
118
+ * 是否是群消息
119
+ */
120
+ declare const isGroupMsg: (event: MessageEvent) => event is GroupMessageEvent;
121
+ /**
122
+ * 是否是私聊消息
123
+ */
124
+ declare const isPrivateMsg: (event: MessageEvent) => event is PrivateMessageEvent;
125
+ /**
126
+ * 异步延时函数
127
+ *
128
+ * @param {number} ms 等待毫秒数
129
+ * @return {Promise<void>}
130
+ */
131
+ declare function wait(ms: number): Promise<void>;
132
+ interface FormatOptions {
133
+ locale?: string;
134
+ timeZone?: string;
135
+ }
136
+ /**
137
+ * 获取今天的固定日期字符串,可用来作为「稳定随机」的参数,用于签到、每日任务等场景
138
+ *
139
+ * 格式: 2024/12/12,可选控制时区,默认为 'Asia/Shanghai' (亚洲/上海 时区)
140
+ *
141
+ * @param timeZone 指定的时区,默认为 'Asia/Shanghai'
142
+ * @returns 返回当前日期的字符串格式
143
+ */
144
+ declare function localeDate(ts?: number | string | Date, options?: FormatOptions): string;
145
+ /**
146
+ * 获取当前时间的固定时间字符串
147
+ */
148
+ declare function localeTime(ts?: number | string | Date, options?: FormatOptions & {
149
+ seconds?: boolean;
150
+ }): string;
151
+ /**
152
+ * 生成指定范围(min ~ max)内的随机整数
153
+ *
154
+ * 额外支持「稳定随机」,继续传入额外参数即可,如果额外参数相同(忽略顺序),则生成的随机数相同
155
+ */
156
+ declare function randomInt(min: number, max: number, ...hashArgs: any[]): number;
157
+ /**
158
+ * 取数组内随机一项
159
+ *
160
+ * 额外支持「稳定随机」,继续传入额外参数即可,如果额外参数相同(忽略顺序),则生成的随机项
161
+ */
162
+ declare function randomItem<T = any>(array: readonly T[], ...hashArgs: any[]): T;
163
+ /**
164
+ * 从数组中随机选出指定数量的项(不重复)
165
+ *
166
+ * 额外支持「稳定随机」,继续传入额外参数即可,如果额外参数相同(忽略顺序),则生成的随机项相同
167
+ *
168
+ * @param array 源数组
169
+ * @param count 要选择的项数量
170
+ * @param hashArgs 稳定随机的额外参数
171
+ * @returns 随机选出的项组成的数组
172
+ */
173
+ declare function randomItems<T = any>(array: readonly T[], count: number, ...hashArgs: any[]): T[];
174
+ /**
175
+ * 包含大写字母与数字的 6 位随机 ID 生成器
176
+ */
177
+ declare function randomId(): string;
178
+ /**
179
+ * 简单生成符合 UUID 规范的字符串,但不保证唯一性
180
+ */
181
+ declare function uuid(): string;
182
+ /**
183
+ * clamp 操作,限制数值在指定范围内
184
+ */
185
+ declare function clamp(n: number, min: number, max: number): number;
186
+ /**
187
+ * 排除 null 和 undefined
188
+ */
189
+ declare function noNullish<T>(val: T | null): val is T;
190
+ /**
191
+ * 判断是否定义
192
+ */
193
+ declare function isDefined<T = unknown>(val?: T): val is T;
194
+ /**
195
+ * 通过消息事件生成唯一 id
196
+ */
197
+ declare function toMsgId(event: {
198
+ seq: number;
199
+ rand: number;
200
+ }): string;
201
+ /**
202
+ * 判断是否为函数
203
+ */
204
+ declare function isFunction<T extends AnyFunc>(val: unknown): val is T;
205
+ /**
206
+ * 判断是否为数字
207
+ */
208
+ declare function isNumber(val: unknown): val is number;
209
+ /**
210
+ * 判断是否为布尔值
211
+ */
212
+ declare function isBoolean(val: unknown): val is boolean;
213
+ /**
214
+ * 判断是否为字符串
215
+ */
216
+ declare function isString(val: unknown): val is string;
217
+ /**
218
+ * 判断是否为对象
219
+ */
220
+ declare function isObject(val: unknown): val is object;
221
+ /**
222
+ * 将数字转换为本地化数字字符串
223
+ */
224
+ declare function localNum(num: number, locale?: string): string;
225
+ /**
226
+ * 通过 QQ 号获取任意头像链接
227
+ *
228
+ * size 可选: 0 | 40 | 100 | 160 | 640,0 为原图
229
+ */
230
+ declare function getQQAvatarLink(qq: number, size?: number): string;
231
+ /**
232
+ * 通过群号获取任意群头像链接
233
+ *
234
+ * size 可选: 40 | 100 | 640,0 为原图
235
+ */
236
+ declare function getGroupAvatarLink(group: number, size?: number): string;
237
+ /** 获取引用回复的消息 */
238
+ declare function getQuoteMessage(event: MessageEvent, timeout?: number): Promise<GroupMessageEvent | PrivateMessageEvent | null>;
239
+ /**
240
+ * 获取原创表情包的图片链接
241
+ */
242
+ declare function getBfaceUrl(file: string): Promise<string | null>;
243
+ /**
244
+ * 获取消息中的图片链接
245
+ */
246
+ declare function getImageUrl(event: HasMessage): Promise<string>;
247
+ /**
248
+ * 获取引用回复的消息中的图片链接
249
+ */
250
+ declare function getQuoteImageUrl(event: MessageEvent): Promise<string>;
251
+ /**
252
+ * 获取消息提及的图片链接(消息或者引用消息)
253
+ */
254
+ declare function getMentionedImageUrl(event: MessageEvent): Promise<string>;
255
+ /**
256
+ * 获取消息中的图片元素
257
+ */
258
+ declare function getImage(event: HasMessage): RecvImageElement | null;
259
+ /**
260
+ * 获取引用回复的图片消息
261
+ */
262
+ declare function getQuoteImage(event: MessageEvent): Promise<RecvImageElement | null>;
263
+ /**
264
+ * 获取消息提及的图片(消息或者引用消息)
265
+ */
266
+ declare function getMentionedImage(event: MessageEvent): Promise<RecvImageElement | null>;
267
+ /**
268
+ * 获取消息中的文本内容,默认采取 'whole' 模式,去除整体的首尾空格,可选 'each' 模式,去除每个文本的首尾空格
269
+ *
270
+ * 如: whole 模式下 => ' 123 [表情] 456 ' => '123 456'
271
+ * 如: each 模式下 => ' 123 [表情] 456 ' => '123456'
272
+ */
273
+ declare function text(event: HasMessage, options?: {
274
+ trim?: boolean | "whole" | "each";
275
+ }): string;
276
+ /**
277
+ * 获取回复的消息中的文本内容
278
+ */
279
+ declare function getQuoteText(event: MessageEvent): Promise<string>;
280
+ /**
281
+ * 获取提到的用户 QQ 号,可以通过 if(!qq) 判断是否提到了用户,返回 0 代表没有提到用户
282
+ */
283
+ declare function getMentionedUserId(event: MessageEvent): Promise<number | 0>;
284
+ /**
285
+ * 获取 **一个** 指定类型的消息元素,如获取图片、表情等,如果没有则返回 undefined
286
+ */
287
+ declare function find<Type extends Pick<RecvElement, "type">["type"], TargetType extends Extract<RecvElement, {
288
+ type: Type;
289
+ }> = Extract<RecvElement, {
290
+ type: Type;
291
+ }>>(event: HasMessage, type: Type): TargetType | undefined;
292
+ /**
293
+ * 获取 **所有** 指定类型的消息元素,如获取图片、表情等,如果没有则返回 []
294
+ */
295
+ declare function filter<Type extends Pick<RecvElement, "type">["type"], TargetType extends Extract<RecvElement, {
296
+ type: Type;
297
+ }> = Extract<RecvElement, {
298
+ type: Type;
299
+ }>>(event: HasMessage, type: Type): TargetType[];
300
+ /**
301
+ * 错误信息字符串格式化
302
+ *
303
+ * @param {any} error 待处理错误
304
+ * @return {string} stringify 结果
305
+ */
306
+ declare function stringifyError(error: any): string;
307
+ /**
308
+ * Encodes string | number | buffer using base64.
309
+ */
310
+ declare function base64Encode(str: string | number | Buffer): string;
311
+ /**
312
+ * Decodes the string from base64 to UTF-8.
313
+ *
314
+ * @param {string} str - The base64-encoded string.
315
+ */
316
+ declare function base64Decode(str: string, type?: "buffer" | BufferEncoding): string | Buffer;
317
+ /**
318
+ * JS 对象转换成 `urlencoded` 格式字符串 { name: 'Bob', age: 18 } => name=Bob&age=18
319
+ *
320
+ * @param {Record<number | string, any>} obj JS 对象
321
+ * @return {string} 转换后的字符串
322
+ */
323
+ declare function qs(obj: Record<number | string, any>): string;
324
+ /**
325
+ * 格式化展示 QQ 等级
326
+ */
327
+ declare function formatQQLevel(level: number): string;
328
+ /**
329
+ * 申请通过开发者工具登录,以获取 Cookie
330
+ */
331
+ declare function requestLoginViaDevTools(): Promise<{
332
+ code: string;
333
+ url: string;
334
+ }>;
335
+ /**
336
+ * 获取开发者工具登录结果
337
+ */
338
+ declare function queryDevToolsLoginStatus(code: string): Promise<{
339
+ status: "OK" | "Wait" | "Expired" | "Used" | "Error";
340
+ ticket?: string;
341
+ }>;
342
+ /**
343
+ * 通过开发者工具登录获取 AuthCode
344
+ */
345
+ declare function getAuthCodeViaTicket(ticket: string, appid: number): Promise<string>;
346
+ /**
347
+ * 通过 Auth Code 获取 minico Token
348
+ */
349
+ declare function getMinicoTokenViaAuthCode(authCode: string, appid: number): Promise<any>;
350
+ /**
351
+ * 获取终端输入,返回 Promise,支持提示信息
352
+ */
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
+ /**
357
+ * 当前 Node.js 进程的启动时间,常量,Date 类型
358
+ */
359
+ declare const START_TIME: Date;
360
+ declare namespace config_d_exports {
361
+ export { BOT_CWD, MiokiConfig, botConfig, getLogFilePath, hasRight, isAdmin, isInPm2, isOwner, isOwnerOrAdmin, readMiokiConfig, readPackageJson, updateBotCWD, updateBotConfig, writePackageJson };
362
+ }
363
+ /**
364
+ * mioki 配置
365
+ */
366
+ interface MiokiConfig {
367
+ prefix?: string;
368
+ owners: number[];
369
+ admins: number[];
370
+ plugins: string[];
371
+ online_push?: boolean;
372
+ log_level?: string;
373
+ plugin_dir?: string;
374
+ napcat: {
375
+ protocol?: "ws" | "wss";
376
+ port?: number;
377
+ host?: string;
378
+ token: string;
379
+ };
380
+ }
381
+ /**
382
+ * 机器人根目录
383
+ */
384
+ declare const BOT_CWD: {
385
+ value: string;
386
+ };
387
+ declare function readPackageJson(): Record<"mioki" | (string & {}), any>;
388
+ declare function writePackageJson(pkg: Record<string, any>): void;
389
+ declare function readMiokiConfig(): MiokiConfig;
390
+ /**
391
+ * `mioki` 框架相关配置
392
+ */
393
+ declare const botConfig: MiokiConfig;
394
+ /**
395
+ * 更新 `mioki` 配置,同时同步更新本地配置文件
396
+ */
397
+ declare const updateBotConfig: (draftFn: (config: MiokiConfig) => any) => Promise<void>;
398
+ /**
399
+ * 更新机器人根目录
400
+ */
401
+ declare const updateBotCWD: (root: string) => void;
402
+ /**
403
+ * 是否是主人
404
+ */
405
+ declare const isOwner: (id: number | {
406
+ sender: {
407
+ user_id: number;
408
+ };
409
+ } | {
410
+ user_id: number;
411
+ }) => boolean;
412
+ /**
413
+ * 是否是管理员,注意: 主人不是管理员
414
+ */
415
+ declare const isAdmin: (id: number | {
416
+ sender: {
417
+ user_id: number;
418
+ };
419
+ } | {
420
+ user_id: number;
421
+ }) => boolean;
422
+ /**
423
+ * 是否是主人或管理员
424
+ */
425
+ declare const isOwnerOrAdmin: (id: number | {
426
+ sender: {
427
+ user_id: number;
428
+ };
429
+ } | {
430
+ user_id: number;
431
+ }) => boolean;
432
+ /**
433
+ * 是否有权限,即:主人或管理员
434
+ */
435
+ declare const hasRight: (id: number | {
436
+ sender: {
437
+ user_id: number;
438
+ };
439
+ } | {
440
+ user_id: number;
441
+ }) => boolean;
442
+ /**
443
+ * 是否在 PM2 中运行
444
+ */
445
+ declare const isInPm2: boolean;
446
+ /**
447
+ * 获取日志文件名
448
+ */
449
+ declare function getLogFilePath(uin: number, platformName: string): string;
450
+ declare namespace actions_d_exports {
451
+ export { createForwardMsg, getViolationRecords, noticeAdmins, noticeFriends, noticeGroups, noticeMainOwner, noticeOwners, runWithErrorHandler, signArk, uploadImageToCollection, uploadImageToGroupHomework, uploadImageToGroupNotice };
452
+ }
453
+ /**
454
+ * 群发群消息
455
+ */
456
+ declare function noticeGroups(bot: NapCat, groupIdList: number[], message?: Sendable | null, delay?: number): Promise<void>;
457
+ /**
458
+ * 群发好友消息
459
+ */
460
+ declare function noticeFriends(bot: NapCat, friendIdList: number[], message?: Sendable | null, delay?: number): Promise<void>;
461
+ /**
462
+ * 群发通知给管理员
463
+ */
464
+ declare function noticeAdmins(bot: NapCat, message?: Sendable | null, delay?: number): Promise<void>;
465
+ /**
466
+ * 群发通知给主人
467
+ */
468
+ declare function noticeOwners(bot: NapCat, message?: Sendable | null, delay?: number): Promise<void>;
469
+ /**
470
+ * 群发通知给第一个主人
471
+ */
472
+ declare function noticeMainOwner(bot: NapCat, message?: Sendable | null): Promise<void>;
473
+ /**
474
+ * 签名卡片 json
475
+ */
476
+ declare function signArk(bot: NapCat, json: string): Promise<string>;
477
+ /**
478
+ * 运行函数并捕获错误, 并通过 event.reply 发送错误信息
479
+ */
480
+ declare function runWithErrorHandler(bot: NapCat, fn: () => any, event?: {
481
+ reply: (content: Sendable, quote?: boolean) => Promise<{
482
+ message_id: number;
483
+ }>;
484
+ }, message?: Sendable | ((error: string) => Sendable)): Promise<any>;
485
+ /** 创建和并转发消息 */
486
+ declare function createForwardMsg(bot: NapCat, message?: Sendable[], options?: {
487
+ user_id?: number;
488
+ nickname?: string;
489
+ }): Sendable;
490
+ /**
491
+ * 上传图片到收藏
492
+ */
493
+ declare function uploadImageToCollection(bot: NapCat, buffer: ArrayBuffer): Promise<string>;
494
+ /**
495
+ * 上传图片到群作业
496
+ */
497
+ declare function uploadImageToGroupHomework(bot: NapCat, imgBase64: string): Promise<string>;
498
+ /**
499
+ * 上传图片到群公告
500
+ */
501
+ declare function uploadImageToGroupNotice(bot: NapCat, urlOrBlob: string | Blob): Promise<{
502
+ h: string;
503
+ w: string;
504
+ id: string;
505
+ url: string;
506
+ url2: string;
507
+ url3: string;
508
+ url4: string;
509
+ url5: string;
510
+ url6: string;
511
+ }>;
512
+ /**
513
+ * 获取 QQ 安全中心违规记录
514
+ */
515
+ declare function getViolationRecords(bot: NapCat, authCode: string, appid: number, size?: number): Promise<{
516
+ type: string;
517
+ time: string;
518
+ duration: string;
519
+ reason: number;
520
+ }[]>;
521
+ //#endregion
522
+ //#region src/builtins/cmd/status.d.ts
523
+ interface MiokiStatus {
524
+ bot: {
525
+ uin: number;
526
+ nickname: string;
527
+ };
528
+ plugins: {
529
+ enabled: number;
530
+ total: number;
531
+ };
532
+ stats: {
533
+ uptime: number;
534
+ };
535
+ versions: {
536
+ node: string;
537
+ mioki: string;
538
+ napcat: string;
539
+ protocol: string;
540
+ };
541
+ system: {
542
+ name: string;
543
+ version: string;
544
+ arch: string;
545
+ };
546
+ memory: {
547
+ used: number;
548
+ total: number;
549
+ percent: number;
550
+ rss: {
551
+ used: number;
552
+ percent: number;
553
+ };
554
+ };
555
+ disk: {
556
+ total: number;
557
+ used: number;
558
+ free: number;
559
+ percent: number;
560
+ };
561
+ cpu: {
562
+ name: string;
563
+ count: number;
564
+ percent: number;
565
+ };
566
+ }
567
+ //#endregion
568
+ //#region src/builtins/cmd/index.d.ts
569
+ interface MiokiCmdServiceContrib {
570
+ /** 获取框架和系统的实时状态 */
571
+ getMiokiStatus(): Promise<MiokiStatus>;
572
+ }
573
+ declare namespace services_d_exports {
574
+ export { MiokiServices, addService, services };
575
+ }
576
+ interface MiokiServices extends Record<string, unknown>, MiokiCmdServiceContrib {}
577
+ /**
578
+ * 服务,由其他插件贡献的方法、数据等
579
+ */
580
+ declare const services: MiokiServices;
581
+ /**
582
+ * 给 `Mioki` 添加公共服务,可用于插件间通信和共享数据
583
+ *
584
+ * 请注意合理设置插件的 `priority` 属性,以确保服务的正确加载顺序,`priority` 默认为 100,越小越先加载
585
+ *
586
+ * 建议需要调用 `addService` 的插件设置 `priority` 为 `10`
587
+ */
588
+ declare function addService(name: string, service: any, cover?: boolean): () => void;
589
+ //#endregion
590
+ //#region src/plugin.d.ts
591
+ type Num = 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9;
592
+ type Utils = typeof utils_d_exports;
593
+ type Configs = typeof config_d_exports;
594
+ type Actions = typeof actions_d_exports;
595
+ type Services = typeof services_d_exports;
596
+ type StrictEqual<T, U> = (<G>() => G extends T ? 1 : 2) extends (<G>() => G extends U ? 1 : 2) ? true : false;
597
+ 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 };
598
+ type OmitBotParamFromFunc<Func extends (bot: NapCat, ...args: any[]) => any> = Func extends ((bot: NapCat, ...args: infer A) => infer Return) ? (...args: A) => Return : never;
599
+ /**
600
+ * Mioki 上下文对象,包含 Mioki 运行时的信息和方法
601
+ */
602
+ interface MiokiContext extends Services, Configs, Utils, RemoveBotParam<Actions> {
603
+ /** 机器人实例 */
604
+ bot: NapCat;
605
+ /** 消息构造器 */
606
+ segment: NapCat["segment"];
607
+ /** 注册事件处理器 */
608
+ handle: <EventName extends keyof EventMap>(eventName: EventName, handler: (event: EventMap[EventName]) => any) => void;
609
+ /** 注册定时任务 */
610
+ cron: (cronExpression: string, handler: (ctx: MiokiContext, task: TaskContext) => any) => ScheduledTask;
611
+ /** 待清理的函数集合,在插件卸载时会被调用 */
612
+ clears: Set<(() => any) | null | undefined>;
613
+ }
614
+ declare const runtimePlugins: Map<string, {
615
+ name: string;
616
+ type: "builtin" | "external";
617
+ version: string;
618
+ description: string;
619
+ plugin: MiokiPlugin;
620
+ disable: () => any;
621
+ }>;
622
+ interface MiokiPlugin {
623
+ /** 插件 ID,请保持唯一,一般为插件目录名称,框架内部通过这个识别不同的插件 */
624
+ name: string;
625
+ /** 插件版本,一般用于判断插件是否更新,暂只是用于区分 */
626
+ version?: `${Num}.${Num}.${Num}` | `${Num}.${Num}` | (string & {});
627
+ /** 插件加载优先级,默认 100,越小越被优先加载 */
628
+ priority?: number;
629
+ /** 插件描述,额外提示信息,暂没有被使用到的地方 */
630
+ description?: string;
631
+ /** 插件额外依赖,框架不处理,仅做参考提醒用途 */
632
+ dependencies?: string[];
633
+ /** 插件初始化,返回一个清理函数,用于在插件卸载时清理资源,比如定时器、数据库连接等 */
634
+ setup?: (ctx: MiokiContext) => any;
635
+ }
636
+ /**
637
+ * 定义一个 Mioki 插件
638
+ * @param plugin Mioki 插件对象
639
+ * @returns Mioki 插件对象
640
+ */
641
+ declare function definePlugin(plugin: MiokiPlugin): MiokiPlugin;
642
+ /**
643
+ * 确保插件目录存在
644
+ */
645
+ declare function ensurePluginDir(): void;
646
+ /**
647
+ * 获取插件目录的绝对路径
648
+ */
649
+ declare function getAbsPluginDir(defaultDir?: string): string;
650
+ declare function enablePlugin(bot: NapCat, plugin: MiokiPlugin, type?: "builtin" | "external"): Promise<MiokiPlugin>;
651
+ declare function findLocalPlugins(): Promise<{
652
+ name: string;
653
+ absPath: string;
654
+ }[]>;
655
+ //#endregion
656
+ 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 };
5
657
  //# sourceMappingURL=index.d.cts.map