node-karin 0.0.3

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 (107) hide show
  1. package/LICENSE +674 -0
  2. package/README.md +57 -0
  3. package/config/defSet/App.yaml +37 -0
  4. package/config/defSet/config.yaml +43 -0
  5. package/config/defSet/group.yaml +18 -0
  6. package/config/defSet/pm2.yaml +21 -0
  7. package/config/defSet/redis.yaml +18 -0
  8. package/config/defSet/server.yaml +42 -0
  9. package/config/view/App.yaml +74 -0
  10. package/config/view/config.yaml +100 -0
  11. package/config/view/group.yaml +62 -0
  12. package/config/view/pm2.yaml +41 -0
  13. package/config/view/redis.yaml +25 -0
  14. package/config/view/server.yaml +93 -0
  15. package/lib/adapter/onebot/onebot11.d.ts +430 -0
  16. package/lib/adapter/onebot/onebot11.js +1302 -0
  17. package/lib/core/init.d.ts +0 -0
  18. package/lib/core/init.js +4 -0
  19. package/lib/core/karin.d.ts +72 -0
  20. package/lib/core/karin.js +51 -0
  21. package/lib/core/listener.d.ts +121 -0
  22. package/lib/core/listener.js +188 -0
  23. package/lib/core/plugin.app.d.ts +15 -0
  24. package/lib/core/plugin.app.js +18 -0
  25. package/lib/core/plugin.d.ts +182 -0
  26. package/lib/core/plugin.js +138 -0
  27. package/lib/core/plugin.loader.d.ts +149 -0
  28. package/lib/core/plugin.loader.js +462 -0
  29. package/lib/core/server.d.ts +26 -0
  30. package/lib/core/server.js +213 -0
  31. package/lib/db/level.d.ts +20 -0
  32. package/lib/db/level.js +38 -0
  33. package/lib/db/redis.d.ts +41 -0
  34. package/lib/db/redis.js +137 -0
  35. package/lib/db/redis_level.d.ts +113 -0
  36. package/lib/db/redis_level.js +290 -0
  37. package/lib/event/event.d.ts +138 -0
  38. package/lib/event/event.handler.d.ts +29 -0
  39. package/lib/event/event.handler.js +142 -0
  40. package/lib/event/event.js +120 -0
  41. package/lib/event/message.d.ts +102 -0
  42. package/lib/event/message.handler.d.ts +25 -0
  43. package/lib/event/message.handler.js +240 -0
  44. package/lib/event/message.js +70 -0
  45. package/lib/event/notice.d.ts +49 -0
  46. package/lib/event/notice.js +15 -0
  47. package/lib/event/request.d.ts +49 -0
  48. package/lib/event/request.js +15 -0
  49. package/lib/event/review.handler.d.ts +54 -0
  50. package/lib/event/review.handler.js +382 -0
  51. package/lib/index.d.ts +23 -0
  52. package/lib/index.js +40 -0
  53. package/lib/renderer/app.d.ts +53 -0
  54. package/lib/renderer/app.js +93 -0
  55. package/lib/renderer/base.d.ts +30 -0
  56. package/lib/renderer/base.js +71 -0
  57. package/lib/renderer/client.d.ts +30 -0
  58. package/lib/renderer/client.js +159 -0
  59. package/lib/renderer/http.d.ts +19 -0
  60. package/lib/renderer/http.js +51 -0
  61. package/lib/renderer/server.d.ts +42 -0
  62. package/lib/renderer/server.js +112 -0
  63. package/lib/renderer/wormhole.d.ts +1 -0
  64. package/lib/renderer/wormhole.js +154 -0
  65. package/lib/types/adapter.d.ts +575 -0
  66. package/lib/types/adapter.js +1 -0
  67. package/lib/types/config.d.ts +327 -0
  68. package/lib/types/config.js +1 -0
  69. package/lib/types/element.d.ts +576 -0
  70. package/lib/types/element.js +1 -0
  71. package/lib/types/index.d.ts +8 -0
  72. package/lib/types/index.js +8 -0
  73. package/lib/types/logger.d.ts +109 -0
  74. package/lib/types/logger.js +1 -0
  75. package/lib/types/onebots11.d.ts +1371 -0
  76. package/lib/types/onebots11.js +1 -0
  77. package/lib/types/plugin.d.ts +282 -0
  78. package/lib/types/plugin.js +1 -0
  79. package/lib/types/render.d.ts +111 -0
  80. package/lib/types/render.js +1 -0
  81. package/lib/types/reply.d.ts +40 -0
  82. package/lib/types/reply.js +1 -0
  83. package/lib/types/types.d.ts +898 -0
  84. package/lib/types/types.js +1 -0
  85. package/lib/utils/YamlEditor.d.ts +62 -0
  86. package/lib/utils/YamlEditor.js +208 -0
  87. package/lib/utils/button.d.ts +49 -0
  88. package/lib/utils/button.js +79 -0
  89. package/lib/utils/common.d.ts +123 -0
  90. package/lib/utils/common.js +413 -0
  91. package/lib/utils/config.d.ts +72 -0
  92. package/lib/utils/config.js +254 -0
  93. package/lib/utils/exec.d.ts +22 -0
  94. package/lib/utils/exec.js +36 -0
  95. package/lib/utils/ffmpeg.d.ts +12 -0
  96. package/lib/utils/ffmpeg.js +25 -0
  97. package/lib/utils/handler.d.ts +76 -0
  98. package/lib/utils/handler.js +102 -0
  99. package/lib/utils/logger.d.ts +3 -0
  100. package/lib/utils/logger.js +104 -0
  101. package/lib/utils/segment.d.ts +276 -0
  102. package/lib/utils/segment.js +448 -0
  103. package/lib/utils/update.d.ts +69 -0
  104. package/lib/utils/update.js +151 -0
  105. package/lib/utils/updateVersion.d.ts +33 -0
  106. package/lib/utils/updateVersion.js +145 -0
  107. package/package.json +92 -0
