node-karin 0.3.8 → 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 (54) hide show
  1. package/lib/adapter/onebot/onebot11.d.ts +3 -5
  2. package/lib/adapter/onebot/onebot11.js +4 -1
  3. package/lib/core/karin.d.ts +45 -4
  4. package/lib/core/karin.js +52 -1
  5. package/lib/core/listener.d.ts +2 -2
  6. package/lib/core/listener.js +1 -0
  7. package/lib/core/plugin.app.d.ts +4 -1
  8. package/lib/core/plugin.app.js +3 -3
  9. package/lib/core/plugin.d.ts +8 -2
  10. package/lib/core/plugin.loader.d.ts +11 -4
  11. package/lib/core/plugin.loader.js +49 -12
  12. package/lib/db/index.d.ts +2 -4
  13. package/lib/db/index.js +2 -4
  14. package/lib/db/level.d.ts +1 -0
  15. package/lib/db/level.js +1 -0
  16. package/lib/db/redis.d.ts +2 -41
  17. package/lib/db/redis.js +2 -3
  18. package/lib/event/event.d.ts +7 -3
  19. package/lib/event/event.handler.d.ts +7 -6
  20. package/lib/event/event.handler.js +5 -0
  21. package/lib/event/event.js +5 -0
  22. package/lib/event/index.js +2 -2
  23. package/lib/event/message.handler.d.ts +3 -3
  24. package/lib/event/message.handler.js +8 -11
  25. package/lib/event/notice.d.ts +4 -4
  26. package/lib/event/notice.handler.d.ts +17 -0
  27. package/lib/event/notice.handler.js +203 -0
  28. package/lib/event/request.d.ts +4 -4
  29. package/lib/event/request.handler.d.ts +17 -0
  30. package/lib/event/request.handler.js +109 -0
  31. package/lib/event/request.js +1 -0
  32. package/lib/event/review.handler.js +12 -24
  33. package/lib/index.d.ts +5 -66
  34. package/lib/index.js +0 -1
  35. package/lib/render/client.d.ts +0 -1
  36. package/lib/render/server.d.ts +0 -2
  37. package/lib/types/adapter.d.ts +2 -3
  38. package/lib/types/api.d.ts +295 -0
  39. package/lib/types/api.js +1 -0
  40. package/lib/types/event.d.ts +127 -241
  41. package/lib/types/index.d.ts +1 -0
  42. package/lib/types/index.js +1 -0
  43. package/lib/types/plugin.d.ts +4 -5
  44. package/lib/utils/button.d.ts +2 -2
  45. package/lib/utils/common.d.ts +1 -2
  46. package/lib/utils/config.d.ts +3 -4
  47. package/lib/utils/config.js +17 -3
  48. package/lib/utils/exec.d.ts +3 -3
  49. package/lib/utils/ffmpeg.d.ts +3 -3
  50. package/lib/utils/handler.d.ts +6 -13
  51. package/lib/utils/handler.js +3 -1
  52. package/lib/utils/segment.d.ts +6 -6
  53. package/package.json +16 -17
  54. package/lib/utils/kritor-proto.d.ts +0 -1
@@ -1,5 +1,3 @@
1
- /// <reference types="@types/ws" />
2
- /// <reference types="node" />
3
1
  import WebSocket from 'ws';
4
2
  import { IncomingMessage } from 'http';
5
3
  import { KarinAdapter } from '../../types/adapter.js';
@@ -131,10 +129,10 @@ export declare class OneBot11 implements KarinAdapter {
131
129
  data: {
132
130
  content: string;
133
131
  custom_template_id: string;
134
- params: {
132
+ params: Array<{
135
133
  key: string;
136
- values: string[];
137
- }[];
134
+ values: Array<string>;
135
+ }>;
138
136
  text?: undefined;
139
137
  id?: undefined;
140
138
  qq?: undefined;
@@ -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
  }
@@ -1,4 +1,3 @@
1
- /// <reference types="node" />
2
1
  import { EventEmitter } from 'events';
3
2
  import { KarinAdapter, contact, KarinElement } from '../types/index.js';
4
3
  /**
@@ -81,7 +80,7 @@ declare class Listeners extends EventEmitter {
81
80
  * @param isType - 是否返回包含的类型列表 默认返回适配器实例列表
82
81
  */
83
82
  getAdapterAll(isType?: boolean): {
84
- type: "internal" | "http" | "grpc" | "ws" | "render";
83
+ type: KarinAdapter["adapter"]["type"];
85
84
  adapter: new () => KarinAdapter;
86
85
  path: string;
87
86
  }[] | (new () => KarinAdapter)[];
@@ -102,4 +101,5 @@ declare class Listeners extends EventEmitter {
102
101
  }>;
103
102
  }
104
103
  export declare const listener: Listeners;
104
+ export declare const Bot: Listeners;
105
105
  export {};
@@ -185,3 +185,4 @@ class Listeners extends EventEmitter {
185
185
  }
186
186
  }
187
187
  export const listener = new Listeners()
188
+ export const Bot = listener
@@ -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
+ }
@@ -6,7 +6,7 @@ import { PluginApps, PluginTask, dirName, fileName, AppInfo } from '../types/ind
6
6
  * 加载插件
7
7
  */
8
8
  export declare const pluginLoader: {
9
- dir: './plugins';
9
+ dir: "./plugins";
10
10
  dirPath: string;
11
11
  /**
12
12
  * - 插件索引ID
@@ -16,16 +16,23 @@ 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
  */
23
30
  handlerIds: {
24
- [key: string]: {
31
+ [key: string]: Array<{
25
32
  index: string;
26
33
  fnc: string | Function;
27
34
  priority: number;
28
- }[];
35
+ }>;
29
36
  };
30
37
  /**
31
38
  * - 插件列表
@@ -76,7 +83,7 @@ export declare const pluginLoader: {
76
83
  * @param path - 插件路径
77
84
  * @param lang - 语言环境
78
85
  */
79
- getIndex(path: string, lang: 'js' | 'ts'): string | boolean;
86
+ getIndex(path: string, lang: "js" | "ts"): string | boolean;
80
87
  /**
81
88
  * 获取指定文件夹下的所有插件
82
89
  * @param dir - 插件包名称
@@ -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
  */