@alemonjs/qq-bot 2.1.0-alpha.8 → 2.1.0
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 +13 -45
- package/lib/config.d.ts +8 -0
- package/lib/config.js +20 -0
- package/lib/desktop.d.ts +1 -3
- package/lib/desktop.js +3 -12
- package/lib/hook.d.ts +36 -9
- package/lib/hook.js +21 -19
- package/lib/index.d.ts +5 -7
- package/lib/index.js +11 -21
- package/lib/index.webhook.d.ts +1 -0
- package/lib/index.webhook.js +5 -4
- package/lib/index.websoket.d.ts +1 -0
- package/lib/index.websoket.js +31 -23
- package/lib/message/AT_MESSAGE_CREATE.d.ts +35 -0
- package/lib/message/AT_MESSAGE_CREATE.js +1 -0
- package/lib/message/CHANNEL_CREATE.d.ts +15 -0
- package/lib/message/CHANNEL_CREATE.js +1 -0
- package/lib/message/CHANNEL_DELETE.d.ts +15 -0
- package/lib/message/CHANNEL_DELETE.js +1 -0
- package/lib/message/CHANNEL_UPDATE.d.ts +15 -0
- package/lib/message/CHANNEL_UPDATE.js +1 -0
- package/lib/message/DIRECT_MESSAGE_CREATE.d.ts +29 -0
- package/lib/message/DIRECT_MESSAGE_CREATE.js +1 -0
- package/lib/message/DIRECT_MESSAGE_DELETE.d.ts +17 -0
- package/lib/message/DIRECT_MESSAGE_DELETE.js +1 -0
- package/lib/message/ERROR.d.ts +1 -0
- package/lib/message/ERROR.js +1 -0
- package/lib/message/GUILD_CREATE.d.ts +15 -0
- package/lib/message/GUILD_CREATE.js +1 -0
- package/lib/message/GUILD_DELETE.d.ts +15 -0
- package/lib/message/GUILD_DELETE.js +1 -0
- package/lib/message/GUILD_MEMBER_ADD.d.ts +14 -0
- package/lib/message/GUILD_MEMBER_ADD.js +1 -0
- package/lib/message/GUILD_MEMBER_REMOVE.d.ts +14 -0
- package/lib/message/GUILD_MEMBER_REMOVE.js +1 -0
- package/lib/message/GUILD_MEMBER_UPDATE.d.ts +14 -0
- package/lib/message/GUILD_MEMBER_UPDATE.js +1 -0
- package/lib/message/GUILD_UPDATE.d.ts +15 -0
- package/lib/message/GUILD_UPDATE.js +1 -0
- package/lib/message/INTERACTION_CREATE.d.ts +53 -0
- package/lib/message/INTERACTION_CREATE.js +1 -0
- package/lib/message/MESSAGE_CREATE.d.ts +1 -0
- package/lib/message/MESSAGE_CREATE.js +1 -0
- package/lib/message/MESSAGE_DELETE.d.ts +1 -0
- package/lib/message/MESSAGE_DELETE.js +1 -0
- package/lib/message/MESSAGE_REACTION_ADD.d.ts +13 -0
- package/lib/message/MESSAGE_REACTION_ADD.js +1 -0
- package/lib/message/MESSAGE_REACTION_REMOVE.d.ts +13 -0
- package/lib/message/MESSAGE_REACTION_REMOVE.js +1 -0
- package/lib/message/PUBLIC_MESSAGE_DELETE.d.ts +15 -0
- package/lib/message/PUBLIC_MESSAGE_DELETE.js +1 -0
- package/lib/message/READY.d.ts +6 -0
- package/lib/message/READY.js +1 -0
- package/lib/message/group/C2C_MESSAGE_CREATE.d.ts +9 -0
- package/lib/message/group/C2C_MESSAGE_CREATE.js +1 -0
- package/lib/message/group/C2C_MSG_RECEIVE.d.ts +4 -0
- package/lib/message/group/C2C_MSG_RECEIVE.js +1 -0
- package/lib/message/group/C2C_MSG_REJECT.d.ts +4 -0
- package/lib/message/group/C2C_MSG_REJECT.js +1 -0
- package/lib/message/group/FRIEND_ADD.d.ts +4 -0
- package/lib/message/group/FRIEND_ADD.js +1 -0
- package/lib/message/group/FRIEND_DEL.d.ts +4 -0
- package/lib/message/group/FRIEND_DEL.js +1 -0
- package/lib/message/group/GROUP_ADD_ROBOT.d.ts +5 -0
- package/lib/message/group/GROUP_ADD_ROBOT.js +1 -0
- package/lib/message/group/GROUP_AT_MESSAGE_CREATE.d.ts +11 -0
- package/lib/message/group/GROUP_AT_MESSAGE_CREATE.js +1 -0
- package/lib/message/group/GROUP_DEL_ROBOT.d.ts +5 -0
- package/lib/message/group/GROUP_DEL_ROBOT.js +1 -0
- package/lib/message/group/GROUP_MSG_RECEIVE.d.ts +5 -0
- package/lib/message/group/GROUP_MSG_RECEIVE.js +1 -0
- package/lib/message/group/GROUP_MSG_REJECT.d.ts +5 -0
- package/lib/message/group/GROUP_MSG_REJECT.js +1 -0
- package/lib/register.d.ts +2 -3
- package/lib/register.js +427 -252
- package/lib/sdk/api.d.ts +10 -567
- package/lib/sdk/api.js +234 -796
- package/lib/sdk/client.webhook.d.ts +9 -0
- package/lib/sdk/{client.js → client.webhook.js} +18 -55
- package/lib/sdk/client.websoket.d.ts +9 -0
- package/lib/sdk/client.websoket.js +52 -97
- package/lib/sdk/config.d.ts +1 -0
- package/lib/sdk/instance.d.ts +3 -0
- package/lib/sdk/instance.js +93 -0
- package/lib/sdk/intents.d.ts +3 -0
- package/lib/sdk/intents.js +25 -90
- package/lib/sdk/message.d.ts +4 -0
- package/lib/sdk/message.group.d.ts +24 -0
- package/lib/sdk/message.group.js +1 -0
- package/lib/sdk/message.guild.d.ts +38 -0
- package/lib/sdk/message.guild.js +1 -0
- package/lib/sdk/message.js +1 -0
- package/lib/sdk/message.public.d.ts +6 -0
- package/lib/sdk/message.public.js +1 -0
- package/lib/sdk/typing.d.ts +22 -11
- package/lib/sdk/typing.js +1 -0
- package/lib/sdk/webhook.secret.d.ts +14 -0
- package/lib/sdk/webhook.secret.js +6 -21
- package/lib/sends.d.ts +29 -0
- package/lib/sends.js +326 -745
- package/lib/utils.d.ts +1 -0
- package/lib/utils.js +7 -12
- package/package.json +9 -5
- package/lib/index.group.js +0 -19
- package/lib/index.guild.js +0 -36
- package/lib/sdk/client.websoket.group.js +0 -221
- package/lib/sdk/client.websoket.guild.js +0 -205
- package/lib/sdk/counter.js +0 -19
- package/lib/sdk/from.js +0 -44
package/lib/sends.js
CHANGED
|
@@ -2,150 +2,80 @@ import { readFileSync } from 'fs';
|
|
|
2
2
|
import { createResult, ResultCode } from 'alemonjs';
|
|
3
3
|
import axios from 'axios';
|
|
4
4
|
|
|
5
|
-
const
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
return {
|
|
11
|
-
buttons: val.map(button => {
|
|
12
|
-
const value = button.value;
|
|
13
|
-
const options = button.options;
|
|
14
|
-
id++;
|
|
15
|
-
const typing = options?.type ?? 'command';
|
|
16
|
-
const map = {
|
|
17
|
-
command: 2,
|
|
18
|
-
link: 0,
|
|
19
|
-
call: 1
|
|
20
|
-
};
|
|
21
|
-
return {
|
|
22
|
-
id: String(id),
|
|
23
|
-
render_data: {
|
|
24
|
-
label: typeof value == 'object' ? value.title : value,
|
|
25
|
-
visited_label: typeof value == 'object' ? value.label : value,
|
|
26
|
-
style: 0
|
|
27
|
-
},
|
|
28
|
-
action: {
|
|
29
|
-
// 0 link 1 callback , 2 command
|
|
30
|
-
type: map[typing],
|
|
31
|
-
permission: {
|
|
32
|
-
// 所有人
|
|
33
|
-
type: 2
|
|
34
|
-
// "specify_role_ids": ["1", "2", "3"]
|
|
35
|
-
},
|
|
36
|
-
// "click_limit": 10,
|
|
37
|
-
unsupport_tips: options?.toolTip ?? '',
|
|
38
|
-
data: options?.data ?? '',
|
|
39
|
-
// reply: true,
|
|
40
|
-
at_bot_show_channel_list: options.showList ?? false,
|
|
41
|
-
enter: options?.autoEnter ?? false
|
|
42
|
-
}
|
|
43
|
-
};
|
|
44
|
-
})
|
|
45
|
-
};
|
|
46
|
-
})
|
|
47
|
-
};
|
|
48
|
-
return data;
|
|
49
|
-
};
|
|
50
|
-
const createArkCardData = (value) => {
|
|
5
|
+
const MAX_BUTTON_ROWS = 5;
|
|
6
|
+
const MAX_BUTTONS_PER_ROW = 5;
|
|
7
|
+
const createButtonsData = (rows, startId = 0) => {
|
|
8
|
+
let id = startId;
|
|
9
|
+
const clippedRows = rows.slice(0, MAX_BUTTON_ROWS);
|
|
51
10
|
return {
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
{
|
|
79
|
-
key: '#SUBTITLE#',
|
|
80
|
-
value: value.subtitle
|
|
81
|
-
}
|
|
82
|
-
]
|
|
83
|
-
};
|
|
84
|
-
};
|
|
85
|
-
const createArkBigCardData = (value) => {
|
|
86
|
-
return {
|
|
87
|
-
template_id: 37,
|
|
88
|
-
kv: [
|
|
89
|
-
{
|
|
90
|
-
key: '#PROMPT#',
|
|
91
|
-
value: value.prompt
|
|
92
|
-
},
|
|
93
|
-
{
|
|
94
|
-
key: '#METATITLE#',
|
|
95
|
-
value: value.title
|
|
96
|
-
},
|
|
97
|
-
{
|
|
98
|
-
key: '#METASUBTITLE#',
|
|
99
|
-
value: value.subtitle
|
|
100
|
-
},
|
|
101
|
-
{
|
|
102
|
-
key: '#METACOVER#',
|
|
103
|
-
value: value.cover
|
|
104
|
-
},
|
|
105
|
-
{
|
|
106
|
-
key: '#METAURL#',
|
|
107
|
-
value: value.link
|
|
108
|
-
}
|
|
109
|
-
]
|
|
11
|
+
rows: clippedRows.map(row => ({
|
|
12
|
+
buttons: row.value.slice(0, MAX_BUTTONS_PER_ROW).map(button => {
|
|
13
|
+
const value = button.value;
|
|
14
|
+
const options = button.options;
|
|
15
|
+
id++;
|
|
16
|
+
const typing = options?.type ?? 'command';
|
|
17
|
+
const typeMap = { command: 2, link: 0, call: 1 };
|
|
18
|
+
return {
|
|
19
|
+
id: String(id),
|
|
20
|
+
render_data: {
|
|
21
|
+
label: value,
|
|
22
|
+
visited_label: value,
|
|
23
|
+
style: 0
|
|
24
|
+
},
|
|
25
|
+
action: {
|
|
26
|
+
type: typeMap[typing],
|
|
27
|
+
permission: { type: 2 },
|
|
28
|
+
unsupport_tips: options?.toolTip ?? '',
|
|
29
|
+
data: options?.data ?? '',
|
|
30
|
+
at_bot_show_channel_list: false,
|
|
31
|
+
enter: options?.autoEnter ?? false
|
|
32
|
+
}
|
|
33
|
+
};
|
|
34
|
+
})
|
|
35
|
+
})),
|
|
36
|
+
nextId: id
|
|
110
37
|
};
|
|
111
38
|
};
|
|
112
|
-
const
|
|
39
|
+
const createArkCardData = (value) => ({
|
|
40
|
+
template_id: 24,
|
|
41
|
+
kv: [
|
|
42
|
+
{ key: '#DESC#', value: value.decs },
|
|
43
|
+
{ key: '#PROMPT#', value: value.prompt },
|
|
44
|
+
{ key: '#TITLE#', value: value.title },
|
|
45
|
+
{ key: '#METADESC#', value: value.metadecs },
|
|
46
|
+
{ key: '#IMG#', value: value.cover },
|
|
47
|
+
{ key: '#LINK#', value: value.link },
|
|
48
|
+
{ key: '#SUBTITLE#', value: value.subtitle }
|
|
49
|
+
]
|
|
50
|
+
});
|
|
51
|
+
const createArkBigCardData = (value) => ({
|
|
52
|
+
template_id: 37,
|
|
53
|
+
kv: [
|
|
54
|
+
{ key: '#PROMPT#', value: value.prompt },
|
|
55
|
+
{ key: '#METATITLE#', value: value.title },
|
|
56
|
+
{ key: '#METASUBTITLE#', value: value.subtitle },
|
|
57
|
+
{ key: '#METACOVER#', value: value.cover },
|
|
58
|
+
{ key: '#METAURL#', value: value.link }
|
|
59
|
+
]
|
|
60
|
+
});
|
|
61
|
+
const createArkListData = (value) => {
|
|
113
62
|
const [tip, data] = value;
|
|
114
63
|
return {
|
|
115
64
|
template_id: 23,
|
|
116
65
|
kv: [
|
|
117
|
-
{
|
|
118
|
-
|
|
119
|
-
value: tip.value.desc
|
|
120
|
-
},
|
|
121
|
-
{
|
|
122
|
-
key: '#PROMPT#',
|
|
123
|
-
value: tip.value.prompt
|
|
124
|
-
},
|
|
66
|
+
{ key: '#DESC#', value: tip.value.desc },
|
|
67
|
+
{ key: '#PROMPT#', value: tip.value.prompt },
|
|
125
68
|
{
|
|
126
69
|
key: '#LIST#',
|
|
127
70
|
obj: data.value.map(item => {
|
|
128
|
-
const
|
|
129
|
-
if (typeof
|
|
130
|
-
return {
|
|
131
|
-
obj_kv: [
|
|
132
|
-
{
|
|
133
|
-
key: 'desc',
|
|
134
|
-
value: value
|
|
135
|
-
}
|
|
136
|
-
]
|
|
137
|
-
};
|
|
71
|
+
const v = item.value;
|
|
72
|
+
if (typeof v === 'string') {
|
|
73
|
+
return { obj_kv: [{ key: 'desc', value: v }] };
|
|
138
74
|
}
|
|
139
75
|
return {
|
|
140
76
|
obj_kv: [
|
|
141
|
-
{
|
|
142
|
-
|
|
143
|
-
value: value.title
|
|
144
|
-
},
|
|
145
|
-
{
|
|
146
|
-
key: 'link',
|
|
147
|
-
value: value.link
|
|
148
|
-
}
|
|
77
|
+
{ key: 'desc', value: v.title },
|
|
78
|
+
{ key: 'link', value: v.link }
|
|
149
79
|
]
|
|
150
80
|
};
|
|
151
81
|
})
|
|
@@ -153,680 +83,331 @@ const createArkList = (value) => {
|
|
|
153
83
|
]
|
|
154
84
|
};
|
|
155
85
|
};
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
86
|
+
const mdFormatters = {
|
|
87
|
+
'MD.title': value => `# ${value}`,
|
|
88
|
+
'MD.subtitle': value => `## ${value}`,
|
|
89
|
+
'MD.text': value => `${value} `,
|
|
90
|
+
'MD.bold': value => `**${value}** `,
|
|
91
|
+
'MD.divider': () => '\n————————\n',
|
|
92
|
+
'MD.italic': value => `_${value}_ `,
|
|
93
|
+
'MD.italicStar': value => `*${value}* `,
|
|
94
|
+
'MD.strikethrough': value => `~~${value}~~ `,
|
|
95
|
+
'MD.blockquote': value => `\n> ${value}`,
|
|
96
|
+
'MD.newline': () => '\n',
|
|
97
|
+
'MD.link': value => `[🔗${value.text}](${value.url}) `,
|
|
98
|
+
'MD.image': (value, options) => `\n\n`,
|
|
99
|
+
'MD.mention': (value, options) => {
|
|
100
|
+
const { belong } = options || {};
|
|
101
|
+
if (belong === 'channel') {
|
|
102
|
+
return '';
|
|
163
103
|
}
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
return `## ${mdItem.value}\n`;
|
|
104
|
+
if (belong === 'user') {
|
|
105
|
+
return `<qqbot-at-user id="${value}" />`;
|
|
167
106
|
}
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
return `${mdItem.value} `;
|
|
107
|
+
if (value === 'everyone') {
|
|
108
|
+
return '<qqbot-at-everyone />';
|
|
171
109
|
}
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
110
|
+
return `<qqbot-at-user id="${value}" />`;
|
|
111
|
+
},
|
|
112
|
+
'MD.content': value => `${value}`,
|
|
113
|
+
'MD.button': (title, options) => {
|
|
114
|
+
const { data } = options || {};
|
|
115
|
+
return `<qqbot-cmd-input text="${data}" show="${title}" />`;
|
|
116
|
+
}
|
|
117
|
+
};
|
|
118
|
+
const createMarkdownText = (data) => {
|
|
119
|
+
return data
|
|
120
|
+
.map(mdItem => {
|
|
121
|
+
if (mdFormatters[mdItem.type]) {
|
|
122
|
+
return mdFormatters[mdItem.type](mdItem?.value, mdItem?.options);
|
|
175
123
|
}
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
124
|
+
if (mdItem.type === 'MD.list' && typeof mdItem.value !== 'string') {
|
|
125
|
+
const listStr = mdItem.value.map(listItem => {
|
|
126
|
+
return typeof listItem.value === 'object' ? `\n${listItem.value.index}. ${listItem.value.text}` : `\n- ${listItem.value}`;
|
|
127
|
+
});
|
|
128
|
+
return `${listStr.join('')}\n`;
|
|
179
129
|
}
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
return
|
|
130
|
+
if (mdItem.type === 'MD.code') {
|
|
131
|
+
const language = mdItem?.options?.language || '';
|
|
132
|
+
return `\n\`\`\`${language}\n${mdItem.value}\n\`\`\`\n`;
|
|
183
133
|
}
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
134
|
+
return String(mdItem['value'] || '');
|
|
135
|
+
})
|
|
136
|
+
.join('');
|
|
137
|
+
};
|
|
138
|
+
const formatMention = (item, mode) => {
|
|
139
|
+
if (mode === 'guild-direct') {
|
|
140
|
+
return '';
|
|
141
|
+
}
|
|
142
|
+
const value = item.value;
|
|
143
|
+
const isEmptyMention = value === 'everyone' || value === 'all' || value === '' || typeof value !== 'string';
|
|
144
|
+
if (mode === 'guild-public') {
|
|
145
|
+
if (isEmptyMention) {
|
|
146
|
+
return '@everyone';
|
|
187
147
|
}
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
return `~~${mdItem.value}~~ `;
|
|
148
|
+
if (item.options?.belong === 'user') {
|
|
149
|
+
return `<@!${value}>`;
|
|
191
150
|
}
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
return `> ${mdItem.value}\n`;
|
|
151
|
+
if (item.options?.belong === 'channel') {
|
|
152
|
+
return `<#${value}>`;
|
|
195
153
|
}
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
154
|
+
return '';
|
|
155
|
+
}
|
|
156
|
+
if (isEmptyMention) {
|
|
157
|
+
return '';
|
|
158
|
+
}
|
|
159
|
+
if (item.options?.belong === 'user') {
|
|
160
|
+
return `<@${value}>`;
|
|
161
|
+
}
|
|
162
|
+
return '';
|
|
163
|
+
};
|
|
164
|
+
const extractContent = (val, mode) => {
|
|
165
|
+
return val
|
|
166
|
+
.filter(item => item.type === 'Mention' || item.type === 'Text' || item.type === 'Link')
|
|
167
|
+
.map(item => {
|
|
168
|
+
if (item.type === 'Link') {
|
|
169
|
+
return `[${item.value}](${item?.options?.link})`;
|
|
199
170
|
}
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
return `[🔗${mdItem.value.text}](${mdItem.value.url}) `;
|
|
171
|
+
if (item.type === 'Mention') {
|
|
172
|
+
return formatMention(item, mode);
|
|
203
173
|
}
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
return ` `;
|
|
174
|
+
if (item.type === 'Text') {
|
|
175
|
+
return item.value;
|
|
207
176
|
}
|
|
208
|
-
|
|
209
|
-
const listStr = mdItem.value.map(listItem => {
|
|
210
|
-
// 有序
|
|
211
|
-
if (typeof listItem.value === 'object') {
|
|
212
|
-
return `\n${listItem.value.index}. ${listItem.value.text}`;
|
|
213
|
-
}
|
|
214
|
-
// 无序
|
|
215
|
-
return `\n- ${listItem.value}`;
|
|
216
|
-
});
|
|
217
|
-
return `${listStr}\n`;
|
|
218
|
-
}
|
|
219
|
-
return;
|
|
177
|
+
return '';
|
|
220
178
|
})
|
|
221
179
|
.join('');
|
|
222
|
-
return content;
|
|
223
180
|
};
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
* @param event
|
|
228
|
-
* @param val
|
|
229
|
-
* @returns
|
|
230
|
-
*/
|
|
231
|
-
const GROUP_AT_MESSAGE_CREATE = async (client, event, val) => {
|
|
232
|
-
const baseParams = {};
|
|
233
|
-
if (event.tag === 'INTERACTION_CREATE_GROUP') {
|
|
234
|
-
baseParams['event_id'] = event.MessageId;
|
|
181
|
+
const buildBaseParams = (tag, messageId, interactionTag) => {
|
|
182
|
+
if (tag === interactionTag) {
|
|
183
|
+
return { event_id: messageId };
|
|
235
184
|
}
|
|
236
|
-
|
|
237
|
-
|
|
185
|
+
return { msg_id: messageId };
|
|
186
|
+
};
|
|
187
|
+
const buildMdAndButtonsParams = (val) => {
|
|
188
|
+
const items = val.filter(item => item.type === 'Markdown' || item.type === 'BT.group' || item.type === 'ButtonTemplate');
|
|
189
|
+
if (items.length === 0) {
|
|
190
|
+
return null;
|
|
238
191
|
}
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
return `[${item.value}](${item?.options?.link})`;
|
|
192
|
+
const params = {};
|
|
193
|
+
for (const item of items) {
|
|
194
|
+
if (item.type === 'ButtonTemplate') {
|
|
195
|
+
if (item?.value) {
|
|
196
|
+
params['keyboard'] = { id: item.value };
|
|
245
197
|
}
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
198
|
+
}
|
|
199
|
+
else if (item.type === 'BT.group' && typeof item?.value !== 'string') {
|
|
200
|
+
if (params['keyboard']?.content?.rows) {
|
|
201
|
+
const existingRows = params['keyboard'].content.rows;
|
|
202
|
+
const currentId = params['keyboard'].content.nextId ?? existingRows.length;
|
|
203
|
+
const remaining = MAX_BUTTON_ROWS - existingRows.length;
|
|
204
|
+
if (remaining > 0) {
|
|
205
|
+
const { rows: newRows, nextId } = createButtonsData(item.value.slice(0, remaining), currentId);
|
|
206
|
+
existingRows.push(...newRows);
|
|
207
|
+
params['keyboard'].content.nextId = nextId;
|
|
255
208
|
}
|
|
256
|
-
return '';
|
|
257
|
-
}
|
|
258
|
-
else if (item.type == 'Text') {
|
|
259
|
-
return item.value;
|
|
260
209
|
}
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
if (images && images.length > 0) {
|
|
265
|
-
let url = '';
|
|
266
|
-
for (let i = 0; i < images.length; i++) {
|
|
267
|
-
// 已经处理。
|
|
268
|
-
if (url)
|
|
269
|
-
break;
|
|
270
|
-
const item = images[i];
|
|
271
|
-
if (item.type == 'ImageURL') {
|
|
272
|
-
url = item.value;
|
|
273
|
-
}
|
|
274
|
-
else if (item.type === 'ImageFile' || item.type === 'Image') {
|
|
275
|
-
const getFileBase64 = () => readFileSync(item.value, 'base64');
|
|
276
|
-
const file_data = item.type == 'ImageFile' ? getFileBase64() : item.value;
|
|
277
|
-
const file_info = await client
|
|
278
|
-
.postRichMediaByGroup(event.GuildId, {
|
|
279
|
-
file_type: 1,
|
|
280
|
-
file_data: file_data
|
|
281
|
-
})
|
|
282
|
-
.then(res => res?.file_info);
|
|
283
|
-
if (file_info) {
|
|
284
|
-
url = file_info;
|
|
285
|
-
}
|
|
286
|
-
}
|
|
210
|
+
else {
|
|
211
|
+
const result = createButtonsData(item.value);
|
|
212
|
+
params['keyboard'] = { content: result };
|
|
287
213
|
}
|
|
288
|
-
const res = await client.groupOpenMessages(event.GuildId, {
|
|
289
|
-
content: content,
|
|
290
|
-
media: {
|
|
291
|
-
file_info: url
|
|
292
|
-
},
|
|
293
|
-
msg_type: 7,
|
|
294
|
-
...baseParams
|
|
295
|
-
});
|
|
296
|
-
return [
|
|
297
|
-
createResult(ResultCode.Ok, 'client.groupOpenMessages', {
|
|
298
|
-
id: res.id
|
|
299
|
-
})
|
|
300
|
-
];
|
|
301
|
-
}
|
|
302
|
-
const mdAndButtons = val.filter(item => item.type == 'Markdown' || item.type == 'BT.group');
|
|
303
|
-
if (mdAndButtons && mdAndButtons.length > 0) {
|
|
304
|
-
const params = {};
|
|
305
|
-
mdAndButtons.forEach(async (item) => {
|
|
306
|
-
if (item.type === 'BT.group') {
|
|
307
|
-
// 如果是按钮,获取参数
|
|
308
|
-
const template_id = item?.options?.template_id;
|
|
309
|
-
if (template_id) {
|
|
310
|
-
params['keyboard'] = {
|
|
311
|
-
id: template_id
|
|
312
|
-
};
|
|
313
|
-
}
|
|
314
|
-
else {
|
|
315
|
-
const rows = item.value;
|
|
316
|
-
// 构造成按钮
|
|
317
|
-
const content = createButtonsData(rows);
|
|
318
|
-
params['keyboard'] = {
|
|
319
|
-
content: content
|
|
320
|
-
};
|
|
321
|
-
}
|
|
322
|
-
}
|
|
323
|
-
else if (item.type === 'Markdown') {
|
|
324
|
-
// 如果是markdown,获取内容
|
|
325
|
-
const content = createMarkdownText(item.value);
|
|
326
|
-
if (content) {
|
|
327
|
-
params['markdown'] = {
|
|
328
|
-
content: content
|
|
329
|
-
};
|
|
330
|
-
}
|
|
331
|
-
}
|
|
332
|
-
});
|
|
333
|
-
const res = await client.groupOpenMessages(event.GuildId, {
|
|
334
|
-
content: content,
|
|
335
|
-
msg_type: 2,
|
|
336
|
-
...params,
|
|
337
|
-
...baseParams
|
|
338
|
-
});
|
|
339
|
-
return [createResult(ResultCode.Ok, 'client.groupOpenMessages', { id: res.id })];
|
|
340
214
|
}
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
if (item.type === 'Ark.Card') {
|
|
347
|
-
const arkData = createArkCardData(item.value);
|
|
348
|
-
params['ark'] = arkData;
|
|
215
|
+
else if (item.type === 'Markdown' && typeof item?.value !== 'string') {
|
|
216
|
+
const content = createMarkdownText(item.value);
|
|
217
|
+
if (content) {
|
|
218
|
+
if (params['markdown']?.content) {
|
|
219
|
+
params['markdown'].content += content;
|
|
349
220
|
}
|
|
350
|
-
else
|
|
351
|
-
|
|
352
|
-
params['ark'] = arkData;
|
|
353
|
-
}
|
|
354
|
-
else if (item.type === 'Ark.list') {
|
|
355
|
-
const arkData = createArkList(item.value);
|
|
356
|
-
params['ark'] = arkData;
|
|
221
|
+
else {
|
|
222
|
+
params['markdown'] = { content };
|
|
357
223
|
}
|
|
358
|
-
}
|
|
359
|
-
const res = await client.groupOpenMessages(event.GuildId, {
|
|
360
|
-
content: content,
|
|
361
|
-
msg_type: 3,
|
|
362
|
-
...params,
|
|
363
|
-
...baseParams
|
|
364
|
-
});
|
|
365
|
-
return [createResult(ResultCode.Ok, 'client.groupOpenMessages', { id: res.id })];
|
|
366
|
-
}
|
|
367
|
-
if (content) {
|
|
368
|
-
const res = await client.groupOpenMessages(event.GuildId, {
|
|
369
|
-
content: content,
|
|
370
|
-
msg_type: 0,
|
|
371
|
-
...baseParams
|
|
372
|
-
});
|
|
373
|
-
return [
|
|
374
|
-
createResult(ResultCode.Ok, 'client.groupOpenMessages', {
|
|
375
|
-
id: res.id
|
|
376
|
-
})
|
|
377
|
-
];
|
|
224
|
+
}
|
|
378
225
|
}
|
|
379
226
|
}
|
|
380
|
-
|
|
381
|
-
|
|
227
|
+
if (params['keyboard']?.content?.nextId !== undefined) {
|
|
228
|
+
delete params['keyboard'].content.nextId;
|
|
382
229
|
}
|
|
383
|
-
return
|
|
230
|
+
return params;
|
|
384
231
|
};
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
* @param val
|
|
390
|
-
* @returns
|
|
391
|
-
*/
|
|
392
|
-
const C2C_MESSAGE_CREATE = async (client, event, val) => {
|
|
393
|
-
const baseParams = {};
|
|
394
|
-
if (event.tag === 'INTERACTION_CREATE_C2C') {
|
|
395
|
-
baseParams['event_id'] = event.MessageId;
|
|
232
|
+
const buildArkParams = (val) => {
|
|
233
|
+
const items = val.filter(item => item.type === 'Ark.BigCard' || item.type === 'Ark.Card' || item.type === 'Ark.list');
|
|
234
|
+
if (items.length === 0) {
|
|
235
|
+
return null;
|
|
396
236
|
}
|
|
397
|
-
|
|
398
|
-
|
|
237
|
+
const params = {};
|
|
238
|
+
for (const item of items) {
|
|
239
|
+
if (item.type === 'Ark.Card' && typeof item?.value !== 'string') {
|
|
240
|
+
params['ark'] = createArkCardData(item.value);
|
|
241
|
+
}
|
|
242
|
+
else if (item.type === 'Ark.BigCard' && typeof item?.value !== 'string') {
|
|
243
|
+
params['ark'] = createArkBigCardData(item.value);
|
|
244
|
+
}
|
|
245
|
+
else if (item.type === 'Ark.list' && typeof item?.value !== 'string') {
|
|
246
|
+
params['ark'] = createArkListData(item.value);
|
|
247
|
+
}
|
|
399
248
|
}
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
249
|
+
return params;
|
|
250
|
+
};
|
|
251
|
+
const filterImages = (val) => {
|
|
252
|
+
return val.filter(item => item.type === 'Image' || item.type === 'ImageFile' || item.type === 'ImageURL');
|
|
253
|
+
};
|
|
254
|
+
const resolveRichMediaUrl = async (images, uploadMedia) => {
|
|
255
|
+
for (const item of images) {
|
|
256
|
+
let fileData;
|
|
257
|
+
let fileInfo;
|
|
258
|
+
if (item.type === 'ImageURL') {
|
|
259
|
+
fileData = await axios.get(item.value, { responseType: 'arraybuffer' }).then(res => Buffer.from(res.data, 'binary').toString('base64'));
|
|
260
|
+
}
|
|
261
|
+
else if (item.type === 'Image') {
|
|
262
|
+
if (typeof item.value === 'string' && (item.value.startsWith('https://') || item.value.startsWith('http://'))) {
|
|
263
|
+
fileData = await axios.get(item.value, { responseType: 'arraybuffer' }).then(res => Buffer.from(res.data, 'binary').toString('base64'));
|
|
406
264
|
}
|
|
407
|
-
else if (item.
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
item.value == '' ||
|
|
411
|
-
typeof item.value != 'string') {
|
|
412
|
-
return ``;
|
|
413
|
-
}
|
|
414
|
-
if (item.options?.belong == 'user') {
|
|
415
|
-
return `<@${item.value}>`;
|
|
416
|
-
}
|
|
417
|
-
return '';
|
|
265
|
+
else if (typeof item.value === 'string' && item.value.startsWith('file://')) {
|
|
266
|
+
const localFilePath = item.value.replace('file://', '');
|
|
267
|
+
fileData = readFileSync(localFilePath, 'base64');
|
|
418
268
|
}
|
|
419
|
-
else if (item.
|
|
420
|
-
|
|
269
|
+
else if (typeof item.value === 'string' && item.value.startsWith('base64://')) {
|
|
270
|
+
fileData = item.value.replace('base64://', '');
|
|
421
271
|
}
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
for (let i = 0; i < images.length; i++) {
|
|
428
|
-
// 已经处理。
|
|
429
|
-
if (url)
|
|
430
|
-
break;
|
|
431
|
-
const item = images[i];
|
|
432
|
-
if (item.type == 'ImageURL') {
|
|
433
|
-
url = item.value;
|
|
434
|
-
}
|
|
435
|
-
else if (item.type === 'ImageFile' || item.type === 'Image') {
|
|
436
|
-
const getFileBase64 = () => readFileSync(item.value, 'base64');
|
|
437
|
-
const file_data = item.type == 'ImageFile' ? getFileBase64() : item.value;
|
|
438
|
-
const file_info = await client
|
|
439
|
-
.postRichMediaByGroup(event.GuildId, {
|
|
440
|
-
file_type: 1,
|
|
441
|
-
file_data: file_data
|
|
442
|
-
})
|
|
443
|
-
.then(res => res?.file_info);
|
|
444
|
-
if (file_info) {
|
|
445
|
-
url = file_info;
|
|
446
|
-
}
|
|
447
|
-
}
|
|
272
|
+
else if (Buffer.isBuffer(item.value)) {
|
|
273
|
+
fileData = item.value.toString('base64');
|
|
274
|
+
}
|
|
275
|
+
else if (typeof item.value === 'string') {
|
|
276
|
+
fileData = item.value;
|
|
448
277
|
}
|
|
449
|
-
const res = await client.usersOpenMessages(event.OpenId, {
|
|
450
|
-
content: content,
|
|
451
|
-
media: {
|
|
452
|
-
file_info: url
|
|
453
|
-
},
|
|
454
|
-
msg_type: 7,
|
|
455
|
-
...baseParams
|
|
456
|
-
});
|
|
457
|
-
return [
|
|
458
|
-
createResult(ResultCode.Ok, 'client.usersOpenMessages', {
|
|
459
|
-
id: res.id
|
|
460
|
-
})
|
|
461
|
-
];
|
|
462
278
|
}
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
const params = {};
|
|
466
|
-
mdAndButtons.forEach(async (item) => {
|
|
467
|
-
if (item.type === 'BT.group') {
|
|
468
|
-
// 如果是按钮,获取参数
|
|
469
|
-
const template_id = item?.options?.template_id;
|
|
470
|
-
if (template_id) {
|
|
471
|
-
params['keyboard'] = {
|
|
472
|
-
id: template_id
|
|
473
|
-
};
|
|
474
|
-
}
|
|
475
|
-
else {
|
|
476
|
-
const rows = item.value;
|
|
477
|
-
// 构造成按钮
|
|
478
|
-
const content = createButtonsData(rows);
|
|
479
|
-
params['keyboard'] = {
|
|
480
|
-
content: content
|
|
481
|
-
};
|
|
482
|
-
}
|
|
483
|
-
}
|
|
484
|
-
else if (item.type === 'Markdown') {
|
|
485
|
-
// 如果是markdown,获取内容
|
|
486
|
-
const content = createMarkdownText(item.value);
|
|
487
|
-
if (content) {
|
|
488
|
-
params['markdown'] = {
|
|
489
|
-
content: content
|
|
490
|
-
};
|
|
491
|
-
}
|
|
492
|
-
}
|
|
493
|
-
});
|
|
494
|
-
const res = await client.usersOpenMessages(event.OpenId, {
|
|
495
|
-
content: content,
|
|
496
|
-
msg_type: 2,
|
|
497
|
-
...params,
|
|
498
|
-
...baseParams
|
|
499
|
-
});
|
|
500
|
-
return [createResult(ResultCode.Ok, 'client.usersOpenMessages', { id: res.id })];
|
|
279
|
+
else if (item.type === 'ImageFile') {
|
|
280
|
+
fileData = readFileSync(item.value, 'base64');
|
|
501
281
|
}
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
if (ark && ark.length > 0) {
|
|
505
|
-
const params = {};
|
|
506
|
-
ark.forEach(async (item) => {
|
|
507
|
-
if (item.type === 'Ark.Card') {
|
|
508
|
-
const arkData = createArkCardData(item.value);
|
|
509
|
-
params['ark'] = arkData;
|
|
510
|
-
}
|
|
511
|
-
else if (item.type === 'Ark.BigCard') {
|
|
512
|
-
const arkData = createArkBigCardData(item.value);
|
|
513
|
-
params['ark'] = arkData;
|
|
514
|
-
}
|
|
515
|
-
else if (item.type === 'Ark.list') {
|
|
516
|
-
const arkData = createArkList(item.value);
|
|
517
|
-
params['ark'] = arkData;
|
|
518
|
-
}
|
|
519
|
-
});
|
|
520
|
-
const res = await client.usersOpenMessages(event.OpenId, {
|
|
521
|
-
content: content,
|
|
522
|
-
msg_type: 3,
|
|
523
|
-
...params,
|
|
524
|
-
...baseParams
|
|
525
|
-
});
|
|
526
|
-
return [createResult(ResultCode.Ok, 'client.usersOpenMessages', { id: res.id })];
|
|
282
|
+
if (fileData) {
|
|
283
|
+
fileInfo = await uploadMedia({ file_type: 1, file_data: fileData }).then(res => res?.file_info);
|
|
527
284
|
}
|
|
528
|
-
if (
|
|
529
|
-
|
|
530
|
-
content: content,
|
|
531
|
-
msg_type: 0,
|
|
532
|
-
...baseParams
|
|
533
|
-
});
|
|
534
|
-
return [
|
|
535
|
-
createResult(ResultCode.Ok, 'client.usersOpenMessages', {
|
|
536
|
-
id: res.id
|
|
537
|
-
})
|
|
538
|
-
];
|
|
285
|
+
if (fileInfo) {
|
|
286
|
+
return fileInfo;
|
|
539
287
|
}
|
|
540
288
|
}
|
|
541
|
-
|
|
542
|
-
return [createResult(ResultCode.Fail, err?.response?.data ?? err?.message ?? err, null)];
|
|
543
|
-
}
|
|
544
|
-
return [];
|
|
289
|
+
return undefined;
|
|
545
290
|
};
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
const
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
291
|
+
const sendOpenApiMessage = async (content, val, baseParams, uploadMedia, sendMessage, label) => {
|
|
292
|
+
const images = filterImages(val);
|
|
293
|
+
if (images.length > 0) {
|
|
294
|
+
const url = await resolveRichMediaUrl(images, uploadMedia);
|
|
295
|
+
if (!url) {
|
|
296
|
+
return [createResult(ResultCode.Fail, '图片上传失败', null)];
|
|
297
|
+
}
|
|
298
|
+
const res = await sendMessage({
|
|
299
|
+
content,
|
|
300
|
+
media: { file_info: url },
|
|
301
|
+
msg_type: 7,
|
|
302
|
+
...baseParams
|
|
303
|
+
});
|
|
304
|
+
return [createResult(ResultCode.Ok, label, { id: res.id })];
|
|
557
305
|
}
|
|
558
|
-
|
|
559
|
-
|
|
306
|
+
const mdParams = buildMdAndButtonsParams(val);
|
|
307
|
+
if (mdParams) {
|
|
308
|
+
const res = await sendMessage({ content, msg_type: 2, ...mdParams, ...baseParams });
|
|
309
|
+
return [createResult(ResultCode.Ok, label, { id: res.id })];
|
|
560
310
|
}
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
311
|
+
const arkParams = buildArkParams(val);
|
|
312
|
+
if (arkParams) {
|
|
313
|
+
const res = await sendMessage({ content, msg_type: 3, ...arkParams, ...baseParams });
|
|
314
|
+
return [createResult(ResultCode.Ok, label, { id: res.id })];
|
|
315
|
+
}
|
|
316
|
+
if (content) {
|
|
317
|
+
const res = await sendMessage({ content, msg_type: 0, ...baseParams });
|
|
318
|
+
return [createResult(ResultCode.Ok, label, { id: res.id })];
|
|
319
|
+
}
|
|
320
|
+
return [];
|
|
321
|
+
};
|
|
322
|
+
const resolveImageBuffer = async (images) => {
|
|
323
|
+
for (const item of images) {
|
|
324
|
+
if (item.type === 'ImageURL') {
|
|
325
|
+
return await axios.get(item.value, { responseType: 'arraybuffer' }).then(res => res?.data);
|
|
326
|
+
}
|
|
327
|
+
if (item.type === 'ImageFile') {
|
|
328
|
+
return readFileSync(item.value);
|
|
329
|
+
}
|
|
330
|
+
if (typeof item.value === 'string') {
|
|
331
|
+
if (item.value.startsWith('https://') || item.value.startsWith('http://')) {
|
|
332
|
+
return await axios.get(item.value, { responseType: 'arraybuffer' }).then(res => res?.data);
|
|
567
333
|
}
|
|
568
|
-
if (item.
|
|
569
|
-
return item.value;
|
|
334
|
+
if (item.value.startsWith('base64://')) {
|
|
335
|
+
return Buffer.from(item.value.replace('base64://', ''), 'base64');
|
|
570
336
|
}
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
.join('');
|
|
574
|
-
const images = val.filter(item => item.type == 'Image' || item.type == 'ImageFile' || item.type == 'ImageURL');
|
|
575
|
-
if (images && images.length > 0) {
|
|
576
|
-
let imageBuffer = null;
|
|
577
|
-
for (let i = 0; i < images.length; i++) {
|
|
578
|
-
// 已经处理。
|
|
579
|
-
if (imageBuffer)
|
|
580
|
-
break;
|
|
581
|
-
const item = images[i];
|
|
582
|
-
if (item.value == 'ImageURL') {
|
|
583
|
-
// 请求得到buffer
|
|
584
|
-
const data = await axios
|
|
585
|
-
.get(item.value, {
|
|
586
|
-
responseType: 'arraybuffer'
|
|
587
|
-
})
|
|
588
|
-
.then(res => res?.data);
|
|
589
|
-
imageBuffer = data;
|
|
590
|
-
}
|
|
591
|
-
else {
|
|
592
|
-
const file_data = item.type == 'ImageFile' ? readFileSync(item.value) : Buffer.from(item.value, 'base64');
|
|
593
|
-
imageBuffer = file_data;
|
|
594
|
-
}
|
|
337
|
+
if (item.value.startsWith('file://')) {
|
|
338
|
+
return readFileSync(item.value.replace('file://', ''));
|
|
595
339
|
}
|
|
596
|
-
|
|
597
|
-
content: content,
|
|
598
|
-
...baseParams
|
|
599
|
-
}, imageBuffer);
|
|
600
|
-
return [createResult(ResultCode.Ok, 'client.postDirectImage', { id: res?.id })];
|
|
601
|
-
}
|
|
602
|
-
const mdAndButtons = val.filter(item => item.type == 'Markdown' || item.type == 'BT.group');
|
|
603
|
-
if (mdAndButtons && mdAndButtons.length > 0) {
|
|
604
|
-
const params = {};
|
|
605
|
-
mdAndButtons.forEach(async (item) => {
|
|
606
|
-
if (item.type === 'BT.group') {
|
|
607
|
-
// 如果是按钮,获取参数
|
|
608
|
-
const template_id = item?.options?.template_id;
|
|
609
|
-
if (template_id) {
|
|
610
|
-
params['keyboard'] = {
|
|
611
|
-
id: template_id
|
|
612
|
-
};
|
|
613
|
-
}
|
|
614
|
-
else {
|
|
615
|
-
const rows = item.value;
|
|
616
|
-
// 构造成按钮
|
|
617
|
-
const content = createButtonsData(rows);
|
|
618
|
-
params['keyboard'] = {
|
|
619
|
-
content: content
|
|
620
|
-
};
|
|
621
|
-
}
|
|
622
|
-
}
|
|
623
|
-
else if (item.type === 'Markdown') {
|
|
624
|
-
// 如果是markdown,获取内容
|
|
625
|
-
const content = createMarkdownText(item.value);
|
|
626
|
-
if (content) {
|
|
627
|
-
params['markdown'] = {
|
|
628
|
-
content: content
|
|
629
|
-
};
|
|
630
|
-
}
|
|
631
|
-
}
|
|
632
|
-
});
|
|
633
|
-
const res = await client.dmsMessages(event.OpenId, {
|
|
634
|
-
content: '',
|
|
635
|
-
...params,
|
|
636
|
-
...baseParams
|
|
637
|
-
});
|
|
638
|
-
return [createResult(ResultCode.Ok, 'client.dmsMessage', { id: res.id })];
|
|
639
|
-
}
|
|
640
|
-
// ark
|
|
641
|
-
const ark = val.filter(item => item.type == 'Ark.BigCard' || item.type == 'Ark.Card' || item.type == 'Ark.list');
|
|
642
|
-
if (ark && ark.length > 0) {
|
|
643
|
-
const params = {};
|
|
644
|
-
ark.forEach(async (item) => {
|
|
645
|
-
if (item.type === 'Ark.Card') {
|
|
646
|
-
const arkData = createArkCardData(item.value);
|
|
647
|
-
params['ark'] = arkData;
|
|
648
|
-
}
|
|
649
|
-
else if (item.type === 'Ark.BigCard') {
|
|
650
|
-
const arkData = createArkBigCardData(item.value);
|
|
651
|
-
params['ark'] = arkData;
|
|
652
|
-
}
|
|
653
|
-
else if (item.type === 'Ark.list') {
|
|
654
|
-
const arkData = createArkList(item.value);
|
|
655
|
-
params['ark'] = arkData;
|
|
656
|
-
}
|
|
657
|
-
});
|
|
658
|
-
const res = await client.dmsMessages(event.OpenId, {
|
|
659
|
-
content: content,
|
|
660
|
-
...params,
|
|
661
|
-
...baseParams
|
|
662
|
-
});
|
|
663
|
-
return [createResult(ResultCode.Ok, 'client.dmsMessage', { id: res.id })];
|
|
340
|
+
return Buffer.from(item.value, 'base64');
|
|
664
341
|
}
|
|
665
|
-
if (
|
|
666
|
-
|
|
667
|
-
content: content,
|
|
668
|
-
...baseParams
|
|
669
|
-
});
|
|
670
|
-
return [createResult(ResultCode.Ok, 'client.dmsMessage', { id: res?.id })];
|
|
342
|
+
if (Buffer.isBuffer(item.value)) {
|
|
343
|
+
return item.value;
|
|
671
344
|
}
|
|
672
|
-
|
|
345
|
+
}
|
|
346
|
+
return null;
|
|
347
|
+
};
|
|
348
|
+
const sendGuildMessage = async (content, val, baseParams, sendMessage, label) => {
|
|
349
|
+
const images = filterImages(val);
|
|
350
|
+
if (images.length > 0) {
|
|
351
|
+
const imageBuffer = await resolveImageBuffer(images);
|
|
352
|
+
const res = await sendMessage({ content, ...baseParams }, imageBuffer);
|
|
353
|
+
return [createResult(ResultCode.Ok, label, { id: res?.id })];
|
|
354
|
+
}
|
|
355
|
+
const mdParams = buildMdAndButtonsParams(val);
|
|
356
|
+
if (mdParams) {
|
|
357
|
+
const res = await sendMessage({ content: '', ...mdParams, ...baseParams });
|
|
358
|
+
return [createResult(ResultCode.Ok, label, { id: res.id })];
|
|
359
|
+
}
|
|
360
|
+
const arkParams = buildArkParams(val);
|
|
361
|
+
if (arkParams) {
|
|
362
|
+
const res = await sendMessage({ content, ...arkParams, ...baseParams });
|
|
363
|
+
return [createResult(ResultCode.Ok, label, { id: res.id })];
|
|
364
|
+
}
|
|
365
|
+
if (content) {
|
|
366
|
+
const res = await sendMessage({ content, ...baseParams });
|
|
367
|
+
return [createResult(ResultCode.Ok, label, { id: res?.id })];
|
|
368
|
+
}
|
|
369
|
+
return [];
|
|
370
|
+
};
|
|
371
|
+
const GROUP_AT_MESSAGE_CREATE = async (client, event, val) => {
|
|
372
|
+
const baseParams = buildBaseParams(event._tag, event.MessageId, 'INTERACTION_CREATE_GROUP');
|
|
373
|
+
const content = extractContent(val, 'group');
|
|
374
|
+
try {
|
|
375
|
+
return await sendOpenApiMessage(content, val, baseParams, data => client.postRichMediaByGroup(event.ChannelId, data), data => client.groupOpenMessages(event.ChannelId, data), 'client.groupOpenMessages');
|
|
673
376
|
}
|
|
674
377
|
catch (err) {
|
|
675
378
|
return [createResult(ResultCode.Fail, err?.response?.data ?? err?.message ?? err, null)];
|
|
676
379
|
}
|
|
677
380
|
};
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
*/
|
|
684
|
-
const MESSAGE_CREATE = async (client, event, val) => {
|
|
685
|
-
const baseParams = {};
|
|
686
|
-
if (event.tag === 'INTERACTION_CREATE_GUILD') {
|
|
687
|
-
baseParams['event_id'] = event.MessageId;
|
|
381
|
+
const C2C_MESSAGE_CREATE = async (client, event, val) => {
|
|
382
|
+
const baseParams = buildBaseParams(event._tag, event.MessageId, 'INTERACTION_CREATE_C2C');
|
|
383
|
+
const content = extractContent(val, 'group');
|
|
384
|
+
try {
|
|
385
|
+
return await sendOpenApiMessage(content, val, baseParams, data => client.postRichMediaByUser(event.UserId, data), data => client.usersOpenMessages(event.UserId, data), 'client.usersOpenMessages');
|
|
688
386
|
}
|
|
689
|
-
|
|
690
|
-
|
|
387
|
+
catch (err) {
|
|
388
|
+
return [createResult(ResultCode.Fail, err?.response?.data ?? err?.message ?? err, null)];
|
|
691
389
|
}
|
|
390
|
+
};
|
|
391
|
+
const DIRECT_MESSAGE_CREATE = async (client, event, val) => {
|
|
392
|
+
const baseParams = buildBaseParams(event._tag, event.MessageId, 'INTERACTION_CREATE_GUILD');
|
|
393
|
+
const content = extractContent(val, 'guild-direct');
|
|
692
394
|
try {
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
return `@everyone`;
|
|
705
|
-
}
|
|
706
|
-
if (item.options?.belong == 'user') {
|
|
707
|
-
return `<@!${item.value}>`;
|
|
708
|
-
}
|
|
709
|
-
else if (item.options?.belong == 'channel') {
|
|
710
|
-
return `<#${item.value}>`;
|
|
711
|
-
}
|
|
712
|
-
return '';
|
|
713
|
-
}
|
|
714
|
-
else if (item.type == 'Text') {
|
|
715
|
-
return item.value;
|
|
716
|
-
}
|
|
717
|
-
})
|
|
718
|
-
.join('');
|
|
719
|
-
const images = val.filter(item => item.type == 'Image' || item.type == 'ImageFile' || item.type == 'ImageURL');
|
|
720
|
-
if (images && images.length > 0) {
|
|
721
|
-
let imageBuffer = null;
|
|
722
|
-
for (let i = 0; i < images.length; i++) {
|
|
723
|
-
// 已经处理。
|
|
724
|
-
if (imageBuffer)
|
|
725
|
-
break;
|
|
726
|
-
const item = images[i];
|
|
727
|
-
if (item.value == 'ImageURL') {
|
|
728
|
-
// 请求得到buffer
|
|
729
|
-
const data = await axios
|
|
730
|
-
.get(item.value, {
|
|
731
|
-
responseType: 'arraybuffer'
|
|
732
|
-
})
|
|
733
|
-
.then(res => res?.data);
|
|
734
|
-
imageBuffer = data;
|
|
735
|
-
}
|
|
736
|
-
else {
|
|
737
|
-
const file_data = item.type == 'ImageFile' ? readFileSync(item.value) : Buffer.from(item.value, 'base64');
|
|
738
|
-
imageBuffer = file_data;
|
|
739
|
-
}
|
|
740
|
-
}
|
|
741
|
-
const res = await client.channelsMessages(event.ChannelId, {
|
|
742
|
-
content: content,
|
|
743
|
-
...baseParams
|
|
744
|
-
}, imageBuffer);
|
|
745
|
-
return [createResult(ResultCode.Ok, 'client.postImage', { id: res?.id })];
|
|
746
|
-
}
|
|
747
|
-
const mdAndButtons = val.filter(item => item.type == 'Markdown' || item.type == 'BT.group');
|
|
748
|
-
if (mdAndButtons && mdAndButtons.length > 0) {
|
|
749
|
-
const params = {};
|
|
750
|
-
mdAndButtons.forEach(async (item) => {
|
|
751
|
-
if (item.type === 'BT.group') {
|
|
752
|
-
// 如果是按钮,获取参数
|
|
753
|
-
const template_id = item?.options?.template_id;
|
|
754
|
-
if (template_id) {
|
|
755
|
-
params['keyboard'] = {
|
|
756
|
-
id: template_id
|
|
757
|
-
};
|
|
758
|
-
}
|
|
759
|
-
else {
|
|
760
|
-
const rows = item.value;
|
|
761
|
-
// 构造成按钮
|
|
762
|
-
const content = createButtonsData(rows);
|
|
763
|
-
params['keyboard'] = {
|
|
764
|
-
content: content
|
|
765
|
-
};
|
|
766
|
-
}
|
|
767
|
-
}
|
|
768
|
-
else if (item.type === 'Markdown') {
|
|
769
|
-
// 如果是markdown,获取内容
|
|
770
|
-
const content = createMarkdownText(item.value);
|
|
771
|
-
if (content) {
|
|
772
|
-
params['markdown'] = {
|
|
773
|
-
content: content
|
|
774
|
-
};
|
|
775
|
-
}
|
|
776
|
-
}
|
|
777
|
-
});
|
|
778
|
-
const res = await client.channelsMessages(event.ChannelId, {
|
|
779
|
-
content: '',
|
|
780
|
-
...params,
|
|
781
|
-
...baseParams
|
|
782
|
-
});
|
|
783
|
-
return [createResult(ResultCode.Ok, 'client.channelsMessagesPost', { id: res.id })];
|
|
784
|
-
}
|
|
785
|
-
// ark
|
|
786
|
-
const ark = val.filter(item => item.type == 'Ark.BigCard' || item.type == 'Ark.Card' || item.type == 'Ark.list');
|
|
787
|
-
if (ark && ark.length > 0) {
|
|
788
|
-
const params = {};
|
|
789
|
-
ark.forEach(async (item) => {
|
|
790
|
-
if (item.type === 'Ark.Card') {
|
|
791
|
-
const arkData = createArkCardData(item.value);
|
|
792
|
-
params['ark'] = arkData;
|
|
793
|
-
}
|
|
794
|
-
else if (item.type === 'Ark.BigCard') {
|
|
795
|
-
const arkData = createArkBigCardData(item.value);
|
|
796
|
-
params['ark'] = arkData;
|
|
797
|
-
}
|
|
798
|
-
else if (item.type === 'Ark.list') {
|
|
799
|
-
const arkData = createArkList(item.value);
|
|
800
|
-
params['ark'] = arkData;
|
|
801
|
-
}
|
|
802
|
-
});
|
|
803
|
-
const res = await client.channelsMessages(event.GuildId, {
|
|
804
|
-
content: content,
|
|
805
|
-
msg_id: event.MessageId,
|
|
806
|
-
...params
|
|
807
|
-
});
|
|
808
|
-
return [createResult(ResultCode.Ok, 'client.channelsMessagesPost', { id: res.id })];
|
|
809
|
-
}
|
|
810
|
-
if (content) {
|
|
811
|
-
const res = await client.channelsMessages(event.ChannelId, {
|
|
812
|
-
content: content,
|
|
813
|
-
...baseParams
|
|
814
|
-
});
|
|
815
|
-
return [createResult(ResultCode.Ok, 'client.channelsMessagesPost', { id: res?.id })];
|
|
816
|
-
}
|
|
817
|
-
return [];
|
|
395
|
+
return await sendGuildMessage(content, val, baseParams, (data, buf) => client.dmsMessages(event.UserId, data, buf), 'client.dmsMessage');
|
|
396
|
+
}
|
|
397
|
+
catch (err) {
|
|
398
|
+
return [createResult(ResultCode.Fail, err?.response?.data ?? err?.message ?? err, null)];
|
|
399
|
+
}
|
|
400
|
+
};
|
|
401
|
+
const MESSAGE_CREATE = async (client, event, val) => {
|
|
402
|
+
const baseParams = buildBaseParams(event._tag, event.MessageId, 'INTERACTION_CREATE_GUILD');
|
|
403
|
+
const content = extractContent(val, 'guild-public');
|
|
404
|
+
try {
|
|
405
|
+
return await sendGuildMessage(content, val, baseParams, (data, buf) => client.channelsMessages(event.ChannelId, data, buf), 'client.channelsMessagesPost');
|
|
818
406
|
}
|
|
819
407
|
catch (err) {
|
|
820
408
|
return [createResult(ResultCode.Fail, err?.response?.data ?? err?.message ?? err, null)];
|
|
821
409
|
}
|
|
822
410
|
};
|
|
823
|
-
/**
|
|
824
|
-
* 频道公聊 @
|
|
825
|
-
* @param client
|
|
826
|
-
* @param event
|
|
827
|
-
* @param val
|
|
828
|
-
* @returns
|
|
829
|
-
*/
|
|
830
411
|
const AT_MESSAGE_CREATE = (client, event, val) => {
|
|
831
412
|
return MESSAGE_CREATE(client, event, val);
|
|
832
413
|
};
|