@alemonjs/qq-bot 0.0.8 → 0.0.10
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 +2 -1
- package/dist/assets/index.css +476 -0
- package/dist/assets/index.js +11032 -0
- package/dist/index.html +15 -0
- package/lib/api.d.ts +975 -0
- package/lib/api.js +1172 -1156
- package/lib/client.d.ts +26 -0
- package/lib/client.js +201 -217
- package/lib/config.js +2 -2
- package/lib/desktop.d.ts +3 -0
- package/lib/desktop.js +66 -0
- package/lib/from.js +27 -34
- package/lib/index.d.ts +4 -1
- package/lib/index.js +406 -405
- package/lib/message/AT_MESSAGE_CREATE.d.ts +37 -0
- package/lib/message/C2C_MESSAGE_CREATE.d.ts +11 -0
- package/lib/message/CHANNEL_CREATE.d.ts +17 -0
- package/lib/message/CHANNEL_DELETE.d.ts +22 -0
- package/lib/message/CHANNEL_UPDATE.d.ts +22 -0
- package/lib/message/DIRECT_MESSAGE_CREATE.d.ts +36 -0
- package/lib/message/DIRECT_MESSAGE_DELETE.d.ts +24 -0
- package/lib/message/ERROR.d.ts +3 -0
- package/lib/message/GROUP_AT_MESSAGE_CREATE.d.ts +16 -0
- package/lib/message/GUILD_CREATE.d.ts +22 -0
- package/lib/message/GUILD_DELETE.d.ts +22 -0
- package/lib/message/GUILD_MEMBER_ADD.d.ts +21 -0
- package/lib/message/GUILD_MEMBER_REMOVE.d.ts +21 -0
- package/lib/message/GUILD_MEMBER_UPDATE.d.ts +21 -0
- package/lib/message/GUILD_UPDATE.d.ts +22 -0
- package/lib/message/INTERACTION_CREATE.d.ts +8 -0
- package/lib/message/MESSAGE_CREATE.d.ts +11 -0
- package/lib/message/MESSAGE_DELETE.d.ts +11 -0
- package/lib/message/MESSAGE_REACTION_ADD.d.ts +15 -0
- package/lib/message/MESSAGE_REACTION_REMOVE.d.ts +15 -0
- package/lib/message/PUBLIC_MESSAGE_DELETE.d.ts +21 -0
- package/lib/message/READY.d.ts +11 -0
- package/lib/message.d.ts +49 -0
- package/lib/send/index.js +230 -192
- package/lib/typing.d.ts +73 -0
- package/lib/webhook.js +46 -48
- package/package.json +24 -2
package/lib/send/index.js
CHANGED
|
@@ -1,101 +1,111 @@
|
|
|
1
1
|
const GROUP_AT_MESSAGE_CREATE = (client, event, val) => {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
2
|
+
const content = val
|
|
3
|
+
.filter(item => item.type == 'Link' || item.type == 'Mention' || item.type == 'Text')
|
|
4
|
+
.map(item => {
|
|
5
|
+
if (item.type == 'Link') {
|
|
6
|
+
return `[${item.options?.title ?? item.value}](${item.value})`
|
|
7
|
+
} else if (item.type == 'Mention') {
|
|
8
|
+
if (
|
|
9
|
+
item.value == 'everyone' ||
|
|
10
|
+
item.value == 'all' ||
|
|
11
|
+
item.value == '' ||
|
|
12
|
+
typeof item.value != 'string'
|
|
13
|
+
) {
|
|
14
|
+
return ``
|
|
7
15
|
}
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
item.value == 'all' ||
|
|
11
|
-
item.value == '' ||
|
|
12
|
-
typeof item.value != 'string') {
|
|
13
|
-
return ``;
|
|
14
|
-
}
|
|
15
|
-
if (item.options?.belong == 'user') {
|
|
16
|
-
return `<@${item.value}>`;
|
|
17
|
-
}
|
|
18
|
-
return '';
|
|
19
|
-
}
|
|
20
|
-
else if (item.type == 'Text') {
|
|
21
|
-
return item.value;
|
|
16
|
+
if (item.options?.belong == 'user') {
|
|
17
|
+
return `<@${item.value}>`
|
|
22
18
|
}
|
|
19
|
+
return ''
|
|
20
|
+
} else if (item.type == 'Text') {
|
|
21
|
+
return item.value
|
|
22
|
+
}
|
|
23
23
|
})
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
}
|
|
24
|
+
.join('')
|
|
25
|
+
if (content) {
|
|
26
|
+
return Promise.all(
|
|
27
|
+
[content].map(item =>
|
|
28
|
+
client.groupOpenMessages(event.GuildId, {
|
|
29
|
+
content: item,
|
|
30
|
+
msg_id: event.MessageId,
|
|
31
|
+
msg_type: 0,
|
|
32
|
+
msg_seq: client.getMessageSeq(event.MessageId)
|
|
33
|
+
})
|
|
34
|
+
)
|
|
35
|
+
)
|
|
36
|
+
}
|
|
37
|
+
const images = val.filter(item => item.type == 'Image').map(item => item.value)
|
|
38
|
+
if (images) {
|
|
39
|
+
return Promise.all(
|
|
40
|
+
images.map(async msg => {
|
|
41
|
+
const file_info = await client
|
|
42
|
+
.postRichMediaByGroup(event.GuildId, {
|
|
43
|
+
file_type: 1,
|
|
44
|
+
file_data: msg.toString('base64')
|
|
45
|
+
})
|
|
46
|
+
.then(res => res?.file_info)
|
|
47
|
+
if (!file_info) return Promise.resolve(null)
|
|
48
|
+
return client.groupOpenMessages(event.GuildId, {
|
|
49
|
+
content: '',
|
|
50
|
+
media: {
|
|
51
|
+
file_info
|
|
52
|
+
},
|
|
53
|
+
msg_id: event.MessageId,
|
|
54
|
+
msg_type: 7,
|
|
55
|
+
msg_seq: client.getMessageSeq(event.MessageId)
|
|
56
|
+
})
|
|
57
|
+
})
|
|
58
|
+
)
|
|
59
|
+
}
|
|
60
|
+
return []
|
|
61
|
+
}
|
|
57
62
|
const C2C_MESSAGE_CREATE = (client, event, val) => {
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
63
|
+
const content = val
|
|
64
|
+
.filter(item => item.type == 'Link' || item.type == 'Mention' || item.type == 'Text')
|
|
65
|
+
.map(item => {
|
|
66
|
+
if (item.type == 'Text') {
|
|
67
|
+
return item.value
|
|
68
|
+
}
|
|
69
|
+
return ''
|
|
65
70
|
})
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
}
|
|
71
|
+
.join('')
|
|
72
|
+
if (content) {
|
|
73
|
+
return Promise.all(
|
|
74
|
+
[content].map(item =>
|
|
75
|
+
client.usersOpenMessages(event.OpenId, {
|
|
76
|
+
content: item,
|
|
77
|
+
msg_id: event.MessageId,
|
|
78
|
+
msg_type: 0,
|
|
79
|
+
msg_seq: client.getMessageSeq(event.MessageId)
|
|
80
|
+
})
|
|
81
|
+
)
|
|
82
|
+
)
|
|
83
|
+
}
|
|
84
|
+
const images = val.filter(item => item.type == 'Image').map(item => item.value)
|
|
85
|
+
if (images) {
|
|
86
|
+
return Promise.all(
|
|
87
|
+
images.map(async msg => {
|
|
88
|
+
const file_info = await client
|
|
89
|
+
.postRichMediaByUsers(event.OpenId, {
|
|
90
|
+
file_type: 1,
|
|
91
|
+
file_data: msg.toString('base64')
|
|
92
|
+
})
|
|
93
|
+
.then(res => res?.file_info)
|
|
94
|
+
if (!file_info) return Promise.resolve(null)
|
|
95
|
+
return client.usersOpenMessages(event.OpenId, {
|
|
96
|
+
content: '',
|
|
97
|
+
media: {
|
|
98
|
+
file_info
|
|
99
|
+
},
|
|
100
|
+
msg_id: event.MessageId,
|
|
101
|
+
msg_type: 7,
|
|
102
|
+
msg_seq: client.getMessageSeq(event.MessageId)
|
|
103
|
+
})
|
|
104
|
+
})
|
|
105
|
+
)
|
|
106
|
+
}
|
|
107
|
+
return []
|
|
108
|
+
}
|
|
99
109
|
/**
|
|
100
110
|
* 频道私聊
|
|
101
111
|
* @param client
|
|
@@ -104,72 +114,87 @@ const C2C_MESSAGE_CREATE = (client, event, val) => {
|
|
|
104
114
|
* @returns
|
|
105
115
|
*/
|
|
106
116
|
const DIRECT_MESSAGE_CREATE = (client, event, val) => {
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
117
|
+
const content = val
|
|
118
|
+
.filter(item => item.type == 'Link' || item.type == 'Mention' || item.type == 'Text')
|
|
119
|
+
.map(item => {
|
|
120
|
+
if (item.type == 'Text') {
|
|
121
|
+
return item.value
|
|
122
|
+
}
|
|
123
|
+
return ''
|
|
114
124
|
})
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
125
|
+
.join('')
|
|
126
|
+
if (content) {
|
|
127
|
+
return Promise.all(
|
|
128
|
+
[content].map(item =>
|
|
129
|
+
client.dmsMessage(event.OpenId, {
|
|
130
|
+
content: item,
|
|
131
|
+
msg_id: event.MessageId
|
|
132
|
+
})
|
|
133
|
+
)
|
|
134
|
+
)
|
|
135
|
+
}
|
|
136
|
+
const images = val.filter(item => item.type == 'Image').map(item => item.value)
|
|
137
|
+
if (images) {
|
|
138
|
+
return Promise.all(
|
|
139
|
+
images.map(item =>
|
|
140
|
+
client.postDirectImage(event.OpenId, {
|
|
141
|
+
msg_id: event.MessageId,
|
|
142
|
+
image: item
|
|
143
|
+
})
|
|
144
|
+
)
|
|
145
|
+
)
|
|
146
|
+
}
|
|
147
|
+
return []
|
|
148
|
+
}
|
|
131
149
|
const AT_MESSAGE_CREATE = (client, event, val) => {
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
150
|
+
const content = val
|
|
151
|
+
.filter(item => item.type == 'Link' || item.type == 'Mention' || item.type == 'Text')
|
|
152
|
+
.map(item => {
|
|
153
|
+
if (item.type == 'Link') {
|
|
154
|
+
return `[${item.options?.title ?? item.value}](${item.value})`
|
|
155
|
+
} else if (item.type == 'Mention') {
|
|
156
|
+
if (
|
|
157
|
+
item.value == 'everyone' ||
|
|
158
|
+
item.value == 'all' ||
|
|
159
|
+
item.value == '' ||
|
|
160
|
+
typeof item.value != 'string'
|
|
161
|
+
) {
|
|
162
|
+
return `@everyone`
|
|
137
163
|
}
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
typeof item.value != 'string') {
|
|
143
|
-
return `@everyone`;
|
|
144
|
-
}
|
|
145
|
-
if (item.options?.belong == 'user') {
|
|
146
|
-
return `<@!${item.value}>`;
|
|
147
|
-
}
|
|
148
|
-
else if (item.options?.belong == 'channel') {
|
|
149
|
-
return `<#${item.value}>`;
|
|
150
|
-
}
|
|
151
|
-
return '';
|
|
152
|
-
}
|
|
153
|
-
else if (item.type == 'Text') {
|
|
154
|
-
return item.value;
|
|
164
|
+
if (item.options?.belong == 'user') {
|
|
165
|
+
return `<@!${item.value}>`
|
|
166
|
+
} else if (item.options?.belong == 'channel') {
|
|
167
|
+
return `<#${item.value}>`
|
|
155
168
|
}
|
|
169
|
+
return ''
|
|
170
|
+
} else if (item.type == 'Text') {
|
|
171
|
+
return item.value
|
|
172
|
+
}
|
|
156
173
|
})
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
174
|
+
.join('')
|
|
175
|
+
if (content) {
|
|
176
|
+
return Promise.all(
|
|
177
|
+
[content].map(item =>
|
|
178
|
+
client.channelsMessagesPost(event.ChannelId, {
|
|
179
|
+
content: item,
|
|
180
|
+
msg_id: event.MessageId
|
|
181
|
+
})
|
|
182
|
+
)
|
|
183
|
+
)
|
|
184
|
+
}
|
|
185
|
+
const images = val.filter(item => item.type == 'Image').map(item => item.value)
|
|
186
|
+
if (images) {
|
|
187
|
+
return Promise.all(
|
|
188
|
+
images.map(item =>
|
|
189
|
+
client.postImage(event.ChannelId, {
|
|
190
|
+
msg_id: event.MessageId,
|
|
191
|
+
image: item
|
|
192
|
+
})
|
|
193
|
+
)
|
|
194
|
+
)
|
|
195
|
+
}
|
|
196
|
+
return []
|
|
197
|
+
}
|
|
173
198
|
/**
|
|
174
199
|
*
|
|
175
200
|
* @param event
|
|
@@ -177,46 +202,59 @@ const AT_MESSAGE_CREATE = (client, event, val) => {
|
|
|
177
202
|
* @returns
|
|
178
203
|
*/
|
|
179
204
|
const MESSAGE_CREATE = (client, event, val) => {
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
if (item.options?.belong == 'user') {
|
|
194
|
-
return `<@!${item.value}>`;
|
|
195
|
-
}
|
|
196
|
-
else if (item.options?.belong == 'channel') {
|
|
197
|
-
return `<#${item.value}>`;
|
|
198
|
-
}
|
|
199
|
-
return '';
|
|
205
|
+
const content = val
|
|
206
|
+
.filter(item => item.type == 'Link' || item.type == 'Mention' || item.type == 'Text')
|
|
207
|
+
.map(item => {
|
|
208
|
+
if (item.type == 'Link') {
|
|
209
|
+
return `[${item.options?.title ?? item.value}](${item.value})`
|
|
210
|
+
} else if (item.type == 'Mention') {
|
|
211
|
+
if (
|
|
212
|
+
item.value == 'everyone' ||
|
|
213
|
+
item.value == 'all' ||
|
|
214
|
+
item.value == '' ||
|
|
215
|
+
typeof item.value != 'string'
|
|
216
|
+
) {
|
|
217
|
+
return `@everyone`
|
|
200
218
|
}
|
|
201
|
-
|
|
202
|
-
|
|
219
|
+
if (item.options?.belong == 'user') {
|
|
220
|
+
return `<@!${item.value}>`
|
|
221
|
+
} else if (item.options?.belong == 'channel') {
|
|
222
|
+
return `<#${item.value}>`
|
|
203
223
|
}
|
|
224
|
+
return ''
|
|
225
|
+
} else if (item.type == 'Text') {
|
|
226
|
+
return item.value
|
|
227
|
+
}
|
|
204
228
|
})
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
229
|
+
.join('')
|
|
230
|
+
if (content) {
|
|
231
|
+
return Promise.all(
|
|
232
|
+
[content].map(item =>
|
|
233
|
+
client.channelsMessagesPost(event.ChannelId, {
|
|
234
|
+
content: item,
|
|
235
|
+
msg_id: event.MessageId
|
|
236
|
+
})
|
|
237
|
+
)
|
|
238
|
+
)
|
|
239
|
+
}
|
|
240
|
+
const images = val.filter(item => item.type == 'Image').map(item => item.value)
|
|
241
|
+
if (images) {
|
|
242
|
+
return Promise.all(
|
|
243
|
+
images.map(item =>
|
|
244
|
+
client.postImage(event.ChannelId, {
|
|
245
|
+
msg_id: event.MessageId,
|
|
246
|
+
image: item
|
|
247
|
+
})
|
|
248
|
+
)
|
|
249
|
+
)
|
|
250
|
+
}
|
|
251
|
+
return []
|
|
252
|
+
}
|
|
221
253
|
|
|
222
|
-
export {
|
|
254
|
+
export {
|
|
255
|
+
AT_MESSAGE_CREATE,
|
|
256
|
+
C2C_MESSAGE_CREATE,
|
|
257
|
+
DIRECT_MESSAGE_CREATE,
|
|
258
|
+
GROUP_AT_MESSAGE_CREATE,
|
|
259
|
+
MESSAGE_CREATE
|
|
260
|
+
}
|
package/lib/typing.d.ts
ADDED
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
type MessageType = 0 | 1 | 2 | 3 | 4 | 7
|
|
2
|
+
type FileType = 1 | 2 | 3 | 4
|
|
3
|
+
interface ButtonType {
|
|
4
|
+
id: string
|
|
5
|
+
render_data: {
|
|
6
|
+
label: string
|
|
7
|
+
visited_label: string
|
|
8
|
+
style: number
|
|
9
|
+
}
|
|
10
|
+
action: {
|
|
11
|
+
type: number
|
|
12
|
+
permission: {
|
|
13
|
+
type: number
|
|
14
|
+
}
|
|
15
|
+
reply?: boolean
|
|
16
|
+
enter?: boolean
|
|
17
|
+
unsupport_tips: string
|
|
18
|
+
data: string
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
interface KeyboardType {
|
|
22
|
+
id?: string
|
|
23
|
+
content?: {
|
|
24
|
+
rows: {
|
|
25
|
+
buttons: ButtonType[]
|
|
26
|
+
}[]
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
interface MarkdownType {
|
|
30
|
+
/** markdown 模版id,申请模版后获得 */
|
|
31
|
+
custom_template_id: string
|
|
32
|
+
/** 原生 markdown 文本内容(内邀使用) */
|
|
33
|
+
content?: string
|
|
34
|
+
/** 模版内变量与填充值的kv映射 */
|
|
35
|
+
params?: Array<{
|
|
36
|
+
key: string
|
|
37
|
+
values: string[]
|
|
38
|
+
}>
|
|
39
|
+
}
|
|
40
|
+
interface ApiRequestData {
|
|
41
|
+
content?: string
|
|
42
|
+
msg_type: MessageType
|
|
43
|
+
markdown?: MarkdownType
|
|
44
|
+
keyboard?: KeyboardType
|
|
45
|
+
media?: {
|
|
46
|
+
file_info: string
|
|
47
|
+
}
|
|
48
|
+
ark?: any
|
|
49
|
+
image?: any
|
|
50
|
+
message_reference?: any
|
|
51
|
+
event_id?: any
|
|
52
|
+
msg_id?: string
|
|
53
|
+
msg_seq?: number
|
|
54
|
+
}
|
|
55
|
+
interface Options {
|
|
56
|
+
secret: string
|
|
57
|
+
app_id: string
|
|
58
|
+
token: string
|
|
59
|
+
sandbox?: boolean
|
|
60
|
+
route?: string
|
|
61
|
+
port?: string
|
|
62
|
+
ws?: string
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
export type {
|
|
66
|
+
ApiRequestData,
|
|
67
|
+
ButtonType,
|
|
68
|
+
FileType,
|
|
69
|
+
KeyboardType,
|
|
70
|
+
MarkdownType,
|
|
71
|
+
MessageType,
|
|
72
|
+
Options
|
|
73
|
+
}
|
package/lib/webhook.js
CHANGED
|
@@ -1,53 +1,51 @@
|
|
|
1
|
-
import { ed25519 } from '@noble/curves/ed25519'
|
|
1
|
+
import { ed25519 } from '@noble/curves/ed25519'
|
|
2
2
|
|
|
3
3
|
class WebhookAPI {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
privateKey,
|
|
48
|
-
publicKey: ed25519.getPublicKey(privateKey)
|
|
49
|
-
};
|
|
4
|
+
config
|
|
5
|
+
constructor(config) {
|
|
6
|
+
this.config = config
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* 验证签名
|
|
10
|
+
* @param ts
|
|
11
|
+
* @param body
|
|
12
|
+
* @param sign
|
|
13
|
+
* @returns
|
|
14
|
+
*/
|
|
15
|
+
validSign(ts, body, sign) {
|
|
16
|
+
const { publicKey } = this.getKey()
|
|
17
|
+
const sig = Buffer.isBuffer(sign) ? sign : Buffer.from(sign, 'hex')
|
|
18
|
+
const httpBody = Buffer.from(body)
|
|
19
|
+
const msg = Buffer.from(ts + httpBody)
|
|
20
|
+
return ed25519.verify(sig, msg, publicKey)
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* 生成签名
|
|
24
|
+
* @param eventTs
|
|
25
|
+
* @param plainToken
|
|
26
|
+
* @returns
|
|
27
|
+
*/
|
|
28
|
+
getSign(eventTs, plainToken) {
|
|
29
|
+
const { privateKey } = this.getKey()
|
|
30
|
+
const msg = Buffer.from(eventTs + plainToken)
|
|
31
|
+
const signature = Buffer.from(ed25519.sign(msg, privateKey)).toString('hex')
|
|
32
|
+
return signature
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* 获取 key
|
|
36
|
+
* @returns
|
|
37
|
+
*/
|
|
38
|
+
getKey() {
|
|
39
|
+
let seed = this.config.secret
|
|
40
|
+
if (!seed) throw new Error("secret not set, can't calc ed25519 key")
|
|
41
|
+
while (seed.length < 32) seed = seed.repeat(2) // Ed25519 的种子大小是 32 字节
|
|
42
|
+
seed = seed.slice(0, 32) // 修剪到 32 字节
|
|
43
|
+
const privateKey = Buffer.from(seed)
|
|
44
|
+
return {
|
|
45
|
+
privateKey,
|
|
46
|
+
publicKey: ed25519.getPublicKey(privateKey)
|
|
50
47
|
}
|
|
48
|
+
}
|
|
51
49
|
}
|
|
52
50
|
|
|
53
|
-
export { WebhookAPI }
|
|
51
|
+
export { WebhookAPI }
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@alemonjs/qq-bot",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.10",
|
|
4
4
|
"description": "qq-bot",
|
|
5
5
|
"author": "lemonade",
|
|
6
6
|
"license": "MIT",
|
|
@@ -37,7 +37,29 @@
|
|
|
37
37
|
"import": "./lib/index.js",
|
|
38
38
|
"types": "./lib/index.d.ts"
|
|
39
39
|
},
|
|
40
|
-
"./package": "./package.json"
|
|
40
|
+
"./package": "./package.json",
|
|
41
|
+
"./desktop": "./lib/desktop.js"
|
|
42
|
+
},
|
|
43
|
+
"alemonjs": {
|
|
44
|
+
"desktop": {
|
|
45
|
+
"platform": [
|
|
46
|
+
{
|
|
47
|
+
"name": "qq-bot"
|
|
48
|
+
}
|
|
49
|
+
],
|
|
50
|
+
"commond": [
|
|
51
|
+
{
|
|
52
|
+
"name": "qq-bot",
|
|
53
|
+
"commond": "open.qq-bot"
|
|
54
|
+
}
|
|
55
|
+
],
|
|
56
|
+
"sidebars": [
|
|
57
|
+
{
|
|
58
|
+
"name": "qq-bot",
|
|
59
|
+
"commond": "open.qq-bot"
|
|
60
|
+
}
|
|
61
|
+
]
|
|
62
|
+
}
|
|
41
63
|
},
|
|
42
64
|
"keywords": [
|
|
43
65
|
"alemonjs"
|