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,307 +0,0 @@
1
- import lodash from 'lodash';
2
- import { review } from './review.js';
3
- import { EventBaseHandler } from './base.js';
4
- import { logger, config } from '../../utils/index.js';
5
- import { karin, stateArr, pluginLoader } from '../../core/index.js';
6
- /**
7
- * 消息事件
8
- */
9
- export class MessageHandler extends EventBaseHandler {
10
- e;
11
- constructor(e) {
12
- super(e);
13
- this.e = e;
14
- this.init();
15
- if (this.e.group_id) {
16
- if (!this.getCd())
17
- return;
18
- if (!this.getMode())
19
- return;
20
- if (!this.getGroupEnable())
21
- return;
22
- if (!this.getUserEnable())
23
- return;
24
- }
25
- else {
26
- if (!this.private())
27
- return;
28
- }
29
- /** 处理消息 */
30
- this.deal();
31
- }
32
- /**
33
- * 先对消息事件进行初始化
34
- */
35
- init() {
36
- karin.emit('karin:count:recv', 1);
37
- const logs = [];
38
- for (const val of this.e.elements) {
39
- switch (val.type) {
40
- case 'text': {
41
- const msg = (val.text || '').replace(/^\s*[#井#]+\s*/, '#').trim();
42
- this.e.msg += msg;
43
- logs.push(msg);
44
- break;
45
- }
46
- case 'face':
47
- logs.push(`[face:${val.id}]`);
48
- break;
49
- case 'video':
50
- logs.push(`[video:${val.file}]`);
51
- break;
52
- case 'record':
53
- this.e.record = val.file;
54
- logs.push(`[record:${val.file}]`);
55
- break;
56
- case 'image':
57
- this.e.image.push(val.file);
58
- logs.push(`[image:${val.file}]`);
59
- break;
60
- case 'file':
61
- this.e.file = val;
62
- logs.push(`[file:${val.file}]`);
63
- break;
64
- case 'at':
65
- /** atBot不计入e.at */
66
- if (val.uid && val.uid === this.e.bot.account.uid) {
67
- this.e.atBot = true;
68
- }
69
- else if (val.uin === this.e.bot.account.uin) {
70
- this.e.atBot = true;
71
- }
72
- else if (val.uid && val.uid === 'all') {
73
- this.e.atAll = true;
74
- }
75
- else {
76
- const id = (val.uid || val.uin);
77
- this.e.at.push(id);
78
- }
79
- logs.push(`[at:${val.uid || val.uin}]`);
80
- break;
81
- case 'rps':
82
- logs.push(`[rps:${val.id}]`);
83
- break;
84
- case 'dice':
85
- logs.push(`[dice:${val.id}]`);
86
- break;
87
- case 'poke':
88
- logs.push(`[poke:${val.id}]`);
89
- break;
90
- case 'share':
91
- logs.push(`[share:${val.url}]`);
92
- break;
93
- case 'contact':
94
- logs.push(`[contact:${val.peer}]`);
95
- break;
96
- case 'location':
97
- logs.push(`[location:${val.lat}-${val.lon}]`);
98
- break;
99
- case 'music':
100
- logs.push(`[music:${JSON.stringify(val)}]`);
101
- break;
102
- case 'reply':
103
- this.e.reply_id = val.message_id;
104
- logs.push(`[reply:${val.message_id}]`);
105
- break;
106
- case 'forward':
107
- logs.push(`[forward:${val.res_id}]`);
108
- break;
109
- case 'xml':
110
- this.e.msg += val.data;
111
- logs.push(`[xml:${val.data}]`);
112
- break;
113
- case 'json':
114
- this.e.msg += val.data;
115
- logs.push(`[json:${JSON.stringify(val.data)}]`);
116
- break;
117
- case 'markdown': {
118
- logs.push(`[markdown:${val.content}]`);
119
- break;
120
- }
121
- case 'markdown_tpl': {
122
- const params = val.params;
123
- if (!params)
124
- break;
125
- const content = { id: val.custom_template_id };
126
- for (const v of params)
127
- content[v.key] = v.values[0];
128
- logs.push(`[markdown_tpl:${JSON.stringify(content)}]`);
129
- break;
130
- }
131
- case 'keyboard': {
132
- logs.push(`[rows:${JSON.stringify(val.rows)}]`);
133
- break;
134
- }
135
- case 'button':
136
- logs.push(`[button:${JSON.stringify(val.data)}]`);
137
- break;
138
- case 'long_msg':
139
- logs.push(`[long_msg:${val.id}]`);
140
- break;
141
- default:
142
- logs.push(`[未知:${JSON.stringify(val)}]`);
143
- }
144
- }
145
- this.e.raw_message = logs.join('');
146
- /** 主人 */
147
- if (config.master.includes(String(this.e.user_id))) {
148
- this.e.isMaster = true;
149
- this.e.isAdmin = true;
150
- }
151
- else if (config.admin.includes(String(this.e.user_id))) {
152
- /** 管理员 */
153
- this.e.isAdmin = true;
154
- }
155
- if (this.e.contact.scene === 'friend') {
156
- this.e.isPrivate = true;
157
- this.e.logText = `[Private:${this.e.sender.nick || ''}(${this.e.user_id})]`;
158
- logger.bot('info', this.e.self_id, `私聊:[${this.e.user_id}(${this.e.sender.nick || ''})] ${this.e.raw_message}`);
159
- }
160
- else if (this.e.contact.scene === 'group') {
161
- this.e.isGroup = true;
162
- this.e.logText = `[Group:${this.e.group_id}-${this.e.user_id}(${this.e.sender.nick || ''})]`;
163
- this.GroupMsgPrint = review.GroupMsgPrint(this.e);
164
- /** 前缀处理 */
165
- this.e.group_id && review.alias(this.e, this.config);
166
- this.GroupMsgPrint && logger.bot('info', this.e.self_id, `群消息:[${this.e.group_id}-${this.e.user_id}(${this.e.sender.nick || ''})] ${this.e.raw_message}`);
167
- }
168
- else if (this.e.contact.scene === 'guild') {
169
- this.e.isGuild = true;
170
- this.e.logText = `[Guild:${this.e.contact.peer}-${this.e.contact.sub_peer}-${this.e.user_id}(${this.e.sender.nick || ''})]`;
171
- logger.bot('info', this.e.self_id, `频道消息:[${this.e.contact.peer}-${this.e.contact.sub_peer}-${this.e.user_id}(${this.e.sender.nick || ''})] ${this.e.raw_message}`);
172
- }
173
- else {
174
- logger.bot('info', this.e.self_id, `未知消息:${JSON.stringify(this.e)}`);
175
- }
176
- logs.length = 0;
177
- this.reply();
178
- karin.emit('message', this.e);
179
- }
180
- /**
181
- * 响应模式检查 返回false表示未通过
182
- */
183
- getMode() {
184
- if (review.mode(this.e, this.config))
185
- return true;
186
- logger.debug(`[消息拦截][${this.e.group_id}][${this.e.user_id}] 响应模式不匹配`);
187
- return false;
188
- }
189
- /**
190
- * 打印
191
- */
192
- print() {
193
- }
194
- /**
195
- * 处理消息
196
- */
197
- async deal() {
198
- /** 先调用中间件 */
199
- for (const info of pluginLoader.use.recvMsg) {
200
- try {
201
- let next = false;
202
- let exit = false;
203
- const nextFn = () => { next = true; };
204
- const exitFn = () => { exit = true; };
205
- await info.fn(this.e, nextFn, exitFn);
206
- if (exit) {
207
- const plugin = pluginLoader.plugin.get(info.key);
208
- logger.debug(`[消息中间件][${plugin.plugin}][${plugin.file}] 主动操作退出`);
209
- return;
210
- }
211
- if (!next)
212
- break;
213
- }
214
- catch (e) {
215
- logger.error('[消息中间件] 调用失败,已跳过');
216
- logger.error(e);
217
- }
218
- }
219
- /** 上下文 */
220
- if (await this.context())
221
- return;
222
- const app = this.e.group_id
223
- ? (info) => review.PluginEnable(info, this.config)
224
- : () => true;
225
- for (const info of pluginLoader.command) {
226
- /** 判断事件 */
227
- if (!this.filtEvent(info.event))
228
- continue;
229
- const reg = info.reg;
230
- if (reg.test(this.e.msg)) {
231
- /** 检查黑白名单插件 */
232
- if (!app(info))
233
- continue;
234
- /** 判断子事件 */
235
- if (!this.filtEvent(info.event))
236
- continue;
237
- this.e.logFnc = `[${info.name}][${info.fnname}]`;
238
- const logFnc = logger.fnc(this.e.logFnc);
239
- this.GroupMsgPrint && info.log(this.e.self_id, `${logFnc}${this.e.logText} ${lodash.truncate(this.e.msg, { length: 80 })}`);
240
- /** 判断权限 */
241
- if (!this.filterPermission(info.perm))
242
- continue;
243
- /** 计算插件处理时间 */
244
- const start = Date.now();
245
- karin.emit('karin:count:fnc', this.e.logFnc);
246
- try {
247
- let res;
248
- if (info.type === 'function') {
249
- res = await info.fn(this.e);
250
- }
251
- else {
252
- const Fnc = info.data;
253
- const app = new Fnc();
254
- app.e = this.e;
255
- res = await info.fn.call(app, this.e);
256
- }
257
- this.GroupMsgPrint && info.log(this.e.self_id, `${logFnc} ${lodash.truncate(this.e.msg, { length: 80 })} 处理完成 ${logger.green(Date.now() - start + 'ms')}`);
258
- if (res === false)
259
- continue;
260
- return;
261
- }
262
- catch (error) {
263
- logger.error(`${this.e.logFnc}`);
264
- logger.error(error.stack || error.message || JSON.stringify(error));
265
- return;
266
- }
267
- }
268
- }
269
- }
270
- /**
271
- * 处理上下文
272
- */
273
- async context() {
274
- const key = this.e.isGroup ? `${this.e.group_id}.${this.e.user_id}` : this.e.user_id;
275
- const App = stateArr[key];
276
- if (App) {
277
- switch (App.type) {
278
- case 'ctx': {
279
- karin.emit(`ctx:${key}`, this.e);
280
- delete stateArr[key];
281
- return true;
282
- }
283
- case 'class': {
284
- const { fnc, name } = App;
285
- this.e.logFnc = `[${fnc.name}][${name}]`;
286
- /** 计算插件处理时间 */
287
- const start = Date.now();
288
- fnc.e = this.e;
289
- await fnc[name]();
290
- logger.bot('mark', this.e.self_id, `${this.e.logFnc} 上下文处理完成 ${Date.now() - start}ms`);
291
- return true;
292
- }
293
- case 'fnc': {
294
- const { fnc } = App;
295
- this.e.logFnc = `[${fnc.name}]`;
296
- /** 计算插件处理时间 */
297
- const start = Date.now();
298
- await fnc(this.e);
299
- logger.bot('mark', this.e.self_id, `${this.e.logFnc} 上下文处理完成 ${Date.now() - start}ms`);
300
- delete stateArr[key];
301
- return true;
302
- }
303
- }
304
- }
305
- return false;
306
- }
307
- }
@@ -1,18 +0,0 @@
1
- import { EventBaseHandler } from './base.js';
2
- import { KarinNoticeType } from '../../types/index.js';
3
- /**
4
- * 通知事件
5
- */
6
- export declare class NoticeHandler extends EventBaseHandler {
7
- e: KarinNoticeType;
8
- constructor(e: KarinNoticeType);
9
- init(): void;
10
- /**
11
- * 处理事件
12
- */
13
- deal(): Promise<void>;
14
- /**
15
- * 构建原始消息
16
- */
17
- raw_message(): void;
18
- }
@@ -1,214 +0,0 @@
1
- import { review } from './review.js';
2
- import { EventBaseHandler } from './base.js';
3
- import { logger, config } from '../../utils/index.js';
4
- import { karin, pluginLoader } from '../../core/index.js';
5
- /**
6
- * 通知事件
7
- */
8
- export class NoticeHandler extends EventBaseHandler {
9
- e;
10
- constructor(e) {
11
- super(e);
12
- this.e = e;
13
- this.init();
14
- if (this.e.group_id) {
15
- if (!this.getCd())
16
- return;
17
- if (!this.getGroupEnable())
18
- return;
19
- if (!this.getUserEnable())
20
- return;
21
- }
22
- else {
23
- if (!this.private())
24
- return;
25
- }
26
- /** 处理消息 */
27
- this.deal();
28
- }
29
- init() {
30
- this.raw_message();
31
- /** 主人 */
32
- if (config.master.includes(String(this.e.user_id))) {
33
- this.e.isMaster = true;
34
- this.e.isAdmin = true;
35
- }
36
- else if (config.admin.includes(String(this.e.user_id))) {
37
- /** 管理员 */
38
- this.e.isAdmin = true;
39
- }
40
- if (this.e.contact.scene === 'friend') {
41
- this.e.isPrivate = true;
42
- this.e.logText = `[Private:${this.e.sender.nick || ''}(${this.e.user_id})]`;
43
- logger.bot('info', this.e.self_id, `${logger.green('私聊通知: ')}[${this.e.user_id}(${this.e.sender.nick || ''})] ${this.e.raw_message}`);
44
- }
45
- else if (this.e.contact.scene === 'group') {
46
- this.e.isGroup = true;
47
- this.e.logText = `[Group:${this.e.group_id}-${this.e.user_id}(${this.e.sender.nick || ''})]`;
48
- this.GroupMsgPrint = review.GroupMsgPrint(this.e);
49
- this.GroupMsgPrint && logger.bot('info', this.e.self_id, `${logger.green('群通知: ')}[${this.e.group_id}-${this.e.user_id}(${this.e.sender.nick || ''})] ${this.e.raw_message}`);
50
- }
51
- else if (this.e.contact.scene === 'guild') {
52
- this.e.isGuild = true;
53
- this.e.logText = `[Guild:${this.e.contact.peer}-${this.e.contact.sub_peer}-${this.e.user_id}(${this.e.sender.nick || ''})]`;
54
- logger.bot('info', this.e.self_id, `${logger.green('频道通知: ')}[${this.e.contact.peer}-${this.e.contact.sub_peer}-${this.e.user_id}(${this.e.sender.nick || ''})] ${this.e.raw_message}`);
55
- }
56
- else {
57
- logger.bot('info', this.e.self_id, `未知来源通知事件:${JSON.stringify(this.e)}`);
58
- }
59
- this.reply();
60
- karin.emit('notice', this.e);
61
- }
62
- /**
63
- * 处理事件
64
- */
65
- async deal() {
66
- for (const info of pluginLoader.accept) {
67
- /** 判断事件 */
68
- if (!this.filtEvent(info.event))
69
- continue;
70
- /** 检查黑白名单插件 */
71
- if (!review.PluginEnable(info, this.config))
72
- continue;
73
- /** 日志方法字符串 */
74
- this.e.logFnc = `[${info.name}][accept]`;
75
- const logFnc = logger.fnc(this.e.logFnc + `[${this.e.event}.${this.e.sub_event}]`);
76
- this.GroupMsgPrint && info.log(this.e.self_id, `${logFnc + this.e.logText} 开始处理`);
77
- /** 计算插件处理时间 */
78
- const start = Date.now();
79
- try {
80
- const res = await info.fn(this.e);
81
- this.GroupMsgPrint && info.log(this.e.self_id, `${logFnc} 处理完成 ${logger.green(Date.now() - start + 'ms')}`);
82
- if (res !== false)
83
- break;
84
- }
85
- catch (error) {
86
- logger.error(`${logFnc}`);
87
- logger.error(error.stack || error.message || JSON.stringify(error));
88
- break;
89
- }
90
- }
91
- }
92
- /**
93
- * 构建原始消息
94
- */
95
- raw_message() {
96
- switch (this.e.sub_event) {
97
- /** 好友头像戳一戳 */
98
- case "private_poke" /* NoticeSubType.PrivatePoke */: {
99
- this.e.raw_message = '[好友戳一戳]: 戳了你一下';
100
- break;
101
- }
102
- /** 好友消息撤回 */
103
- case "private_recall" /* NoticeSubType.PrivateRecall */: {
104
- this.e.raw_message = `[好友消息撤回]: ${this.e.content.message_id}`;
105
- break;
106
- }
107
- /** 私聊文件上传 */
108
- case "private_file_uploaded" /* NoticeSubType.PrivateFileUploaded */: {
109
- const content = this.e.content;
110
- const { file_url } = content;
111
- this.e.raw_message = `[私聊文件上传]: ${file_url}`;
112
- break;
113
- }
114
- /** 群头像戳一戳 */
115
- case "group_poke" /* NoticeSubType.GroupPoke */: {
116
- const { operator_uid, operator_uin, target_uid, target_uin } = this.e.content;
117
- this.e.raw_message = `[群戳一戳]: ${operator_uid || operator_uin} 戳了戳 ${target_uid || target_uin}`;
118
- break;
119
- }
120
- /** 群消息撤回 */
121
- case "group_recall" /* NoticeSubType.GroupRecall */: {
122
- const { operator_uid, operator_uin, message_id } = this.e.content;
123
- this.e.raw_message = `[群消息撤回]: ${operator_uid || operator_uin} 撤回了一条消息 ${message_id}`;
124
- break;
125
- }
126
- /** 群文件上传 */
127
- case "group_file_uploaded" /* NoticeSubType.GroupFileUploaded */: {
128
- const { file_url, operator_uid, operator_uin } = this.e.content;
129
- this.e.raw_message = `[群文件上传]: ${operator_uid || operator_uin} 上传了 ${file_url}`;
130
- break;
131
- }
132
- /** 群成员增加 */
133
- case "group_member_increase" /* NoticeSubType.GroupMemberIncrease */: {
134
- const { operator_uid, operator_uin, target_uid, target_uin, type } = this.e.content;
135
- this.e.raw_message = `[群成员新增]: ${operator_uid || operator_uin} ${type === 'invite' ? '邀请' : '同意'} ${target_uid || target_uin} 加入群聊`;
136
- break;
137
- }
138
- /** 群成员减少 */
139
- case "group_member_decrease" /* NoticeSubType.GroupMemberDecrease */: {
140
- switch (this.e.content.type) {
141
- case 'leave': {
142
- const { target_uid, target_uin } = this.e.content;
143
- this.e.raw_message = `[群成员减少]: ${target_uid || target_uin} 主动退出群聊`;
144
- break;
145
- }
146
- // 群成员被踢
147
- case 'kick': {
148
- const { operator_uid, operator_uin, target_uid, target_uin } = this.e.content;
149
- this.e.raw_message = `[群成员减少]: ${operator_uid || operator_uin} 将 ${target_uid || target_uin} 踢出群聊`;
150
- break;
151
- }
152
- // bot被踢
153
- case 'kick_me': {
154
- const { operator_uid, operator_uin } = this.e.content;
155
- this.e.raw_message = `[群成员减少]: 机器人被移除群聊,操作人:${operator_uid || operator_uin}`;
156
- break;
157
- }
158
- }
159
- break;
160
- }
161
- /** 群管理员变动 */
162
- case "group_admin_changed" /* NoticeSubType.GroupAdminChanged */: {
163
- const { target_uid, target_uin, is_admin } = this.e.content;
164
- this.e.raw_message = `[群管理员变动]: ${target_uid || target_uin} 被${is_admin ? '设置' : '取消'}群管理员`;
165
- break;
166
- }
167
- /** 群成员被禁言 */
168
- case "group_member_ban" /* NoticeSubType.GroupMemberBan */: {
169
- const { operator_uid, operator_uin, target_uid, target_uin, type } = this.e.content;
170
- this.e.raw_message = `[群成员禁言]: ${operator_uid || operator_uin} ${type === 'ban' ? '禁言' : '解禁'}了 ${target_uid || target_uin}`;
171
- break;
172
- }
173
- /** 群签到 */
174
- case "group_sign_in" /* NoticeSubType.GroupSignIn */: {
175
- const { target_uid, target_uin } = this.e.content;
176
- this.e.raw_message = `[群签到]: ${target_uid || target_uin}`;
177
- break;
178
- }
179
- /** 群全员禁言 */
180
- case "group_whole_ban" /* NoticeSubType.GroupWholeBan */: {
181
- const { operator_uid, operator_uin, is_ban } = this.e.content;
182
- this.e.raw_message = `[群全员禁言]: ${operator_uid || operator_uin} ${is_ban ? '开启全员禁言' : '解除全员禁言'}`;
183
- break;
184
- }
185
- /** 群名片改变 */
186
- case "group_card_changed" /* NoticeSubType.GroupCardChanged */: {
187
- const { operator_uid, operator_uin, target_uid, target_uin, new_card } = this.e.content;
188
- this.e.raw_message = `[群名片改变]: ${operator_uid || operator_uin} 修改了 ${target_uid || target_uin} 的名片为 ${new_card}`;
189
- break;
190
- }
191
- /** 群成员专属头衔改变 */
192
- case "group_member_unique_title_changed" /* NoticeSubType.GroupMemberUniqueTitleChanged */: {
193
- const { target_uid, target_uin, title } = this.e.content;
194
- this.e.raw_message = `[群头衔更改]: ${target_uid || target_uin} 的专属头衔改变为 ${title}`;
195
- break;
196
- }
197
- /** 群精华消息改变 */
198
- case "group_essence_changed" /* NoticeSubType.GroupEssenceChanged */: {
199
- const { operator_uid, operator_uin, target_uid, target_uin, message_id, is_set } = this.e.content;
200
- this.e.raw_message = `[群精华消息]: ${operator_uid || operator_uin} ${is_set ? `将${target_uid || target_uin}的消息${message_id}设置为精华消息` : `取消了${target_uid || target_uin}精华消息 ${message_id}`}`;
201
- break;
202
- }
203
- /** 群表情回应 */
204
- case "group_message_reaction" /* NoticeSubType.GroupMessageReaction */: {
205
- const { message_id, face_id } = this.e.content;
206
- this.e.raw_message = `[群表情回应]: ${this.e.user_id} 给消息 ${message_id} 回应了一个${face_id}的表情`;
207
- break;
208
- }
209
- default: {
210
- this.e.raw_message = `[未知事件]: ${JSON.stringify(this.e)}`;
211
- }
212
- }
213
- }
214
- }
@@ -1,18 +0,0 @@
1
- import { EventBaseHandler } from './base.js';
2
- import { KarinRequestType } from '../../types/index.js';
3
- /**
4
- * 请求事件
5
- */
6
- export declare class RequestHandler extends EventBaseHandler {
7
- e: KarinRequestType;
8
- constructor(e: KarinRequestType);
9
- init(): void;
10
- /**
11
- * 处理事件
12
- */
13
- deal(): Promise<void>;
14
- /**
15
- * 构建原始消息
16
- */
17
- raw_message(): void;
18
- }
@@ -1,115 +0,0 @@
1
- import { review } from './review.js';
2
- import { EventBaseHandler } from './base.js';
3
- import { karin, pluginLoader } from '../../core/index.js';
4
- import { logger, config } from '../../utils/index.js';
5
- /**
6
- * 请求事件
7
- */
8
- export class RequestHandler extends EventBaseHandler {
9
- e;
10
- constructor(e) {
11
- super(e);
12
- this.e = e;
13
- this.init();
14
- if (this.e.group_id) {
15
- if (!this.getCd())
16
- return;
17
- if (!this.getGroupEnable())
18
- return;
19
- if (!this.getUserEnable())
20
- return;
21
- }
22
- else {
23
- if (!this.private())
24
- return;
25
- }
26
- /** 处理消息 */
27
- this.deal();
28
- }
29
- init() {
30
- this.raw_message();
31
- /** 主人 */
32
- if (config.master.includes(String(this.e.user_id))) {
33
- this.e.isMaster = true;
34
- this.e.isAdmin = true;
35
- }
36
- else if (config.admin.includes(String(this.e.user_id))) {
37
- /** 管理员 */
38
- this.e.isAdmin = true;
39
- }
40
- if (this.e.contact.scene === 'friend') {
41
- this.e.isPrivate = true;
42
- this.e.logText = `[Private:${this.e.sender.nick || ''}(${this.e.user_id})]`;
43
- logger.bot('info', this.e.self_id, `${logger.green('私聊请求: ')}[${this.e.user_id}(${this.e.sender.nick || ''})] ${this.e.raw_message}`);
44
- }
45
- else if (this.e.contact.scene === 'group') {
46
- this.e.isGroup = true;
47
- this.e.logText = `[Group:${this.e.group_id}-${this.e.user_id}(${this.e.sender.nick || ''})]`;
48
- this.GroupMsgPrint = review.GroupMsgPrint(this.e);
49
- this.GroupMsgPrint && logger.bot('info', this.e.self_id, `${logger.green('群请求: ')}[${this.e.group_id}-${this.e.user_id}(${this.e.sender.nick || ''})] ${this.e.raw_message}`);
50
- }
51
- else {
52
- logger.bot('info', this.e.self_id, `未知来源请求事件:${JSON.stringify(this.e)}`);
53
- }
54
- this.reply();
55
- karin.emit('request', this.e);
56
- }
57
- /**
58
- * 处理事件
59
- */
60
- async deal() {
61
- for (const info of pluginLoader.accept) {
62
- /** 判断事件 */
63
- if (!this.filtEvent(info.event))
64
- continue;
65
- /** 检查黑白名单插件 */
66
- if (!review.PluginEnable(info, this.config))
67
- continue;
68
- /** 日志方法字符串 */
69
- this.e.logFnc = `[${info.name}][accept]`;
70
- const logFnc = logger.fnc(this.e.logFnc + `[${this.e.event}.${this.e.sub_event}]`);
71
- this.GroupMsgPrint && info.log(this.e.self_id, `${logFnc + this.e.logText} 开始处理`);
72
- /** 计算插件处理时间 */
73
- const start = Date.now();
74
- try {
75
- const res = await info.fn(this.e);
76
- this.GroupMsgPrint && info.log(this.e.self_id, `${logFnc} 处理完成 ${logger.green(Date.now() - start + 'ms')}`);
77
- if (res !== false)
78
- break;
79
- }
80
- catch (error) {
81
- logger.error(`${logFnc}`);
82
- logger.error(error.stack || error.message || JSON.stringify(error));
83
- break;
84
- }
85
- }
86
- }
87
- /**
88
- * 构建原始消息
89
- */
90
- raw_message() {
91
- switch (this.e.sub_event) {
92
- /** 好友申请 */
93
- case "private_apply" /* RequestSubType.PrivateApply */: {
94
- const { applier_uid, applier_uin, message } = this.e.content;
95
- this.e.raw_message = `[好友申请]: ${applier_uid || applier_uin} 申请理由: ${message}`;
96
- break;
97
- }
98
- /** 群申请 */
99
- case "group_apply" /* RequestSubType.GroupApply */: {
100
- const { group_id, applier_uid, applier_uin, inviter_uid, inviter_uin, reason } = this.e.content;
101
- this.e.raw_message = `[群申请]: ${group_id} 申请人: ${applier_uid || applier_uin} 邀请人: ${inviter_uid || inviter_uin} 理由: ${reason}`;
102
- break;
103
- }
104
- /** 邀请入群 */
105
- case "invited_group" /* RequestSubType.InvitedGroup */: {
106
- const { group_id, inviter_uid, inviter_uin } = this.e.content;
107
- this.e.raw_message = `[邀请入群]: ${group_id} 邀请人: ${inviter_uid || inviter_uin}`;
108
- break;
109
- }
110
- default: {
111
- this.e.raw_message = `[未知事件]: ${JSON.stringify(this.e)}`;
112
- }
113
- }
114
- }
115
- }