node-karin 0.3.9 → 0.4.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.
Files changed (43) hide show
  1. package/lib/adapter/onebot/onebot11.js +4 -1
  2. package/lib/core/karin.d.ts +45 -4
  3. package/lib/core/karin.js +52 -1
  4. package/lib/core/plugin.app.d.ts +4 -1
  5. package/lib/core/plugin.app.js +3 -3
  6. package/lib/core/plugin.d.ts +8 -2
  7. package/lib/core/plugin.loader.d.ts +7 -0
  8. package/lib/core/plugin.loader.js +49 -12
  9. package/lib/db/index.d.ts +2 -4
  10. package/lib/db/index.js +2 -4
  11. package/lib/db/level.d.ts +1 -0
  12. package/lib/db/level.js +1 -0
  13. package/lib/db/redis.d.ts +2 -41
  14. package/lib/db/redis.js +2 -3
  15. package/lib/event/event.d.ts +7 -3
  16. package/lib/event/event.handler.d.ts +7 -6
  17. package/lib/event/event.handler.js +5 -0
  18. package/lib/event/event.js +5 -0
  19. package/lib/event/index.js +2 -2
  20. package/lib/event/message.handler.d.ts +3 -3
  21. package/lib/event/message.handler.js +8 -11
  22. package/lib/event/notice.d.ts +4 -4
  23. package/lib/event/notice.handler.d.ts +17 -0
  24. package/lib/event/notice.handler.js +203 -0
  25. package/lib/event/request.d.ts +4 -4
  26. package/lib/event/request.handler.d.ts +17 -0
  27. package/lib/event/request.handler.js +109 -0
  28. package/lib/event/request.js +1 -0
  29. package/lib/event/review.handler.js +12 -24
  30. package/lib/types/adapter.d.ts +2 -1
  31. package/lib/types/api.d.ts +295 -0
  32. package/lib/types/api.js +1 -0
  33. package/lib/types/event.d.ts +127 -241
  34. package/lib/types/index.d.ts +1 -0
  35. package/lib/types/index.js +1 -0
  36. package/lib/types/plugin.d.ts +4 -4
  37. package/lib/utils/button.d.ts +2 -2
  38. package/lib/utils/config.d.ts +0 -1
  39. package/lib/utils/config.js +17 -3
  40. package/lib/utils/handler.d.ts +5 -12
  41. package/lib/utils/handler.js +3 -1
  42. package/package.json +3 -3
  43. package/lib/utils/kritor-proto.d.ts +0 -1
@@ -146,7 +146,10 @@ export class OneBot11 {
146
146
  }, 100);
147
147
  });
148
148
  }
149
- /** 处理事件 */
149
+ /**
150
+ * 处理事件
151
+ * - @param data ob11相关标准数据
152
+ */
150
153
  #event(data) {
