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