@alemonjs/qq-bot 2.1.20 → 2.1.22
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/LICENSE +21 -0
- package/dist/assets/index.js +2 -2
- package/dist/index.html +1 -1
- package/lib/register.js +9 -9
- package/lib/sdk/client.webhook.js +12 -3
- package/lib/sdk/client.websoket.js +10 -1
- package/package.json +3 -3
package/dist/index.html
CHANGED
package/lib/register.js
CHANGED
|
@@ -72,7 +72,7 @@ const register = (client) => {
|
|
|
72
72
|
const msg = getMessageContent(event);
|
|
73
73
|
const meta = getGroupMessageMeta(event);
|
|
74
74
|
cbp.send(FormatEvent.create('message.create')
|
|
75
|
-
.addPlatform({ Platform: platform, value: event, BotId: botId })
|
|
75
|
+
.addPlatform({ Platform: platform, value: event, BotId: botId, IsAtMe: false, IsPrivate: false })
|
|
76
76
|
.addGuild({ GuildId: meta.groupId, SpaceId: `GROUP:${meta.groupId}` })
|
|
77
77
|
.addChannel({ ChannelId: meta.groupId })
|
|
78
78
|
.addUser({
|
|
@@ -95,7 +95,7 @@ const register = (client) => {
|
|
|
95
95
|
const msg = getMessageContent(event);
|
|
96
96
|
const meta = getGroupMessageMeta(event);
|
|
97
97
|
cbp.send(FormatEvent.create('message.create')
|
|
98
|
-
.addPlatform({ Platform: platform, value: event, BotId: botId })
|
|
98
|
+
.addPlatform({ Platform: platform, value: event, BotId: botId, IsAtMe: true, IsPrivate: false })
|
|
99
99
|
.addGuild({ GuildId: meta.groupId, SpaceId: `GROUP:${meta.groupId}` })
|
|
100
100
|
.addChannel({ ChannelId: meta.groupId })
|
|
101
101
|
.addUser({
|
|
@@ -116,7 +116,7 @@ const register = (client) => {
|
|
|
116
116
|
const [isMaster, UserKey] = getMaster(UserId);
|
|
117
117
|
const UserAvatar = createUserAvatarURL(event.author.id);
|
|
118
118
|
cbp.send(FormatEvent.create('private.message.create')
|
|
119
|
-
.addPlatform({ Platform: platform, value: event, BotId: botId })
|
|
119
|
+
.addPlatform({ Platform: platform, value: event, BotId: botId, IsAtMe: false, IsPrivate: true })
|
|
120
120
|
.addUser({
|
|
121
121
|
UserId: event.author.id,
|
|
122
122
|
UserKey,
|
|
@@ -139,7 +139,7 @@ const register = (client) => {
|
|
|
139
139
|
const UserId = event.author.id;
|
|
140
140
|
const [isMaster, UserKey] = getMaster(UserId);
|
|
141
141
|
cbp.send(FormatEvent.create('private.message.create')
|
|
142
|
-
.addPlatform({ Platform: platform, value: event, BotId: botId })
|
|
142
|
+
.addPlatform({ Platform: platform, value: event, BotId: botId, IsAtMe: false, IsPrivate: true })
|
|
143
143
|
.addUser({
|
|
144
144
|
UserId: event?.author?.id ?? '',
|
|
145
145
|
UserKey,
|
|
@@ -162,7 +162,7 @@ const register = (client) => {
|
|
|
162
162
|
const UserId = event.author.id;
|
|
163
163
|
const [isMaster, UserKey] = getMaster(UserId);
|
|
164
164
|
cbp.send(FormatEvent.create('message.create')
|
|
165
|
-
.addPlatform({ Platform: platform, value: event, BotId: botId })
|
|
165
|
+
.addPlatform({ Platform: platform, value: event, BotId: botId, IsAtMe: true, IsPrivate: false })
|
|
166
166
|
.addGuild({ GuildId: event.guild_id, SpaceId: `GUILD:${event.channel_id}` })
|
|
167
167
|
.addChannel({ ChannelId: event.channel_id })
|
|
168
168
|
.addUser({
|
|
@@ -205,7 +205,7 @@ const register = (client) => {
|
|
|
205
205
|
const UserAvatar = event?.author?.avatar;
|
|
206
206
|
const [isMaster, UserKey] = getMaster(UserId);
|
|
207
207
|
cbp.send(FormatEvent.create('message.create')
|
|
208
|
-
.addPlatform({ Platform: platform, value: event, BotId: botId })
|
|
208
|
+
.addPlatform({ Platform: platform, value: event, BotId: botId, IsAtMe: false, IsPrivate: false })
|
|
209
209
|
.addGuild({ GuildId: event.guild_id, SpaceId: `GUILD:${event.channel_id}` })
|
|
210
210
|
.addChannel({ ChannelId: event.channel_id })
|
|
211
211
|
.addUser({
|
|
@@ -228,7 +228,7 @@ const register = (client) => {
|
|
|
228
228
|
const [isMaster, UserKey] = getMaster(UserId);
|
|
229
229
|
const MessageText = event.data.resolved.button_data?.trim() || '';
|
|
230
230
|
const e = FormatEvent.create('interaction.create')
|
|
231
|
-
.addPlatform({ Platform: platform, value: event, BotId: botId })
|
|
231
|
+
.addPlatform({ Platform: platform, value: event, BotId: botId, IsAtMe: false, IsPrivate: false })
|
|
232
232
|
.addGuild({ GuildId: event.group_openid, SpaceId: `GROUP:${event.group_openid}` })
|
|
233
233
|
.addChannel({ ChannelId: event.group_openid })
|
|
234
234
|
.addUser({
|
|
@@ -250,7 +250,7 @@ const register = (client) => {
|
|
|
250
250
|
const [isMaster, UserKey] = getMaster(UserId);
|
|
251
251
|
const MessageText = event.data.resolved.button_data?.trim() || '';
|
|
252
252
|
const e = FormatEvent.create('private.interaction.create')
|
|
253
|
-
.addPlatform({ Platform: platform, value: event, BotId: botId })
|
|
253
|
+
.addPlatform({ Platform: platform, value: event, BotId: botId, IsAtMe: false, IsPrivate: true })
|
|
254
254
|
.addUser({
|
|
255
255
|
UserId: event.user_openid,
|
|
256
256
|
UserKey,
|
|
@@ -270,7 +270,7 @@ const register = (client) => {
|
|
|
270
270
|
const [isMaster, UserKey] = getMaster(UserId);
|
|
271
271
|
const MessageText = event.data.resolved.button_data?.trim() || '';
|
|
272
272
|
const e = FormatEvent.create('interaction.create')
|
|
273
|
-
.addPlatform({ Platform: platform, value: event, BotId: botId })
|
|
273
|
+
.addPlatform({ Platform: platform, value: event, BotId: botId, IsAtMe: false, IsPrivate: false })
|
|
274
274
|
.addGuild({ GuildId: event.guild_id, SpaceId: `GUILD:${event.channel_id}` })
|
|
275
275
|
.addChannel({ ChannelId: event.channel_id })
|
|
276
276
|
.addUser({ UserId: event.data.resolved.user_id, UserKey, UserAvatar: UserAvatar, IsMaster: isMaster, IsBot: false })
|
|
@@ -7,6 +7,15 @@ import { config } from './config.js';
|
|
|
7
7
|
import { v4 } from 'uuid';
|
|
8
8
|
import { WebSocketServer, WebSocket } from 'ws';
|
|
9
9
|
|
|
10
|
+
const normalizeGatewayMessage = (message) => {
|
|
11
|
+
if (!message?.id || !message?.d || typeof message.d !== 'object' || Array.isArray(message.d)) {
|
|
12
|
+
return message;
|
|
13
|
+
}
|
|
14
|
+
if (message.d.id === undefined || message.d.id === null || message.d.id === '') {
|
|
15
|
+
message.d.id = message.id;
|
|
16
|
+
}
|
|
17
|
+
return message;
|
|
18
|
+
};
|
|
10
19
|
class QQBotClient extends QQBotAPI {
|
|
11
20
|
#events = {};
|
|
12
21
|
#app = null;
|
|
@@ -74,7 +83,7 @@ class QQBotClient extends QQBotAPI {
|
|
|
74
83
|
ctx.body = { msg: 'invalid signature' };
|
|
75
84
|
return;
|
|
76
85
|
}
|
|
77
|
-
const body = ctx.request.body;
|
|
86
|
+
const body = normalizeGatewayMessage(ctx.request.body);
|
|
78
87
|
if (+body.op === 13) {
|
|
79
88
|
ctx.status = 200;
|
|
80
89
|
ctx.body = {
|
|
@@ -115,7 +124,7 @@ class QQBotClient extends QQBotAPI {
|
|
|
115
124
|
this.#client.push({ id: clientId, ws });
|
|
116
125
|
ws.on('message', (message) => {
|
|
117
126
|
try {
|
|
118
|
-
const body = JSON.parse(message.toString());
|
|
127
|
+
const body = normalizeGatewayMessage(JSON.parse(message.toString()));
|
|
119
128
|
for (const event of this.#events[body.t] || []) {
|
|
120
129
|
event(body.d);
|
|
121
130
|
}
|
|
@@ -139,7 +148,7 @@ class QQBotClient extends QQBotAPI {
|
|
|
139
148
|
});
|
|
140
149
|
this.#ws.on('message', data => {
|
|
141
150
|
try {
|
|
142
|
-
const body = JSON.parse(data.toString());
|
|
151
|
+
const body = normalizeGatewayMessage(JSON.parse(data.toString()));
|
|
143
152
|
const accessToken = body['access_token'];
|
|
144
153
|
if (accessToken) {
|
|
145
154
|
config.set('access_token', accessToken);
|
|
@@ -4,6 +4,15 @@ import { config } from './config.js';
|
|
|
4
4
|
import { getIntentsMask } from './intents.js';
|
|
5
5
|
import { Counter } from 'alemonjs/utils';
|
|
6
6
|
|
|
7
|
+
const normalizeGatewayMessage = (message) => {
|
|
8
|
+
if (!message?.id || !message?.d || typeof message.d !== 'object' || Array.isArray(message.d)) {
|
|
9
|
+
return message;
|
|
10
|
+
}
|
|
11
|
+
if (message.d.id === undefined || message.d.id === null || message.d.id === '') {
|
|
12
|
+
message.d.id = message.id;
|
|
13
|
+
}
|
|
14
|
+
return message;
|
|
15
|
+
};
|
|
7
16
|
class QQBotClients extends QQBotAPI {
|
|
8
17
|
#counter = new Counter(1);
|
|
9
18
|
#isConnected = false;
|
|
@@ -150,7 +159,7 @@ class QQBotClients extends QQBotAPI {
|
|
|
150
159
|
console.info('[ws-qqbot] open');
|
|
151
160
|
});
|
|
152
161
|
this.#ws.on('message', msg => {
|
|
153
|
-
const message = JSON.parse(msg.toString('utf8'));
|
|
162
|
+
const message = normalizeGatewayMessage(JSON.parse(msg.toString('utf8')));
|
|
154
163
|
if (process.env.NTQQ_WS === 'dev') {
|
|
155
164
|
console.info('message', message);
|
|
156
165
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@alemonjs/qq-bot",
|
|
3
|
-
"version": "2.1.
|
|
3
|
+
"version": "2.1.22",
|
|
4
4
|
"description": "阿柠檬qq-bot平台连接",
|
|
5
5
|
"author": "lemonade",
|
|
6
6
|
"license": "MIT",
|
|
@@ -74,5 +74,5 @@
|
|
|
74
74
|
"type": "git",
|
|
75
75
|
"url": "https://github.com/lemonade-lab/alemonjs.git"
|
|
76
76
|
},
|
|
77
|
-
"gitHead": "
|
|
78
|
-
}
|
|
77
|
+
"gitHead": "7dab16a2167bbdf5706931b67e7eab2fc67835d6"
|
|
78
|
+
}
|