node-karin 0.12.0 → 0.12.2-5.pr.206.027f2f2

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 (254) hide show
  1. package/CHANGELOG.md +1029 -0
  2. package/default/comment/config.json +34 -0
  3. package/default/comment/friendDirect.json +10 -0
  4. package/default/comment/groupGuild.json +11 -0
  5. package/default/comment/server.json +17 -0
  6. package/default/config/adapter.json +28 -0
  7. package/default/config/config.json +47 -0
  8. package/default/config/groups.json +47 -0
  9. package/default/config/groups.yaml +70 -0
  10. package/default/config/pm2.json +16 -0
  11. package/default/config/privates.json +23 -0
  12. package/default/config/privates.yaml +31 -0
  13. package/default/config/redis.json +10 -0
  14. package/default/config/render.json +19 -0
  15. package/default/view/group.yaml +73 -0
  16. package/dist/index.d.ts +9869 -0
  17. package/dist/index.js +12643 -0
  18. package/dist/module/art-template.cjs +11 -0
  19. package/dist/module/art-template.d.ts +1 -0
  20. package/dist/module/axios.cjs +22 -0
  21. package/dist/module/axios.d.ts +2 -0
  22. package/dist/module/chalk.cjs +22 -0
  23. package/dist/module/chalk.d.ts +2 -0
  24. package/dist/module/chokidar.cjs +22 -0
  25. package/dist/module/chokidar.d.ts +2 -0
  26. package/dist/module/commander.cjs +35 -0
  27. package/dist/module/commander.d.ts +3 -0
  28. package/dist/module/commander.js +3 -0
  29. package/dist/module/dotenv.cjs +22 -0
  30. package/dist/module/dotenv.d.ts +2 -0
  31. package/dist/module/dotenv.js +2 -0
  32. package/dist/module/express.cjs +112 -0
  33. package/dist/module/express.d.ts +1 -0
  34. package/dist/module/express.js +1 -0
  35. package/dist/module/level.cjs +22 -0
  36. package/dist/module/level.d.ts +2 -0
  37. package/dist/module/lodash.cjs +11 -0
  38. package/dist/module/lodash.d.ts +1 -0
  39. package/dist/module/log4js.cjs +22 -0
  40. package/dist/module/log4js.d.ts +2 -0
  41. package/dist/module/moment.cjs +11 -0
  42. package/dist/module/moment.d.ts +1 -0
  43. package/dist/module/node-schedule.cjs +22 -0
  44. package/dist/module/node-schedule.d.ts +2 -0
  45. package/dist/module/redis.cjs +22 -0
  46. package/dist/module/redis.d.ts +2 -0
  47. package/dist/module/ws.cjs +28 -0
  48. package/dist/module/ws.d.ts +1 -0
  49. package/dist/module/ws.js +1 -0
  50. package/dist/module/yaml.cjs +22 -0
  51. package/dist/module/yaml.d.ts +2 -0
  52. package/dist/root.d.ts +40 -0
  53. package/dist/root.js +44 -0
  54. package/package.json +142 -128
  55. package/LICENSE +0 -674
  56. package/README.md +0 -56
  57. package/config/defSet/App.yaml +0 -42
  58. package/config/defSet/config.yaml +0 -65
  59. package/config/defSet/group.yaml +0 -56
  60. package/config/defSet/pm2.yaml +0 -21
  61. package/config/defSet/redis.yaml +0 -18
  62. package/config/defSet/server.yaml +0 -42
  63. package/config/view/group.yaml +0 -92
  64. package/lib/adapter/index.d.ts +0 -2
  65. package/lib/adapter/index.js +0 -2
  66. package/lib/adapter/input/index.d.ts +0 -78
  67. package/lib/adapter/input/index.js +0 -205
  68. package/lib/adapter/onebot/11/convert.d.ts +0 -12
  69. package/lib/adapter/onebot/11/convert.js +0 -167
  70. package/lib/adapter/onebot/11/event.d.ts +0 -25
  71. package/lib/adapter/onebot/11/event.js +0 -442
  72. package/lib/adapter/onebot/11/index.d.ts +0 -508
  73. package/lib/adapter/onebot/11/index.js +0 -1047
  74. package/lib/cli/index.d.ts +0 -92
  75. package/lib/cli/index.js +0 -307
  76. package/lib/cli/init.d.ts +0 -2
  77. package/lib/cli/init.js +0 -22
  78. package/lib/cli/karin.d.ts +0 -2
  79. package/lib/cli/karin.js +0 -16
  80. package/lib/cli/pkg.d.ts +0 -4
  81. package/lib/cli/pkg.js +0 -14
  82. package/lib/cli/start.d.ts +0 -1
  83. package/lib/cli/start.js +0 -8
  84. package/lib/core/index.d.ts +0 -10
  85. package/lib/core/index.js +0 -10
  86. package/lib/core/init/config.d.ts +0 -43
  87. package/lib/core/init/config.js +0 -201
  88. package/lib/core/init/dir.d.ts +0 -4
  89. package/lib/core/init/dir.js +0 -7
  90. package/lib/core/init/init.d.ts +0 -1
  91. package/lib/core/init/init.js +0 -47
  92. package/lib/core/karin/karin.d.ts +0 -198
  93. package/lib/core/karin/karin.js +0 -226
  94. package/lib/core/listener/listener.d.ts +0 -145
  95. package/lib/core/listener/listener.js +0 -235
  96. package/lib/core/plugin/base.d.ts +0 -156
  97. package/lib/core/plugin/base.js +0 -131
  98. package/lib/core/plugin/loader.d.ts +0 -141
  99. package/lib/core/plugin/loader.js +0 -618
  100. package/lib/core/process/process.d.ts +0 -18
  101. package/lib/core/process/process.js +0 -96
  102. package/lib/core/server/server.d.ts +0 -25
  103. package/lib/core/server/server.js +0 -295
  104. package/lib/db/index.d.ts +0 -2
  105. package/lib/db/index.js +0 -2
  106. package/lib/db/level/level.d.ts +0 -19
  107. package/lib/db/level/level.js +0 -36
  108. package/lib/db/redis/redis.d.ts +0 -2
  109. package/lib/db/redis/redis.js +0 -135
  110. package/lib/db/redis/redis_level.d.ts +0 -112
  111. package/lib/db/redis/redis_level.js +0 -281
  112. package/lib/event/handler/base.d.ts +0 -42
  113. package/lib/event/handler/base.js +0 -200
  114. package/lib/event/handler/message.d.ts +0 -29
  115. package/lib/event/handler/message.js +0 -307
  116. package/lib/event/handler/notice.d.ts +0 -18
  117. package/lib/event/handler/notice.js +0 -214
  118. package/lib/event/handler/request.d.ts +0 -18
  119. package/lib/event/handler/request.js +0 -115
  120. package/lib/event/handler/review.d.ts +0 -55
  121. package/lib/event/handler/review.js +0 -386
  122. package/lib/event/index.d.ts +0 -5
  123. package/lib/event/index.js +0 -5
  124. package/lib/index.d.ts +0 -8
  125. package/lib/index.js +0 -8
  126. package/lib/modules/art-template.d.ts +0 -1
  127. package/lib/modules/axios.d.ts +0 -2
  128. package/lib/modules/chalk.d.ts +0 -2
  129. package/lib/modules/chokidar.d.ts +0 -2
  130. package/lib/modules/commander.d.ts +0 -2
  131. package/lib/modules/commander.js +0 -2
  132. package/lib/modules/express.d.ts +0 -3
  133. package/lib/modules/express.js +0 -3
  134. package/lib/modules/level.d.ts +0 -2
  135. package/lib/modules/lodash.d.ts +0 -1
  136. package/lib/modules/log4js.d.ts +0 -2
  137. package/lib/modules/moment.d.ts +0 -1
  138. package/lib/modules/node-schedule.d.ts +0 -2
  139. package/lib/modules/redis.d.ts +0 -2
  140. package/lib/modules/ws.d.ts +0 -3
  141. package/lib/modules/ws.js +0 -3
  142. package/lib/modules/yaml.d.ts +0 -2
  143. package/lib/modules.d.ts +0 -15
  144. package/lib/modules.js +0 -15
  145. package/lib/render/app.d.ts +0 -56
  146. package/lib/render/app.js +0 -120
  147. package/lib/render/base.d.ts +0 -30
  148. package/lib/render/base.js +0 -69
  149. package/lib/render/client.d.ts +0 -41
  150. package/lib/render/client.js +0 -238
  151. package/lib/render/http.d.ts +0 -19
  152. package/lib/render/http.js +0 -50
  153. package/lib/render/index.d.ts +0 -6
  154. package/lib/render/index.js +0 -6
  155. package/lib/render/server.d.ts +0 -25
  156. package/lib/render/server.js +0 -101
  157. package/lib/render/wormhole.d.ts +0 -1
  158. package/lib/render/wormhole.js +0 -156
  159. package/lib/types/adapter/api.d.ts +0 -399
  160. package/lib/types/adapter/api.js +0 -1
  161. package/lib/types/adapter/base.d.ts +0 -560
  162. package/lib/types/adapter/base.js +0 -1
  163. package/lib/types/config/config.d.ts +0 -379
  164. package/lib/types/config/config.js +0 -1
  165. package/lib/types/element/element.d.ts +0 -565
  166. package/lib/types/element/element.js +0 -1
  167. package/lib/types/element/qqbot.d.ts +0 -123
  168. package/lib/types/element/qqbot.js +0 -1
  169. package/lib/types/event/contact.d.ts +0 -28
  170. package/lib/types/event/contact.js +0 -1
  171. package/lib/types/event/event.d.ts +0 -305
  172. package/lib/types/event/event.js +0 -1
  173. package/lib/types/event/index.d.ts +0 -12
  174. package/lib/types/event/index.js +0 -7
  175. package/lib/types/event/message.d.ts +0 -109
  176. package/lib/types/event/message.js +0 -74
  177. package/lib/types/event/notice.d.ts +0 -513
  178. package/lib/types/event/notice.js +0 -52
  179. package/lib/types/event/reply.d.ts +0 -50
  180. package/lib/types/event/reply.js +0 -1
  181. package/lib/types/event/request.d.ts +0 -126
  182. package/lib/types/event/request.js +0 -52
  183. package/lib/types/event/sender.d.ts +0 -44
  184. package/lib/types/event/sender.js +0 -1
  185. package/lib/types/index.d.ts +0 -13
  186. package/lib/types/index.js +0 -13
  187. package/lib/types/logger/logger.d.ts +0 -110
  188. package/lib/types/logger/logger.js +0 -1
  189. package/lib/types/onebot11/api.d.ts +0 -53
  190. package/lib/types/onebot11/api.js +0 -1
  191. package/lib/types/onebot11/event.d.ts +0 -619
  192. package/lib/types/onebot11/event.js +0 -2
  193. package/lib/types/onebot11/index.d.ts +0 -6
  194. package/lib/types/onebot11/index.js +0 -6
  195. package/lib/types/onebot11/params.d.ts +0 -609
  196. package/lib/types/onebot11/params.js +0 -1
  197. package/lib/types/onebot11/response.d.ts +0 -516
  198. package/lib/types/onebot11/response.js +0 -1
  199. package/lib/types/onebot11/segment.d.ts +0 -269
  200. package/lib/types/onebot11/segment.js +0 -1
  201. package/lib/types/onebot11/sender.d.ts +0 -59
  202. package/lib/types/onebot11/sender.js +0 -1
  203. package/lib/types/plugin/app.d.ts +0 -71
  204. package/lib/types/plugin/app.js +0 -1
  205. package/lib/types/plugin/plugin.d.ts +0 -473
  206. package/lib/types/plugin/plugin.js +0 -1
  207. package/lib/types/render/render.d.ts +0 -118
  208. package/lib/types/render/render.js +0 -1
  209. package/lib/types/type/global.d.ts +0 -25
  210. package/lib/types/type/global.js +0 -1
  211. package/lib/utils/common/common.d.ts +0 -236
  212. package/lib/utils/common/common.js +0 -708
  213. package/lib/utils/config/config.d.ts +0 -193
  214. package/lib/utils/config/config.js +0 -328
  215. package/lib/utils/config/updateVersion.d.ts +0 -33
  216. package/lib/utils/config/updateVersion.js +0 -145
  217. package/lib/utils/config/yamlEditor.d.ts +0 -101
  218. package/lib/utils/config/yamlEditor.js +0 -330
  219. package/lib/utils/core/handler.d.ts +0 -18
  220. package/lib/utils/core/handler.js +0 -46
  221. package/lib/utils/core/logger.d.ts +0 -3
  222. package/lib/utils/core/logger.js +0 -105
  223. package/lib/utils/core/segment.d.ts +0 -279
  224. package/lib/utils/core/segment.js +0 -451
  225. package/lib/utils/index.d.ts +0 -13
  226. package/lib/utils/index.js +0 -13
  227. package/lib/utils/tools/button.d.ts +0 -2
  228. package/lib/utils/tools/button.js +0 -27
  229. package/lib/utils/tools/exec.d.ts +0 -20
  230. package/lib/utils/tools/exec.js +0 -54
  231. package/lib/utils/tools/ffmpeg.d.ts +0 -12
  232. package/lib/utils/tools/ffmpeg.js +0 -25
  233. package/lib/utils/tools/restart.d.ts +0 -15
  234. package/lib/utils/tools/restart.js +0 -39
  235. package/lib/utils/tools/stop.d.ts +0 -7
  236. package/lib/utils/tools/stop.js +0 -13
  237. package/lib/utils/tools/update.d.ts +0 -67
  238. package/lib/utils/tools/update.js +0 -151
  239. /package/{config → default}/view/App.yaml +0 -0
  240. /package/{config → default}/view/config.yaml +0 -0
  241. /package/{config → default}/view/pm2.yaml +0 -0
  242. /package/{config → default}/view/redis.yaml +0 -0
  243. /package/{config → default}/view/server.yaml +0 -0
  244. /package/{lib/modules → dist/module}/art-template.js +0 -0
  245. /package/{lib/modules → dist/module}/axios.js +0 -0
  246. /package/{lib/modules → dist/module}/chalk.js +0 -0
  247. /package/{lib/modules → dist/module}/chokidar.js +0 -0
  248. /package/{lib/modules → dist/module}/level.js +0 -0
  249. /package/{lib/modules → dist/module}/lodash.js +0 -0
  250. /package/{lib/modules → dist/module}/log4js.js +0 -0
  251. /package/{lib/modules → dist/module}/moment.js +0 -0
  252. /package/{lib/modules → dist/module}/node-schedule.js +0 -0
  253. /package/{lib/modules → dist/module}/redis.js +0 -0
  254. /package/{lib/modules → dist/module}/yaml.js +0 -0
