@alemonjs/discord 2.1.0-alpha.0 → 2.1.0-alpha.12
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/dist/assets/index.js +6 -1
- package/lib/config.d.ts +35 -0
- package/lib/config.js +22 -0
- package/lib/hook.d.ts +39 -0
- package/lib/hook.js +24 -0
- package/lib/index.d.ts +5 -2
- package/lib/index.js +47 -85
- package/lib/sdk/api.d.ts +879 -965
- package/lib/sdk/api.js +30 -43
- package/lib/sdk/message/INTERACTION_CREATE.d.ts +113 -113
- package/lib/sdk/message/MESSAGE_CREATE.d.ts +53 -53
- package/lib/sdk/types.d.ts +4 -4
- package/lib/sdk/typings.d.ts +221 -0
- package/lib/sdk/wss.js +15 -38
- package/lib/send.js +167 -83
- package/package.json +9 -2
- package/lib/sdk/config.js +0 -10
- package/lib/sdk/core/config.js +0 -46
- package/lib/sdk/message/CHANNEL_TOPIC_UPDATE.d.ts +0 -11
- package/lib/sdk/message/CHANNEL_UPDATE.d.ts +0 -48
- package/lib/sdk/message/GUILD_MEMBER_ADD.d.ts +0 -28
- package/lib/sdk/message/GUILD_MEMBER_REMOVE.d.ts +0 -18
- package/lib/sdk/message/GUILD_MEMBER_UPDATE.d.ts +0 -33
- package/lib/sdk/message/MESSAGE_DELETE.d.ts +0 -11
- package/lib/sdk/message/MESSAGE_REACTION_ADD.d.ts +0 -42
- package/lib/sdk/message/MESSAGE_UPDATE.d.ts +0 -56
- package/lib/sdk/message/PRESENCE_UPDATE.d.ts +0 -69
- package/lib/sdk/message/READY.d.ts +0 -9
- package/lib/sdk/message/TYPING_START.d.ts +0 -35
- package/lib/sdk/message/VOICE_CHANNEL_STATUS_UPDATE.d.ts +0 -10
- package/lib/sdk/message/VOICE_STATE_UPDATE.d.ts +0 -41
- package/lib/sdk/message.d.ts +0 -101
- package/lib/sdk/types.js +0 -25
- package/lib/sdk/wss.d.ts +0 -27
- package/lib/sdk/wss.types.d.ts +0 -30
- /package/lib/sdk/{core/from.js → createPicFrom.js} +0 -0
package/lib/sdk/api.js
CHANGED
|
@@ -1,23 +1,30 @@
|
|
|
1
1
|
import FormData from 'form-data';
|
|
2
2
|
import axios from 'axios';
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
3
|
+
import { getDiscordConfig } from '../config.js';
|
|
4
|
+
import { HttpsProxyAgent } from 'https-proxy-agent';
|
|
5
|
+
import { createPicFrom } from './createPicFrom.js';
|
|
5
6
|
|
|
7
|
+
const API_URL = 'https://discord.com/api/v10';
|
|
8
|
+
const CDB_URL = 'https://cdn.discordapp.com';
|
|
6
9
|
/**
|
|
7
10
|
* api接口
|
|
8
11
|
*/
|
|
9
12
|
class DCAPI {
|
|
10
|
-
API_URL = 'https://discord.com/api/v10';
|
|
11
|
-
CDB_URL = 'https://cdn.discordapp.com';
|
|
12
13
|
/**
|
|
13
14
|
* 基础请求
|
|
14
15
|
* @param opstion
|
|
15
16
|
* @returns
|
|
16
17
|
*/
|
|
17
18
|
request(options) {
|
|
18
|
-
const
|
|
19
|
+
const value = getDiscordConfig();
|
|
20
|
+
const token = value.token;
|
|
21
|
+
const requestConfig = value.request_config || {};
|
|
22
|
+
if (value.request_proxy) {
|
|
23
|
+
requestConfig.httpsAgent = new HttpsProxyAgent(value.request_proxy);
|
|
24
|
+
}
|
|
19
25
|
const service = axios.create({
|
|
20
|
-
|
|
26
|
+
...requestConfig,
|
|
27
|
+
baseURL: API_URL,
|
|
21
28
|
timeout: 6000,
|
|
22
29
|
headers: {
|
|
23
30
|
'Content-Type': 'application/json',
|
|
@@ -32,16 +39,10 @@ class DCAPI {
|
|
|
32
39
|
* @returns
|
|
33
40
|
*/
|
|
34
41
|
requestCDN(options) {
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
timeout: 6000,
|
|
39
|
-
headers: {
|
|
40
|
-
'Content-Type': 'application/json',
|
|
41
|
-
'Authorization': `Bot ${token}`
|
|
42
|
-
}
|
|
42
|
+
return this.request({
|
|
43
|
+
baseURL: CDB_URL,
|
|
44
|
+
...options
|
|
43
45
|
});
|
|
44
|
-
return service(options);
|
|
45
46
|
}
|
|
46
47
|
/**
|
|
47
48
|
* 创建用户url地址
|
|
@@ -50,7 +51,7 @@ class DCAPI {
|
|
|
50
51
|
* @returns
|
|
51
52
|
*/
|
|
52
53
|
userAvatar(user_id, avatar_hash) {
|
|
53
|
-
return `${
|
|
54
|
+
return `${CDB_URL}/avatars/${user_id}/${avatar_hash}.png`;
|
|
54
55
|
}
|
|
55
56
|
/**
|
|
56
57
|
*
|
|
@@ -72,34 +73,20 @@ class DCAPI {
|
|
|
72
73
|
* @param headers
|
|
73
74
|
* @returns
|
|
74
75
|
*/
|
|
75
|
-
async
|
|
76
|
-
return this.request({
|
|
77
|
-
url: `channels/${channel_id}/messages`,
|
|
78
|
-
method: 'post',
|
|
79
|
-
headers: headers,
|
|
80
|
-
data
|
|
81
|
-
}).then(res => res?.data);
|
|
82
|
-
}
|
|
83
|
-
/**
|
|
84
|
-
*
|
|
85
|
-
* @param channel_id
|
|
86
|
-
* @param img
|
|
87
|
-
* @returns
|
|
88
|
-
*/
|
|
89
|
-
async channelsMessagesImage(channel_id, img, param) {
|
|
90
|
-
const from = await createPicFrom(img);
|
|
91
|
-
if (!from)
|
|
92
|
-
return;
|
|
93
|
-
const { picData, name } = from;
|
|
76
|
+
async channelsMessagesForm(channel_id, param = {}, img) {
|
|
94
77
|
const formData = new FormData();
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
78
|
+
for (const key in param) {
|
|
79
|
+
if (param[key]) {
|
|
80
|
+
formData.append(key, param[key]);
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
if (img) {
|
|
84
|
+
const from = await createPicFrom(img);
|
|
85
|
+
if (from) {
|
|
86
|
+
const { picData, name } = from;
|
|
87
|
+
formData.append('file', picData, name);
|
|
100
88
|
}
|
|
101
89
|
}
|
|
102
|
-
formData.append('file', picData, name);
|
|
103
90
|
return this.request({
|
|
104
91
|
method: 'post',
|
|
105
92
|
url: `channels/${channel_id}/messages`,
|
|
@@ -107,7 +94,7 @@ class DCAPI {
|
|
|
107
94
|
headers: {
|
|
108
95
|
'Content-Type': 'multipart/form-data'
|
|
109
96
|
}
|
|
110
|
-
});
|
|
97
|
+
}).then(res => res.data);
|
|
111
98
|
}
|
|
112
99
|
/**
|
|
113
100
|
* ************
|
|
@@ -1571,4 +1558,4 @@ class DCAPI {
|
|
|
1571
1558
|
}
|
|
1572
1559
|
}
|
|
1573
1560
|
|
|
1574
|
-
export { DCAPI };
|
|
1561
|
+
export { API_URL, CDB_URL, DCAPI };
|
|
@@ -1,126 +1,126 @@
|
|
|
1
1
|
interface User {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
2
|
+
username: string;
|
|
3
|
+
public_flags: number;
|
|
4
|
+
primary_guild: null;
|
|
5
|
+
id: string;
|
|
6
|
+
global_name: string | null;
|
|
7
|
+
discriminator: string;
|
|
8
|
+
collectibles: null;
|
|
9
|
+
clan: null;
|
|
10
|
+
avatar_decoration_data: null;
|
|
11
|
+
avatar: string;
|
|
12
12
|
}
|
|
13
13
|
type Message = {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
}
|
|
14
|
+
type: number;
|
|
15
|
+
tts: boolean;
|
|
16
|
+
timestamp: string;
|
|
17
|
+
pinned: boolean;
|
|
18
|
+
mentions: unknown[];
|
|
19
|
+
mention_roles: unknown[];
|
|
20
|
+
mention_everyone: boolean;
|
|
21
|
+
id: string;
|
|
22
|
+
flags: number;
|
|
23
|
+
embeds: unknown[];
|
|
24
|
+
edited_timestamp: string | null;
|
|
25
|
+
content: string;
|
|
26
|
+
components: unknown[];
|
|
27
|
+
channel_id: string;
|
|
28
|
+
author: User;
|
|
29
|
+
attachments: unknown[];
|
|
30
|
+
};
|
|
31
31
|
type Member = {
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
}
|
|
32
|
+
user: User;
|
|
33
|
+
unusual_dm_activity_until: string | null;
|
|
34
|
+
roles: string[];
|
|
35
|
+
premium_since: string | null;
|
|
36
|
+
permissions: string;
|
|
37
|
+
pending: boolean;
|
|
38
|
+
nick: string | null;
|
|
39
|
+
mute: boolean;
|
|
40
|
+
joined_at: string;
|
|
41
|
+
flags: number;
|
|
42
|
+
deaf: boolean;
|
|
43
|
+
communication_disabled_until: string | null;
|
|
44
|
+
banner: string | null;
|
|
45
|
+
avatar: string | null;
|
|
46
|
+
};
|
|
47
47
|
type DiscordGuild = {
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
}
|
|
48
|
+
locale: string;
|
|
49
|
+
id: string;
|
|
50
|
+
features: string[];
|
|
51
|
+
};
|
|
52
52
|
type PublicChannel = {
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
}
|
|
53
|
+
type: number;
|
|
54
|
+
topic: string | null;
|
|
55
|
+
theme_color: number | null;
|
|
56
|
+
rate_limit_per_user: number;
|
|
57
|
+
position: number;
|
|
58
|
+
permissions: string;
|
|
59
|
+
parent_id: string;
|
|
60
|
+
nsfw: boolean;
|
|
61
|
+
name: string;
|
|
62
|
+
last_message_id: string;
|
|
63
|
+
id: string;
|
|
64
|
+
icon_emoji: {
|
|
65
|
+
name: string;
|
|
66
|
+
id: string | null;
|
|
67
|
+
};
|
|
68
|
+
guild_id: string;
|
|
69
|
+
flags: number;
|
|
70
|
+
};
|
|
71
71
|
interface Channel {
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
72
|
+
type: number;
|
|
73
|
+
recipients: any[];
|
|
74
|
+
recipient_flags: number;
|
|
75
|
+
last_message_id: string;
|
|
76
|
+
id: string;
|
|
77
|
+
flags: number;
|
|
78
78
|
}
|
|
79
79
|
interface Data {
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
80
|
+
id: number;
|
|
81
|
+
custom_id: string;
|
|
82
|
+
component_type: number;
|
|
83
83
|
}
|
|
84
84
|
type Public = {
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
}
|
|
85
|
+
version: number;
|
|
86
|
+
type: number;
|
|
87
|
+
token: string;
|
|
88
|
+
member: Member;
|
|
89
|
+
message: Message;
|
|
90
|
+
locale: string;
|
|
91
|
+
id: string;
|
|
92
|
+
guild_locale: string;
|
|
93
|
+
guild_id: string;
|
|
94
|
+
guild: DiscordGuild;
|
|
95
|
+
entitlement_sku_ids: any[];
|
|
96
|
+
entitlements: any[];
|
|
97
|
+
data: Data;
|
|
98
|
+
context: number;
|
|
99
|
+
channel_id: string;
|
|
100
|
+
channel: PublicChannel;
|
|
101
|
+
authorizing_integration_owners: Record<string, string>;
|
|
102
|
+
attachment_size_limit: number;
|
|
103
|
+
application_id: string;
|
|
104
|
+
app_permissions: string;
|
|
105
|
+
};
|
|
106
106
|
type Private = {
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
}
|
|
124
|
-
type INTERACTION_CREATE_TYPE = Public | Private
|
|
107
|
+
version: number;
|
|
108
|
+
type: number;
|
|
109
|
+
token: string;
|
|
110
|
+
user: User;
|
|
111
|
+
message: Message;
|
|
112
|
+
locale: string;
|
|
113
|
+
id: string;
|
|
114
|
+
entitlements: any[];
|
|
115
|
+
data: Data;
|
|
116
|
+
context: number;
|
|
117
|
+
channel_id: string;
|
|
118
|
+
channel: Channel;
|
|
119
|
+
authorizing_integration_owners: Record<string, string>;
|
|
120
|
+
attachment_size_limit: number;
|
|
121
|
+
application_id: string;
|
|
122
|
+
app_permissions: string;
|
|
123
|
+
};
|
|
124
|
+
type INTERACTION_CREATE_TYPE = Public | Private;
|
|
125
125
|
|
|
126
|
-
export type { INTERACTION_CREATE_TYPE }
|
|
126
|
+
export type { INTERACTION_CREATE_TYPE };
|
|
@@ -3,57 +3,57 @@
|
|
|
3
3
|
* @param event
|
|
4
4
|
*/
|
|
5
5
|
type MESSAGE_CREATE_TYPE = {
|
|
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
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
}
|
|
6
|
+
type: number;
|
|
7
|
+
tts: boolean;
|
|
8
|
+
timestamp: string;
|
|
9
|
+
referenced_message: null;
|
|
10
|
+
pinned: boolean;
|
|
11
|
+
nonce: string;
|
|
12
|
+
mentions: {
|
|
13
|
+
username: string;
|
|
14
|
+
public_flags: number;
|
|
15
|
+
member: any;
|
|
16
|
+
id: string;
|
|
17
|
+
global_name: null;
|
|
18
|
+
discriminator: string;
|
|
19
|
+
bot: boolean;
|
|
20
|
+
avatar_decoration_data: null;
|
|
21
|
+
avatar: string;
|
|
22
|
+
}[];
|
|
23
|
+
mention_roles: any[];
|
|
24
|
+
mention_everyone: boolean;
|
|
25
|
+
member: {
|
|
26
|
+
roles: any[];
|
|
27
|
+
premium_since: null;
|
|
28
|
+
pending: boolean;
|
|
29
|
+
nick: null;
|
|
30
|
+
mute: boolean;
|
|
31
|
+
joined_at: string;
|
|
32
|
+
flags: number;
|
|
33
|
+
deaf: boolean;
|
|
34
|
+
communication_disabled_until: null;
|
|
35
|
+
avatar: null;
|
|
36
|
+
};
|
|
37
|
+
id: string;
|
|
38
|
+
flags: number;
|
|
39
|
+
embeds: any[];
|
|
40
|
+
edited_timestamp: null;
|
|
41
|
+
content: string;
|
|
42
|
+
components: any[];
|
|
43
|
+
channel_id: string;
|
|
44
|
+
author: {
|
|
45
|
+
username: string;
|
|
46
|
+
public_flags: number;
|
|
47
|
+
premium_type: number;
|
|
48
|
+
id: string;
|
|
49
|
+
global_name: string;
|
|
50
|
+
discriminator: string;
|
|
51
|
+
avatar_decoration_data: null;
|
|
52
|
+
avatar: string;
|
|
53
|
+
bot?: boolean;
|
|
54
|
+
};
|
|
55
|
+
attachments: any[];
|
|
56
|
+
guild_id: string;
|
|
57
|
+
};
|
|
58
58
|
|
|
59
|
-
export type { MESSAGE_CREATE_TYPE }
|
|
59
|
+
export type { MESSAGE_CREATE_TYPE };
|
package/lib/sdk/types.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
declare const AvailableIntentsEventsEnum: string[]
|
|
2
|
-
type DCIntentsEnum = (typeof AvailableIntentsEventsEnum)[number]
|
|
1
|
+
declare const AvailableIntentsEventsEnum: string[];
|
|
2
|
+
type DCIntentsEnum = (typeof AvailableIntentsEventsEnum)[number];
|
|
3
3
|
|
|
4
|
-
export { AvailableIntentsEventsEnum }
|
|
5
|
-
export type { DCIntentsEnum }
|
|
4
|
+
export { AvailableIntentsEventsEnum };
|
|
5
|
+
export type { DCIntentsEnum };
|