@mrlingxd/koishi-plugin-adapter-onebot 0.2.2 → 0.2.3
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/lib/bot/index.js +1 -2
- package/lib/http.js +3 -0
- package/lib/ws.js +4 -3
- package/package.json +1 -1
package/lib/bot/index.js
CHANGED
|
@@ -11,8 +11,7 @@ export class OneBot extends Bot {
|
|
|
11
11
|
internal;
|
|
12
12
|
constructor(ctx, config) {
|
|
13
13
|
super(ctx, config, "onebot");
|
|
14
|
-
this.selfId = config.selfId;
|
|
15
|
-
this.user.avatar = `http://q.qlogo.cn/headimg_dl?dst_uin=${config.selfId}&spec=640`;
|
|
14
|
+
this.selfId = this.userId = config.selfId;
|
|
16
15
|
this.internal = new Internal(this);
|
|
17
16
|
if (config.protocol === "http") {
|
|
18
17
|
ctx.plugin(HttpServer, this);
|
package/lib/http.js
CHANGED
|
@@ -36,6 +36,9 @@ export class HttpServer extends Adapter {
|
|
|
36
36
|
if (signature !== `sha1=${sig}`)
|
|
37
37
|
return (ctx.status = 403);
|
|
38
38
|
}
|
|
39
|
+
const bot = this.bots.find((bot) => bot.selfId === ctx.headers["x-self-id"].toString());
|
|
40
|
+
if (!bot)
|
|
41
|
+
return (ctx.status = 403);
|
|
39
42
|
if (!isBaseEvent(ctx.request.response.body))
|
|
40
43
|
return (ctx.status = 400);
|
|
41
44
|
dispatchSession(bot, ctx.request.response.body);
|
package/lib/ws.js
CHANGED
|
@@ -42,13 +42,14 @@ export class WsServer extends Adapter {
|
|
|
42
42
|
super(ctx);
|
|
43
43
|
this.logger = ctx.logger("onebot");
|
|
44
44
|
const { path = "/onebot" } = bot.config;
|
|
45
|
-
this.wsServer = ctx.server.ws(path, (socket, { headers }) => {
|
|
45
|
+
this.wsServer = ctx.server.ws(path, async (socket, { headers }) => {
|
|
46
46
|
this.logger.debug("connected with", headers);
|
|
47
47
|
if (headers["x-client-role"] !== "Universal") {
|
|
48
48
|
return socket.close(1008, "invalid x-client-role");
|
|
49
49
|
}
|
|
50
|
-
|
|
51
|
-
|
|
50
|
+
const bot = this.bots.find((bot) => bot.selfId === headers["x-self-id"].toString());
|
|
51
|
+
if (!bot)
|
|
52
|
+
return socket.close(1008, "invalid x-self-id");
|
|
52
53
|
bot[kSocket] = socket;
|
|
53
54
|
accept(socket, bot);
|
|
54
55
|
});
|