node-karin 0.12.15 → 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 (45) 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/index.d.ts +1 -2
  28. package/lib/index.js +1 -2
  29. package/lib/types/adapter/base.d.ts +21 -63
  30. package/lib/types/config/config.d.ts +65 -195
  31. package/lib/types/event/contact.d.ts +5 -9
  32. package/lib/types/event/event.d.ts +15 -30
  33. package/lib/types/event/message.d.ts +6 -15
  34. package/lib/types/event/message.js +2 -0
  35. package/lib/types/event/notice.d.ts +1 -0
  36. package/lib/types/event/notice.js +2 -0
  37. package/lib/types/event/request.d.ts +1 -0
  38. package/lib/types/event/request.js +2 -0
  39. package/lib/types/plugin/app.d.ts +13 -15
  40. package/lib/types/plugin/plugin.d.ts +22 -39
  41. package/lib/utils/index.d.ts +1 -0
  42. package/lib/utils/index.js +1 -0
  43. package/lib/utils/tools/yaml.d.ts +15 -0
  44. package/lib/utils/tools/yaml.js +43 -0
  45. package/package.json +1 -1
@@ -2,6 +2,7 @@ import schedule from 'node-schedule';
2
2
  import { Reply, replyCallback, replyForward } from '../event/reply.js';
3
3
  import { KarinNoticeType, KarinRequestType, AllListenEvent, KarinMessageType, AllMessageSubType, Permission } from '../event/index.js';
4
4
  import { AcceptInfo, ButtonInfo, CommandInfo, HandlerInfo, Plugin, UseForwardMsgFn, UseInfo, UseNotFoundMsgFn, UseRecvMsgFn, UseSendMsgFn, UseSendNoticeFn } from '../../core/index.js';
5
+ import { KarinAdapter } from '../adapter/base.js';
5
6
  /**
6
7
  * - 插件根目录名称
7
8
  * - 例如: karin-plugin-example
@@ -15,9 +16,7 @@ export type dirName = `karin-plugin-${string}` | string;
15
16
  * - 例如: index.js index.ts
16
17
  */
17
18
  export type fileName = `${string}.js` | `${string}.ts`;
