@alemonjs/qq-bot 0.0.19 → 0.0.21
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 +6 -10
- package/lib/index.d.ts +2 -2
- package/lib/index.group.js +6 -203
- package/lib/index.guild.js +25 -298
- package/lib/index.js +42 -403
- package/lib/index.webhook.js +26 -0
- package/lib/register.d.ts +3 -0
- package/lib/register.js +405 -0
- package/lib/sdk/api.d.ts +5 -10
- package/lib/sdk/api.js +5 -10
- package/lib/sdk/client.websoket.js +221 -0
- package/lib/sdk/intents.js +12 -23
- package/lib/send/index.js +417 -366
- package/lib/sends.js +576 -0
- package/package.json +1 -1
- package/lib/api.d.ts +0 -975
- package/lib/api.js +0 -1188
- package/lib/client.d.ts +0 -26
- package/lib/client.js +0 -212
- package/lib/config.js +0 -3
- package/lib/from.js +0 -37
- package/lib/message/AT_MESSAGE_CREATE.d.ts +0 -37
- package/lib/message/C2C_MESSAGE_CREATE.d.ts +0 -11
- package/lib/message/CHANNEL_CREATE.d.ts +0 -17
- package/lib/message/CHANNEL_DELETE.d.ts +0 -22
- package/lib/message/CHANNEL_UPDATE.d.ts +0 -22
- package/lib/message/DIRECT_MESSAGE_CREATE.d.ts +0 -36
- package/lib/message/DIRECT_MESSAGE_DELETE.d.ts +0 -24
- package/lib/message/ERROR.d.ts +0 -3
- package/lib/message/GROUP_AT_MESSAGE_CREATE.d.ts +0 -16
- package/lib/message/GUILD_CREATE.d.ts +0 -22
- package/lib/message/GUILD_DELETE.d.ts +0 -22
- package/lib/message/GUILD_MEMBER_ADD.d.ts +0 -21
- package/lib/message/GUILD_MEMBER_REMOVE.d.ts +0 -21
- package/lib/message/GUILD_MEMBER_UPDATE.d.ts +0 -21
- package/lib/message/GUILD_UPDATE.d.ts +0 -22
- package/lib/message/INTERACTION_CREATE.d.ts +0 -8
- package/lib/message/MESSAGE_CREATE.d.ts +0 -11
- package/lib/message/MESSAGE_DELETE.d.ts +0 -11
- package/lib/message/MESSAGE_REACTION_ADD.d.ts +0 -15
- package/lib/message/MESSAGE_REACTION_REMOVE.d.ts +0 -15
- package/lib/message/PUBLIC_MESSAGE_DELETE.d.ts +0 -21
- package/lib/message/READY.d.ts +0 -11
- package/lib/message.d.ts +0 -49
- package/lib/typing.d.ts +0 -73
- package/lib/webhook.js +0 -51
- /package/lib/sdk/{websoket.group.js → client.websoket.group.js} +0 -0
- /package/lib/sdk/{websoket.guild.js → client.websoket.guild.js} +0 -0
package/lib/send/index.js
CHANGED
|
@@ -1,236 +1,257 @@
|
|
|
1
|
-
import { readFileSync } from 'fs'
|
|
2
|
-
import axios from 'axios'
|
|
1
|
+
import { readFileSync } from 'fs'
|
|
2
|
+
import axios from 'axios'
|
|
3
3
|
|
|
4
|
-
const createButtonsData =
|
|
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
|
-
};
|
|
4
|
+
const createButtonsData = rows => {
|
|
5
|
+
let id = 0
|
|
6
|
+
const data = {
|
|
7
|
+
rows: rows.map(row => {
|
|
8
|
+
const val = row.value
|
|
9
|
+
return {
|
|
10
|
+
buttons: val.map(button => {
|
|
11
|
+
const value = button.value
|
|
12
|
+
const options = button.options
|
|
13
|
+
id++
|
|
14
|
+
return {
|
|
15
|
+
id: String(id),
|
|
16
|
+
render_data: {
|
|
17
|
+
label: typeof value == 'object' ? value.title : value,
|
|
18
|
+
visited_label: typeof value == 'object' ? value.label : value,
|
|
19
|
+
// tudo
|
|
20
|
+
style: 0
|
|
21
|
+
},
|
|
22
|
+
action: {
|
|
23
|
+
// 0 link 1 callback , 2 command
|
|
24
|
+
type: typeof options.data === 'object' ? 1 : options?.isLink ? 0 : 2,
|
|
25
|
+
permission: {
|
|
26
|
+
// 所有人
|
|
27
|
+
type: 2
|
|
28
|
+
// "specify_role_ids": ["1", "2", "3"]
|
|
29
|
+
},
|
|
30
|
+
// "click_limit": 10,
|
|
31
|
+
unsupport_tips: options?.toolTip ?? '',
|
|
32
|
+
data: options?.data ?? '',
|
|
33
|
+
// reply: true,
|
|
34
|
+
at_bot_show_channel_list: options.showList ?? false,
|
|
35
|
+
enter: options?.autoEnter ?? false
|
|
36
|
+
}
|
|
37
|
+
}
|
|
40
38
|
})
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
}
|
|
39
|
+
}
|
|
40
|
+
})
|
|
41
|
+
}
|
|
42
|
+
return data
|
|
43
|
+
}
|
|
44
44
|
const GROUP_AT_MESSAGE_CREATE = (client, event, val) => {
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
return `<@${item.value}>`;
|
|
60
|
-
}
|
|
61
|
-
return '';
|
|
45
|
+
const content = val
|
|
46
|
+
.filter(item => item.type == 'Mention' || item.type == 'Text')
|
|
47
|
+
.map(item => {
|
|
48
|
+
// if (item.type == 'Link') {
|
|
49
|
+
// return `[${item.options?.title ?? item.value}](${item.value})`
|
|
50
|
+
// } else
|
|
51
|
+
if (item.type == 'Mention') {
|
|
52
|
+
if (
|
|
53
|
+
item.value == 'everyone' ||
|
|
54
|
+
item.value == 'all' ||
|
|
55
|
+
item.value == '' ||
|
|
56
|
+
typeof item.value != 'string'
|
|
57
|
+
) {
|
|
58
|
+
return ``
|
|
62
59
|
}
|
|
63
|
-
|
|
64
|
-
|
|
60
|
+
if (item.options?.belong == 'user') {
|
|
61
|
+
return `<@${item.value}>`
|
|
65
62
|
}
|
|
63
|
+
return ''
|
|
64
|
+
} else if (item.type == 'Text') {
|
|
65
|
+
return item.value
|
|
66
|
+
}
|
|
66
67
|
})
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
68
|
+
.join('')
|
|
69
|
+
if (content) {
|
|
70
|
+
return Promise.all(
|
|
71
|
+
[content].map(item =>
|
|
72
|
+
client.groupOpenMessages(event.GuildId, {
|
|
73
|
+
content: item,
|
|
74
|
+
msg_id: event.MessageId,
|
|
75
|
+
msg_type: 0,
|
|
76
|
+
msg_seq: client.getMessageSeq(event.MessageId)
|
|
77
|
+
})
|
|
78
|
+
)
|
|
79
|
+
)
|
|
80
|
+
}
|
|
81
|
+
const images = val.filter(
|
|
82
|
+
item => item.type == 'Image' || item.type == 'ImageFile' || item.type == 'ImageURL'
|
|
83
|
+
)
|
|
84
|
+
if (images && images.length > 0) {
|
|
85
|
+
return Promise.all(
|
|
86
|
+
images.map(async item => {
|
|
87
|
+
if (item.type == 'ImageURL') {
|
|
88
|
+
return client.groupOpenMessages(event.GuildId, {
|
|
89
|
+
content: '',
|
|
90
|
+
media: {
|
|
91
|
+
file_info: item.value
|
|
92
|
+
},
|
|
71
93
|
msg_id: event.MessageId,
|
|
72
|
-
msg_type:
|
|
94
|
+
msg_type: 7,
|
|
73
95
|
msg_seq: client.getMessageSeq(event.MessageId)
|
|
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
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
return Promise.all(buttons.map(async (item) => {
|
|
116
|
-
const template_id = item?.options?.template_id;
|
|
117
|
-
if (template_id) {
|
|
118
|
-
return client.groupOpenMessages(event.GuildId, {
|
|
119
|
-
content: '',
|
|
120
|
-
msg_id: event.MessageId,
|
|
121
|
-
keyboard: {
|
|
122
|
-
id: template_id
|
|
123
|
-
},
|
|
124
|
-
msg_type: 2,
|
|
125
|
-
msg_seq: client.getMessageSeq(event.MessageId)
|
|
126
|
-
});
|
|
127
|
-
}
|
|
128
|
-
const rows = item.value;
|
|
129
|
-
// 构造成按钮
|
|
130
|
-
const data = createButtonsData(rows);
|
|
131
|
-
return client.groupOpenMessages(event.GuildId, {
|
|
132
|
-
content: '',
|
|
133
|
-
msg_id: event.MessageId,
|
|
134
|
-
keyboard: {
|
|
135
|
-
content: data
|
|
136
|
-
},
|
|
137
|
-
msg_type: 2,
|
|
138
|
-
msg_seq: client.getMessageSeq(event.MessageId)
|
|
139
|
-
});
|
|
140
|
-
}));
|
|
141
|
-
}
|
|
142
|
-
return Promise.all([]);
|
|
143
|
-
};
|
|
144
|
-
const C2C_MESSAGE_CREATE = (client, event, val) => {
|
|
145
|
-
const content = val
|
|
146
|
-
.filter(item => item.type == 'Mention' || item.type == 'Text')
|
|
147
|
-
.map(item => {
|
|
148
|
-
if (item.type == 'Text') {
|
|
149
|
-
return item.value;
|
|
96
|
+
})
|
|
97
|
+
}
|
|
98
|
+
const file_data =
|
|
99
|
+
item.type == 'ImageFile'
|
|
100
|
+
? readFileSync(item.value, 'base64')
|
|
101
|
+
: item.value.toString('base64')
|
|
102
|
+
const file_info = await client
|
|
103
|
+
.postRichMediaByGroup(event.GuildId, {
|
|
104
|
+
file_type: 1,
|
|
105
|
+
file_data: file_data
|
|
106
|
+
})
|
|
107
|
+
.then(res => res?.file_info)
|
|
108
|
+
if (!file_info) return Promise.resolve(null)
|
|
109
|
+
return client.groupOpenMessages(event.GuildId, {
|
|
110
|
+
content: '',
|
|
111
|
+
media: {
|
|
112
|
+
file_info
|
|
113
|
+
},
|
|
114
|
+
msg_id: event.MessageId,
|
|
115
|
+
msg_type: 7,
|
|
116
|
+
msg_seq: client.getMessageSeq(event.MessageId)
|
|
117
|
+
})
|
|
118
|
+
})
|
|
119
|
+
)
|
|
120
|
+
}
|
|
121
|
+
// buttons
|
|
122
|
+
const buttons = val.filter(item => item.type == 'BT.group')
|
|
123
|
+
if (buttons && buttons.length > 0) {
|
|
124
|
+
return Promise.all(
|
|
125
|
+
buttons.map(async item => {
|
|
126
|
+
const template_id = item?.options?.template_id
|
|
127
|
+
if (template_id) {
|
|
128
|
+
return client.groupOpenMessages(event.GuildId, {
|
|
129
|
+
content: '',
|
|
130
|
+
msg_id: event.MessageId,
|
|
131
|
+
keyboard: {
|
|
132
|
+
id: template_id
|
|
133
|
+
},
|
|
134
|
+
msg_type: 2,
|
|
135
|
+
msg_seq: client.getMessageSeq(event.MessageId)
|
|
136
|
+
})
|
|
150
137
|
}
|
|
151
|
-
|
|
138
|
+
const rows = item.value
|
|
139
|
+
// 构造成按钮
|
|
140
|
+
const data = createButtonsData(rows)
|
|
141
|
+
return client.groupOpenMessages(event.GuildId, {
|
|
142
|
+
content: '',
|
|
143
|
+
msg_id: event.MessageId,
|
|
144
|
+
keyboard: {
|
|
145
|
+
content: data
|
|
146
|
+
},
|
|
147
|
+
msg_type: 2,
|
|
148
|
+
msg_seq: client.getMessageSeq(event.MessageId)
|
|
149
|
+
})
|
|
150
|
+
})
|
|
151
|
+
)
|
|
152
|
+
}
|
|
153
|
+
return Promise.all([])
|
|
154
|
+
}
|
|
155
|
+
const C2C_MESSAGE_CREATE = (client, event, val) => {
|
|
156
|
+
const content = val
|
|
157
|
+
.filter(item => item.type == 'Mention' || item.type == 'Text')
|
|
158
|
+
.map(item => {
|
|
159
|
+
if (item.type == 'Text') {
|
|
160
|
+
return item.value
|
|
161
|
+
}
|
|
162
|
+
return ''
|
|
152
163
|
})
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
164
|
+
.join('')
|
|
165
|
+
if (content) {
|
|
166
|
+
return Promise.all(
|
|
167
|
+
[content].map(item =>
|
|
168
|
+
client.usersOpenMessages(event.OpenId, {
|
|
169
|
+
content: item,
|
|
170
|
+
msg_id: event.MessageId,
|
|
171
|
+
msg_type: 0,
|
|
172
|
+
msg_seq: client.getMessageSeq(event.MessageId)
|
|
173
|
+
})
|
|
174
|
+
)
|
|
175
|
+
)
|
|
176
|
+
}
|
|
177
|
+
const images = val.filter(
|
|
178
|
+
item => item.type == 'Image' || item.type == 'ImageFile' || item.type == 'ImageURL'
|
|
179
|
+
)
|
|
180
|
+
if (images && images.length > 0) {
|
|
181
|
+
return Promise.all(
|
|
182
|
+
images.map(async item => {
|
|
183
|
+
if (item.type == 'ImageURL') {
|
|
184
|
+
return client.usersOpenMessages(event.OpenId, {
|
|
185
|
+
content: '',
|
|
186
|
+
media: {
|
|
187
|
+
file_info: item.value
|
|
188
|
+
},
|
|
157
189
|
msg_id: event.MessageId,
|
|
158
|
-
msg_type:
|
|
190
|
+
msg_type: 7,
|
|
159
191
|
msg_seq: client.getMessageSeq(event.MessageId)
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
msg_id: event.MessageId,
|
|
224
|
-
keyboard: {
|
|
225
|
-
content: data
|
|
226
|
-
},
|
|
227
|
-
msg_type: 2,
|
|
228
|
-
msg_seq: client.getMessageSeq(event.MessageId)
|
|
229
|
-
});
|
|
230
|
-
}));
|
|
231
|
-
}
|
|
232
|
-
return Promise.all([]);
|
|
233
|
-
};
|
|
192
|
+
})
|
|
193
|
+
}
|
|
194
|
+
const file_data =
|
|
195
|
+
item.type == 'ImageFile'
|
|
196
|
+
? readFileSync(item.value, 'base64')
|
|
197
|
+
: item.value.toString('base64')
|
|
198
|
+
const file_info = await client
|
|
199
|
+
.postRichMediaByUsers(event.OpenId, {
|
|
200
|
+
file_type: 1,
|
|
201
|
+
file_data: file_data
|
|
202
|
+
})
|
|
203
|
+
.then(res => res?.file_info)
|
|
204
|
+
if (!file_info) return Promise.resolve(null)
|
|
205
|
+
return client.usersOpenMessages(event.OpenId, {
|
|
206
|
+
content: '',
|
|
207
|
+
media: {
|
|
208
|
+
file_info
|
|
209
|
+
},
|
|
210
|
+
msg_id: event.MessageId,
|
|
211
|
+
msg_type: 7,
|
|
212
|
+
msg_seq: client.getMessageSeq(event.MessageId)
|
|
213
|
+
})
|
|
214
|
+
})
|
|
215
|
+
)
|
|
216
|
+
}
|
|
217
|
+
// buttons
|
|
218
|
+
const buttons = val.filter(item => item.type == 'BT.group')
|
|
219
|
+
if (buttons && buttons.length > 0) {
|
|
220
|
+
return Promise.all(
|
|
221
|
+
buttons.map(async item => {
|
|
222
|
+
const template_id = item?.options?.template_id
|
|
223
|
+
if (template_id) {
|
|
224
|
+
return client.groupOpenMessages(event.GuildId, {
|
|
225
|
+
content: '',
|
|
226
|
+
msg_id: event.MessageId,
|
|
227
|
+
keyboard: {
|
|
228
|
+
id: template_id
|
|
229
|
+
},
|
|
230
|
+
msg_type: 2,
|
|
231
|
+
msg_seq: client.getMessageSeq(event.MessageId)
|
|
232
|
+
})
|
|
233
|
+
}
|
|
234
|
+
const rows = item.value
|
|
235
|
+
// 看看是否是模板id的
|
|
236
|
+
rows.map(row => {
|
|
237
|
+
return row
|
|
238
|
+
})
|
|
239
|
+
// 构造成按钮
|
|
240
|
+
const data = createButtonsData(rows)
|
|
241
|
+
return client.groupOpenMessages(event.GuildId, {
|
|
242
|
+
content: '',
|
|
243
|
+
msg_id: event.MessageId,
|
|
244
|
+
keyboard: {
|
|
245
|
+
content: data
|
|
246
|
+
},
|
|
247
|
+
msg_type: 2,
|
|
248
|
+
msg_seq: client.getMessageSeq(event.MessageId)
|
|
249
|
+
})
|
|
250
|
+
})
|
|
251
|
+
)
|
|
252
|
+
}
|
|
253
|
+
return Promise.all([])
|
|
254
|
+
}
|
|
234
255
|
/**
|
|
235
256
|
* 频道私聊
|
|
236
257
|
* @param client
|
|
@@ -239,102 +260,118 @@ const C2C_MESSAGE_CREATE = (client, event, val) => {
|
|
|
239
260
|
* @returns
|
|
240
261
|
*/
|
|
241
262
|
const DIRECT_MESSAGE_CREATE = (client, event, val) => {
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
263
|
+
const content = val
|
|
264
|
+
.filter(item => item.type == 'Mention' || item.type == 'Text')
|
|
265
|
+
.map(item => {
|
|
266
|
+
if (item.type == 'Text') {
|
|
267
|
+
return item.value
|
|
268
|
+
}
|
|
269
|
+
return ''
|
|
249
270
|
})
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
271
|
+
.join('')
|
|
272
|
+
if (content) {
|
|
273
|
+
return Promise.all(
|
|
274
|
+
[content].map(item =>
|
|
275
|
+
client.dmsMessage(event.OpenId, {
|
|
276
|
+
content: item,
|
|
277
|
+
msg_id: event.MessageId
|
|
278
|
+
})
|
|
279
|
+
)
|
|
280
|
+
)
|
|
281
|
+
}
|
|
282
|
+
const images = val.filter(
|
|
283
|
+
item => item.type == 'Image' || item.type == 'ImageFile' || item.type == 'ImageURL'
|
|
284
|
+
)
|
|
285
|
+
if (images) {
|
|
286
|
+
return Promise.all(
|
|
287
|
+
images.map(async item => {
|
|
288
|
+
if (item.value == 'ImageURL') {
|
|
289
|
+
// 请求得到buffer
|
|
290
|
+
const data = await axios
|
|
291
|
+
.get(item.value, {
|
|
292
|
+
responseType: 'arraybuffer'
|
|
293
|
+
})
|
|
294
|
+
.then(res => res.data)
|
|
295
|
+
return client.postDirectImage(event.OpenId, {
|
|
296
|
+
msg_id: event.MessageId,
|
|
297
|
+
image: data
|
|
298
|
+
})
|
|
299
|
+
}
|
|
300
|
+
const file_data = item.type == 'ImageFile' ? readFileSync(item.value) : item.value
|
|
301
|
+
return client.postDirectImage(event.OpenId, {
|
|
302
|
+
msg_id: event.MessageId,
|
|
303
|
+
image: Buffer.isBuffer(file_data) ? file_data : Buffer.from(file_data)
|
|
304
|
+
})
|
|
305
|
+
})
|
|
306
|
+
)
|
|
307
|
+
}
|
|
308
|
+
return []
|
|
309
|
+
}
|
|
281
310
|
const AT_MESSAGE_CREATE = (client, event, val) => {
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
return `<@!${item.value}>`;
|
|
297
|
-
}
|
|
298
|
-
else if (item.options?.belong == 'channel') {
|
|
299
|
-
return `<#${item.value}>`;
|
|
300
|
-
}
|
|
301
|
-
return '';
|
|
311
|
+
const content = val
|
|
312
|
+
.filter(item => item.type == 'Mention' || item.type == 'Text')
|
|
313
|
+
.map(item => {
|
|
314
|
+
// if (item.type == 'Link') {
|
|
315
|
+
// return `[${item.options?.title ?? item.value}](${item.value})`
|
|
316
|
+
// } else
|
|
317
|
+
if (item.type == 'Mention') {
|
|
318
|
+
if (
|
|
319
|
+
item.value == 'everyone' ||
|
|
320
|
+
item.value == 'all' ||
|
|
321
|
+
item.value == '' ||
|
|
322
|
+
typeof item.value != 'string'
|
|
323
|
+
) {
|
|
324
|
+
return `@everyone`
|
|
302
325
|
}
|
|
303
|
-
|
|
304
|
-
|
|
326
|
+
if (item.options?.belong == 'user') {
|
|
327
|
+
return `<@!${item.value}>`
|
|
328
|
+
} else if (item.options?.belong == 'channel') {
|
|
329
|
+
return `<#${item.value}>`
|
|
305
330
|
}
|
|
331
|
+
return ''
|
|
332
|
+
} else if (item.type == 'Text') {
|
|
333
|
+
return item.value
|
|
334
|
+
}
|
|
306
335
|
})
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
336
|
+
.join('')
|
|
337
|
+
if (content) {
|
|
338
|
+
return Promise.all(
|
|
339
|
+
[content].map(item =>
|
|
340
|
+
client.channelsMessagesPost(event.ChannelId, {
|
|
341
|
+
content: item,
|
|
342
|
+
msg_id: event.MessageId
|
|
343
|
+
})
|
|
344
|
+
)
|
|
345
|
+
)
|
|
346
|
+
}
|
|
347
|
+
const images = val.filter(
|
|
348
|
+
item => item.type == 'Image' || item.type == 'ImageFile' || item.type == 'ImageURL'
|
|
349
|
+
)
|
|
350
|
+
if (images && images.length > 0) {
|
|
351
|
+
return Promise.all(
|
|
352
|
+
images.map(async item => {
|
|
353
|
+
if (item.value == 'ImageURL') {
|
|
354
|
+
// 请求得到buffer
|
|
355
|
+
const data = await axios
|
|
356
|
+
.get(item.value, {
|
|
357
|
+
responseType: 'arraybuffer'
|
|
358
|
+
})
|
|
359
|
+
.then(res => res.data)
|
|
360
|
+
return client.postImage(event.ChannelId, {
|
|
361
|
+
msg_id: event.MessageId,
|
|
362
|
+
image: data
|
|
363
|
+
})
|
|
364
|
+
}
|
|
365
|
+
const file_data = item.type == 'ImageFile' ? readFileSync(item.value) : item.value
|
|
366
|
+
return client.postImage(event.ChannelId, {
|
|
367
|
+
msg_id: event.MessageId,
|
|
368
|
+
image: Buffer.isBuffer(file_data) ? file_data : Buffer.from(file_data)
|
|
369
|
+
})
|
|
370
|
+
})
|
|
371
|
+
)
|
|
372
|
+
}
|
|
373
|
+
return Promise.all([])
|
|
374
|
+
}
|
|
338
375
|
/**
|
|
339
376
|
*
|
|
340
377
|
* @param event
|
|
@@ -342,61 +379,75 @@ const AT_MESSAGE_CREATE = (client, event, val) => {
|
|
|
342
379
|
* @returns
|
|
343
380
|
*/
|
|
344
381
|
const MESSAGE_CREATE = (client, event, val) => {
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
return `<@!${item.value}>`;
|
|
360
|
-
}
|
|
361
|
-
else if (item.options?.belong == 'channel') {
|
|
362
|
-
return `<#${item.value}>`;
|
|
363
|
-
}
|
|
364
|
-
return '';
|
|
382
|
+
const content = val
|
|
383
|
+
.filter(item => item.type == 'Mention' || item.type == 'Text')
|
|
384
|
+
.map(item => {
|
|
385
|
+
// if (item.type == 'Link') {
|
|
386
|
+
// return `[${item.options?.title ?? item.value}](${item.value})`
|
|
387
|
+
// } else
|
|
388
|
+
if (item.type == 'Mention') {
|
|
389
|
+
if (
|
|
390
|
+
item.value == 'everyone' ||
|
|
391
|
+
item.value == 'all' ||
|
|
392
|
+
item.value == '' ||
|
|
393
|
+
typeof item.value != 'string'
|
|
394
|
+
) {
|
|
395
|
+
return `@everyone`
|
|
365
396
|
}
|
|
366
|
-
|
|
367
|
-
|
|
397
|
+
if (item.options?.belong == 'user') {
|
|
398
|
+
return `<@!${item.value}>`
|
|
399
|
+
} else if (item.options?.belong == 'channel') {
|
|
400
|
+
return `<#${item.value}>`
|
|
368
401
|
}
|
|
402
|
+
return ''
|
|
403
|
+
} else if (item.type == 'Text') {
|
|
404
|
+
return item.value
|
|
405
|
+
}
|
|
369
406
|
})
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
407
|
+
.join('')
|
|
408
|
+
if (content) {
|
|
409
|
+
return Promise.all(
|
|
410
|
+
[content].map(item =>
|
|
411
|
+
client.channelsMessagesPost(event.ChannelId, {
|
|
412
|
+
content: item,
|
|
413
|
+
msg_id: event.MessageId
|
|
414
|
+
})
|
|
415
|
+
)
|
|
416
|
+
)
|
|
417
|
+
}
|
|
418
|
+
const images = val.filter(
|
|
419
|
+
item => item.type == 'Image' || item.type == 'ImageFile' || item.type == 'ImageURL'
|
|
420
|
+
)
|
|
421
|
+
if (images && images.length > 0) {
|
|
422
|
+
return Promise.all(
|
|
423
|
+
images.map(async item => {
|
|
424
|
+
if (item.value == 'ImageURL') {
|
|
425
|
+
// 请求得到buffer
|
|
426
|
+
const data = await axios
|
|
427
|
+
.get(item.value, {
|
|
428
|
+
responseType: 'arraybuffer'
|
|
429
|
+
})
|
|
430
|
+
.then(res => res.data)
|
|
431
|
+
return client.postImage(event.ChannelId, {
|
|
432
|
+
msg_id: event.MessageId,
|
|
433
|
+
image: data
|
|
434
|
+
})
|
|
435
|
+
}
|
|
436
|
+
const file_data = item.type == 'ImageFile' ? readFileSync(item.value) : item.value
|
|
437
|
+
return client.postImage(event.ChannelId, {
|
|
438
|
+
msg_id: event.MessageId,
|
|
439
|
+
image: Buffer.isBuffer(file_data) ? file_data : Buffer.from(file_data)
|
|
440
|
+
})
|
|
441
|
+
})
|
|
442
|
+
)
|
|
443
|
+
}
|
|
444
|
+
return Promise.all([])
|
|
445
|
+
}
|
|
401
446
|
|
|
402
|
-
export {
|
|
447
|
+
export {
|
|
448
|
+
AT_MESSAGE_CREATE,
|
|
449
|
+
C2C_MESSAGE_CREATE,
|
|
450
|
+
DIRECT_MESSAGE_CREATE,
|
|
451
|
+
GROUP_AT_MESSAGE_CREATE,
|
|
452
|
+
MESSAGE_CREATE
|
|
453
|
+
}
|