onebots 0.4.16 → 0.4.18
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/README.md +1 -1
- package/lib/service/V11/index.d.ts +1 -0
- package/lib/service/V11/index.js +60 -3
- package/package.json +2 -1
package/README.md
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
<h1>基于icqq的oneBot实现</h1>
|
|
3
3
|
<p>
|
|
4
4
|
|
|
5
|
-

|
|
5
|
+
[](https://www.npmjs.com/package/onebots)
|
|
6
6
|
[](https://github.com/icqqjs/onebots/actions/workflows/release.yml)
|
|
7
7
|
[](https://www.npmjs.com/package/onebots)
|
|
8
8
|
[](https://onebot.dev/)
|
package/lib/service/V11/index.js
CHANGED
|
@@ -224,7 +224,63 @@ class V11 extends events_1.EventEmitter {
|
|
|
224
224
|
// if (!['user_id', 'group_id', 'discuss_id', 'member_id', 'channel_id', 'guild_id'].includes(key)) return value
|
|
225
225
|
// return value + ''
|
|
226
226
|
// })
|
|
227
|
-
this.emit('dispatch',
|
|
227
|
+
this.emit('dispatch', this._formatEvent(data));
|
|
228
|
+
}
|
|
229
|
+
_formatEvent(data) {
|
|
230
|
+
if (data.post_type === 'notice') {
|
|
231
|
+
// console.log(JSON.stringify(data))
|
|
232
|
+
const data1 = { ...data };
|
|
233
|
+
if (data.notice_type === 'group') {
|
|
234
|
+
delete data1.group;
|
|
235
|
+
delete data1.member;
|
|
236
|
+
switch (data.sub_type) {
|
|
237
|
+
case 'decrease':
|
|
238
|
+
data1.sub_type = data.operator_id === data.user_id ? 'leave' : data.user_id === this.client.uin ? 'kick_me' : 'kick';
|
|
239
|
+
data1.notice_type = `${data.notice_type}_${data.sub_type}`;
|
|
240
|
+
break;
|
|
241
|
+
case 'increase':
|
|
242
|
+
data1.notice_type = `${data.notice_type}_${data.sub_type}`;
|
|
243
|
+
data1.sub_type = 'approve'; // todo 尚未实现
|
|
244
|
+
data1.operator_id = data1.user_id; // todo 尚未实现
|
|
245
|
+
break;
|
|
246
|
+
case 'ban':
|
|
247
|
+
data1.notice_type = `${data.notice_type}_${data.sub_type}`;
|
|
248
|
+
data1.subtype = data.duration ? 'ban' : 'lift_ban';
|
|
249
|
+
break;
|
|
250
|
+
case 'recall':
|
|
251
|
+
data1.notice_type = `${data.notice_type}_${data.sub_type}`;
|
|
252
|
+
delete data1.sub_type;
|
|
253
|
+
break;
|
|
254
|
+
case 'admin':
|
|
255
|
+
data1.notice_type = `${data.notice_type}_${data.sub_type}`;
|
|
256
|
+
data1.sub_type = data.set ? 'set' : 'unset';
|
|
257
|
+
break;
|
|
258
|
+
case 'poke':
|
|
259
|
+
data1.notice_type = 'notify';
|
|
260
|
+
data1.user_id = data.operator_id;
|
|
261
|
+
break;
|
|
262
|
+
default:
|
|
263
|
+
break;
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
else {
|
|
267
|
+
delete data1.friend;
|
|
268
|
+
switch (data.sub_type) {
|
|
269
|
+
case 'increase':
|
|
270
|
+
data1.notice_type = `friend_add`;
|
|
271
|
+
break;
|
|
272
|
+
case 'recall':
|
|
273
|
+
data1.notice_type = `friend_recall`;
|
|
274
|
+
break;
|
|
275
|
+
default:
|
|
276
|
+
break;
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
return JSON.stringify(data1);
|
|
280
|
+
}
|
|
281
|
+
else {
|
|
282
|
+
return JSON.stringify(data);
|
|
283
|
+
}
|
|
228
284
|
}
|
|
229
285
|
async _httpRequestHandler(ctx) {
|
|
230
286
|
if (ctx.method === 'OPTIONS') {
|
|
@@ -280,10 +336,11 @@ class V11 extends events_1.EventEmitter {
|
|
|
280
336
|
*/
|
|
281
337
|
_webSocketHandler(ws) {
|
|
282
338
|
ws.on("message", async (msg) => {
|
|
283
|
-
|
|
339
|
+
const msgStr = msg.toString();
|
|
340
|
+
this.logger.info(" 收到ws消息:", msgStr.length > 2e3 ? msgStr.slice(0, 2e3) + ` ... ${msgStr.length - 2e3} more chars` : msgStr);
|
|
284
341
|
var data;
|
|
285
342
|
try {
|
|
286
|
-
data = JSON.parse(
|
|
343
|
+
data = JSON.parse(msgStr);
|
|
287
344
|
let ret;
|
|
288
345
|
if (data.action.startsWith(".handle_quick_operation")) {
|
|
289
346
|
const event = data.params.context, res = data.params.operation;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "onebots",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.18",
|
|
4
4
|
"description": "基于icqq的多例oneBot实现",
|
|
5
5
|
"engines": {
|
|
6
6
|
"node": ">=16"
|
|
@@ -63,6 +63,7 @@
|
|
|
63
63
|
"koa": "^2.13.4",
|
|
64
64
|
"koa-bodyparser": "^4.3.0",
|
|
65
65
|
"log4js": "^6.5.2",
|
|
66
|
+
"mime-types": "^2.1.35",
|
|
66
67
|
"ws": "^8.8.0"
|
|
67
68
|
}
|
|
68
69
|
}
|