node-karin 0.12.16 → 0.12.17

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 (39) hide show
  1. package/lib/adapter/input/index.d.ts +1 -3
  2. package/lib/adapter/input/index.js +2 -4
  3. package/lib/adapter/onebot/11/event.d.ts +3 -9
  4. package/lib/adapter/onebot/11/event.js +7 -13
  5. package/lib/adapter/onebot/11/index.d.ts +21 -58
  6. package/lib/adapter/onebot/11/index.js +22 -59
  7. package/lib/cli/index.d.ts +5 -15
  8. package/lib/cli/index.js +6 -16
  9. package/lib/core/karin/karin.d.ts +8 -2
  10. package/lib/core/karin/karin.js +7 -3
  11. package/lib/core/listener/listener.d.ts +5 -15
  12. package/lib/core/listener/listener.js +5 -13
  13. package/lib/core/plugin/loader.d.ts +10 -16
  14. package/lib/core/plugin/loader.js +18 -15
  15. package/lib/core/server/server.d.ts +3 -9
  16. package/lib/core/server/server.js +3 -9
  17. package/lib/event/handler/base.d.ts +13 -24
  18. package/lib/event/handler/base.js +25 -24
  19. package/lib/event/handler/message.d.ts +8 -24
  20. package/lib/event/handler/message.js +11 -24
  21. package/lib/event/handler/notice.d.ts +3 -9
  22. package/lib/event/handler/notice.js +6 -9
  23. package/lib/event/handler/request.d.ts +3 -9
  24. package/lib/event/handler/request.js +6 -9
  25. package/lib/event/handler/review.d.ts +7 -21
  26. package/lib/event/handler/review.js +7 -21
  27. package/lib/types/adapter/base.d.ts +21 -63
  28. package/lib/types/config/config.d.ts +65 -195
  29. package/lib/types/event/contact.d.ts +5 -9
  30. package/lib/types/event/event.d.ts +15 -30
  31. package/lib/types/event/message.d.ts +6 -15
  32. package/lib/types/event/message.js +2 -0
  33. package/lib/types/event/notice.d.ts +1 -0
  34. package/lib/types/event/notice.js +2 -0
  35. package/lib/types/event/request.d.ts +1 -0
  36. package/lib/types/event/request.js +2 -0
  37. package/lib/types/plugin/app.d.ts +13 -15
  38. package/lib/types/plugin/plugin.d.ts +22 -39
  39. package/package.json +1 -1
@@ -6,9 +6,7 @@ type onAdapter = {
6
6
  adapter: new () => KarinAdapter;
7
7
  path?: string;
8
8
  };