@@ -1,201 +0,0 @@
1
- import fs from 'fs';
2
- import path from 'path';
3
- import { exec } from 'child_process';
4
- /** 必须详细指向根文件 否则会导致模块乱导入 */
5
- import { karinDir } from '../../core/init/dir.js';
6
- export class KarinCfgInit {
7
- /**
8
- * 基础目录
9
- */
10
- baseDir;
11
- constructor() {
12
- this.baseDir = [
13
- './config/config',
14
- './config/view',
15
- './config/plugin',
16
- './temp/input',
17
- './temp/html',
18
- './plugins/karin-plugin-example',
19
- ];
20
- }
21
- init() {
22
- this.baseDir.forEach(dir => this.mkdir(dir));
23
- /** 非src源代码环境才创建 */
24
- if (!fs.existsSync('./src')) {
25
- this.copyFile();
26
- this.modifyPackage();
27
- }
28
- }
29
- /**
30
- * 递归创建目录
31
- * @param dirname - 路径
32
- */
33
- mkdir(dirname) {
34
- if (fs.existsSync(dirname))
35
- return true;
36
- if (this.mkdir(path.dirname(dirname)))
37
- fs.mkdirSync(dirname);
38
- return true;
39
- }
40
- /**
41
- * 解析json
42
- */
43
- readJson(file) {
44
- return JSON.parse(fs.readFileSync(file, 'utf-8'));
45
- }
46
- /**
47
- * 获取插件列表
48
- */
49
- getPlugins() {
50
- const pluginsDir = './plugins';
51
- const plugins = fs.readdirSync(pluginsDir);
52
- return plugins.filter(dir => dir.startsWith('karin-plugin-'));
53
- }
54
- /**
55
- * 从npm包内复制默认配置出来
56
- */
57
- copyFile() {
58
- /** 配置 */
59
- const list = ['config/view'];
60
- list.forEach(dir => {
61
- const pkgDir = path.join(karinDir, dir);
62
- const projDir = path.join(process.cwd(), dir);
63
- /** 清空projDir目录下的文件 保留目录 */
64
- if (fs.existsSync(projDir))
65
- fs.rmSync(projDir, { recursive: true });
66
- this.mkdir(projDir);
67
- /** 读取pkgDir目录下的所有文件 复制到projDir下 */
68
- const files = fs.readdirSync(pkgDir).filter(file => file.endsWith('.yaml'));
69
- files.forEach(file => {
70
- const destPath = path.join(projDir, file);
71
- const srcPath = path.join(pkgDir, file);
72
- fs.copyFileSync(srcPath, destPath);
73
- });
74
- });
75
- /** 创建pnpm工作区配置 */
76
- fs.writeFileSync('./pnpm-workspace.yaml', `packages:\n - 'plugins/**'\n`);
77
- /** 为每个插件包创建统一存储的文件夹 */
78
- const plugins = this.getPlugins();
79
- const DataList = [
80
- 'data',
81
- 'temp',
82
- 'resources',
83
- 'temp/html',
84
- 'config/plugin',
85
- ];
86
- DataList.forEach(_path => {
87
- _path = path.join(process.cwd(), _path);
88
- plugins.forEach(plugin => this.mkdir(path.join(_path, plugin)));
89
- });
90
- }
91
- /**
92
- * 修改package.json以支持运行
93
- */
94
- modifyPackage() {
95
- const pkg = this.readJson(path.join(karinDir, 'package.json'));
96
- const projPkg = this.readJson('./package.json');
97
- const main = 'node_modules/node-karin/lib/index.js';
98
- delete pkg.bin;
99
- pkg.main = `./${main}`;
100
- pkg.types = `./${main.replace('.js', '.d.ts')}`;
101
- pkg.dependencies = { ...projPkg.dependencies, ...pkg.dependencies };
102
- pkg.devDependencies = { ...projPkg.devDependencies, ...pkg.devDependencies };
103
- projPkg.type = 'module';
104
- projPkg.private = true;
105
- projPkg.main = `./${main}`;
106
- projPkg.dependencies = { ...projPkg.dependencies, ...pkg.dependencies };
107
- projPkg.dependencies['node-karin'] = 'latest';
108
- projPkg.dependencies['kritor-proto'] = 'latest';
109
- if (!projPkg.scripts)
110
- projPkg.scripts = {};
111
- if (!projPkg.devDependencies)
112
- projPkg.devDependencies = {};
113
- projPkg.scripts.debug = `node --watch ${main}`;
114
- projPkg.scripts.dev = `tsx --watch ${main}`;
115
- fs.writeFileSync('./package.json', JSON.stringify(projPkg, null, 2));
116
- }
117
- /**
118
- * 更换镜像源为淘宝源
119
- */
120
- async changeRegistry(host) {
121
- const cmd = `npm config set registry ${host}`;
122
- // 检查当前镜像源是否为淘宝源
123
- const registry = await this.shell('npm config get registry');
124
- if (registry === host) {
125
- console.log(`当前npm源已经是 ${host} ~`);
126
- return;
127
- }
128
- if (!await this.shell(cmd)) {
129
- console.log('更换npm源失败,请手动更换npm源!');
130
- console.log(`可尝试手动执行 【 npm config set registry ${host} 】 更换镜像源~`);
131
- }
132
- else {
133
- console.log('更换npm源成功~');
134
- }
135
- }
136
- /**
137
- * 安装pnpm或者yarn
138
- * @param type - 包管理器名称
139
- */
140
- async install(type) {
141
- /** 检查是否已经安装对应的包管理器 */
142
- if (!(await this.shell(`${type} -v`))) {
143
- console.log(`检测到未安装${type},开始安装...`);
144
- if (!await this.shell(`npm install -g ${type}`)) {
145
- console.log(`${type}安装失败,请手动安装${type}!`);
146
- console.log(`可尝试手动执行 【 npm install -g ${type} 】 安装${type}~`);
147
- return;
148
- }
149
- else {
150
- console.log(`${type}安装完成~`);
151
- }
152
- }
153
- else {
154
- console.log('检测到已安装pnpm,开始安装依赖...');
155
- }
156
- /** 安装依赖 */
157
- if (!(await this.shell(`${type} install -P --force`))) {
158
- console.log('安装依赖失败,请手动安装依赖!');
159
- console.log(`可尝试手动执行 【 ${type} install -P 】 安装依赖~`);
160
- console.log('如中国大陆用户安装失败,请尝试执行换源 【 npm config set registry https://registry.npmmirror.com 】后再安装依赖~');
161
- }
162
- else {
163
- console.log('依赖安装完成~');
164
- }
165
- /** 检查安装pm2 */
166
- if (!(await this.shell('pm2 -v'))) {
167
- console.log('检测到未安装pm2,开始安装pm2...');
168
- if (!(await this.shell(`${type} install -g pm2`))) {
169
- console.log('安装pm2失败,请手动安装pm2!');
170
- console.log('可尝试手动执行 【 npm install -g pm2 】 安装pm2~');
171
- }
172
- else {
173
- console.log('pm2安装完成~');
174
- }
175
- }
176
- else {
177
- console.log('检测到已安装pm2~');
178
- }
179
- console.log('依赖环境初始化完成~');
180
- }
181
- /**
182
- * 执行命令
183
- * @param cmd - 命令
184
- */
185
- shell(cmd) {
186
- return new Promise(resolve => {
187
- exec(cmd, { env: process.env, cwd: process.cwd() }, (err, stdout, stderr) => {
188
- if (stdout)
189
- return resolve(stdout.trim());
190
- if (err) {
191
- console.error(err);
192
- return resolve(false);
193
- }
194
- if (stderr) {
195
- console.error(stderr);
196
- return resolve(false);
197
- }
198
- });
199
- });
200
- }
201
- }
@@ -1,4 +0,0 @@
1
- /**
2
- * - 获取当前npm包的根目录
3
- */
4
- export declare const karinDir: string;
@@ -1,7 +0,0 @@
1
- import path from 'path';
2
- import { fileURLToPath } from 'url';
3
- const filename = fileURLToPath(import.meta.url);
4
- /**
5
- * - 获取当前npm包的根目录
6
- */
7
- export const karinDir = path.resolve(filename, '../../../../').replace(/\\/g, '/').replace(/\/$/, '');
@@ -1 +0,0 @@
1
- export {};
@@ -1,47 +0,0 @@
1
- import { logger } from '../../utils/index.js';
2
- /**
3
- * 启动日志
4
- */
5
- logger.mark('Karin 启动中...');
6
- logger.mark(`当前版本: ${process.env.karin_app_version}`);
7
- logger.mark('https://github.com/KarinJS/Karin');
8
- /**
9
- * 设置标题
10
- */
11
- process.title = 'Karin';
12
- /**
13
- * 设置时区
14
- */
15
- process.env.TZ = 'Asia/Shanghai';
16
- const init = () => {
17
- if (!process.env.karin_app_lang)
18
- process.env.karin_app_lang = 'js';
19
- if (!process.env.karin_app_mode)
20
- process.env.karin_app_mode = 'prod';
21
- if (!process.env.karin_app_runner)
22
- process.env.karin_app_runner = 'node';
23
- if (!process.env.karin_app_start_count)
24
- process.env.karin_app_start_count = '0';
25
- /** 正常启动 */
26
- if (process.env.karin_app_runner === 'node' && process.env.karin_app_lang === 'js' && process.env.karin_app_mode === 'prod') {
27
- logger.debug('当前为 JavaScript 生产模式');
28
- return;
29
- }
30
- /** pm2 */
31
- if (process.env.karin_app_runner === 'pm2') {
32
- logger.info('当前为 PM2 模式');
33
- return;
34
- }
35
- /** js开发模式 */
36
- if (process.env.karin_app_lang === 'js' && process.env.karin_app_mode === 'dev') {
37
- logger.info('当前为 JavaScript 开发模式');
38
- return;
39
- }
40
- /** ts开发模式 */
41
- if (process.env.karin_app_lang === 'ts' && process.env.karin_app_mode === 'dev') {
42
- logger.info('当前为 TypeScript 开发模式');
43
- return;
44
- }
45
- logger.error('未知的启动模式');
46
- };
47
- init();
@@ -1,198 +0,0 @@
1
- import { Contact, KarinElement, KarinMessage, KarinRenderType, PermissionType, RenderResult, KarinNoticeType, KarinRequestType, KarinMessageType, AllMessageSubType, CommandInfo, TaskInfo, HandlerInfo, AcceptInfo, UseInfo, AllNoticeSubType, AllRequestSubType } from '../../types/index.js';
2
- import { Listeners } from '../listener/listener.js';
3
- type FncFunction = (e: KarinMessage) => Promise<boolean>;
4
- type FncElement = string | KarinElement | Array<KarinElement>;
5
- type UseReceive = (e: KarinMessageType, next: Function, exit: Function) => Promise<void>;
6
- type UseReply = (e: KarinMessageType, element: KarinElement[], next: Function, exit: Function) => Promise<void>;
7
- type UseRecord = (uid: string, contact: Contact, elements: KarinElement[], next: Function, exit: Function) => Promise<void>;
8
- /**
9
- * 中间件类型
10
- */
11
- export declare const enum MiddlewareType {
12
- /** 收到消息后 */
13
- ReceiveMsg = "recvMsg",
14
- /** 回复消息前 */
15
- ReplyMsg = "replyMsg",
16
- /** 发送主动消息前 */
17
- SendMsg = "sendMsg"
18
- }
19
- export interface Options {
20
- /**
21
- * - 插件名称 不传则使用 插件名称:函数名
22
- */
23
- name?: string;
24
- /**
25
- * - 插件优先级 数字越小优先级越高
26
- * @default 10000
27
- */
28
- priority?: number;
29
- /**
30
- * - 打印日志
31
- * @default false
32
- */
33
- log?: boolean | Function;
34
- }
35
- export interface OptionsCommand extends Options {
36
- /**
37
- * - 监听事件
38
- */
39
- event?: `${AllMessageSubType}`;
40
- /**
41
- * - 权限
42
- * @default 'all'
43
- */
44
- permission?: PermissionType;
45
- }
46
- export interface OptionsElement extends OptionsCommand {
47
- /**
48
- * - 是否加上at 仅在群聊中有效
49
- * @default false
50
- */
51
- at?: boolean;
52
- /**
53
- * - 是否加上引用回复
54
- * @default false
55
- */
56
- reply?: boolean;
57
- /**
58
- * - 延迟回复 单位毫秒
59
- */
60
- delay?: number;
61
- /**
62
- * - 发送是否撤回消息 单位秒
63
- * @default 0
64
- */
65
- recallMsg?: number;
66
- /**
67
- * - 是否停止执行后续插件
68
- * @default true
69
- */
70
- stop?: boolean;
71
- }
72
- export declare class Karin extends Listeners {
73
- #private;
74
- constructor();
75
- /**
76
- * @param reg - 正则表达式
77
- * @param fn - 函数
78
- * @param options - 选项
79
- */
80
- command(reg: string | RegExp, fn: FncFunction, options?: OptionsCommand): CommandInfo;
81
- /**
82
- * @param reg - 正则表达式
83
- * @param element - 字符串或者KarinElement、KarinElement数组
84
- * @param options - 选项
85
- */
86
- command(reg: string | RegExp, element: FncElement, options?: OptionsElement): CommandInfo;
87
- /**
88
- * - 构建定时任务
89
- * @param name - 任务名称
90
- * @param cron - cron表达式
91
- * @param fn - 执行函数
92
- * @param options - 选项
93
- */
94
- task(name: string, cron: string, fn: Function, options?: Omit<Options, 'priority'>): TaskInfo;
95
- /**
96
- * - 构建handler
97
- * @param key - 事件key
98
- * @param fn - 函数实现
99
- * @param options - 选项
100
- */
101
- handler(key: string, fn: (
102
- /**
103
- * - 自定义参数 由调用方传递
104
- */
105
- args: {
106
- [key: string]: any;
107
- },
108
- /**
109
- * - 停止循环函数 调用后则不再继续执行下一个处理器
110
- */
111
- reject: (msg?: string) => void) => Promise<any>, options?: Omit<Options, 'log'>): HandlerInfo;
112
- /**
113
- * 构建contact
114
- * @param scene - 场景
115
- * @param peer - 群号或者用户id
116
- * @param sub_peer - 子id
117
- */
118
- contact(scene: Contact['scene'], peer: Contact['peer'], sub_peer?: Contact['sub_peer']): Contact;
119
- /**
120
- * 构建group_contact
121
- * @param peer - 群号
122
- */
123
- contactGroup(peer: Contact['peer']): Contact;
124
- /**
125
- * 构建friend_contact
126
- * @param peer - 用户id
127
- */
128
- contactFriend(peer: Contact['peer']): Contact;
129
- /**
130
- * 构建guild_contact
131
- * @param peer - 频道id
132
- * @param sub_peer - 子频道id
133
- */
134
- contactGuild(peer: Contact['peer'], sub_peer: string): Contact;
135
- /**
136
- * 快速渲染
137
- * @param file - 文件路径、http地址
138
- */
139
- render(file: string): Promise<string>;
140
- /**
141
- * 分片渲染
142
- * @param options - 渲染参数
143
- */
144
- render(file: string, multiPage: number | true): Promise<Array<string>>;
145
- /**
146
- * 正常渲染
147
- * @param options - 渲染参数
148
- */
149
- render<T extends KarinRenderType>(options: T): Promise<RenderResult<T>>;
150
- /**
151
- * 上下文
152
- * @param e - 消息事件
153
- * @param options - 上下文选项
154
- */
155
- ctx(e: KarinMessage, options?: {
156
- /**
157
- * - 指定用户id触发下文 不指定则使用默认e.user_id
158
- */
159
- userId?: string;
160
- /**
161
- * - 超时时间 默认120秒
162
- */
163
- time?: number;
164
- /**
165
- * - 超时后是否回复
166
- */
167
- reply?: boolean;
168
- /**
169
- * - 超时回复文本 默认为'操作超时已取消'
170
- */
171
- replyMsg?: string;
172
- }): Promise<KarinMessage>;
173
- /**
174
- * accept
175
- * @param event - 监听事件
176
- * @param fn - 实现函数
177
- */
178
- accept(event: AllNoticeSubType | AllRequestSubType, fn: (e: KarinNoticeType | KarinRequestType) => Promise<boolean>, options?: Options): AcceptInfo;
179
- use(type: `${MiddlewareType.ReceiveMsg}`, fn: UseReceive, options?: Omit<Options, 'log'>): UseInfo;
180
- use(type: `${MiddlewareType.ReplyMsg}`, fn: UseReply, options?: Omit<Options, 'log'>): UseInfo;
181
- use(type: `${MiddlewareType.SendMsg}`, fn: UseRecord, options?: Omit<Options, 'log'>): UseInfo;
182
- /**
183
- * - 启动
184
- */
185
- run(): Promise<void>;
186
- }
187
- export declare const karin: Karin;
188
- /**
189
- * 即将废弃 请使用karin
190
- * @deprecated
191
- */
192
- export declare const listener: Karin;
193
- /**
194
- * 即将废弃 请使用karin
195
- * @deprecated
196
- */
197
- export declare const Bot: Karin;
198
- export default karin;
@@ -1,226 +0,0 @@
1
- import { stateArr } from '../plugin/base.js';
2
- import onebot11 from '../../adapter/onebot/11/index.js';
3
- import { render } from '../../render/app.js';
4
- import { RenderServer } from '../../render/server.js';
5
- import { pluginLoader } from '../plugin/loader.js';
6
- import { common } from '../../utils/common/common.js';
7
- import { logger } from '../../utils/core/logger.js';
8
- import { Listeners } from '../listener/listener.js';
9
- export class Karin extends Listeners {
10
- /** 是否启动 */
11
- #start;
12
- constructor() {
13
- super();
14
- this.#start = false;
15
- this.run();
16
- }
17
- /**
18
- * - 快速构建命令
19
- * @param reg - 正则表达式
20
- * @param second - 函数或者字符串或者KarinElement、KarinElement数组
21
- * @param options - 选项
22
- * @returns - 返回插件对象
23
- */
24
- command(reg, second, options = {}) {
25
- reg = typeof reg === 'string' ? new RegExp(reg) : reg;
26
- const fn = typeof second === 'function'
27
- ? second
28
- : async (e) => {
29
- const element = typeof second === 'number' ? String(second) : second;
30
- if ('delay' in options && options.delay)
31
- await common.sleep(options.delay);
32
- await e.reply(element, {
33
- at: ('at' in options && options.at) || false,
34
- reply: ('reply' in options && options.reply) || false,
35
- recallMsg: ('recallMsg' in options && Number(options.recallMsg)) || 0,
36
- });
37
- return !('stop' in options && !options.stop);
38
- };
39
- const log = options.log === false
40
- ? (id, text) => logger.bot('debug', id, text)
41
- : (id, text) => logger.bot('info', id, text);
42
- return {
43
- data: '',
44
- event: options.event || 'message',
45
- fn,
46
- fnname: 'fnc',
47
- log,
48
- name: options.name || 'command',
49
- perm: options.permission || 'all',
50
- rank: options.priority || 10000,
51
- reg,
52
- type: 'command',
53
- };
54
- }
55
- /**
56
- * - 构建定时任务
57
- * @param name - 任务名称
58
- * @param cron - cron表达式
59
- * @param fn - 执行函数
60
- * @param options - 选项
61
- */
62
- task(name, cron, fn, options) {
63
- if (!name)
64
- throw new Error('[task]: 缺少参数[name]');
65
- if (!cron)
66
- throw new Error('[task]: 缺少参数[cron]');
67
- if (!fn)
68
- throw new Error('[task]: 缺少参数[fnc]');
69
- const log = options?.log === false ? (text) => logger.debug(text) : (text) => logger.info(text);
70
- return {
71
- cron,
72
- fn,
73
- log,
74
- name: options?.name || 'task',
75
- fnname: name,
76
- type: 'task',
77
- };
78
- }
79
- /**
80
- * - 构建handler
81
- * @param key - 事件key
82
- * @param fn - 函数实现
83
- * @param options - 选项
84
- */
85
- handler(key, fn, options) {
86
- if (!key)
87
- throw new Error('[handler]: 缺少参数[key]');
88
- if (!fn)
89
- throw new Error('[handler]: 缺少参数[fnc]');
90
- return {
91
- fn,
92
- key,
93
- name: options?.name || 'handler',
94
- rank: options?.priority || 10000,
95
- type: 'handler',
96
- };
97
- }
98
- /**
99
- * 构建contact
100
- * @param scene - 场景
101
- * @param peer - 群号或者用户id
102
- * @param sub_peer - 子id
103
- */
104
- contact(scene, peer, sub_peer) {
105
- return { scene, peer, sub_peer };
106
- }
107
- /**
108
- * 构建group_contact
109
- * @param peer - 群号
110
- */
111
- contactGroup(peer) {
112
- return { scene: "group" /* Scene.Group */, peer };
113
- }
114
- /**
115
- * 构建friend_contact
116
- * @param peer - 用户id
117
- */
118
- contactFriend(peer) {
119
- return { scene: "friend" /* Scene.Private */, peer };
120
- }
121
- /**
122
- * 构建guild_contact
123
- * @param peer - 频道id
124
- * @param sub_peer - 子频道id
125
- */
126
- contactGuild(peer, sub_peer) {
127
- return { scene: "guild" /* Scene.Guild */, peer, sub_peer };
128
- }
129
- /**
130
- * - 渲染
131
- * @param data - 渲染参数
132
- * @param multiPage - 分片高度
133
- * @returns - 返回图片base64或数组
134
- */
135
- render(data, multiPage) {
136
- if (typeof data === 'string') {
137
- /** 分片 */
138
- if (typeof multiPage === 'number' || multiPage === true)
139
- return render.renderMultiHtml(data, multiPage);
140
- /** 快速渲染 */
141
- return render.renderHtml(data);
142
- }
143
- /** 正常渲染 */
144
- return render.render(data);
145
- }
146
- /**
147
- * 上下文
148
- * @param e - 消息事件
149
- * @param options - 上下文选项
150
- */
151
- async ctx(e, options) {
152
- const time = options?.time || 120;
153
- const userId = options?.userId || e.user_id;
154
- const key = e.group_id ? `${e.group_id}.${userId}` : userId;
155
- stateArr[key] = { type: 'ctx' };
156
- return new Promise((resolve, reject) => {
157
- setTimeout(() => {
158
- if (stateArr[key]) {
159
- delete stateArr[key];
160
- if (options?.reply)
161
- e.reply(options.replyMsg || '操作超时已取消');
162
- reject(new Error('操作超时已取消'));
163
- return true;
164
- }
165
- }, time * 1000);
166
- this.once(`ctx:${key}`, (e) => resolve(e));
167
- });
168
- }
169
- /**
170
- * accept
171
- * @param event - 监听事件
172
- * @param fn - 实现函数
173
- */
174
- accept(event, fn, options) {
175
- const log = options?.log === false
176
- ? (id, text) => logger.bot('debug', id, text)
177
- : (id, text) => logger.bot('info', id, text);
178
- return {
179
- event,
180
- fn,
181
- log,
182
- name: options?.name || 'accept',
183
- rank: options?.priority || 10000,
184
- type: 'accept',
185
- };
186
- }
187
- /**
188
- * 中间件
189
- * @param type 中间件类型
190
- * @param fn 中间件函数
191
- */
192
- use(type, fn, options) {
193
- return {
194
- fn,
195
- key: type,
196
- name: options?.name || 'use',
197
- rank: options?.priority || 10000,
198
- type: 'use',
199
- };
200
- }
201
- /**
202
- * - 启动
203
- */
204
- async run() {
205
- if (this.#start)
206
- return;
207
- this.#start = true;
208
- const { server } = await import('../server/server.js');
209
- server.init();
210
- pluginLoader.load();
211
- this.emit('adapter', RenderServer);
212
- this.emit('adapter', onebot11);
213
- }
214
- }
215
- export const karin = new Karin();
216
- /**
217
- * 即将废弃 请使用karin
218
- * @deprecated
219
- */
220
- export const listener = karin;
221
- /**
222
- * 即将废弃 请使用karin
223
- * @deprecated
224
- */
225
- export const Bot = karin;
226
- export default karin;