151
154
  switch (data.post_type) {
152
155
  case 'meta_event': {
@@ -7,10 +7,6 @@ export interface OptionsCommand {
7
7
  * - 插件名称 不传则使用 插件名称:函数名
8
8
  */
9
9
  name?: string;
10
- /**
11
- * - 插件描述
12
- */
13
- desc?: string;
14
10
  /**
15
11
  * - 插件优先级 数字越小优先级越高
16
12
  * @default 10000
@@ -66,5 +62,50 @@ export declare class Karin {
66
62
  * @param options - 选项
67
63
  */
68
64
  command(reg: string | RegExp, element: FncElement, options?: OptionsElement): PluginApps;
65
+ /**
66
+ * - 构建定时任务
67
+ * @param name - 任务名称
68
+ * @param cron - cron表达式
69
+ * @param fnc - 执行函数
70
+ * @param options - 选项
71
+ */
72
+ task(name: string, cron: string, fnc: Function, options?: {
73
+ /**
74
+ * - 任务插件名称
75
+ */
76
+ name?: string;
77
+ /**
78
+ * - 任务优先级
79
+ */
80
+ priority?: number;
81
+ /**
82
+ * - 是否打印日志 传递布尔值
83
+ */
84
+ log?: boolean | Function;
85
+ }): PluginApps;
86
+ /**
87
+ * - 构建handler
88
+ * @param key - 事件key
89
+ * @param fnc - 函数实现
90
+ * @param options - 选项
91
+ */
92
+ handler(key: string, fnc: (
93
+ /**
94
+ * - 自定义参数 由调用方传递
95
+ */
96
+ args: any,
97
+ /**
98
+ * - 拒绝处理器 调用后则不再继续执行下一个处理器
99
+ */
100
+ reject: (msg?: string) => void) => Promise<any>, options?: {
101
+ /**
102
+ * - 插件名称
103
+ */
104
+ name?: string;
105
+ /**
106
+ * - handler优先级
107
+ */
108
+ priority?: number;
109
+ }): PluginApps;
69
110
  }
70
111
  export {};
package/lib/core/karin.js CHANGED
@@ -8,6 +8,7 @@ export class Karin {
8
8
  * @param options - 选项
9
9
  * @returns - 返回插件对象
10
10
  */
11
+
11
12
  command (reg, second, options = {}) {
12
13
  const Reg = typeof reg === 'string' ? new RegExp(reg) : reg
13
14
  const data = {
@@ -29,7 +30,7 @@ export class Karin {
29
30
  case 'string':
30
31
  case 'number':
31
32
  case 'object': {
32
- const element = common.makeMessage(typeof second === 'function' ? second : String(second))
33
+ const element = common.makeMessage(typeof second === 'number' ? String(second) : second)
33
34
  const fnc = async (e) => {
34
35
  if ('delay' in options && options.delay) { await common.sleep(options.delay) }
35
36
  await e.reply(element, {
@@ -48,4 +49,54 @@ export class Karin {
48
49
  }
49
50
  }
50
51
  }
52
+
53
+ /**
54
+ * - 构建定时任务
55
+ * @param name - 任务名称
56
+ * @param cron - cron表达式
57
+ * @param fnc - 执行函数
58
+ * @param options - 选项
59
+ */
60
+ task (name, cron, fnc, options) {
61
+ if (!name) { throw new Error('[task]: 缺少参数[name]') }
62
+ if (!cron) { throw new Error('[task]: 缺少参数[cron]') }
63
+ if (!fnc) { throw new Error('[task]: 缺少参数[fnc]') }
64
+ const data = {
65
+ name: options?.name || 'task',
66
+ priority: options?.priority,
67
+ task: [
68
+ {
69
+ name,
70
+ cron,
71
+ fnc,
72
+ log: options?.log ?? true,
73
+ },
74
+ ],
75
+ }
76
+ return PluginApp(data)
77
+ }
78
+
79
+ /**
80
+ * - 构建handler
81
+ * @param key - 事件key
82
+ * @param fnc - 函数实现
83
+ * @param options - 选项
84
+ */
85
+ handler (key, fnc, options) {
86
+ if (!key) { throw new Error('[handler]: 缺少参数[key]') }
87
+ if (!fnc) { throw new Error('[handler]: 缺少参数[fnc]') }
88
+ const priority = options?.priority || 10000
89
+ const data = {
90
+ name: options?.name || 'handler',
91
+ priority,
92
+ handler: [
93
+ {
94
+ key,
95
+ fnc,
96
+ priority,
97
+ },
98
+ ],
99
+ }
100
+ return PluginApp(data)
101
+ }
51
102
  }
@@ -9,7 +9,10 @@ export interface PluginAppType {
9
9
  name?: string;
10
10
  event?: PluginApps['event'];
11
11
  priority?: number;
12
- accept?: boolean;
12
+ accept?: boolean | Function;
13
13
  rule?: PluginApps['rule'];
14
+ task?: PluginApps['task'];
15
+ handler?: PluginApps['handler'];
16
+ button?: PluginApps['button'];
14
17
  }
15
18
  export default function PluginApp(options: PluginAppType): PluginApps;
@@ -11,8 +11,8 @@ export default function PluginApp (options) {
11
11
  priority: options.priority || 10000,
12
12
  accept: options.accept ?? false,
13
13
  rule: options.rule || [],
14
- task: [],
15
- handler: [],
16
- button: [],
14
+ task: options.task || [],
15
+ handler: options.handler || [],
16
+ button: options.button || [],
17
17
  }
18
18
  }
@@ -1,11 +1,11 @@
1
- import { PluginType, KarinElement, KarinNodeElement, EventType } from '../types/index.js';
1
+ import { PluginType, KarinElement, KarinNodeElement, EventType, KarinNoticeEvent, KarinRequestEvent } from '../types/index.js';
2
2
  /**
3
3
  * 插件基类
4
4
  */
5
5
  export declare class Plugin implements PluginType {
6
6
  e: EventType<this>;
7
7
  init?: () => void;
8
- accept?: (e: EventType<this>) => Promise<void>;
8
+ accept?: (e: any) => Promise<void>;
9
9
  replyCallback: PluginType['replyCallback'];
10
10
  /**
11
11
  * @param name - 插件名称
@@ -178,3 +178,9 @@ export declare const stateArr: {
178
178
  fnc: string;
179
179
  };
180
180
  };
181
+ /**
182
+ * 通知事件 插件类型
183
+ */
184
+ export interface ExtendedPlugin extends Plugin {
185
+ accept: (e: KarinNoticeEvent | KarinRequestEvent) => Promise<void>;
186
+ }
@@ -16,7 +16,14 @@ export declare const pluginLoader: {
16
16
  * - 命令插件索引列表
17
17
  */
18
18
  ruleIds: Array<number>;
19
+ /**
20
+ * - 按钮插件索引列表
21
+ */
19
22
  buttonIds: Array<number>;
23
+ /**
24
+ * - accept插件索引列表
25
+ */
26
+ acceptIds: Array<number>;
20
27
  /**
21
28
  * - handler
22
29
  */
@@ -21,7 +21,14 @@ export const pluginLoader = new (class PluginLoader {
21
21
  * - 命令插件索引列表
22
22
  */
23
23
  ruleIds
24
+ /**
25
+ * - 按钮插件索引列表
26
+ */
24
27
  buttonIds
28
+ /**
29
+ * - accept插件索引列表
30
+ */
31
+ acceptIds
25
32
  /**
26
33
  * - handler
27
34
  */
@@ -61,6 +68,7 @@ export const pluginLoader = new (class PluginLoader {
61
68
  this.PluginList = {}
62
69
  this.task = []
63
70
  this.ruleIds = []
71
+ this.acceptIds = []
64
72
  this.buttonIds = []
65
73
  this.handlerIds = {}
66
74
  }
@@ -181,15 +189,18 @@ export const pluginLoader = new (class PluginLoader {
181
189
  let handlerCount = 0
182
190
  const rule = []
183
191
  const button = []
192
+ const accept = []
184
193
  Object.keys(this.PluginList).forEach(key => {
185
194
  taskCount += this.PluginList[key].task.length
186
195
  if (this.PluginList[key].rule.length) { rule.push({ key, val: this.PluginList[key].priority }) }
187
196
  if (this.PluginList[key].button.length) { button.push({ key, val: this.PluginList[key].priority }) }
197
+ if (this.PluginList[key].accept) { accept.push({ key, val: this.PluginList[key].priority }) }
188
198
  })
189
199
  this.ruleIds = lodash.orderBy(rule, ['val'], ['asc']).map((v) => Number(v.key))
190
200
  logger.debug('rule排序完成...')
191
201
  this.buttonIds = lodash.orderBy(button, ['val'], ['asc']).map((v) => Number(v.key))
192
202
  logger.debug('button排序完成...')
203
+ this.acceptIds = lodash.orderBy(accept, ['val'], ['asc']).map((v) => Number(v.key))
193
204
  if (!isPrint) { return }
194
205
  const PluginListKeys = Object.keys(this.PluginList)
195
206
  const handlerKeys = Object.keys(this.handlerIds)
@@ -200,6 +211,7 @@ export const pluginLoader = new (class PluginLoader {
200
211
  logger.info(`[渲染器][${render.Apps.length}个] 加载完成`)
201
212
  logger.info(`[rule][${this.ruleIds.length}个] 加载完成`)
202
213
  logger.info(`[button][${this.buttonIds.length}个] 加载完成`)
214
+ logger.info(`[accept][${this.acceptIds.length}个] 加载完成`)
203
215
  logger.info(`[定时任务][${taskCount}个] 加载完成`)
204
216
  logger.info(`[Handler][Key:${handlerKeys.length}个][fnc:${handlerCount}个] 加载完成`)
205
217
  logger.info(logger.green('-----------'))
@@ -220,12 +232,36 @@ export const pluginLoader = new (class PluginLoader {
220
232
  lodash.forEach(tmp, (App) => {
221
233
  const index = this.index
222
234
  this.index++
223
- if (typeof App === 'object') {
224
- if (App?.file?.type !== 'function') { return }
235
+ if (typeof App === 'object' && App?.file?.type === 'function') {
225
236
  if (!App?.name) { return logger.error(`[${dir}][${name}] 插件名称错误`) }
226
237
  App.file.dir = dir
227
238
  App.file.name = name
239
+ /** handler */
240
+ handler.add(index + '', App)
241
+ const task = []
242
+ /** 定时任务 */
243
+ lodash.forEach(App.task, val => {
244
+ task.push({
245
+ name: val.name,
246
+ cron: val.cron,
247
+ fnc: val.fnc,
248
+ log: val.log === false ? (log) => logger.debug(log) : (log) => logger.mark(log),
249
+ schedule: schedule.scheduleJob(val.cron, async () => {
250
+ try {
251
+ typeof val.log === 'function' && val.log(`[定时任务][${dir}][${val.name}] 开始执行`)
252
+ if (typeof val.fnc === 'function') { await val.fnc() }
253
+ typeof val.log === 'function' && val.log(`[定时任务][${dir}][${val.name}] 执行完毕`)
254
+ } catch (error) {
255
+ logger.error(`[定时任务][${dir}][${val.name}] 执行报错`)
256
+ logger.error(error)
257
+ }
258
+ }),
259
+ })
260
+ })
261
+ App.task = task
228
262
  this.PluginList[index] = App
263
+ if (App.accept) { this.acceptIds.push(index) }
264
+ return true
229
265
  }
230
266
  if (typeof App !== 'function' || !App?.prototype?.constructor) { return }
231
267
  const Class = new App()
@@ -288,16 +324,13 @@ export const pluginLoader = new (class PluginLoader {
288
324
  fnc: val.fnc,
289
325
  })
290
326
  })
327
+ /** accept */
328
+ if (Class.accept && typeof Class.accept === 'function') { this.acceptIds.push(index) }
291
329
  /** handler */
292
330
  handler.add(index + '', Class)
293
331
  /** 执行初始化 */
294
332
  Class.init && Class.init()
295
333
  this.PluginList[index] = info
296
- // const Class = new App()
297
- /** 注册Handler */
298
- // if (!lodash.isEmpty(Class.handler)) handler.add({ name, dir, App, Class })
299
- /** 注册按钮 */
300
- // if (!lodash.isEmpty(Class.button)) button.add({ name, dir, App, Class })
301
334
  return true
302
335
  })
303
336
  // rule收集并排序
@@ -325,16 +358,20 @@ export const pluginLoader = new (class PluginLoader {
325
358
  * 卸载插件
326
359
  */
327
360
  uninstallApp (dir, name) {
328
- // this.Apps = this.Apps.filter((v) => !(v.file.dir === dir && v.file.name === name))
329
- // this.uninstallTask(dir, name)
330
- // button.del(dir, name)
331
- // handler.del({ dir, name, key: '' })
361
+ const index = []
332
362
  Object.keys(this.PluginList).forEach(key => {
333
363
  const info = this.PluginList[key]
334
364
  /** 停止定时任务 */
335
365
  info.task.forEach(val => val.schedule?.cancel())
336
- info.file.dir === dir && info.file.name === name && delete this.PluginList[key]
366
+ if (info.file.dir === dir && info.file.name === name) {
367
+ index.push(key)
368
+ delete this.PluginList[key]
369
+ }
337
370
  })
371
+ /** 删除handler */
372
+ index.forEach(key => handler.del(key))
373
+ /** 重新排序 */
374
+ this.orderBy()
338
375
  }
339
376
 
340
377
  /**
package/lib/db/index.d.ts CHANGED
@@ -1,4 +1,2 @@
1
- import LevelDB from './level.js';
2
- import { RedisClientType } from 'redis';
3
- export declare const level: LevelDB;
4
- export declare const redis: RedisClientType;
1
+ export * from './level.js';
2
+ export * from './redis.js';
package/lib/db/index.js CHANGED
@@ -1,4 +1,2 @@
1
- import Redis from './redis.js'
2
- import LevelDB from './level.js'
3
- export const level = new LevelDB()
4
- export const redis = await new Redis().start()
1
+ export * from './level.js'
2
+ export * from './redis.js'
package/lib/db/level.d.ts CHANGED
@@ -16,3 +16,4 @@ export default class LevelDB extends Level {
16
16
  */
17
17
  set(key: string, value: string | object): Promise<void>;
18
18
  }
19
+ export declare const level: LevelDB;
package/lib/db/level.js CHANGED
@@ -34,3 +34,4 @@ export default class LevelDB extends Level {
34
34
  return await super.put(key, value)
35
35
  }
36
36
  }
37
+ export const level = new LevelDB()
package/lib/db/redis.d.ts CHANGED
@@ -1,41 +1,2 @@
1
- import RedisLevel from './redis_level.js';
2
- import redis from 'redis';
3
- export default class Redis {
4
- id: 'redis';
5
- RunCmd: string;
6
- constructor();
7
- /**
8
- * redis实例化
9
- */
10
- start(): Promise<(redis.RedisClientType | string) | RedisLevel | false>;
11
- /**
12
- * 降级为 LevelDB
13
- */
14
- LevelDB(): Promise<false | RedisLevel>;
15
- /**
16
- * 连接 Redis 单例
17
- * @param {import("redis").RedisClientOptions} options
18
- * @return {Promise<{status: 'ok', data: import("redis").RedisClientType} | {status: 'error', data: Error}>}
19
- */
20
- connect(options: redis.RedisClientOptions): Promise<{
21
- status: 'ok';
22
- data: redis.RedisClientType;
23
- } | {
24
- status: 'error';
25
- data: string;
26
- }>;
27
- /**
28
- * 连接 Redis 集群
29
- */
30
- connectCluster(rootNodes: {
31
- url: string;
32
- }[]): Promise<{
33
- status: string;
34
- data: unknown;
35
- }>;
36
- /**
37
- * 判断是否为 ARM64 并返回参数
38
- */
39
- aarch64(): Promise<string>;
40
- execSync(cmd: string): Promise<string>;
41
- }
1
+ import { RedisClientType } from 'redis';
2
+ export declare const redis: RedisClientType;
package/lib/db/redis.js CHANGED
@@ -2,7 +2,7 @@ import { exec } from 'child_process'
2
2
  import RedisLevel from './redis_level.js'
3
3
  import { logger, config } from '../utils/index.js'
4
4
  import { createClient, createCluster } from 'redis'
5
- export default class Redis {
5
+ class Redis {
6
6
  id
7
7
  RunCmd
8
8
  constructor () {
@@ -76,8 +76,6 @@ export default class Redis {
76
76
 
77
77
  /**
78
78
  * 连接 Redis 单例
79
- * @param {import("redis").RedisClientOptions} options
80
- * @return {Promise<{status: 'ok', data: import("redis").RedisClientType} | {status: 'error', data: Error}>}
81
79
  */
82
80
  async connect (options) {
83
81
  const client = createClient(options)
@@ -134,3 +132,4 @@ export default class Redis {
134
132
  })
135
133
  }
136
134
  }
135
+ export const redis = await new Redis().start()
@@ -1,4 +1,4 @@
1
- import { KarinAdapter, Reply, replyCallback, Event, contact, Sender, SubEventForEvent } from '../types/index.js';
1
+ import { KarinAdapter, Reply, replyCallback, Event, contact, Sender, EventToSubEvent } from '../types/index.js';
2
2
  /**
3
3
  * - 事件基类 所有事件都继承自此类并且需要实现此类的所有属性
4
4
  * @class KarinEvent
@@ -24,7 +24,7 @@ export declare class KarinEvent {
24
24
  /**
25
25
  * - 事件子类型
26
26
  */
27
- sub_event: SubEventForEvent<Event>;
27
+ sub_event: EventToSubEvent[Event];
28
28
  /**
29
29
  * - 事件ID
30
30
  */
@@ -83,6 +83,10 @@ export declare class KarinEvent {
83
83
  * - 存储器 由开发者自行调用
84
84
  */
85
85
  store: Map<string, any>;
86
+ /**
87
+ * - 原始消息
88
+ */
89
+ raw_message: string;
86
90
  /**
87
91
  * - 回复函数
88
92
  */
@@ -127,7 +131,7 @@ export declare class KarinEvent {
127
131
  /**
128
132
  * - 事件子类型
129
133
  */
130
- sub_event: SubEventForEvent<Event>;
134
+ sub_event: EventToSubEvent[Event];
131
135
  /**
132
136
  * - 事件ID
133
137
  */
@@ -1,14 +1,15 @@
1
- import { KarinMessage } from './message.js';
2
- import { KarinNotice } from './notice.js';
3
- import { KarinRequest } from './request.js';
4
- import { Event, Permission, SubEvent, GroupCfg } from '../types/index.js';
1
+ import { Event, Permission, SubEvent, GroupCfg, KarinMessageEvent, KarinNoticeEvent, KarinRequestEvent } from '../types/index.js';
5
2
  export default class EventHandler {
6
- e: KarinMessage | KarinNotice | KarinRequest;
3
+ e: KarinMessageEvent | KarinNoticeEvent | KarinRequestEvent;
7
4
  config: GroupCfg | {};
5
+ /**
6
+ * - 是否打印群消息日志
7
+ */
8
+ GroupMsgPrint: boolean;
8
9
  /**
9
10
  * 处理事件,加入自定义字段
10
11
  */
11
- constructor(e: KarinMessage | KarinNotice | KarinRequest);
12
+ constructor(e: KarinMessageEvent | KarinNoticeEvent | KarinRequestEvent);
12
13
  /**
13
14
  * 事件处理
14
15
  */
@@ -4,12 +4,17 @@ import { segment, common, logger, config } from '../utils/index.js'
4
4
  export default class EventHandler {
5
5
  e
6
6
  config
7
+ /**
8
+ * - 是否打印群消息日志
9
+ */
10
+ GroupMsgPrint
7
11
  /**
8
12
  * 处理事件,加入自定义字段
9
13
  */
10
14
  constructor (e) {
11
15
  this.e = e
12
16
  this.config = {}
17
+ this.GroupMsgPrint = false
13
18
  /** 加入e.bot */
14
19
  Object.defineProperty(this.e, 'bot', { value: listener.getBot(this.e.self_id) })
15
20
  if (this.e.group_id) { this.config = config.group(this.e.group_id) }
@@ -82,6 +82,10 @@ export class KarinEvent {
82
82
  * - 存储器 由开发者自行调用
83
83
  */
84
84
  store
85
+ /**
86
+ * - 原始消息
87
+ */
88
+ raw_message
85
89
  /**
86
90
  * - 回复函数
87
91
  */
@@ -113,6 +117,7 @@ export class KarinEvent {
113
117
  this.logFnc = ''
114
118
  this.logText = ''
115
119
  this.store = new Map()
120
+ this.raw_message = ''
116
121
  this.reply = (elements, options) => Promise.resolve({ message_id: '' })
117
122
  this.replyCallback = (elements, options) => Promise.resolve({ message_id: '' })
118
123
  this.bot = {}
@@ -3,7 +3,7 @@ export * from './event.handler.js'
3
3
  export * from './message.js'
4
4
  export * from './message.handler.js'
5
5
  export * from './notice.js'
6
- // export * from './notice.handler'
6
+ // export * from './notice.handler.js'
7
7
  export * from './request.js'
8
- // export * from './request.handler'
8
+ // export * from './request.handler.js'
9
9
  export * from './review.handler.js'
@@ -1,15 +1,15 @@
1
- import { KarinMessage } from './message.js';
2
1
  import EventHandler from './event.handler.js';
2
+ import { KarinMessageEvent } from '../types/index.js';
3
3
  /**
4
4
  * 消息事件
5
5
  */
6
6
  export declare class MessageHandler extends EventHandler {
7
- e: KarinMessage;
7
+ e: KarinMessageEvent;
8
8
  /**
9
9
  * - 是否打印群消息日志
10
10
  */
11
11
  GroupMsgPrint: boolean;
12
- constructor(e: KarinMessage);
12
+ constructor(e: KarinMessageEvent);
13
13
  /**
14
14
  * 处理消息
15
15
  */
@@ -56,19 +56,18 @@ export class MessageHandler extends EventHandler {
56
56
  this.GroupMsgPrint && typeof v.log === 'function' && v.log(this.e.self_id, `${logFnc}${this.e.logText} ${lodash.truncate(this.e.msg, { length: 80 })}`)
57
57
  /** 判断权限 */
58
58
  if (!this.filterPermission(v.permission)) { break a }
59
+ /** 计算插件处理时间 */
60
+ const start = Date.now()
61
+ listener.emit('karin:count:fnc', this.e.logFnc)
59
62
  try {
60
63
  let res
61
64
  if (app.file.type === 'function' && typeof v.fnc === 'function') {
62
- res = v.fnc(this.e)
65
+ res = await v.fnc(this.e)
63
66
  } else {
64
67
  const cla = new app.file.Fnc()
65
68
  cla.e = this.e
66
- res = cla[v.fnc](this.e)
69
+ res = await cla[v.fnc](this.e)
67
70
  }
68
- /** 计算插件处理时间 */
69
- const start = Date.now()
70
- listener.emit('karin:count:fnc', this.e.logFnc)
71
- res = await res
72
71
  this.GroupMsgPrint && typeof v.log === 'function' && v.log(this.e.self_id, `${logFnc} ${lodash.truncate(this.e.msg, { length: 80 })} 处理完成 ${logger.green(Date.now() - start + 'ms')}`)
73
72
  if (res !== false) { break a }
74
73
  } catch (error) {
@@ -191,16 +190,14 @@ export class MessageHandler extends EventHandler {
191
190
  this.e.raw_message = logs.join('')
192
191
  /** 前缀处理 */
193
192
  this.e.group_id && 'GroupCD' in this.config && review.alias(this.e, this.config)
194
- /** 主人 这里强制是因为yaml在自动保存QQ号的时候会强制化为数字 */
195
- const masterId = (Number(this.e.user_id) || String(this.e.user_id))
196
- if (config.master.includes(masterId)) {
193
+ /** 主人 */
194
+ if (config.master.includes(String(this.e.user_id))) {
197
195
  this.e.isMaster = true
198
196
  this.e.isAdmin = true
199
- } else if (config.admin.includes(masterId)) {
197
+ } else if (config.admin.includes(String(this.e.user_id))) {
200
198
  /** 管理员 */
201
199
  this.e.isAdmin = true
202
200
  }
203
- this.GroupMsgPrint = false
204
201
  if (this.e.contact.scene === 'private') {
205
202
  this.e.isPrivate = true
206
203
  this.e.logText = `[Private:${this.e.sender.nick || ''}(${this.e.user_id})]`
@@ -1,5 +1,5 @@
1
1
  import { KarinEvent } from './event.js';
2
- import { contact, Sender, SubEventForEvent, NoticeEvent } from '../types/index.js';
2
+ import { contact, Sender, NoticeType, EventToSubEvent } from '../types/index.js';
3
3
  /**
4
4
  * - 通知事件基类
5
5
  */
@@ -32,11 +32,11 @@ export declare class KarinNotice extends KarinEvent {
32
32
  /**
33
33
  * 事件子类型
34
34
  */
35
- sub_event: SubEventForEvent<'notice'>;
35
+ sub_event: EventToSubEvent['notice'];
36
36
  /**
37
37
  * 事件对应的内容参数
38
38
  */
39
- content: NoticeEvent<SubEventForEvent<'notice'>>;
39
+ content: NoticeType[EventToSubEvent['notice']];
40
40
  /**
41
41
  * 群ID
42
42
  */
@@ -45,5 +45,5 @@ export declare class KarinNotice extends KarinEvent {
45
45
  /**
46
46
  * - 事件对应的内容参数
47
47
  */
48
- content: NoticeEvent<SubEventForEvent<'notice'>>;
48
+ content: NoticeType[EventToSubEvent['notice']];
49
49
  }
@@ -0,0 +1,17 @@
1
+ import EventHandler from './event.handler.js';
2
+ import { KarinNoticeEvent } from '../types/index.js';
3
+ /**
4
+ * 通知事件
5
+ */
6
+ export default class NoticeHandler extends EventHandler {
7
+ e: KarinNoticeEvent;
8
+ constructor(e: KarinNoticeEvent);
9
+ /**
10
+ * 处理事件
11
+ */
12
+ deal(): Promise<void>;
13
+ /**
14
+ * 构建原始消息
15
+ */
16
+ raw_message(): void;
17
+ }