9
- /**
10
- * 产生事件映射
11
- */
9
+ /** 产生事件映射 */
12
10
  export interface EmittEventMap {
13
11
  'karin:count:send': number;
14
12
  'karin:count:fnc': string;
@@ -28,9 +26,7 @@ export interface EmittEventMap {
28
26
  type ContextEvents = {
29
27
  [K in `ctx:${string}`]: (e: KarinMessage) => void;
30
28
  };
31
- /**
32
- * 监听事件映射
33
- */
29
+ /** 监听事件映射 */
34
30
  export interface OnEventMap extends ContextEvents {
35
31
  'karin:count:send': (count: number) => void;
36
32
  'karin:count:fnc': (fnc: string) => void;
@@ -46,9 +42,7 @@ export interface OnEventMap extends ContextEvents {
46
42
  'restart.grpc': undefined;
47
43
  'restart.http': undefined;
48
44
  }
49
- /**
50
- * 监听器实例
51
- */
45
+ /** 监听器实例 */
52
46
  export declare class Listeners extends EventEmitter {
53
47
  #private;
54
48
  /** 框架名称 */
@@ -70,9 +64,7 @@ export declare class Listeners extends EventEmitter {
70
64
  on(event: string, listener: (...args: any[]) => void): this;
71
65
  emit<K extends keyof EmittEventMap>(event: K, ...args: Parameters<EmittEventMap[K]>): boolean;
72
66
  emit(event: string | symbol, ...args: any[]): boolean;
73
- /**
74
- * 注册Bot 返回索引id
75
- */
67
+ /** 注册Bot 返回索引id */
76
68
  addBot(data: {
77
69
  bot: KarinAdapter;
78
70
  type: AdapterType;
@@ -92,9 +84,7 @@ export declare class Listeners extends EventEmitter {
92
84
  * @param index - Bot的索引id
93
85
  */
94
86
  getBotByIndex(index: number): KarinAdapter;
95
- /**
96
- * 获取当前已注册Bot数量
97
- */
87
+ /** 获取当前已注册Bot数量 */
98
88
  getBotCount(): number;
99
89
  /**
100
90
  * 获取所有Bot列表
@@ -3,9 +3,7 @@ import { EventEmitter } from 'events';
3
3
  import { pluginLoader } from '../plugin/loader.js';
4
4
  import { common, logger, config, segment } from '../../utils/index.js';
5
5
  import { MessageHandler, NoticeHandler, RequestHandler } from '../../event/index.js';
6
- /**
7
- * 监听器实例
8
- */
6
+ /** 监听器实例 */
9
7
  export class Listeners extends EventEmitter {
10
8
  /** 框架名称 */
11
9
  name;
@@ -36,9 +34,7 @@ export class Listeners extends EventEmitter {
36
34
  emit(event, ...args) {
37
35
  return super.emit(event, ...args);
38
36
  }
39
- /**
40
- * 注册Bot 返回索引id
41
- */
37
+ /** 注册Bot 返回索引id */
42
38
  addBot(data) {
43
39
  this.#index++;
44
40
  const index = this.#index;
@@ -78,9 +74,7 @@ export class Listeners extends EventEmitter {
78
74
  logger.debug('注册', this.list);
79
75
  return index;
80
76
  }
81
- /**
82
- * 发送上线通知
83
- */
77
+ /** 发送上线通知 */
84
78
  async #online(uid) {
85
79
  /** 重启 */
86
80
  const key = `karin:restart:${uid}`;
@@ -97,7 +91,7 @@ export class Listeners extends EventEmitter {
97
91
  }
98
92
  const element = [
99
93
  segment.reply(messageId),
100
- segment.text(`\nKarin 重启成功:${restartTime}秒`),
94
+ segment.text(`\n重启成功:${restartTime}秒`),
101
95
  ];
102
96
  await this.sendMsg(id, contact, element);
103
97
  await level.del(key);
@@ -141,9 +135,7 @@ export class Listeners extends EventEmitter {
141
135
  }
142
136
  return this.list[index].bot;
143
137
  }
144
- /**
145
- * 获取当前已注册Bot数量
146
- */
138
+ /** 获取当前已注册Bot数量 */
147
139
  getBotCount() {
148
140
  return this.list.length;
149
141
  }
@@ -1,5 +1,5 @@
1
1
  import chokidar from 'chokidar';
2
- import { UseInfo, AppsType, TaskInfo, ButtonInfo, AcceptInfo, CommandInfo, HandlerInfo, UseMapType, PluginInfoType, PluginTaskInfoType, PluginButtonInfoType, PluginAcceptInfoType, PluginHandlerInfoType, PluginCommandInfoType } from '../../types/index.js';
2
+ import { UseInfo, AppsType, TaskInfo, ButtonInfo, AcceptInfo, CommandInfo, HandlerInfo, UseMapType, PluginInfoType, PluginTaskInfoType, PluginButtonInfoType, PluginAcceptInfoType, PluginHandlerInfoType, PluginCommandInfoType, KarinAdapter } from '../../types/index.js';
3
3
  type AppType = CommandInfo | TaskInfo | HandlerInfo | ButtonInfo | AcceptInfo | UseInfo;
4
4
  export interface AppFile {
5
5
  /** 插件包名称 */
@@ -12,6 +12,10 @@ export interface AppFile {
12
12
  type: `${AppsType}`;
13
13
  /** 热更新 */
14
14
  isWatch: boolean;
15
+ /** 只有对应的适配器才会生效 */
16
+ adapter?: Array<KarinAdapter['adapter']['name']>;
17
+ /** 指定的适配器无效 */
18
+ notAdapter?: Array<KarinAdapter['adapter']['name']>;
15
19
  }
16
20
  declare class PluginLoader {
17
21
  dir: './plugins';
@@ -53,17 +57,11 @@ declare class PluginLoader {
53
57
  /** 加载的文件数组 .js .ts */
54
58
  ext: string[];
55
59
  constructor();
56
- /**
57
- * 插件初始化
58
- */
60
+ /** 插件初始化 */
59
61
  load(): Promise<this>;
60
- /**
61
- * 获取Git插件
62
- */
62
+ /** 获取Git插件 */
63
63
  getGitPlugin(): Promise<Promise<boolean>[]>;
64
- /**
65
- * 获取Npm插件
66
- */
64
+ /** 获取Npm插件 */
67
65
  getNpmPlugin(): Promise<Promise<boolean>[]>;
68
66
  /**
69
67
  * 加载入口文件 只加载
@@ -115,9 +113,7 @@ declare class PluginLoader {
115
113
  * @param App - 插件类
116
114
  */
117
115
  cachePlugin(index: number, plugin: string, file: string, info: AppType, App?: any): Promise<boolean>;
118
- /**
119
- * 打印依赖缺失
120
- */
116
+ /** 打印依赖缺失 */
121
117
  printDependErr(): void;
122
118
  /**
123
119
  * 卸载插件
@@ -134,8 +130,6 @@ declare class PluginLoader {
134
130
  */
135
131
  watchDir(plugin: string, _path: string): Promise<boolean>;
136
132
  }
137
- /**
138
- * 加载插件
139
- */
133
+ /** 加载插件 */
140
134
  export declare const pluginLoader: PluginLoader;
141
135
  export {};
@@ -55,9 +55,7 @@ class PluginLoader {
55
55
  this.watchList = [];
56
56
  this.dependErr = {};
57
57
  }
58
- /**
59
- * 插件初始化
60
- */
58
+ /** 插件初始化 */
61
59
  async load() {
62
60
  karin.once('plugin.watch', () => {
63
61
  this.watchList.forEach(async ({ plugin, path }) => {
@@ -79,9 +77,7 @@ class PluginLoader {
79
77
  karin.emit('plugin.watch');
80
78
  return this;
81
79
  }
82
- /**
83
- * 获取Git插件
84
- */
80
+ /** 获取Git插件 */
85
81
  async getGitPlugin() {
86
82
  /** 获取所有插件包 */
87
83
  const plugins = common.getPlugins();
@@ -183,9 +179,7 @@ class PluginLoader {
183
179
  }
184
180
  return list;
185
181
  }
186
- /**
187
- * 获取Npm插件
188
- */
182
+ /** 获取Npm插件 */
189
183
  async getNpmPlugin() {
190
184
  const list = [];
191
185
  const info = await common.getNpmPlugins(true);
@@ -319,6 +313,13 @@ class PluginLoader {
319
313
  rootPath = rootPath + `?${Date.now()}`;
320
314
  const tmp = await import(rootPath);
321
315
  lodash.forEach(tmp, (Fn) => {
316
+ /** 函数语法糖数组 */
317
+ if (Array.isArray(Fn)) {
318
+ for (const Val of Fn) {
319
+ logger.debug(`载入插件 [${plugin}]${_path ? `${common.getRelPath(_path)}` : ''}[${file}][${Val.name}]`);
320
+ list.push(this.cachePlugin(index, plugin, file, Val));
321
+ }
322
+ }
322
323
  /** 函数语法糖 */
323
324
  if (typeof Fn === 'object' && Fn?.type) {
324
325
  logger.debug(`载入插件 [${plugin}]${_path ? `${common.getRelPath(_path)}` : ''}[${file}][${Fn.name}]`);
@@ -351,6 +352,8 @@ class PluginLoader {
351
352
  perm: val.permission || "all" /* Permission.All */,
352
353
  rank: val.priority || Class.priority || 10000,
353
354
  reg: val.reg instanceof RegExp ? val.reg : new RegExp(val.reg),
355
+ adapter: [],
356
+ notAdapter: [],
354
357
  }, Fn);
355
358
  };
356
359
  list.push(fnc());
@@ -427,6 +430,8 @@ class PluginLoader {
427
430
  key: index,
428
431
  log: info.log,
429
432
  rank: info.rank,
433
+ adapter: info.adapter || [],
434
+ notAdapter: info.notAdapter || [],
430
435
  });
431
436
  return true;
432
437
  }
@@ -464,6 +469,8 @@ class PluginLoader {
464
469
  rank: info.rank,
465
470
  reg: info.reg,
466
471
  type: App ? 'class' : 'function',
472
+ adapter: info.adapter,
473
+ notAdapter: info.notAdapter,
467
474
  });
468
475
  return true;
469
476
  }
@@ -507,9 +514,7 @@ class PluginLoader {
507
514
  }
508
515
  }
509
516
  }
510
- /**
511
- * 打印依赖缺失
512
- */
517
+ /** 打印依赖缺失 */
513
518
  printDependErr() {
514
519
  try {
515
520
  const keys = Object.keys(this.dependErr);
@@ -627,7 +632,5 @@ class PluginLoader {
627
632
  return true;
628
633
  }
629
634
  }
630
- /**
631
- * 加载插件
632
- */
635
+ /** 加载插件 */
633
636
  export const pluginLoader = new PluginLoader();
@@ -8,17 +8,11 @@ export declare const server: {
8
8
  server: ServerType<typeof IncomingMessage, typeof ServerResponse>;
9
9
  WebSocketServer: WebSocketServer;
10
10
  RegExp: RegExp;
11
- /**
12
- * 监听WebSocket连接并初始化http服务器
13
- */
11
+ /** 监听WebSocket连接并初始化http服务器 */
14
12
  init(): Promise<false | any>;
15
- /**
16
- * HTTP渲染器
17
- */
13
+ /** HTTP渲染器 */
18
14
  static(): void;
19
- /**
20
- * 构建静态资源路径
21
- */
15
+ /** 构建静态资源路径 */
22
16
  staticPath(): Promise<void>;
23
17
  /** 重启当前HTTP服务器 */
24
18
  "__#15@#restartServer"(): Promise<void>;
@@ -23,9 +23,7 @@ export const server = new (class Server {
23
23
  this.WebSocketServer = new WebSocketServer({ server: this.server });
24
24
  this.RegExp = new RegExp(`(${process.cwd()}|${process.cwd().replace(/\\/g, '/')})`, 'g');
25
25
  }
26
- /**
27
- * 监听WebSocket连接并初始化http服务器
28
- */
26
+ /** 监听WebSocket连接并初始化http服务器 */
29
27
  async init() {
30
28
  try {
31
29
  /** 防止多进程端口冲突 启动失败 */
@@ -160,9 +158,7 @@ export const server = new (class Server {
160
158
  return false;
161
159
  }
162
160
  }
163
- /**
164
- * HTTP渲染器
165
- */
161
+ /** HTTP渲染器 */
166
162
  static() {
167
163
  this.staticPath();
168
164
  /** GET接口 - 渲染 */
@@ -215,9 +211,7 @@ export const server = new (class Server {
215
211
  /** 设置静态文件目录 */
216
212
  this.app.use(express.static(process.cwd()));
217
213
  }
218
- /**
219
- * 构建静态资源路径
220
- */
214
+ /** 构建静态资源路径 */
221
215
  async staticPath() {
222
216
  this.list = [];
223
217
  /** 读取./resources文件夹 */
@@ -1,40 +1,29 @@
1
- import { GroupCfg, KarinEventTypes, AllListenEvent, PluginRule } from '../../types/index.js';
1
+ import { GroupCfg, KarinEventTypes, AllListenEvent, PluginRule, PluginCommandInfoType, PluginAcceptInfoType } from '../../types/index.js';
2
2
  export declare class EventBaseHandler {
3
3
  e: KarinEventTypes;
4
4
  /** 仅在群聊下存在 */
5
5
  config: GroupCfg;
6
6
  /** 是否打印群消息日志 */
7
7
  GroupMsgPrint: boolean;
8
- /**
9
- * 处理事件,加入自定义字段
10
- */
8
+ /** 处理事件,加入自定义字段 */
11
9
  constructor(e: KarinEventTypes);
12
- /**
13
- * cd检查 返回false表示在cd中
14
- */
10
+ /** cd检查 返回false表示在cd中 */
15
11
  getCd(): boolean;
16
- /**
17
- * 群聊黑白名单检查 返回false表示未通过
18
- */
12
+ /** 群聊黑白名单检查 返回false表示未通过 */
19
13
  getGroupEnable(): boolean;
20
- /**
21
- * 用户黑白名单检查 返回false表示未通过
22
- */
14
+ /** 用户黑白名单检查 返回false表示未通过 */
23
15
  getUserEnable(): boolean;
24
- /**
25
- * 处理私聊功能 功能开启返回true
26
- */
16
+ /** 处理私聊功能 功能开启返回true */
27
17
  private(): boolean;
28
- /**
29
- * 根据事件类型过滤事件 返回false表示未通过
30
- */
18
+ /** 根据事件类型过滤事件 返回false表示未通过 */
31
19
  filtEvent(event: AllListenEvent): boolean;
32
- /**
33
- * 判断权限
34
- */
20
+ /** 判断权限 */
35
21
  filterPermission(permission?: PluginRule['permission']): boolean;
22
+ /** 快速回复 */
23
+ reply(): void;
36
24
  /**
37
- * 快速回复
25
+ * 处理适配器
26
+ * @param info 插件信息
38
27
  */
39
- reply(): void;
28
+ filterAdapter(info: PluginCommandInfoType | PluginAcceptInfoType): boolean;
40
29
  }
@@ -7,9 +7,7 @@ export class EventBaseHandler {
7
7
  config;
8
8
  /** 是否打印群消息日志 */
9
9
  GroupMsgPrint;
10
- /**
11
- * 处理事件,加入自定义字段
12
- */
10
+ /** 处理事件,加入自定义字段 */
13
11
  constructor(e) {
14
12
  this.e = e;
15
13
  this.GroupMsgPrint = true;
@@ -18,36 +16,28 @@ export class EventBaseHandler {
18
16
  if (this.e.group_id)
19
17
  this.config = config.group(this.e.group_id, this.e);
20
18
  }
21
- /**
22
- * cd检查 返回false表示在cd中
23
- */
19
+ /** cd检查 返回false表示在cd中 */
24
20
  getCd() {
25
21
  if (review.CD(this.e, this.config))
26
22
  return true;
27
23
  logger.debug(`[消息拦截][${this.e.group_id}][${this.e.user_id}] 正在冷却中`);
28
24
  return false;
29
25
  }
30
- /**
31
- * 群聊黑白名单检查 返回false表示未通过
32
- */
26
+ /** 群聊黑白名单检查 返回false表示未通过 */
33
27
  getGroupEnable() {
34
28
  if (review.GroupEnable(this.e))
35
29
  return true;
36
30
  logger.debug(`[消息拦截][${this.e.group_id}][${this.e.user_id}] 未通过群聊黑白名单检查`);
37
31
  return false;
38
32
  }
39
- /**
40
- * 用户黑白名单检查 返回false表示未通过
41
- */
33
+ /** 用户黑白名单检查 返回false表示未通过 */
42
34
  getUserEnable() {
43
35
  if (review.UserEnable(this.e))
44
36
  return true;
45
37
  logger.debug(`[消息拦截][${this.e.group_id}][${this.e.user_id}] 未通过用户黑白名单检查`);
46
38
  return false;
47
39
  }
48
- /**
49
- * 处理私聊功能 功能开启返回true
50
- */
40
+ /** 处理私聊功能 功能开启返回true */
51
41
  private() {
52
42
  /** 检查私聊是否开启 */
53
43
  if (this.e.user_id !== 'input' && this.e.isPrivate && !review.Private()) {
@@ -62,9 +52,7 @@ export class EventBaseHandler {
62
52
  }
63
53
  return true;
64
54
  }
65
- /**
66
- * 根据事件类型过滤事件 返回false表示未通过
67
- */
55
+ /** 根据事件类型过滤事件 返回false表示未通过 */
68
56
  filtEvent(event) {
69
57
  /** 事件映射表 */
70
58
  const eventMap = {
@@ -77,9 +65,7 @@ export class EventBaseHandler {
77
65
  const eventType = eventMap[this.e.event]();
78
66
  return eventType.includes(event);
79
67
  }
80
- /**
81
- * 判断权限
82
- */
68
+ /** 判断权限 */
83
69
  filterPermission(permission) {
84
70
  if (!permission || permission === 'all')
85
71
  return true;
@@ -120,9 +106,7 @@ export class EventBaseHandler {
120
106
  }
121
107
  return true;
122
108
  }
123
- /**
124
- * 快速回复
125
- */
109
+ /** 快速回复 */
126
110
  reply() {
127
111
  /**
128
112
  * 快速回复
@@ -195,4 +179,21 @@ export class EventBaseHandler {
195
179
  };
196
180
  Object.freeze(this.e.reply);
197
181
  }
182
+ /**
183
+ * 处理适配器
184
+ * @param info 插件信息
185
+ */
186
+ filterAdapter(info) {
187
+ if (!info.adapter.length && !info.notAdapter.length)
188
+ return true;
189
+ if (info.notAdapter.includes(this.e.bot.adapter.name)) {
190
+ logger.debug(`[插件适配器][${info.name}] 该插件不支持当前适配器`);
191
+ return false;
192
+ }
193
+ if (!info.adapter.includes(this.e.bot.adapter.name)) {
194
+ logger.debug(`[插件适配器][${info.name}] 该插件不支持当前适配器`);
195
+ return false;
196
+ }
197
+ return true;
198
+ }
198
199
  }
@@ -1,37 +1,23 @@
1
1
  import { EventBaseHandler } from './base.js';
2
2
  import { KarinMessageType } from '../../types/index.js';
3
- /**
4
- * 消息事件
5
- */
3
+ /** 消息事件 */
6
4
  export declare class MessageHandler extends EventBaseHandler {
7
5
  e: KarinMessageType;
8
6
  /** 当前事件是否是上下文事件 */
9
7
  isContext: boolean;
10
8
  constructor(e: KarinMessageType);
11
9
  start(): Promise<void>;
12
- /**
13
- * 先对消息事件进行初始化
14
- */
10
+ /** 先对消息事件进行初始化 */
15
11
  init(): void;
16
- /**
17
- * 开始中间件
18
- */
12
+ /** 开始中间件 */
19
13
  startUse(): Promise<void>;
20
- /**
21
- * 结束中间件
22
- */
14
+ /** 结束中间件 */
23
15
  endUse(): Promise<void>;
24
- /**
25
- * 响应模式检查 返回false表示未通过
26
- */
16
+ /** 响应模式检查 返回false表示未通过 */
27
17
  getMode(): boolean;
28
- /**
29
- * 处理消息
30
- */
18
+ /** 处理消息 */
31
19
  deal(): Promise<void>;
32
- /**
33
- * 获取下文
34
- */
20
+ /** 获取下文 */
35
21
  getContext(): {
36
22
  type: "fnc";
37
23
  fnc: Function;
@@ -42,8 +28,6 @@ export declare class MessageHandler extends EventBaseHandler {
42
28
  } | {
43
29
  type: "ctx";
44
30
  };
45
- /**
46
- * 处理上下文
47
- */
31
+ /** 处理上下文 */
48
32
  context(): Promise<boolean>;
49
33
  }
@@ -3,9 +3,7 @@ import { review } from './review.js';
3
3
  import { EventBaseHandler } from './base.js';
4
4
  import { logger, config } from '../../utils/index.js';
5
5
  import { karin, stateArr, pluginLoader } from '../../core/index.js';
6
- /**
7
- * 消息事件
8
- */
6
+ /** 消息事件 */
9
7
  export class MessageHandler extends EventBaseHandler {
10
8
  e;
11
9
  /** 当前事件是否是上下文事件 */
@@ -40,9 +38,7 @@ export class MessageHandler extends EventBaseHandler {
40
38
  /** 处理消息 */
41
39
  this.deal();
42
40
  }
43
- /**
44
- * 先对消息事件进行初始化
45
- */
41
+ /** 先对消息事件进行初始化 */
46
42
  init() {
47
43
  karin.emit('karin:count:recv', this.e);
48
44
  const logs = [];
@@ -194,9 +190,7 @@ export class MessageHandler extends EventBaseHandler {
194
190
  this.reply();
195
191
  karin.emit('message', this.e);
196
192
  }
197
- /**
198
- * 开始中间件
199
- */
193
+ /** 开始中间件 */
200
194
  async startUse() {
201
195
  for (const info of pluginLoader.use.recvMsg) {
202
196
  try {
@@ -219,9 +213,7 @@ export class MessageHandler extends EventBaseHandler {
219
213
  }
220
214
  }
221
215
  }
222
- /**
223
- * 结束中间件
224
- */
216
+ /** 结束中间件 */
225
217
  async endUse() {
226
218
  for (const info of pluginLoader.use.notFoundMsg) {
227
219
  try {
@@ -244,18 +236,14 @@ export class MessageHandler extends EventBaseHandler {
244
236
  }
245
237
  }
246
238
  }
247
- /**
248
- * 响应模式检查 返回false表示未通过
249
- */
239
+ /** 响应模式检查 返回false表示未通过 */
250
240
  getMode() {
251
241
  if (review.mode(this.e, this.config))
252
242
  return true;
253
243
  logger.debug(`[消息拦截][${this.e.group_id}][${this.e.user_id}] 响应模式不匹配`);
254
244
  return false;
255
245
  }
256
- /**
257
- * 处理消息
258
- */
246
+ /** 处理消息 */
259
247
  async deal() {
260
248
  const app = this.e.group_id
261
249
  ? (info) => review.PluginEnable(info, this.config)
@@ -266,6 +254,9 @@ export class MessageHandler extends EventBaseHandler {
266
254
  continue;
267
255
  const reg = info.reg;
268
256
  if (reg.test(this.e.msg)) {
257
+ /** 判断适配器 */
258
+ if (!this.filterAdapter(info))
259
+ continue;
269
260
  /** 检查黑白名单插件 */
270
261
  if (!app(info))
271
262
  continue;
@@ -307,16 +298,12 @@ export class MessageHandler extends EventBaseHandler {
307
298
  logger.debug(`[事件处理][${this.e.self_id}][${this.e.user_id}][${this.e.event_id}] 未匹配到任何插件`);
308
299
  await this.endUse();
309
300
  }
310
- /**
311
- * 获取下文
312
- */
301
+ /** 获取下文 */
313
302
  getContext() {
314
303
  const key = this.e.isGroup ? `${this.e.group_id}.${this.e.user_id}` : this.e.user_id;
315
304
  return stateArr[key];
316
305
  }
317
- /**
318
- * 处理上下文
319
- */
306
+ /** 处理上下文 */
320
307
  async context() {
321
308
  const key = this.e.isGroup ? `${this.e.group_id}.${this.e.user_id}` : this.e.user_id;
322
309
  const App = stateArr[key];
@@ -1,18 +1,12 @@
1
1
  import { EventBaseHandler } from './base.js';
2
2
  import { KarinNoticeType } from '../../types/index.js';
3
- /**
4
- * 通知事件
5
- */
3
+ /** 通知事件 */
6
4
  export declare class NoticeHandler extends EventBaseHandler {
7
5
  e: KarinNoticeType;
8
6
  constructor(e: KarinNoticeType);
9
7
  init(): void;
10
- /**
11
- * 处理事件
12
- */
8
+ /** 处理事件 */
13
9
  deal(): Promise<void>;
14
- /**
15
- * 构建原始消息
16
- */
10
+ /** 构建原始消息 */
17
11
  raw_message(): void;
18
12
  }
@@ -2,9 +2,7 @@ import { review } from './review.js';
2
2
  import { EventBaseHandler } from './base.js';
3
3
  import { logger, config } from '../../utils/index.js';
4
4
  import { karin, pluginLoader } from '../../core/index.js';
5
- /**
6
- * 通知事件
7
- */
5
+ /** 通知事件 */
8
6
  export class NoticeHandler extends EventBaseHandler {
9
7
  e;
10
8
  constructor(e) {
@@ -59,14 +57,15 @@ export class NoticeHandler extends EventBaseHandler {
59
57
  this.reply();
60
58
  karin.emit('notice', this.e);
61
59
  }
62
- /**
63
- * 处理事件
64
- */
60
+ /** 处理事件 */
65
61
  async deal() {
66
62
  for (const info of pluginLoader.accept) {
67
63
  /** 判断事件 */
68
64
  if (!this.filtEvent(info.event))
69
65
  continue;
66
+ /** 判断适配器 */
67
+ if (!this.filterAdapter(info))
68
+ continue;
70
69
  /** 检查黑白名单插件 */
71
70
  if (!review.PluginEnable(info, this.config))
72
71
  continue;
@@ -90,9 +89,7 @@ export class NoticeHandler extends EventBaseHandler {
90
89
  }
91
90
  logger.debug(`[事件处理][${this.e.self_id}][${this.e.user_id}][${this.e.event_id}] 未匹配到任何插件`);
92
91
  }
93
- /**
94
- * 构建原始消息
95
- */
92
+ /** 构建原始消息 */
96
93
  raw_message() {
97
94
  switch (this.e.sub_event) {
98
95
  /** 好友头像戳一戳 */