@alemonjs/qq-bot 0.0.13 → 0.0.14
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 +16 -12
- package/dist/assets/index.css +472 -1
- package/dist/assets/index.js +11002 -14
- package/dist/index.html +1 -1
- package/lib/index.group.js +3 -15
- package/lib/index.guild.js +4 -22
- package/lib/index.js +18 -38
- package/lib/sdk/api.js +2 -1
- package/lib/sdk/websoket.group.js +1 -1
- package/lib/send/index.js +23 -13
- package/package.json +4 -1
package/dist/index.html
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
|
7
7
|
<title>AlemonJS</title>
|
|
8
8
|
<script type="module" crossorigin src="/assets/index.js"></script>
|
|
9
|
-
<link rel="stylesheet" crossorigin href="/assets/index.css"
|
|
9
|
+
<link rel="stylesheet" crossorigin href="/assets/index.css" />
|
|
10
10
|
</head>
|
|
11
11
|
|
|
12
12
|
<body>
|
package/lib/index.group.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { defineBot, getConfigValue, useUserHashKey,
|
|
1
|
+
import { defineBot, getConfigValue, useUserHashKey, onProcessor } from 'alemonjs';
|
|
2
2
|
import { AT_MESSAGE_CREATE, GROUP_AT_MESSAGE_CREATE, DIRECT_MESSAGE_CREATE, C2C_MESSAGE_CREATE, MESSAGE_CREATE } from './send/index.js';
|
|
3
3
|
import { QQBotGroupClient } from './sdk/websoket.group.js';
|
|
4
4
|
import { isGuild } from './utils.js';
|
|
@@ -73,14 +73,8 @@ var QQBotGroup = defineBot(() => {
|
|
|
73
73
|
tag: 'GROUP_AT_MESSAGE_CREATE',
|
|
74
74
|
value: null
|
|
75
75
|
};
|
|
76
|
-
// 当访问的时候获取
|
|
77
|
-
Object.defineProperty(e, 'value', {
|
|
78
|
-
get() {
|
|
79
|
-
return event;
|
|
80
|
-
}
|
|
81
|
-
});
|
|
82
76
|
// 处理消息
|
|
83
|
-
|
|
77
|
+
onProcessor('message.create', e, event);
|
|
84
78
|
});
|
|
85
79
|
client.on('C2C_MESSAGE_CREATE', async (event) => {
|
|
86
80
|
const master_key = config?.master_key ?? [];
|
|
@@ -124,14 +118,8 @@ var QQBotGroup = defineBot(() => {
|
|
|
124
118
|
tag: 'C2C_MESSAGE_CREATE',
|
|
125
119
|
value: null
|
|
126
120
|
};
|
|
127
|
-
// 当访问的时候获取
|
|
128
|
-
Object.defineProperty(e, 'value', {
|
|
129
|
-
get() {
|
|
130
|
-
return event;
|
|
131
|
-
}
|
|
132
|
-
});
|
|
133
121
|
// 处理消息
|
|
134
|
-
|
|
122
|
+
onProcessor('private.message.create', e, event);
|
|
135
123
|
});
|
|
136
124
|
client.on('ERROR', console.error);
|
|
137
125
|
// FRIEND_ADD
|
package/lib/index.guild.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { defineBot, getConfigValue, useUserHashKey,
|
|
1
|
+
import { defineBot, getConfigValue, useUserHashKey, onProcessor } from 'alemonjs';
|
|
2
2
|
import { AT_MESSAGE_CREATE, GROUP_AT_MESSAGE_CREATE, DIRECT_MESSAGE_CREATE, C2C_MESSAGE_CREATE, MESSAGE_CREATE } from './send/index.js';
|
|
3
3
|
import { QQBotGuildClient } from './sdk/websoket.guild.js';
|
|
4
4
|
import { isGuild } from './utils.js';
|
|
@@ -81,14 +81,8 @@ var QQBotGuild = defineBot(() => {
|
|
|
81
81
|
//
|
|
82
82
|
value: null
|
|
83
83
|
};
|
|
84
|
-
// 当访问的时候获取
|
|
85
|
-
Object.defineProperty(e, 'value', {
|
|
86
|
-
get() {
|
|
87
|
-
return event;
|
|
88
|
-
}
|
|
89
|
-
});
|
|
90
84
|
// 处理消息
|
|
91
|
-
|
|
85
|
+
onProcessor('private.message.create', e, event);
|
|
92
86
|
});
|
|
93
87
|
// 监听消息
|
|
94
88
|
client.on('AT_MESSAGE_CREATE', async (event) => {
|
|
@@ -140,14 +134,8 @@ var QQBotGuild = defineBot(() => {
|
|
|
140
134
|
//
|
|
141
135
|
value: null
|
|
142
136
|
};
|
|
143
|
-
// 当访问的时候获取
|
|
144
|
-
Object.defineProperty(e, 'value', {
|
|
145
|
-
get() {
|
|
146
|
-
return event;
|
|
147
|
-
}
|
|
148
|
-
});
|
|
149
137
|
// 处理消息
|
|
150
|
-
|
|
138
|
+
onProcessor('message.create', e, event);
|
|
151
139
|
});
|
|
152
140
|
/**
|
|
153
141
|
*
|
|
@@ -224,14 +212,8 @@ var QQBotGuild = defineBot(() => {
|
|
|
224
212
|
tag: 'MESSAGE_CREATE',
|
|
225
213
|
value: null
|
|
226
214
|
};
|
|
227
|
-
// 当访问的时候获取
|
|
228
|
-
Object.defineProperty(e, 'value', {
|
|
229
|
-
get() {
|
|
230
|
-
return event;
|
|
231
|
-
}
|
|
232
|
-
});
|
|
233
215
|
// 处理消息
|
|
234
|
-
|
|
216
|
+
onProcessor('message.create', e, event);
|
|
235
217
|
});
|
|
236
218
|
client.on('ERROR', console.error);
|
|
237
219
|
// FRIEND_ADD
|
package/lib/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { defineBot, getConfigValue, useUserHashKey,
|
|
1
|
+
import { defineBot, getConfigValue, useUserHashKey, onProcessor } from 'alemonjs';
|
|
2
2
|
import { QQBotClient } from './sdk/client.js';
|
|
3
3
|
import { AT_MESSAGE_CREATE, GROUP_AT_MESSAGE_CREATE, DIRECT_MESSAGE_CREATE, C2C_MESSAGE_CREATE, MESSAGE_CREATE } from './send/index.js';
|
|
4
4
|
import QQBotGroup from './index.group.js';
|
|
@@ -22,10 +22,20 @@ var index = defineBot(() => {
|
|
|
22
22
|
value = {};
|
|
23
23
|
const config = value[platform];
|
|
24
24
|
if (config.mode == 'guild') {
|
|
25
|
-
|
|
25
|
+
if (typeof QQBotGuild.callback == 'function') {
|
|
26
|
+
return QQBotGuild.callback();
|
|
27
|
+
}
|
|
28
|
+
else {
|
|
29
|
+
return QQBotGuild.callback;
|
|
30
|
+
}
|
|
26
31
|
}
|
|
27
32
|
else if (config.mode == 'group') {
|
|
28
|
-
|
|
33
|
+
if (typeof QQBotGroup.callback == 'function') {
|
|
34
|
+
return QQBotGroup.callback();
|
|
35
|
+
}
|
|
36
|
+
else {
|
|
37
|
+
return QQBotGroup.callback;
|
|
38
|
+
}
|
|
29
39
|
}
|
|
30
40
|
const client = new QQBotClient({
|
|
31
41
|
secret: config?.secret,
|
|
@@ -88,14 +98,8 @@ var index = defineBot(() => {
|
|
|
88
98
|
tag: 'GROUP_AT_MESSAGE_CREATE',
|
|
89
99
|
value: null
|
|
90
100
|
};
|
|
91
|
-
// 当访问的时候获取
|
|
92
|
-
Object.defineProperty(e, 'value', {
|
|
93
|
-
get() {
|
|
94
|
-
return event;
|
|
95
|
-
}
|
|
96
|
-
});
|
|
97
101
|
// 处理消息
|
|
98
|
-
|
|
102
|
+
onProcessor('message.create', e, event);
|
|
99
103
|
});
|
|
100
104
|
client.on('C2C_MESSAGE_CREATE', async (event) => {
|
|
101
105
|
const master_key = config?.master_key ?? [];
|
|
@@ -139,14 +143,8 @@ var index = defineBot(() => {
|
|
|
139
143
|
tag: 'C2C_MESSAGE_CREATE',
|
|
140
144
|
value: null
|
|
141
145
|
};
|
|
142
|
-
// 当访问的时候获取
|
|
143
|
-
Object.defineProperty(e, 'value', {
|
|
144
|
-
get() {
|
|
145
|
-
return event;
|
|
146
|
-
}
|
|
147
|
-
});
|
|
148
146
|
// 处理消息
|
|
149
|
-
|
|
147
|
+
onProcessor('private.message.create', e, event);
|
|
150
148
|
});
|
|
151
149
|
/**
|
|
152
150
|
* guild
|
|
@@ -201,14 +199,8 @@ var index = defineBot(() => {
|
|
|
201
199
|
//
|
|
202
200
|
value: null
|
|
203
201
|
};
|
|
204
|
-
// 当访问的时候获取
|
|
205
|
-
Object.defineProperty(e, 'value', {
|
|
206
|
-
get() {
|
|
207
|
-
return event;
|
|
208
|
-
}
|
|
209
|
-
});
|
|
210
202
|
// 处理消息
|
|
211
|
-
|
|
203
|
+
onProcessor('private.message.create', e, event);
|
|
212
204
|
});
|
|
213
205
|
// 监听消息
|
|
214
206
|
client.on('AT_MESSAGE_CREATE', async (event) => {
|
|
@@ -260,14 +252,8 @@ var index = defineBot(() => {
|
|
|
260
252
|
//
|
|
261
253
|
value: null
|
|
262
254
|
};
|
|
263
|
-
// 当访问的时候获取
|
|
264
|
-
Object.defineProperty(e, 'value', {
|
|
265
|
-
get() {
|
|
266
|
-
return event;
|
|
267
|
-
}
|
|
268
|
-
});
|
|
269
255
|
// 处理消息
|
|
270
|
-
|
|
256
|
+
onProcessor('message.create', e, event);
|
|
271
257
|
});
|
|
272
258
|
/**
|
|
273
259
|
*
|
|
@@ -344,14 +330,8 @@ var index = defineBot(() => {
|
|
|
344
330
|
tag: 'MESSAGE_CREATE',
|
|
345
331
|
value: null
|
|
346
332
|
};
|
|
347
|
-
// 当访问的时候获取
|
|
348
|
-
Object.defineProperty(e, 'value', {
|
|
349
|
-
get() {
|
|
350
|
-
return event;
|
|
351
|
-
}
|
|
352
|
-
});
|
|
353
333
|
// 处理消息
|
|
354
|
-
|
|
334
|
+
onProcessor('message.create', e, event);
|
|
355
335
|
});
|
|
356
336
|
client.on('ERROR', console.error);
|
|
357
337
|
// FRIEND_ADD
|
package/lib/sdk/api.js
CHANGED
|
@@ -36,7 +36,8 @@ class QQBotAPI {
|
|
|
36
36
|
*/
|
|
37
37
|
async groupService(options) {
|
|
38
38
|
const app_id = config.get('app_id');
|
|
39
|
-
|
|
39
|
+
// 群聊是加密token
|
|
40
|
+
const token = config.get('access_token');
|
|
40
41
|
const service = await axios.create({
|
|
41
42
|
baseURL: this.API_URL,
|
|
42
43
|
timeout: 20000,
|
|
@@ -41,7 +41,7 @@ class QQBotGroupClient extends QQBotAPI {
|
|
|
41
41
|
return;
|
|
42
42
|
// 发送请求
|
|
43
43
|
const data = await this.getAuthentication(app_id, secret).then(res => res.data);
|
|
44
|
-
config.set('
|
|
44
|
+
config.set('access_token', data.access_token);
|
|
45
45
|
console.info('refresh', data.expires_in, 's');
|
|
46
46
|
setTimeout(accessToken, data.expires_in * 1000);
|
|
47
47
|
};
|
package/lib/send/index.js
CHANGED
|
@@ -33,7 +33,7 @@ const GROUP_AT_MESSAGE_CREATE = (client, event, val) => {
|
|
|
33
33
|
msg_seq: client.getMessageSeq(event.MessageId)
|
|
34
34
|
})));
|
|
35
35
|
}
|
|
36
|
-
const images = val.filter(item =>
|
|
36
|
+
const images = val.filter(item => item.type == 'Image' || item.type == 'ImageFile' || item.type == 'ImageURL');
|
|
37
37
|
if (images) {
|
|
38
38
|
return Promise.all(images.map(async (item) => {
|
|
39
39
|
if (item.type == 'ImageURL') {
|
|
@@ -47,7 +47,9 @@ const GROUP_AT_MESSAGE_CREATE = (client, event, val) => {
|
|
|
47
47
|
msg_seq: client.getMessageSeq(event.MessageId)
|
|
48
48
|
});
|
|
49
49
|
}
|
|
50
|
-
const file_data = item.type == 'ImageFile'
|
|
50
|
+
const file_data = item.type == 'ImageFile'
|
|
51
|
+
? readFileSync(item.value, 'base64')
|
|
52
|
+
: item.value.toString('base64');
|
|
51
53
|
const file_info = await client
|
|
52
54
|
.postRichMediaByGroup(event.GuildId, {
|
|
53
55
|
file_type: 1,
|
|
@@ -87,7 +89,7 @@ const C2C_MESSAGE_CREATE = (client, event, val) => {
|
|
|
87
89
|
msg_seq: client.getMessageSeq(event.MessageId)
|
|
88
90
|
})));
|
|
89
91
|
}
|
|
90
|
-
const images = val.filter(item =>
|
|
92
|
+
const images = val.filter(item => item.type == 'Image' || item.type == 'ImageFile' || item.type == 'ImageURL');
|
|
91
93
|
if (images) {
|
|
92
94
|
return Promise.all(images.map(async (item) => {
|
|
93
95
|
if (item.type == 'ImageURL') {
|
|
@@ -101,7 +103,9 @@ const C2C_MESSAGE_CREATE = (client, event, val) => {
|
|
|
101
103
|
msg_seq: client.getMessageSeq(event.MessageId)
|
|
102
104
|
});
|
|
103
105
|
}
|
|
104
|
-
const file_data = item.type == 'ImageFile'
|
|
106
|
+
const file_data = item.type == 'ImageFile'
|
|
107
|
+
? readFileSync(item.value, 'base64')
|
|
108
|
+
: item.value.toString('base64');
|
|
105
109
|
const file_info = await client
|
|
106
110
|
.postRichMediaByUsers(event.OpenId, {
|
|
107
111
|
file_type: 1,
|
|
@@ -146,14 +150,16 @@ const DIRECT_MESSAGE_CREATE = (client, event, val) => {
|
|
|
146
150
|
msg_id: event.MessageId
|
|
147
151
|
})));
|
|
148
152
|
}
|
|
149
|
-
const images = val.filter(item =>
|
|
153
|
+
const images = val.filter(item => item.type == 'Image' || item.type == 'ImageFile' || item.type == 'ImageURL');
|
|
150
154
|
if (images) {
|
|
151
155
|
return Promise.all(images.map(async (item) => {
|
|
152
156
|
if (item.value == 'ImageURL') {
|
|
153
157
|
// 请求得到buffer
|
|
154
|
-
const data = await axios
|
|
158
|
+
const data = await axios
|
|
159
|
+
.get(item.value, {
|
|
155
160
|
responseType: 'arraybuffer'
|
|
156
|
-
})
|
|
161
|
+
})
|
|
162
|
+
.then(res => res.data);
|
|
157
163
|
return client.postDirectImage(event.OpenId, {
|
|
158
164
|
msg_id: event.MessageId,
|
|
159
165
|
image: data
|
|
@@ -201,14 +207,16 @@ const AT_MESSAGE_CREATE = (client, event, val) => {
|
|
|
201
207
|
msg_id: event.MessageId
|
|
202
208
|
})));
|
|
203
209
|
}
|
|
204
|
-
const images = val.filter(item =>
|
|
210
|
+
const images = val.filter(item => item.type == 'Image' || item.type == 'ImageFile' || item.type == 'ImageURL');
|
|
205
211
|
if (images) {
|
|
206
212
|
return Promise.all(images.map(async (item) => {
|
|
207
213
|
if (item.value == 'ImageURL') {
|
|
208
214
|
// 请求得到buffer
|
|
209
|
-
const data = await axios
|
|
215
|
+
const data = await axios
|
|
216
|
+
.get(item.value, {
|
|
210
217
|
responseType: 'arraybuffer'
|
|
211
|
-
})
|
|
218
|
+
})
|
|
219
|
+
.then(res => res.data);
|
|
212
220
|
return client.postImage(event.ChannelId, {
|
|
213
221
|
msg_id: event.MessageId,
|
|
214
222
|
image: data
|
|
@@ -262,14 +270,16 @@ const MESSAGE_CREATE = (client, event, val) => {
|
|
|
262
270
|
msg_id: event.MessageId
|
|
263
271
|
})));
|
|
264
272
|
}
|
|
265
|
-
const images = val.filter(item =>
|
|
273
|
+
const images = val.filter(item => item.type == 'Image' || item.type == 'ImageFile' || item.type == 'ImageURL');
|
|
266
274
|
if (images) {
|
|
267
275
|
return Promise.all(images.map(async (item) => {
|
|
268
276
|
if (item.value == 'ImageURL') {
|
|
269
277
|
// 请求得到buffer
|
|
270
|
-
const data = await axios
|
|
278
|
+
const data = await axios
|
|
279
|
+
.get(item.value, {
|
|
271
280
|
responseType: 'arraybuffer'
|
|
272
|
-
})
|
|
281
|
+
})
|
|
282
|
+
.then(res => res.data);
|
|
273
283
|
return client.postImage(event.ChannelId, {
|
|
274
284
|
msg_id: event.MessageId,
|
|
275
285
|
image: data
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@alemonjs/qq-bot",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.14",
|
|
4
4
|
"description": "阿柠檬qqbot平台连接",
|
|
5
5
|
"author": "lemonade",
|
|
6
6
|
"license": "MIT",
|
|
@@ -41,15 +41,18 @@
|
|
|
41
41
|
"name": "qq-bot"
|
|
42
42
|
}
|
|
43
43
|
],
|
|
44
|
+
"logo": "antd.QqOutlined",
|
|
44
45
|
"commond": [
|
|
45
46
|
{
|
|
46
47
|
"name": "qq-bot",
|
|
48
|
+
"icon": "antd.QqOutlined",
|
|
47
49
|
"commond": "open.qq-bot"
|
|
48
50
|
}
|
|
49
51
|
],
|
|
50
52
|
"sidebars": [
|
|
51
53
|
{
|
|
52
54
|
"name": "qq-bot",
|
|
55
|
+
"icon": "antd.QqOutlined",
|
|
53
56
|
"commond": "open.qq-bot"
|
|
54
57
|
}
|
|
55
58
|
]
|