18
- /**
19
- * 插件类型枚举
20
- */
19
+ /** 插件类型枚举 */
21
20
  export declare const enum AppsType {
22
21
  /** git插件 */
23
22
  Git = "git",
@@ -26,18 +25,14 @@ export declare const enum AppsType {
26
25
  /** 单个app插件 */
27
26
  Js = "js"
28
27
  }
29
- /**
30
- * 插件实现方法类型
31
- */
28
+ /** 插件实现方法类型 */
32
29
  export declare const enum MethodType {
33
30
  /** 函数 */
34
31
  Function = "function",
35
32
  /** 类 */
36
33
  Class = "class"
37
34
  }
38
- /**
39
- * plugin基本信息
40
- */
35
+ /** plugin基本信息 */
41
36
  export interface PluginInfoType {
42
37
  /** 插件包类型 */
43
38
  type: `${AppsType}`;
@@ -48,9 +43,7 @@ export interface PluginInfoType {
48
43
  /** 插件文件名称 index.js index.ts */
49
44
  file: string;
50
45
  }
51
- /**
52
- * Command规则集信息
53
- */
46
+ /** Command规则集信息 */
54
47
  export interface PluginCommandInfoType {
55
48
  /** 插件基本信息的映射key */
56
49
  key: number;
@@ -74,10 +67,12 @@ export interface PluginCommandInfoType {
74
67
  event: CommandInfo['event'];
75
68
  /** 优先级 */
76
69
  rank: CommandInfo['rank'];
70
+ /** 只有对应的适配器才会生效 */
71
+ adapter: Array<KarinAdapter['adapter']['name']>;
72
+ /** 指定的适配器无效 */
73
+ notAdapter: Array<KarinAdapter['adapter']['name']>;
77
74
  }
78
- /**
79
- * accept规则集信息
80
- */
75
+ /** accept规则集信息 */
81
76
  export interface PluginAcceptInfoType {
82
77
  /** 插件基本信息的映射key */
83
78
  key: number;
@@ -91,10 +86,12 @@ export interface PluginAcceptInfoType {
91
86
  event: AcceptInfo['event'];
92
87
  /** 执行打印日志方法 */
93
88
  log: AcceptInfo['log'];
89
+ /** 只有对应的适配器才会生效 */
90
+ adapter: Array<KarinAdapter['adapter']['name']>;
91
+ /** 指定的适配器无效 */
92
+ notAdapter: Array<KarinAdapter['adapter']['name']>;
94
93
  }
95
- /**
96
- * task规则集信息
97
- */
94
+ /** task规则集信息 */
98
95
  export interface PluginTaskInfoType {
99
96
  /** 插件基本信息的映射key */
100
97
  key: number;
@@ -113,9 +110,7 @@ export interface PluginTaskInfoType {
113
110
  /** 停止函数 */
114
111
  schedule: schedule.Job;
115
112
  }
116
- /**
117
- * button规则集信息
118
- */
113
+ /** button规则集信息 */
119
114
  export interface PluginButtonInfoType {
120
115
  /** 插件基本信息的映射key */
121
116
  key: number;
@@ -128,9 +123,7 @@ export interface PluginButtonInfoType {
128
123
  /** 优先级 */
129
124
  rank: ButtonInfo['rank'];
130
125
  }
131
- /**
132
- * handler规则集信息
133
- */
126
+ /** handler规则集信息 */
134
127
  export interface PluginHandlerInfoType {
135
128
  /** 插件基本信息的映射key */
136
129
  key: number;
@@ -151,9 +144,7 @@ export interface UseBase<T> {
151
144
  /** 优先级 */
152
145
  rank: UseInfo['rank'];
153
146
  }
154
- /**
155
- * 中间件类型
156
- */
147
+ /** 中间件类型 */
157
148
  export declare const enum UseKeyType {
158
149
  /** 收到消息后 */
159
150
  ReceiveMsg = "recvMsg",
@@ -166,9 +157,7 @@ export declare const enum UseKeyType {
166
157
  /** 消息事件没有找到任何匹配的插件触发 */
167
158
  NotFoundMsg = "notFoundMsg"
168
159
  }
169
- /**
170
- * 中间件映射
171
- */
160
+ /** 中间件映射 */
172
161
  export interface UseMapType {
173
162
  [UseKeyType.ReceiveMsg]: Array<UseBase<UseRecvMsgFn>>;
174
163
  [UseKeyType.ReplyMsg]: Array<UseBase<UseSendMsgFn>>;
@@ -176,9 +165,7 @@ export interface UseMapType {
176
165
  [UseKeyType.ForwardMsg]: Array<UseBase<UseForwardMsgFn>>;
177
166
  [UseKeyType.NotFoundMsg]: Array<UseBase<UseNotFoundMsgFn>>;
178
167
  }
179
- /**
180
- * 上下文状态
181
- */
168
+ /** 上下文状态 */
182
169
  export interface stateArrType {
183
170
  [key: string]: {
184
171
  type: 'fnc';
@@ -201,9 +188,7 @@ export interface PluginRule {
201
188
  event?: AllMessageSubType;
202
189
  /** 优先级 默认为10000 */
203
190
  priority?: number;
204
- /**
205
- * 权限
206
- */
191
+ /** 权限 */
207
192
  permission?: `${Permission}`;
208
193
  /** 打印日志 默认为true */
209
194
  log?: boolean | Function;
@@ -329,7 +314,5 @@ export interface PluginApps {
329
314
  /** handler */
330
315
  handler: Array<PluginHandler>;
331
316
  }
332
- /**
333
- * 未实例化的插件
334
- */
317
+ /** 未实例化的插件 */
335
318
  export type NewMessagePlugin = new (e?: KarinMessageType) => Plugin;
@@ -11,3 +11,4 @@ export * from './core/logger.js';
11
11
  export * from './config/updateVersion.js';
12
12
  export * from './tools/restart.js';
13
13
  export * from './tools/stop.js';
14
+ export * from './tools/yaml.js';
@@ -11,3 +11,4 @@ export * from './core/logger.js';
11
11
  export * from './config/updateVersion.js';
12
12
  export * from './tools/restart.js';
13
13
  export * from './tools/stop.js';
14
+ export * from './tools/yaml.js';
@@ -0,0 +1,15 @@
1
+ import Yaml from 'yaml';
2
+ export declare const yaml: typeof Yaml & {
3
+ /**
4
+ * 传入yaml文件路径 自动读取并解析
5
+ * @param path yaml文件路径
6
+ */
7
+ read: (path: string) => any;
8
+ /**
9
+ * 保存并写入注释
10
+ * @param path 保存的路径
11
+ * @param value 保存的数据
12
+ * @param commentConfig 注释配置文件路径或json
13
+ */
14
+ save: (path: string, value: any, commentConfig?: string) => void;
15
+ };
@@ -0,0 +1,43 @@
1
+ import fs from 'fs';
2
+ import Yaml from 'yaml';
3
+ import logger from '../core/logger.js';
4
+ import { YamlEditor } from '../config/yamlEditor.js';
5
+ const yamlNew = {
6
+ /**
7
+ * 传入yaml文件路径 自动读取并解析
8
+ * @param path yaml文件路径
9
+ */
10
+ read: (path) => {
11
+ const data = fs.readFileSync(path, 'utf-8');
12
+ return Yaml.parse(data);
13
+ },
14
+ /**
15
+ * 保存并写入注释
16
+ * @param path 保存的路径
17
+ * @param value 保存的数据
18
+ * @param commentConfig 注释配置文件路径或json
19
+ */
20
+ save: (path, value, commentConfig) => {
21
+ if (!commentConfig) {
22
+ fs.writeFileSync(path, Yaml.stringify(value));
23
+ return;
24
+ }
25
+ const editor = new YamlEditor(Yaml.stringify(value));
26
+ const comment = JSON.parse(fs.existsSync(commentConfig) ? fs.readFileSync(commentConfig, 'utf8') : commentConfig);
27
+ for (const [key, value] of Object.entries(comment)) {
28
+ try {
29
+ if (typeof value === 'object') {
30
+ editor.comment(key, value.text, value.type === 'start');
31
+ }
32
+ else if (typeof value === 'string') {
33
+ editor.comment(key, value, true);
34
+ }
35
+ }
36
+ catch (error) {
37
+ logger.error(`[YamlEditor] 添加注释时出错,已跳过:${error.stack || error.message || error}`);
38
+ }
39
+ }
40
+ fs.writeFileSync(path, editor.document.toString());
41
+ },
42
+ };
43
+ export const yaml = Object.assign(Yaml, yamlNew);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "node-karin",
3
- "version": "0.12.15",
3
+ "version": "0.12.17",
4
4
  "private": false,
5
5
  "description": "基于 Kritor 进行开发的nodejs机器人框架",
6
6
  "homepage": "https://github.com/KarinJS/Karin",