@alemonjs/discord 2.1.0-alpha.2 → 2.1.0-alpha.20
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 -2
- package/lib/config.d.ts +14 -0
- package/lib/config.js +21 -0
- package/lib/desktop.d.ts +1 -3
- package/lib/desktop.js +4 -12
- package/lib/hook.d.ts +27 -0
- package/lib/hook.js +14 -0
- package/lib/index.d.ts +6 -4
- package/lib/index.js +102 -134
- package/lib/sdk/api.d.ts +147 -971
- package/lib/sdk/api.js +336 -1076
- package/lib/sdk/createPicFrom.d.ts +6 -0
- package/lib/sdk/{core/from.js → createPicFrom.js} +8 -13
- package/lib/sdk/instance.d.ts +3 -0
- package/lib/sdk/instance.js +93 -0
- package/lib/sdk/intents.d.ts +2 -0
- package/lib/sdk/intents.js +0 -121
- package/lib/sdk/message/CHANNEL_TOPIC_UPDATE.d.ts +5 -11
- package/lib/sdk/message/CHANNEL_TOPIC_UPDATE.js +1 -0
- package/lib/sdk/message/CHANNEL_UPDATE.d.ts +42 -48
- package/lib/sdk/message/CHANNEL_UPDATE.js +1 -0
- package/lib/sdk/message/GUILD_MEMBER_ADD.d.ts +23 -28
- package/lib/sdk/message/GUILD_MEMBER_ADD.js +1 -0
- package/lib/sdk/message/GUILD_MEMBER_REMOVE.d.ts +12 -18
- package/lib/sdk/message/GUILD_MEMBER_REMOVE.js +1 -0
- package/lib/sdk/message/GUILD_MEMBER_UPDATE.d.ts +27 -33
- package/lib/sdk/message/GUILD_MEMBER_UPDATE.js +1 -0
- package/lib/sdk/message/INTERACTION_CREATE.d.ts +113 -114
- package/lib/sdk/message/INTERACTION_CREATE.js +1 -0
- package/lib/sdk/message/MESSAGE_CREATE.d.ts +53 -59
- package/lib/sdk/message/MESSAGE_CREATE.js +1 -0
- package/lib/sdk/message/MESSAGE_DELETE.d.ts +5 -11
- package/lib/sdk/message/MESSAGE_DELETE.js +1 -0
- package/lib/sdk/message/MESSAGE_REACTION_ADD.d.ts +36 -42
- package/lib/sdk/message/MESSAGE_REACTION_ADD.js +1 -0
- package/lib/sdk/message/MESSAGE_UPDATE.d.ts +50 -56
- package/lib/sdk/message/MESSAGE_UPDATE.js +1 -0
- package/lib/sdk/message/PRESENCE_UPDATE.d.ts +56 -68
- package/lib/sdk/message/PRESENCE_UPDATE.js +1 -0
- package/lib/sdk/message/READY.d.ts +7 -9
- package/lib/sdk/message/READY.js +1 -0
- package/lib/sdk/message/TYPING_START.d.ts +29 -35
- package/lib/sdk/message/TYPING_START.js +1 -0
- package/lib/sdk/message/VOICE_CHANNEL_STATUS_UPDATE.d.ts +5 -10
- package/lib/sdk/message/VOICE_CHANNEL_STATUS_UPDATE.js +1 -0
- package/lib/sdk/message/VOICE_STATE_UPDATE.d.ts +36 -41
- package/lib/sdk/message/VOICE_STATE_UPDATE.js +1 -0
- package/lib/sdk/message.d.ts +93 -101
- package/lib/sdk/message.js +1 -0
- package/lib/sdk/types.d.ts +2 -5
- package/lib/sdk/typings.d.ts +190 -0
- package/lib/sdk/typings.js +1 -0
- package/lib/sdk/wss.d.ts +7 -26
- package/lib/sdk/wss.js +109 -162
- package/lib/sdk/wss.types.d.ts +6 -29
- package/lib/sdk/wss.types.js +1 -0
- package/lib/send.d.ts +11 -0
- package/lib/send.js +168 -92
- package/package.json +16 -8
- package/lib/env.js +0 -1
- package/lib/sdk/config.js +0 -10
- package/lib/sdk/core/config.js +0 -46
package/lib/send.js
CHANGED
|
@@ -13,120 +13,196 @@ const createButtonsData = (rows) => {
|
|
|
13
13
|
components: val.map(button => {
|
|
14
14
|
const value = button.value;
|
|
15
15
|
let text = '';
|
|
16
|
-
|
|
17
|
-
text = button.options?.data.click;
|
|
18
|
-
}
|
|
19
|
-
else {
|
|
20
|
-
text = button.options.data;
|
|
21
|
-
}
|
|
16
|
+
text = button.options?.data;
|
|
22
17
|
return {
|
|
23
18
|
type: 2,
|
|
24
19
|
custom_id: text,
|
|
25
20
|
style: 1,
|
|
26
|
-
label:
|
|
21
|
+
label: value
|
|
27
22
|
};
|
|
28
23
|
})
|
|
29
24
|
};
|
|
30
25
|
});
|
|
31
26
|
};
|
|
32
|
-
const sendchannel = (client, param, val) => {
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
// images
|
|
37
|
-
const images = val.filter(item => item.type == 'Image' || item.type == 'ImageURL' || item.type == 'ImageFile');
|
|
38
|
-
// buttons
|
|
39
|
-
const buttons = val.filter(item => item.type == 'BT.group');
|
|
40
|
-
// text
|
|
41
|
-
const content = val
|
|
42
|
-
.filter(item => item.type == 'Mention' || item.type == 'Text' || item.type == 'Link')
|
|
43
|
-
.map(item => {
|
|
44
|
-
if (item.type == 'Link') {
|
|
45
|
-
return `[${item.value}](${item?.options?.link ?? item.value})`;
|
|
46
|
-
}
|
|
47
|
-
else if (item.type == 'Mention') {
|
|
48
|
-
if (item.value == 'everyone' ||
|
|
49
|
-
item.value == 'all' ||
|
|
50
|
-
item.value == '' ||
|
|
51
|
-
typeof item.value != 'string') {
|
|
52
|
-
return `<@everyone>`;
|
|
53
|
-
}
|
|
54
|
-
if (item.options?.belong == 'user') {
|
|
55
|
-
return `<@${item.value}>`;
|
|
56
|
-
}
|
|
57
|
-
else if (item.options?.belong == 'channel') {
|
|
58
|
-
return `<#${item.value}>`;
|
|
59
|
-
}
|
|
60
|
-
return '';
|
|
27
|
+
const sendchannel = async (client, param, val) => {
|
|
28
|
+
try {
|
|
29
|
+
if (!val || val.length <= 0) {
|
|
30
|
+
return [];
|
|
61
31
|
}
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
32
|
+
const channel_id = param?.channel_id ?? '';
|
|
33
|
+
const images = val.filter(item => item.type === 'Image' || item.type === 'ImageURL' || item.type === 'ImageFile');
|
|
34
|
+
const buttons = val.filter(item => item.type === 'BT.group');
|
|
35
|
+
const mds = val.filter(item => item.type === 'Markdown');
|
|
36
|
+
const content = val
|
|
37
|
+
.filter(item => item.type === 'Mention' || item.type === 'Text' || item.type === 'Link')
|
|
38
|
+
.map(item => {
|
|
39
|
+
if (item.type === 'Link') {
|
|
40
|
+
return `[${item.value}](${item?.options?.link ?? item.value})`;
|
|
65
41
|
}
|
|
66
|
-
else if (item.
|
|
67
|
-
|
|
42
|
+
else if (item.type === 'Mention') {
|
|
43
|
+
if (item.value === 'everyone' || item.value === 'all' || item.value === '' || typeof item.value !== 'string') {
|
|
44
|
+
return '<@everyone>';
|
|
45
|
+
}
|
|
46
|
+
if (item.options?.belong === 'user') {
|
|
47
|
+
return `<@${item.value}>`;
|
|
48
|
+
}
|
|
49
|
+
else if (item.options?.belong === 'channel') {
|
|
50
|
+
return `<#${item.value}>`;
|
|
51
|
+
}
|
|
52
|
+
return '';
|
|
68
53
|
}
|
|
69
|
-
else if (item.
|
|
70
|
-
|
|
54
|
+
else if (item.type === 'Text') {
|
|
55
|
+
if (item.options?.style === 'block') {
|
|
56
|
+
return `\`${item.value}\``;
|
|
57
|
+
}
|
|
58
|
+
else if (item.options?.style === 'italic') {
|
|
59
|
+
return `*${item.value}*`;
|
|
60
|
+
}
|
|
61
|
+
else if (item.options?.style === 'bold') {
|
|
62
|
+
return `**${item.value}**`;
|
|
63
|
+
}
|
|
64
|
+
else if (item.options?.style === 'strikethrough') {
|
|
65
|
+
return `~~${item.value}~~`;
|
|
66
|
+
}
|
|
67
|
+
return item.value;
|
|
71
68
|
}
|
|
72
|
-
|
|
73
|
-
|
|
69
|
+
})
|
|
70
|
+
.join('');
|
|
71
|
+
if (images.length > 0) {
|
|
72
|
+
let bufferData = null;
|
|
73
|
+
for (let i = 0; i < images.length; i++) {
|
|
74
|
+
if (bufferData) {
|
|
75
|
+
break;
|
|
76
|
+
}
|
|
77
|
+
const item = images[i];
|
|
78
|
+
if (item.type === 'Image') {
|
|
79
|
+
if (Buffer.isBuffer(item.value)) {
|
|
80
|
+
bufferData = item.value;
|
|
81
|
+
}
|
|
82
|
+
else if (typeof item.value === 'string') {
|
|
83
|
+
if (item.value.startsWith('http://') || item.value.startsWith('https://')) {
|
|
84
|
+
bufferData = await ImageURLToBuffer(item.value);
|
|
85
|
+
}
|
|
86
|
+
else if (item.value.startsWith('base64://')) {
|
|
87
|
+
bufferData = Buffer.from(item.value.slice(9), 'base64');
|
|
88
|
+
}
|
|
89
|
+
else if (item.value.startsWith('file://')) {
|
|
90
|
+
bufferData = readFileSync(item.value.slice(7));
|
|
91
|
+
}
|
|
92
|
+
else {
|
|
93
|
+
bufferData = Buffer.from(item.value, 'base64');
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
else if (item.type === 'ImageURL') {
|
|
98
|
+
const res = await ImageURLToBuffer(item.value);
|
|
99
|
+
bufferData = res;
|
|
100
|
+
}
|
|
101
|
+
else if (item.type === 'ImageFile') {
|
|
102
|
+
bufferData = readFileSync(item.value);
|
|
103
|
+
}
|
|
74
104
|
}
|
|
75
|
-
|
|
105
|
+
const res = await client.channelsMessagesForm(channel_id, {
|
|
106
|
+
content: content
|
|
107
|
+
}, bufferData);
|
|
108
|
+
return [createResult(ResultCode.Ok, '完成', res)];
|
|
76
109
|
}
|
|
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
|
-
|
|
110
|
+
let contentMd = '';
|
|
111
|
+
if (mds && mds.length > 0) {
|
|
112
|
+
mds.forEach(item => {
|
|
113
|
+
if (item.type === 'Markdown') {
|
|
114
|
+
const md = item.value;
|
|
115
|
+
md.forEach(line => {
|
|
116
|
+
if (line.type === 'MD.text') {
|
|
117
|
+
contentMd += line.value;
|
|
118
|
+
}
|
|
119
|
+
else if (line.type === 'MD.blockquote') {
|
|
120
|
+
contentMd += `> ${line.value}\n`;
|
|
121
|
+
}
|
|
122
|
+
else if (line.type === 'MD.bold') {
|
|
123
|
+
contentMd += `**${line.value}**`;
|
|
124
|
+
}
|
|
125
|
+
else if (line.type === 'MD.italic') {
|
|
126
|
+
contentMd += `*${line.value}*`;
|
|
127
|
+
}
|
|
128
|
+
else if (line.type === 'MD.divider') {
|
|
129
|
+
contentMd += '---\n';
|
|
130
|
+
}
|
|
131
|
+
else if (line.type === 'MD.image') {
|
|
132
|
+
contentMd += ``;
|
|
133
|
+
}
|
|
134
|
+
else if (line.type === 'MD.italicStar') {
|
|
135
|
+
contentMd += `*${line.value}*`;
|
|
136
|
+
}
|
|
137
|
+
else if (line.type === 'MD.link') {
|
|
138
|
+
contentMd += `[${line.value}](${line.value})`;
|
|
139
|
+
}
|
|
140
|
+
else if (line.type === 'MD.list') {
|
|
141
|
+
const listStr = line.value.map(listItem => {
|
|
142
|
+
if (typeof listItem.value === 'object') {
|
|
143
|
+
return `\n${listItem.value.index}. ${listItem.value.text}`;
|
|
144
|
+
}
|
|
145
|
+
return `\n- ${listItem.value}`;
|
|
146
|
+
});
|
|
147
|
+
contentMd += `${listStr}\n`;
|
|
148
|
+
}
|
|
149
|
+
else if (line.type === 'MD.newline') {
|
|
150
|
+
contentMd += '\n';
|
|
151
|
+
}
|
|
152
|
+
else if (line.type === 'MD.strikethrough') {
|
|
153
|
+
contentMd += `~~${line.value}~~`;
|
|
154
|
+
}
|
|
155
|
+
else if (line.type === 'MD.subtitle') {
|
|
156
|
+
contentMd += `## ${line.value}\n`;
|
|
157
|
+
}
|
|
158
|
+
else if (line.type === 'MD.title') {
|
|
159
|
+
contentMd += `# ${line.value}\n`;
|
|
160
|
+
}
|
|
161
|
+
else if (line.type === 'MD.code') {
|
|
162
|
+
const language = line?.options?.language || '';
|
|
163
|
+
contentMd += `\`\`\`${language}\n${line.value}\n\`\`\`\n`;
|
|
164
|
+
}
|
|
165
|
+
else {
|
|
166
|
+
const value = line['value'] || '';
|
|
167
|
+
contentMd += String(value);
|
|
168
|
+
}
|
|
169
|
+
});
|
|
170
|
+
}
|
|
171
|
+
});
|
|
172
|
+
}
|
|
173
|
+
if (buttons && buttons.length > 0) {
|
|
174
|
+
let components = null;
|
|
175
|
+
buttons.forEach(item => {
|
|
176
|
+
if (components) {
|
|
177
|
+
return;
|
|
178
|
+
}
|
|
179
|
+
const rows = item.value;
|
|
180
|
+
components = createButtonsData(rows);
|
|
181
|
+
});
|
|
107
182
|
const res = await client.channelsMessages(channel_id, {
|
|
108
|
-
content: content,
|
|
109
|
-
components:
|
|
183
|
+
content: contentMd || content,
|
|
184
|
+
components: components
|
|
110
185
|
});
|
|
111
|
-
return createResult(ResultCode.Ok, '
|
|
112
|
-
|
|
186
|
+
return [createResult(ResultCode.Ok, '完成', res)];
|
|
187
|
+
}
|
|
188
|
+
if (content) {
|
|
189
|
+
const res = await client.channelsMessagesForm(channel_id, {
|
|
190
|
+
content: contentMd || content
|
|
113
191
|
});
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
]
|
|
192
|
+
return [createResult(ResultCode.Ok, '完成', res)];
|
|
193
|
+
}
|
|
194
|
+
return [];
|
|
117
195
|
}
|
|
118
|
-
|
|
119
|
-
return
|
|
120
|
-
content: item
|
|
121
|
-
})));
|
|
196
|
+
catch (err) {
|
|
197
|
+
return [createResult(ResultCode.Fail, err?.response?.data ?? err?.message ?? err, null)];
|
|
122
198
|
}
|
|
123
|
-
return Promise.all([]);
|
|
124
199
|
};
|
|
125
200
|
const senduser = async (client, param, val) => {
|
|
126
|
-
if (val.length
|
|
127
|
-
return
|
|
128
|
-
|
|
129
|
-
|
|
201
|
+
if (!val || val.length <= 0) {
|
|
202
|
+
return [];
|
|
203
|
+
}
|
|
204
|
+
const channelId = param?.channel_id ?? (await client.userMeChannels(param.author_id))?.id;
|
|
205
|
+
return sendchannel(client, { channel_id: channelId }, val);
|
|
130
206
|
};
|
|
131
207
|
|
|
132
208
|
export { sendchannel, senduser };
|
package/package.json
CHANGED
|
@@ -1,26 +1,34 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@alemonjs/discord",
|
|
3
|
-
"version": "2.1.0-alpha.
|
|
4
|
-
"description": "
|
|
3
|
+
"version": "2.1.0-alpha.20",
|
|
4
|
+
"description": "discord platform connection",
|
|
5
5
|
"author": "lemonade",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"type": "module",
|
|
8
8
|
"main": "lib/index.js",
|
|
9
9
|
"types": "lib",
|
|
10
10
|
"scripts": {
|
|
11
|
-
"build": "
|
|
11
|
+
"build": "lvy build"
|
|
12
12
|
},
|
|
13
13
|
"exports": {
|
|
14
14
|
".": {
|
|
15
15
|
"import": "./lib/index.js",
|
|
16
|
-
"types": "./lib/index.d.ts"
|
|
16
|
+
"types": "./lib/index.d.ts",
|
|
17
|
+
"require": "./lib/index.js"
|
|
17
18
|
},
|
|
18
19
|
"./package": "./package.json",
|
|
19
20
|
"./desktop": "./lib/desktop.js"
|
|
20
21
|
},
|
|
22
|
+
"dependencies": {
|
|
23
|
+
"http-proxy-agent": "^7.0.2",
|
|
24
|
+
"https-proxy-agent": "^7"
|
|
25
|
+
},
|
|
21
26
|
"devDependencies": {
|
|
22
27
|
"@types/qrcode": "^1.5.5"
|
|
23
28
|
},
|
|
29
|
+
"peerDependencies": {
|
|
30
|
+
"alemonjs": "^2.1.0-alpha.15"
|
|
31
|
+
},
|
|
24
32
|
"alemonjs": {
|
|
25
33
|
"desktop": {
|
|
26
34
|
"platform": [
|
|
@@ -29,18 +37,18 @@
|
|
|
29
37
|
}
|
|
30
38
|
],
|
|
31
39
|
"logo": "antd.DiscordOutlined",
|
|
32
|
-
"
|
|
40
|
+
"command": [
|
|
33
41
|
{
|
|
34
42
|
"name": "打开discord",
|
|
35
43
|
"icon": "antd.DiscordOutlined",
|
|
36
|
-
"
|
|
44
|
+
"command": "open.discord"
|
|
37
45
|
}
|
|
38
46
|
],
|
|
39
47
|
"sidebars": [
|
|
40
48
|
{
|
|
41
49
|
"name": "dc",
|
|
42
50
|
"icon": "antd.DiscordOutlined",
|
|
43
|
-
"
|
|
51
|
+
"command": "open.discord"
|
|
44
52
|
}
|
|
45
53
|
]
|
|
46
54
|
}
|
|
@@ -57,4 +65,4 @@
|
|
|
57
65
|
"type": "git",
|
|
58
66
|
"url": "https://github.com/lemonade-lab/alemonjs.git"
|
|
59
67
|
}
|
|
60
|
-
}
|
|
68
|
+
}
|
package/lib/env.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
process.env.NODE_TLS_REJECT_UNAUTHORIZED = '0';
|
package/lib/sdk/config.js
DELETED
package/lib/sdk/core/config.js
DELETED
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* 基础配置结构
|
|
3
|
-
*/
|
|
4
|
-
class BaseConfig {
|
|
5
|
-
#data = null;
|
|
6
|
-
constructor(val) {
|
|
7
|
-
this.#data = val;
|
|
8
|
-
}
|
|
9
|
-
/**
|
|
10
|
-
* 设置配置
|
|
11
|
-
* @param key
|
|
12
|
-
* @param val
|
|
13
|
-
*/
|
|
14
|
-
set(key, val) {
|
|
15
|
-
if (val !== undefined)
|
|
16
|
-
this.#data[key] = val;
|
|
17
|
-
return this;
|
|
18
|
-
}
|
|
19
|
-
/**
|
|
20
|
-
*
|
|
21
|
-
* @param key
|
|
22
|
-
* @returns
|
|
23
|
-
*/
|
|
24
|
-
has(key) {
|
|
25
|
-
if (Object.prototype.hasOwnProperty.call(this.#data, key)) ;
|
|
26
|
-
return false;
|
|
27
|
-
}
|
|
28
|
-
/**
|
|
29
|
-
* 读取配置
|
|
30
|
-
* @param key
|
|
31
|
-
* @returns
|
|
32
|
-
*/
|
|
33
|
-
all() {
|
|
34
|
-
return this.#data;
|
|
35
|
-
}
|
|
36
|
-
/**
|
|
37
|
-
* 读取配置
|
|
38
|
-
* @param key
|
|
39
|
-
* @returns
|
|
40
|
-
*/
|
|
41
|
-
get(key) {
|
|
42
|
-
return this.#data[key];
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
export { BaseConfig };
|