onebots 0.4.16 → 0.4.17
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/onebot.js +1 -1
- package/lib/server/app.js +6 -6
- package/lib/server/router.d.ts +1 -1
- package/lib/service/V11/index.d.ts +1 -0
- package/lib/service/V11/index.js +58 -2
- package/lib/service/V12/index.js +1 -1
- package/package.json +1 -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/onebot.js
CHANGED
|
@@ -202,5 +202,5 @@ var OneBotStatus;
|
|
|
202
202
|
(function (OneBotStatus) {
|
|
203
203
|
OneBotStatus[OneBotStatus["Good"] = 0] = "Good";
|
|
204
204
|
OneBotStatus[OneBotStatus["Bad"] = 1] = "Bad";
|
|
205
|
-
})(OneBotStatus
|
|
205
|
+
})(OneBotStatus = exports.OneBotStatus || (exports.OneBotStatus = {}));
|
|
206
206
|
exports.BOOLS = ["no_cache", "auto_escape", "as_long", "enable", "reject_add_request", "is_dismiss", "approve", "block"];
|
package/lib/server/app.js
CHANGED
|
@@ -47,7 +47,7 @@ class App extends koa_1.default {
|
|
|
47
47
|
constructor(config = {}) {
|
|
48
48
|
super(config);
|
|
49
49
|
this.oneBots = [];
|
|
50
|
-
this.config = (0, utils_1.deepMerge)((0, utils_1.deepClone)(
|
|
50
|
+
this.config = (0, utils_1.deepMerge)((0, utils_1.deepClone)(App.defaultConfig), config);
|
|
51
51
|
this.logger = (0, log4js_1.getLogger)('[icqq-OneBot]');
|
|
52
52
|
this.logger.level = this.config.log_level;
|
|
53
53
|
this.router = new router_1.Router({ prefix: config.path });
|
|
@@ -86,7 +86,7 @@ class App extends koa_1.default {
|
|
|
86
86
|
this.config[uin] = config;
|
|
87
87
|
const oneBot = this.createOneBot(uin, config);
|
|
88
88
|
oneBot.startListen();
|
|
89
|
-
(0, fs_1.writeFileSync)(
|
|
89
|
+
(0, fs_1.writeFileSync)(App.configPath, js_yaml_1.default.dump((0, utils_1.deepClone)(this.config)));
|
|
90
90
|
}
|
|
91
91
|
updateAccount(uin, config) {
|
|
92
92
|
if (typeof uin !== "number")
|
|
@@ -112,7 +112,7 @@ class App extends koa_1.default {
|
|
|
112
112
|
oneBot.stop(force);
|
|
113
113
|
delete this.config[uin];
|
|
114
114
|
this.oneBots.splice(currentIdx, 1);
|
|
115
|
-
(0, fs_1.writeFileSync)(
|
|
115
|
+
(0, fs_1.writeFileSync)(App.configPath, js_yaml_1.default.dump(this.config));
|
|
116
116
|
}
|
|
117
117
|
createOneBot(uin, config) {
|
|
118
118
|
const oneBot = new onebot_1.OneBot(this, uin, config);
|
|
@@ -132,11 +132,11 @@ class App extends koa_1.default {
|
|
|
132
132
|
});
|
|
133
133
|
this.router.get('/qrcode', (ctx) => {
|
|
134
134
|
const { uin } = ctx.query;
|
|
135
|
-
const uinUrl = path.join(
|
|
135
|
+
const uinUrl = path.join(App.configDir, 'data', uin);
|
|
136
136
|
if (!(0, fs_1.existsSync)(uinUrl)) {
|
|
137
137
|
return ctx.res.writeHead(400).end('未登录');
|
|
138
138
|
}
|
|
139
|
-
const qrcodePath = path.join(
|
|
139
|
+
const qrcodePath = path.join(App.configDir, 'data', uin, 'qrcode.png');
|
|
140
140
|
let file = null;
|
|
141
141
|
try {
|
|
142
142
|
file = (0, fs_2.readFileSync)(qrcodePath); //读取文件
|
|
@@ -243,4 +243,4 @@ exports.defineConfig = defineConfig;
|
|
|
243
243
|
},
|
|
244
244
|
log_level: 'info',
|
|
245
245
|
};
|
|
246
|
-
})(App
|
|
246
|
+
})(App = exports.App || (exports.App = {}));
|
package/lib/server/router.d.ts
CHANGED
|
@@ -5,5 +5,5 @@ import { WebSocketServer } from "ws";
|
|
|
5
5
|
import http from "http";
|
|
6
6
|
export declare class Router extends KoaRouter {
|
|
7
7
|
wsStack: WebSocketServer[];
|
|
8
|
-
ws(path: string, server: http.Server): import("ws").Server<
|
|
8
|
+
ws(path: string, server: http.Server): import("ws").Server<import("ws").WebSocket>;
|
|
9
9
|
}
|
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') {
|
|
@@ -549,4 +605,4 @@ exports.V11 = V11;
|
|
|
549
605
|
};
|
|
550
606
|
}
|
|
551
607
|
V11.genMetaEvent = genMetaEvent;
|
|
552
|
-
})(V11
|
|
608
|
+
})(V11 = exports.V11 || (exports.V11 = {}));
|
package/lib/service/V12/index.js
CHANGED