@@ -0,0 +1 @@
1
+ export {}
@@ -0,0 +1,282 @@
1
+ /// <reference types="node" />
2
+ import schedule from 'node-schedule';
3
+ import { KarinNodeElement } from './element.js';
4
+ import { Reply, replyCallback } from './reply.js';
5
+ import { E, Event, Permission, SubEvent } from './types.js';
6
+ /**
7
+ * - 插件根目录名称
8
+ * - 例如: karin-plugin-example
9
+ * - 例如: karin-plugin-example/apps
10
+ */
11
+ export type dirName = `karin-plugin-${string}`;
12
+ /**
13
+ * - 插件名称
14
+ * - 例如: index.js index.ts
15
+ */
16
+ export type fileName = `${string}.js` | `${string}.ts`;
17
+ /**
18
+ * - 插件规则
19
+ */
20
+ export interface PluginRule {
21
+ /**
22
+ * - 命令正则
23
+ */
24
+ reg: RegExp;
25
+ /**
26
+ * - 命令执行方法名称
27
+ */
28
+ fnc: string | Function;
29
+ /**
30
+ * - 子事件
31
+ */
32
+ event?: Event | `${Event}.${SubEvent}`;
33
+ /**
34
+ * 权限
35
+ */
36
+ permission?: Permission;
37
+ /**
38
+ * - 打印日志 默认为true
39
+ */
40
+ log?: boolean | Function;
41
+ }
42
+ /**
43
+ * - 定时任务规则
44
+ */
45
+ export interface PluginTask {
46
+ /**
47
+ * - 任务名称
48
+ */
49
+ name: string;
50
+ /**
51
+ * - cron表达式
52
+ */
53
+ cron: string;
54
+ /**
55
+ * - 执行方法名称或对应函数
56
+ */
57
+ fnc: string | Function;
58
+ /**
59
+ * - 是否显示执行日志 默认为true
60
+ */
61
+ log: boolean | Function;
62
+ /**
63
+ * - 停止函数
64
+ */
65
+ schedule?: schedule.Job;
66
+ }
67
+ /**
68
+ * - 按钮规则
69
+ */
70
+ export interface PluginButton {
71
+ /**
72
+ * - 按钮命令正则
73
+ */
74
+ reg: string;
75
+ /**
76
+ * - 执行方法名称
77
+ */
78
+ fnc: string;
79
+ /**
80
+ * - 优先级 不填默认为主优先度
81
+ */
82
+ priority: number;
83
+ }
84
+ /**
85
+ * - handler规则
86
+ */
87
+ export interface PluginHandler {
88
+ /**
89
+ * - handler支持的事件key
90
+ */
91
+ key: string;
92
+ /**
93
+ * - handler的处理方法名称
94
+ */
95
+ fnc: string;
96
+ /**
97
+ * - handler优先级 不填默认为主优先度
98
+ */
99
+ priority: number;
100
+ }
101
+ /**
102
+ * - 插件信息
103
+ */
104
+ export interface AppInfo {
105
+ /**
106
+ * - 插件根目录名称
107
+ * - karin-plugin-example
108
+ * - karin-plugin-example/apps
109
+ * - karin-plugin-example/src/apps
110
+ * - karin-plugin-example/dist/apps
111
+ */
112
+ dir: dirName;
113
+ /**
114
+ * - 插件名称 例如: index.js index.ts
115
+ */
116
+ name: fileName;
117
+ }
118
+ /**
119
+ * - 插件基类
120
+ */
121
+ export interface Plugin {
122
+ /**
123
+ * - 插件名称
124
+ */
125
+ name: string;
126
+ /**
127
+ * - 插件描述
128
+ * @deprecated 请使用desc
129
+ */
130
+ dsc: string;
131
+ /**
132
+ * - 插件描述
133
+ */
134
+ desc: string;
135
+ /**
136
+ * - 监听事件 默认为message
137
+ */
138
+ event: Event | `${Event}.${SubEvent}`;
139
+ /**
140
+ * - 优先级 默认为5000
141
+ */
142
+ priority: number;
143
+ /**
144
+ * - 定时任务
145
+ */
146
+ task: Array<PluginTask>;
147
+ /**
148
+ * - 命令规则
149
+ */
150
+ rule: Array<PluginRule>;
151
+ /**
152
+ * - 按钮
153
+ */
154
+ button: Array<PluginButton>;
155
+ /**
156
+ * - handler
157
+ */
158
+ handler: Array<PluginHandler>;
159
+ /**
160
+ * - 用户ID 一般上下文使用
161
+ */
162
+ userId?: number;
163
+ /**
164
+ * - 上下文超时
165
+ */
166
+ timeout: NodeJS.Timeout | undefined;
167
+ /**
168
+ * - 上报事件
169
+ */
170
+ e: E;
171
+ /**
172
+ * - 快速回复
173
+ */
174
+ reply: Reply;
175
+ /**
176
+ * - 快速回复内部方法 由适配器实现
177
+ */
178
+ replyCallback: replyCallback;
179
+ /**
180
+ * - 快速回复合并转发
181
+ */
182
+ replyForward: (msg: KarinNodeElement[]) => Promise<{
183
+ message_id?: string;
184
+ }>;
185
+ /**
186
+ * - 构建上下文键
187
+ */
188
+ conKey: () => string;
189
+ /**
190
+ * - 设置上下文状态
191
+ */
192
+ setContext: (
193
+ /**
194
+ * - 执行方法名称
195
+ */
196
+ fnc: string,
197
+ /**
198
+ * - 超时后是否回复
199
+ */
200
+ reply?: boolean,
201
+ /**
202
+ * - 下文超时时间 默认120秒
203
+ */
204
+ time?: number) => void;
205
+ /**
206
+ * - 获取上下文状态
207
+ */
208
+ getContext: () => {
209
+ /**
210
+ * - 插件实例
211
+ */
212
+ plugin: Plugin;
213
+ /**
214
+ * - 执行方法名称
215
+ */
216
+ fnc: string;
217
+ };
218
+ /**
219
+ * - accept标准方法 给通知、请求事件使用
220
+ */
221
+ accept?(e: E): Promise<void>;
222
+ }
223
+ /**
224
+ * 上下文状态
225
+ */
226
+ export interface stateArr {
227
+ [key: string]: {
228
+ plugin: Plugin;
229
+ fnc: string;
230
+ };
231
+ }
232
+ /**
233
+ * - Apps
234
+ */
235
+ export interface PluginApps {
236
+ /**
237
+ * - 插件文件信息
238
+ */
239
+ file: AppInfo & {
240
+ /**
241
+ * - 插件类型
242
+ */
243
+ type: 'function' | 'class';
244
+ /**
245
+ * - 插件方法
246
+ */
247
+ Fnc: '' | (new () => Plugin);
248
+ };
249
+ /**
250
+ * - 插件名称
251
+ */
252
+ name: string;
253
+ /**
254
+ * - 插件事件
255
+ */
256
+ event: Event | `${Event}.${SubEvent}`;
257
+ /**
258
+ * - 插件优先级
259
+ * @default 10000
260
+ */
261
+ priority: number;
262
+ /**
263
+ * - accept函数存在
264
+ */
265
+ accept: boolean;
266
+ /**
267
+ * - 命令规则
268
+ */
269
+ rule: Array<PluginRule>;
270
+ /**
271
+ * - 定时任务
272
+ */
273
+ task: Array<PluginTask>;
274
+ /**
275
+ * - 按钮
276
+ */
277
+ button: Array<PluginButton>;
278
+ /**
279
+ * - handler
280
+ */
281
+ handler: Array<PluginHandler>;
282
+ }
@@ -0,0 +1 @@
1
+ export {}
@@ -0,0 +1,111 @@
1
+ import chokidar from 'chokidar';
2
+ /**
3
+ * 渲染标准方法传参
4
+ */
5
+ export interface KarinRenderType {
6
+ /**
7
+ * - 渲染文件路径或HTTP地址 与vue二选一
8
+ */
9
+ file: string;
10
+ /**
11
+ * - vue文件路径 与file二选一
12
+ */
13
+ vue?: string;
14
+ /**
15
+ * - 模板名称
16
+ */
17
+ name?: string;
18
+ /**
19
+ * - art-template后的文件名
20
+ */
21
+ fileID?: string;
22
+ /**
23
+ * - 传递给模板的数据 template.render(data)
24
+ */
25
+ data?: object;
26
+ /**
27
+ * - 截图类型 默认'webp'
28
+ */
29
+ type?: 'png' | 'jpeg' | 'webp';
30
+ /**
31
+ * - 截图质量 默认90 1-100
32
+ */
33
+ quality?: number;
34
+ /**
35
+ * - 是否隐藏背景 默认false
36
+ */
37
+ omitBackground?: boolean;
38
+ /**
39
+ * - 设置视窗大小和设备像素比 默认1920*1080、1
40
+ */
41
+ setViewport?: {
42
+ /**
43
+ * - 视窗宽度
44
+ */
45
+ width?: number;
46
+ /**
47
+ * - 视窗高度
48
+ */
49
+ height?: number;
50
+ /**
51
+ * - 设备像素比
52
+ */
53
+ deviceScaleFactor?: string;
54
+ };
55
+ /**
56
+ * - 分页截图 传递数字则视为视窗高度 返回数组
57
+ */
58
+ multiPage?: number | boolean;
59
+ /**
60
+ * - 页面goto时的参数
61
+ */
62
+ pageGotoParams?: {
63
+ /**
64
+ * - 页面加载超时时间
65
+ */
66
+ timeout?: number;
67
+ /**
68
+ * - 页面加载状态
69
+ */
70
+ waitUntil?: 'load' | 'domcontentloaded' | 'networkidle0' | 'networkidle2';
71
+ [key: string]: any;
72
+ };
73
+ }
74
+ /**
75
+ * 渲染基类
76
+ */
77
+ export interface KarinRender {
78
+ dir: './temp/html';
79
+ html: {
80
+ [key: string]: string;
81
+ };
82
+ watcher: {
83
+ [key: string]: chokidar.FSWatcher;
84
+ };
85
+ /**
86
+ * 模板渲染
87
+ * @param options - 渲染参数
88
+ * @param isAbs - 是否返回绝对路径 默认true
89
+ */
90
+ dealTpl(options: KarinRenderType, isAbs: boolean): string;
91
+ /**
92
+ * 监听模板文件
93
+ * @param tplFile 模板文件路径
94
+ */
95
+ watch(tplFile: string): void;
96
+ /**
97
+ * 渲染
98
+ * @param options - 标准渲染方法
99
+ */
100
+ render: (options: KarinRenderType) => Promise<string | Array<string>>;
101
+ }
102
+ /**
103
+ * 渲染器管理
104
+ */
105
+ export interface KarinRenderApp {
106
+ index: number;
107
+ id: string;
108
+ type: string;
109
+ time: number;
110
+ render: KarinRender['render'];
111
+ }
@@ -0,0 +1 @@
1
+ export {}
@@ -0,0 +1,40 @@
1
+ import { KarinElement } from './element.js';
2
+ export type Reply = (
3
+ /**
4
+ * 发送的消息
5
+ */
6
+ elements: string | KarinElement | Array<KarinElement | string>,
7
+ /**
8
+ * 选项
9
+ */
10
+ options?: {
11
+ /**
12
+ * 是否@回复
13
+ */
14
+ at?: boolean;
15
+ /**
16
+ * 是否回复
17
+ */
18
+ reply?: boolean;
19
+ /**
20
+ * 发送成功后撤回发送消息的时间
21
+ */
22
+ recallMsg?: number;
23
+ /**
24
+ * 重试次数
25
+ */
26
+ retry_count?: number;
27
+ }) => Promise<{
28
+ message_id?: string;
29
+ }>;
30
+ export type replyCallback = (
31
+ /**
32
+ * 发送的消息
33
+ */
34
+ elements: KarinElement[],
35
+ /**
36
+ * 重试次数
37
+ */
38
+ retry_count?: number) => Promise<{
39
+ message_id?: string;
40
+ }>;
@@ -0,0 +1 @@
1
+ export {}