@alemonjs/discord 0.2.9 → 0.2.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/assets/index.css +1248 -1
- package/dist/assets/index.js +10990 -4
- package/dist/index.html +1 -1
- package/lib/env.js +1 -0
- package/lib/index.d.ts +4 -3
- package/lib/index.js +120 -221
- package/lib/sdk/{platform/discord/sdk/api.d.ts → api.d.ts} +54 -2
- package/lib/sdk/{platform/discord/sdk/api.js → api.js} +20 -7
- package/lib/sdk/config.js +10 -0
- package/lib/sdk/intents.js +154 -0
- package/lib/sdk/message/INTERACTION_CREATE.d.ts +126 -0
- package/lib/sdk/message.d.ts +101 -0
- package/lib/sdk/types.d.ts +5 -0
- package/lib/sdk/types.js +25 -0
- package/lib/sdk/{platform/discord/sdk/wss.d.ts → wss.d.ts} +1 -1
- package/lib/sdk/{platform/discord/sdk/wss.js → wss.js} +14 -7
- package/lib/sdk/{platform/discord/sdk/wss.types.d.ts → wss.types.d.ts} +4 -0
- package/lib/send.js +204 -0
- package/package.json +4 -1
- package/lib/sdk/platform/discord/sdk/config.js +0 -29
- package/lib/sdk/platform/discord/sdk/intents.js +0 -36
- package/lib/sdk/platform/discord/sdk/message.d.ts +0 -37
- package/lib/sdk/platform/discord/sdk/types.d.ts +0 -4
- /package/lib/sdk/core/{utils/from.js → from.js} +0 -0
- /package/lib/sdk/{platform/discord/sdk/message → message}/CHANNEL_TOPIC_UPDATE.d.ts +0 -0
- /package/lib/sdk/{platform/discord/sdk/message → message}/CHANNEL_UPDATE.d.ts +0 -0
- /package/lib/sdk/{platform/discord/sdk/message → message}/GUILD_MEMBER_ADD.d.ts +0 -0
- /package/lib/sdk/{platform/discord/sdk/message → message}/GUILD_MEMBER_REMOVE.d.ts +0 -0
- /package/lib/sdk/{platform/discord/sdk/message → message}/GUILD_MEMBER_UPDATE.d.ts +0 -0
- /package/lib/sdk/{platform/discord/sdk/message → message}/MESSAGE_CREATE.d.ts +0 -0
- /package/lib/sdk/{platform/discord/sdk/message → message}/MESSAGE_DELETE.d.ts +0 -0
- /package/lib/sdk/{platform/discord/sdk/message → message}/MESSAGE_REACTION_ADD.d.ts +0 -0
- /package/lib/sdk/{platform/discord/sdk/message → message}/MESSAGE_UPDATE.d.ts +0 -0
- /package/lib/sdk/{platform/discord/sdk/message → message}/PRESENCE_UPDATE.d.ts +0 -0
- /package/lib/sdk/{platform/discord/sdk/message → message}/READY.d.ts +0 -0
- /package/lib/sdk/{platform/discord/sdk/message → message}/TYPING_START.d.ts +0 -0
- /package/lib/sdk/{platform/discord/sdk/message → message}/VOICE_CHANNEL_STATUS_UPDATE.d.ts +0 -0
- /package/lib/sdk/{platform/discord/sdk/message → message}/VOICE_STATE_UPDATE.d.ts +0 -0
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* GUILDS (1 << 0)
|
|
3
|
+
- GUILD_CREATE
|
|
4
|
+
- GUILD_UPDATE
|
|
5
|
+
- GUILD_DELETE
|
|
6
|
+
- GUILD_ROLE_CREATE
|
|
7
|
+
- GUILD_ROLE_UPDATE
|
|
8
|
+
- GUILD_ROLE_DELETE
|
|
9
|
+
- CHANNEL_CREATE
|
|
10
|
+
- CHANNEL_UPDATE
|
|
11
|
+
- CHANNEL_DELETE
|
|
12
|
+
- CHANNEL_PINS_UPDATE
|
|
13
|
+
- THREAD_CREATE
|
|
14
|
+
- THREAD_UPDATE
|
|
15
|
+
- THREAD_DELETE
|
|
16
|
+
- THREAD_LIST_SYNC
|
|
17
|
+
- THREAD_MEMBER_UPDATE
|
|
18
|
+
- THREAD_MEMBERS_UPDATE *
|
|
19
|
+
- STAGE_INSTANCE_CREATE
|
|
20
|
+
- STAGE_INSTANCE_UPDATE
|
|
21
|
+
- STAGE_INSTANCE_DELETE
|
|
22
|
+
|
|
23
|
+
GUILD_MEMBERS (1 << 1) **
|
|
24
|
+
- GUILD_MEMBER_ADD
|
|
25
|
+
- GUILD_MEMBER_UPDATE
|
|
26
|
+
- GUILD_MEMBER_REMOVE
|
|
27
|
+
- THREAD_MEMBERS_UPDATE *
|
|
28
|
+
|
|
29
|
+
GUILD_MODERATION (1 << 2)
|
|
30
|
+
- GUILD_AUDIT_LOG_ENTRY_CREATE
|
|
31
|
+
- GUILD_BAN_ADD
|
|
32
|
+
- GUILD_BAN_REMOVE
|
|
33
|
+
|
|
34
|
+
GUILD_EXPRESSIONS (1 << 3)
|
|
35
|
+
- GUILD_EMOJIS_UPDATE
|
|
36
|
+
- GUILD_STICKERS_UPDATE
|
|
37
|
+
- GUILD_SOUNDBOARD_SOUND_CREATE
|
|
38
|
+
- GUILD_SOUNDBOARD_SOUND_UPDATE
|
|
39
|
+
- GUILD_SOUNDBOARD_SOUND_DELETE
|
|
40
|
+
- GUILD_SOUNDBOARD_SOUNDS_UPDATE
|
|
41
|
+
|
|
42
|
+
GUILD_INTEGRATIONS (1 << 4)
|
|
43
|
+
- GUILD_INTEGRATIONS_UPDATE
|
|
44
|
+
- INTEGRATION_CREATE
|
|
45
|
+
- INTEGRATION_UPDATE
|
|
46
|
+
- INTEGRATION_DELETE
|
|
47
|
+
|
|
48
|
+
GUILD_WEBHOOKS (1 << 5)
|
|
49
|
+
- WEBHOOKS_UPDATE
|
|
50
|
+
|
|
51
|
+
GUILD_INVITES (1 << 6)
|
|
52
|
+
- INVITE_CREATE
|
|
53
|
+
- INVITE_DELETE
|
|
54
|
+
|
|
55
|
+
GUILD_VOICE_STATES (1 << 7)
|
|
56
|
+
- VOICE_CHANNEL_EFFECT_SEND
|
|
57
|
+
- VOICE_STATE_UPDATE
|
|
58
|
+
|
|
59
|
+
GUILD_PRESENCES (1 << 8) **
|
|
60
|
+
- PRESENCE_UPDATE
|
|
61
|
+
|
|
62
|
+
GUILD_MESSAGES (1 << 9)
|
|
63
|
+
- MESSAGE_CREATE
|
|
64
|
+
- MESSAGE_UPDATE
|
|
65
|
+
- MESSAGE_DELETE
|
|
66
|
+
- MESSAGE_DELETE_BULK
|
|
67
|
+
|
|
68
|
+
GUILD_MESSAGE_REACTIONS (1 << 10)
|
|
69
|
+
- MESSAGE_REACTION_ADD
|
|
70
|
+
- MESSAGE_REACTION_REMOVE
|
|
71
|
+
- MESSAGE_REACTION_REMOVE_ALL
|
|
72
|
+
- MESSAGE_REACTION_REMOVE_EMOJI
|
|
73
|
+
|
|
74
|
+
GUILD_MESSAGE_TYPING (1 << 11)
|
|
75
|
+
- TYPING_START
|
|
76
|
+
|
|
77
|
+
DIRECT_MESSAGES (1 << 12)
|
|
78
|
+
- MESSAGE_CREATE
|
|
79
|
+
- MESSAGE_UPDATE
|
|
80
|
+
- MESSAGE_DELETE
|
|
81
|
+
- CHANNEL_PINS_UPDATE
|
|
82
|
+
|
|
83
|
+
DIRECT_MESSAGE_REACTIONS (1 << 13)
|
|
84
|
+
- MESSAGE_REACTION_ADD
|
|
85
|
+
- MESSAGE_REACTION_REMOVE
|
|
86
|
+
- MESSAGE_REACTION_REMOVE_ALL
|
|
87
|
+
- MESSAGE_REACTION_REMOVE_EMOJI
|
|
88
|
+
|
|
89
|
+
DIRECT_MESSAGE_TYPING (1 << 14)
|
|
90
|
+
- TYPING_START
|
|
91
|
+
|
|
92
|
+
MESSAGE_CONTENT (1 << 15) ***
|
|
93
|
+
|
|
94
|
+
GUILD_SCHEDULED_EVENTS (1 << 16)
|
|
95
|
+
- GUILD_SCHEDULED_EVENT_CREATE
|
|
96
|
+
- GUILD_SCHEDULED_EVENT_UPDATE
|
|
97
|
+
- GUILD_SCHEDULED_EVENT_DELETE
|
|
98
|
+
- GUILD_SCHEDULED_EVENT_USER_ADD
|
|
99
|
+
- GUILD_SCHEDULED_EVENT_USER_REMOVE
|
|
100
|
+
|
|
101
|
+
AUTO_MODERATION_CONFIGURATION (1 << 20)
|
|
102
|
+
- AUTO_MODERATION_RULE_CREATE
|
|
103
|
+
- AUTO_MODERATION_RULE_UPDATE
|
|
104
|
+
- AUTO_MODERATION_RULE_DELETE
|
|
105
|
+
|
|
106
|
+
AUTO_MODERATION_EXECUTION (1 << 21)
|
|
107
|
+
- AUTO_MODERATION_ACTION_EXECUTION
|
|
108
|
+
|
|
109
|
+
GUILD_MESSAGE_POLLS (1 << 24)
|
|
110
|
+
- MESSAGE_POLL_VOTE_ADD
|
|
111
|
+
- MESSAGE_POLL_VOTE_REMOVE
|
|
112
|
+
|
|
113
|
+
DIRECT_MESSAGE_POLLS (1 << 25)
|
|
114
|
+
- MESSAGE_POLL_VOTE_ADD
|
|
115
|
+
- MESSAGE_POLL_VOTE_REMOVE
|
|
116
|
+
*/
|
|
117
|
+
const DCIntentsMap = {
|
|
118
|
+
GUILDS: 1 << 0,
|
|
119
|
+
GUILD_MEMBERS: 1 << 1,
|
|
120
|
+
GUILD_MODERATION: 1 << 2,
|
|
121
|
+
GUILD_EXPRESSIONS: 1 << 3,
|
|
122
|
+
GUILD_INTEGRATIONS: 1 << 4,
|
|
123
|
+
GUILD_WEBHOOKS: 1 << 5,
|
|
124
|
+
GUILD_INVITES: 1 << 6,
|
|
125
|
+
GUILD_VOICE_STATES: 1 << 7,
|
|
126
|
+
GUILD_PRESENCES: 1 << 8,
|
|
127
|
+
GUILD_MESSAGES: 1 << 9,
|
|
128
|
+
GUILD_MESSAGE_REACTIONS: 1 << 10,
|
|
129
|
+
GUILD_MESSAGE_TYPING: 1 << 11,
|
|
130
|
+
DIRECT_MESSAGES: 1 << 12,
|
|
131
|
+
DIRECT_MESSAGE_REACTIONS: 1 << 13,
|
|
132
|
+
DIRECT_MESSAGE_TYPING: 1 << 14,
|
|
133
|
+
MESSAGE_CONTENT: 1 << 15,
|
|
134
|
+
GUILD_SCHEDULED_EVENTS: 1 << 16,
|
|
135
|
+
AUTO_MODERATION_CONFIGURATION: 1 << 20,
|
|
136
|
+
AUTO_MODERATION_EXECUTION: 1 << 21,
|
|
137
|
+
GUILD_MESSAGE_POLLS: 1 << 24,
|
|
138
|
+
DIRECT_MESSAGE_POLLS: 1 << 25
|
|
139
|
+
};
|
|
140
|
+
/**
|
|
141
|
+
*
|
|
142
|
+
* @param intents
|
|
143
|
+
* @returns
|
|
144
|
+
*/
|
|
145
|
+
function getIntents(intents) {
|
|
146
|
+
let result = 0;
|
|
147
|
+
for (const intent of intents) {
|
|
148
|
+
const i = DCIntentsMap[intent];
|
|
149
|
+
result |= i;
|
|
150
|
+
}
|
|
151
|
+
return result;
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
export { getIntents };
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
interface User {
|
|
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
|
+
}
|
|
13
|
+
type Message = {
|
|
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
|
+
type Member = {
|
|
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
|
+
type DiscordGuild = {
|
|
48
|
+
locale: string;
|
|
49
|
+
id: string;
|
|
50
|
+
features: string[];
|
|
51
|
+
};
|
|
52
|
+
type PublicChannel = {
|
|
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
|
+
interface Channel {
|
|
72
|
+
type: number;
|
|
73
|
+
recipients: any[];
|
|
74
|
+
recipient_flags: number;
|
|
75
|
+
last_message_id: string;
|
|
76
|
+
id: string;
|
|
77
|
+
flags: number;
|
|
78
|
+
}
|
|
79
|
+
interface Data {
|
|
80
|
+
id: number;
|
|
81
|
+
custom_id: string;
|
|
82
|
+
component_type: number;
|
|
83
|
+
}
|
|
84
|
+
type Public = {
|
|
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
|
+
type 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
|
+
|
|
126
|
+
export type { INTERACTION_CREATE_TYPE };
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
import { CHANNEL_TOPIC_UPDATE_TYPE } from './message/CHANNEL_TOPIC_UPDATE.js';
|
|
2
|
+
import { CHANNEL_UPDATE_TYPE } from './message/CHANNEL_UPDATE.js';
|
|
3
|
+
import { GUILD_MEMBER_ADD_TYPE } from './message/GUILD_MEMBER_ADD.js';
|
|
4
|
+
import { GUILD_MEMBER_REMOVE_TYPE } from './message/GUILD_MEMBER_REMOVE.js';
|
|
5
|
+
import { GUILD_MEMBER_UPDATE_TYPE } from './message/GUILD_MEMBER_UPDATE.js';
|
|
6
|
+
import { INTERACTION_CREATE_TYPE } from './message/INTERACTION_CREATE.js';
|
|
7
|
+
import { MESSAGE_CREATE_TYPE } from './message/MESSAGE_CREATE.js';
|
|
8
|
+
import { MESSAGE_DELETE_TYPE } from './message/MESSAGE_DELETE.js';
|
|
9
|
+
import { MESSAGE_REACTION_ADD_TYPE } from './message/MESSAGE_REACTION_ADD.js';
|
|
10
|
+
import { MESSAGE_UPDATE_TYPE } from './message/MESSAGE_UPDATE.js';
|
|
11
|
+
import { PRESENCE_UPDATE_TYPE } from './message/PRESENCE_UPDATE.js';
|
|
12
|
+
import { READY_TYPE } from './message/READY.js';
|
|
13
|
+
import { TYPING_START_TYPE } from './message/TYPING_START.js';
|
|
14
|
+
import { VOICE_CHANNEL_STATUS_UPDATE_TYPE } from './message/VOICE_CHANNEL_STATUS_UPDATE.js';
|
|
15
|
+
import { VOICE_STATE_UPDATE_TYPE } from './message/VOICE_STATE_UPDATE.js';
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Discord 事件映射表
|
|
19
|
+
*/
|
|
20
|
+
type DCEventMap = {
|
|
21
|
+
GUILD_CREATE: any;
|
|
22
|
+
GUILD_UPDATE: any;
|
|
23
|
+
GUILD_DELETE: any;
|
|
24
|
+
GUILD_ROLE_CREATE: any;
|
|
25
|
+
GUILD_ROLE_UPDATE: any;
|
|
26
|
+
GUILD_ROLE_DELETE: any;
|
|
27
|
+
CHANNEL_CREATE: any;
|
|
28
|
+
CHANNEL_UPDATE: CHANNEL_UPDATE_TYPE;
|
|
29
|
+
CHANNEL_DELETE: any;
|
|
30
|
+
CHANNEL_PINS_UPDATE: any;
|
|
31
|
+
CHANNEL_TOPIC_UPDATE: CHANNEL_TOPIC_UPDATE_TYPE;
|
|
32
|
+
THREAD_CREATE: any;
|
|
33
|
+
THREAD_UPDATE: any;
|
|
34
|
+
THREAD_DELETE: any;
|
|
35
|
+
THREAD_LIST_SYNC: any;
|
|
36
|
+
THREAD_MEMBER_UPDATE: any;
|
|
37
|
+
THREAD_MEMBERS_UPDATE: any;
|
|
38
|
+
STAGE_INSTANCE_CREATE: any;
|
|
39
|
+
STAGE_INSTANCE_UPDATE: any;
|
|
40
|
+
STAGE_INSTANCE_DELETE: any;
|
|
41
|
+
GUILD_MEMBER_ADD: GUILD_MEMBER_ADD_TYPE;
|
|
42
|
+
GUILD_MEMBER_UPDATE: GUILD_MEMBER_UPDATE_TYPE;
|
|
43
|
+
GUILD_MEMBER_REMOVE: GUILD_MEMBER_REMOVE_TYPE;
|
|
44
|
+
GUILD_AUDIT_LOG_ENTRY_CREATE: any;
|
|
45
|
+
GUILD_BAN_ADD: any;
|
|
46
|
+
GUILD_BAN_REMOVE: any;
|
|
47
|
+
GUILD_EMOJIS_UPDATE: any;
|
|
48
|
+
GUILD_STICKERS_UPDATE: any;
|
|
49
|
+
GUILD_SOUNDBOARD_SOUND_CREATE: any;
|
|
50
|
+
GUILD_SOUNDBOARD_SOUND_UPDATE: any;
|
|
51
|
+
GUILD_SOUNDBOARD_SOUND_DELETE: any;
|
|
52
|
+
GUILD_SOUNDBOARD_SOUNDS_UPDATE: any;
|
|
53
|
+
GUILD_INTEGRATIONS_UPDATE: any;
|
|
54
|
+
INTEGRATION_CREATE: any;
|
|
55
|
+
INTEGRATION_UPDATE: any;
|
|
56
|
+
INTEGRATION_DELETE: any;
|
|
57
|
+
WEBHOOKS_UPDATE: any;
|
|
58
|
+
INVITE_CREATE: any;
|
|
59
|
+
INVITE_DELETE: any;
|
|
60
|
+
VOICE_STATE_UPDATE: VOICE_STATE_UPDATE_TYPE;
|
|
61
|
+
VOICE_CHANNEL_STATUS_UPDATE: VOICE_CHANNEL_STATUS_UPDATE_TYPE;
|
|
62
|
+
VOICE_CHANNEL_EFFECT_SEND: any;
|
|
63
|
+
PRESENCE_UPDATE: PRESENCE_UPDATE_TYPE;
|
|
64
|
+
MESSAGE_CREATE: MESSAGE_CREATE_TYPE;
|
|
65
|
+
MESSAGE_UPDATE: MESSAGE_UPDATE_TYPE;
|
|
66
|
+
MESSAGE_DELETE: MESSAGE_DELETE_TYPE;
|
|
67
|
+
MESSAGE_DELETE_BULK: any;
|
|
68
|
+
MESSAGE_REACTION_ADD: MESSAGE_REACTION_ADD_TYPE;
|
|
69
|
+
MESSAGE_REACTION_REMOVE: any;
|
|
70
|
+
MESSAGE_REACTION_REMOVE_ALL: any;
|
|
71
|
+
MESSAGE_REACTION_REMOVE_EMOJI: any;
|
|
72
|
+
TYPING_START: TYPING_START_TYPE;
|
|
73
|
+
DIRECT_MESSAGE_CREATE: any;
|
|
74
|
+
DIRECT_MESSAGE_UPDATE: any;
|
|
75
|
+
DIRECT_MESSAGE_DELETE: any;
|
|
76
|
+
DIRECT_MESSAGE_PINS_UPDATE: any;
|
|
77
|
+
DIRECT_MESSAGE_REACTION_ADD: any;
|
|
78
|
+
DIRECT_MESSAGE_REACTION_REMOVE: any;
|
|
79
|
+
DIRECT_MESSAGE_REACTION_REMOVE_ALL: any;
|
|
80
|
+
DIRECT_MESSAGE_REACTION_REMOVE_EMOJI: any;
|
|
81
|
+
DIRECT_MESSAGE_TYPING_START: any;
|
|
82
|
+
GUILD_SCHEDULED_EVENT_CREATE: any;
|
|
83
|
+
GUILD_SCHEDULED_EVENT_UPDATE: any;
|
|
84
|
+
GUILD_SCHEDULED_EVENT_DELETE: any;
|
|
85
|
+
GUILD_SCHEDULED_EVENT_USER_ADD: any;
|
|
86
|
+
GUILD_SCHEDULED_EVENT_USER_REMOVE: any;
|
|
87
|
+
AUTO_MODERATION_RULE_CREATE: any;
|
|
88
|
+
AUTO_MODERATION_RULE_UPDATE: any;
|
|
89
|
+
AUTO_MODERATION_RULE_DELETE: any;
|
|
90
|
+
AUTO_MODERATION_ACTION_EXECUTION: any;
|
|
91
|
+
MESSAGE_POLL_VOTE_ADD: any;
|
|
92
|
+
MESSAGE_POLL_VOTE_REMOVE: any;
|
|
93
|
+
DIRECT_MESSAGE_POLL_VOTE_ADD: any;
|
|
94
|
+
DIRECT_MESSAGE_POLL_VOTE_REMOVE: any;
|
|
95
|
+
READY: READY_TYPE;
|
|
96
|
+
ERROR: any;
|
|
97
|
+
INTERACTION_CREATE: INTERACTION_CREATE_TYPE;
|
|
98
|
+
RESUMED: any;
|
|
99
|
+
};
|
|
100
|
+
|
|
101
|
+
export type { DCEventMap };
|
package/lib/sdk/types.js
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
const AvailableIntentsEventsEnum = [
|
|
2
|
+
'GUILDS',
|
|
3
|
+
'GUILD_MEMBERS',
|
|
4
|
+
'GUILD_MODERATION',
|
|
5
|
+
'GUILD_EXPRESSIONS',
|
|
6
|
+
'GUILD_INTEGRATIONS',
|
|
7
|
+
'GUILD_WEBHOOKS',
|
|
8
|
+
'GUILD_INVITES',
|
|
9
|
+
'GUILD_VOICE_STATES',
|
|
10
|
+
'GUILD_PRESENCES',
|
|
11
|
+
'GUILD_MESSAGES',
|
|
12
|
+
'GUILD_MESSAGE_REACTIONS',
|
|
13
|
+
'GUILD_MESSAGE_TYPING',
|
|
14
|
+
'DIRECT_MESSAGES',
|
|
15
|
+
'DIRECT_MESSAGE_REACTIONS',
|
|
16
|
+
'DIRECT_MESSAGE_TYPING',
|
|
17
|
+
'MESSAGE_CONTENT',
|
|
18
|
+
'GUILD_SCHEDULED_EVENTS',
|
|
19
|
+
'AUTO_MODERATION_CONFIGURATION',
|
|
20
|
+
'AUTO_MODERATION_EXECUTION',
|
|
21
|
+
'GUILD_MESSAGE_POLLS',
|
|
22
|
+
'DIRECT_MESSAGE_POLLS'
|
|
23
|
+
];
|
|
24
|
+
|
|
25
|
+
export { AvailableIntentsEventsEnum };
|
|
@@ -19,6 +19,7 @@ class DCClient extends DCAPI {
|
|
|
19
19
|
config.set('intent', opstion.intent);
|
|
20
20
|
config.set('shard', opstion.shard);
|
|
21
21
|
config.set('token', opstion.token);
|
|
22
|
+
config.set('gatewayURL', opstion.gatewayURL);
|
|
22
23
|
return this;
|
|
23
24
|
}
|
|
24
25
|
/**
|
|
@@ -78,18 +79,19 @@ class DCClient extends DCAPI {
|
|
|
78
79
|
* @param shard
|
|
79
80
|
* @returns
|
|
80
81
|
*/
|
|
81
|
-
async connect() {
|
|
82
|
+
async connect(gatewayURL) {
|
|
82
83
|
// 清除序列号
|
|
83
84
|
this.#seq = null;
|
|
84
85
|
// 清除心跳
|
|
85
86
|
clearTimeout(this.#timeout_id);
|
|
86
87
|
// 获取网关
|
|
87
|
-
const url =
|
|
88
|
-
.
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
this.#events['ERROR']
|
|
92
|
-
|
|
88
|
+
const url = gatewayURL ??
|
|
89
|
+
(await this.gateway()
|
|
90
|
+
.then(res => res?.url)
|
|
91
|
+
.catch(err => {
|
|
92
|
+
if (this.#events['ERROR'])
|
|
93
|
+
this.#events['ERROR'](err?.message ?? err);
|
|
94
|
+
}));
|
|
93
95
|
// 没有网关
|
|
94
96
|
if (!url) {
|
|
95
97
|
console.error('[ws] 无法获取网关');
|
|
@@ -129,6 +131,11 @@ class DCClient extends DCAPI {
|
|
|
129
131
|
console.log('[ws] session_id', this.#session_id);
|
|
130
132
|
}
|
|
131
133
|
}
|
|
134
|
+
// const events = ['PRESENCE_UPDATE','TYPING_START']
|
|
135
|
+
// if (!events.includes(t)) {
|
|
136
|
+
// console.log("t", t)
|
|
137
|
+
// console.log("d", d)
|
|
138
|
+
// }
|
|
132
139
|
// 事件处理
|
|
133
140
|
if (this.#events[t]) {
|
|
134
141
|
try {
|
package/lib/send.js
ADDED
|
@@ -0,0 +1,204 @@
|
|
|
1
|
+
import { createResult, ResultCode } from 'alemonjs';
|
|
2
|
+
import { readFileSync } from 'fs';
|
|
3
|
+
|
|
4
|
+
const ImageURLToBuffer = async (url) => {
|
|
5
|
+
const arrayBuffer = await fetch(url).then(res => res.arrayBuffer());
|
|
6
|
+
return Buffer.from(arrayBuffer);
|
|
7
|
+
};
|
|
8
|
+
const createButtonsData = (rows) => {
|
|
9
|
+
return rows.map(row => {
|
|
10
|
+
const val = row.value;
|
|
11
|
+
return {
|
|
12
|
+
type: 1,
|
|
13
|
+
components: val.map(button => {
|
|
14
|
+
const value = button.value;
|
|
15
|
+
let text = '';
|
|
16
|
+
if (typeof button.options?.data === 'object') {
|
|
17
|
+
text = button.options?.data.click;
|
|
18
|
+
}
|
|
19
|
+
else {
|
|
20
|
+
text = button.options.data;
|
|
21
|
+
}
|
|
22
|
+
return {
|
|
23
|
+
type: 2,
|
|
24
|
+
custom_id: text,
|
|
25
|
+
style: 1,
|
|
26
|
+
label: typeof value == 'object' ? value.title : value
|
|
27
|
+
// action: {
|
|
28
|
+
// // 0 link 1 callback , 2 command
|
|
29
|
+
// type: typeof options.data === 'object' ? 1 : options?.isLink ? 0 : 2,
|
|
30
|
+
// data: options?.data ?? '',
|
|
31
|
+
// enter: options?.autoEnter ?? false
|
|
32
|
+
// }
|
|
33
|
+
};
|
|
34
|
+
})
|
|
35
|
+
};
|
|
36
|
+
});
|
|
37
|
+
};
|
|
38
|
+
const sendchannel = (client, param, val) => {
|
|
39
|
+
if (val.length < 0)
|
|
40
|
+
return Promise.all([]);
|
|
41
|
+
const channel_id = param?.channel_id ?? '';
|
|
42
|
+
const content = val
|
|
43
|
+
.filter(item => item.type == 'Mention' || item.type == 'Text' || item.type == 'Link')
|
|
44
|
+
.map(item => {
|
|
45
|
+
if (item.type == 'Link') {
|
|
46
|
+
return `[${item.value}](${item?.options?.link ?? item.value})`;
|
|
47
|
+
}
|
|
48
|
+
else if (item.type == 'Mention') {
|
|
49
|
+
if (item.value == 'everyone' ||
|
|
50
|
+
item.value == 'all' ||
|
|
51
|
+
item.value == '' ||
|
|
52
|
+
typeof item.value != 'string') {
|
|
53
|
+
return `<@everyone>`;
|
|
54
|
+
}
|
|
55
|
+
if (item.options?.belong == 'user') {
|
|
56
|
+
return `<@${item.value}>`;
|
|
57
|
+
}
|
|
58
|
+
else if (item.options?.belong == 'channel') {
|
|
59
|
+
return `<#${item.value}>`;
|
|
60
|
+
}
|
|
61
|
+
return '';
|
|
62
|
+
}
|
|
63
|
+
else if (item.type == 'Text') {
|
|
64
|
+
if (item.options?.style == 'block') {
|
|
65
|
+
return `\`${item.value}\``;
|
|
66
|
+
}
|
|
67
|
+
else if (item.options?.style == 'italic') {
|
|
68
|
+
return `*${item.value}*`;
|
|
69
|
+
}
|
|
70
|
+
else if (item.options?.style == 'bold') {
|
|
71
|
+
return `**${item.value}**`;
|
|
72
|
+
}
|
|
73
|
+
else if (item.options?.style == 'strikethrough') {
|
|
74
|
+
return `~~${item.value}~~`;
|
|
75
|
+
}
|
|
76
|
+
return item.value;
|
|
77
|
+
}
|
|
78
|
+
})
|
|
79
|
+
.join('');
|
|
80
|
+
if (content) {
|
|
81
|
+
return Promise.all([content].map(item => client.channelsMessages(channel_id, {
|
|
82
|
+
content: item
|
|
83
|
+
})));
|
|
84
|
+
}
|
|
85
|
+
const images = val.filter(item => item.type == 'Image' || item.type == 'ImageURL' || item.type == 'ImageFile');
|
|
86
|
+
if (images.length > 0) {
|
|
87
|
+
return Promise.all(images.map(async (item) => {
|
|
88
|
+
if (item.type == 'Image') {
|
|
89
|
+
return client.channelsMessagesImage(channel_id, item.value);
|
|
90
|
+
}
|
|
91
|
+
else if (item.type == 'ImageURL') {
|
|
92
|
+
return client.channelsMessagesImage(channel_id, ImageURLToBuffer(item.value));
|
|
93
|
+
}
|
|
94
|
+
else if (item.type == 'ImageFile') {
|
|
95
|
+
const data = readFileSync(item.value);
|
|
96
|
+
return client.channelsMessagesImage(channel_id, data);
|
|
97
|
+
}
|
|
98
|
+
}));
|
|
99
|
+
}
|
|
100
|
+
// buttons
|
|
101
|
+
const buttons = val.filter(item => item.type == 'BT.group');
|
|
102
|
+
if (buttons && buttons.length > 0) {
|
|
103
|
+
return Promise.all(buttons.map(async (item) => {
|
|
104
|
+
const rows = item.value;
|
|
105
|
+
// 构造成按钮
|
|
106
|
+
const data = createButtonsData(rows);
|
|
107
|
+
const res = await client.channelsMessages(channel_id, {
|
|
108
|
+
content: '',
|
|
109
|
+
components: data
|
|
110
|
+
});
|
|
111
|
+
return createResult(ResultCode.Ok, 'client.groupOpenMessages', {
|
|
112
|
+
id: res.id
|
|
113
|
+
});
|
|
114
|
+
})).catch(err => [
|
|
115
|
+
createResult(ResultCode.Fail, err?.response?.data ?? err?.message ?? err, null)
|
|
116
|
+
]);
|
|
117
|
+
}
|
|
118
|
+
return Promise.all([]);
|
|
119
|
+
};
|
|
120
|
+
const senduser = async (client, param, val) => {
|
|
121
|
+
if (val.length < 0)
|
|
122
|
+
return Promise.all([]);
|
|
123
|
+
const channel_id = param?.channel_id ?? (await client.userMeChannels(param.author_id))?.id;
|
|
124
|
+
const content = val
|
|
125
|
+
.filter(item => item.type == 'Mention' || item.type == 'Text' || item.type == 'Link')
|
|
126
|
+
.map(item => {
|
|
127
|
+
if (item.type == 'Link') {
|
|
128
|
+
return `[${item.value}](${item?.options?.link ?? item.value})`;
|
|
129
|
+
}
|
|
130
|
+
else if (item.type == 'Mention') {
|
|
131
|
+
if (item.value == 'everyone' ||
|
|
132
|
+
item.value == 'all' ||
|
|
133
|
+
item.value == '' ||
|
|
134
|
+
typeof item.value != 'string') {
|
|
135
|
+
return `<@everyone>`;
|
|
136
|
+
}
|
|
137
|
+
if (item.options?.belong == 'user') {
|
|
138
|
+
return `<@${item.value}>`;
|
|
139
|
+
}
|
|
140
|
+
else if (item.options?.belong == 'channel') {
|
|
141
|
+
return `<#${item.value}>`;
|
|
142
|
+
}
|
|
143
|
+
return '';
|
|
144
|
+
}
|
|
145
|
+
else if (item.type == 'Text') {
|
|
146
|
+
if (item.options?.style == 'block') {
|
|
147
|
+
return `\`${item.value}\``;
|
|
148
|
+
}
|
|
149
|
+
else if (item.options?.style == 'italic') {
|
|
150
|
+
return `*${item.value}*`;
|
|
151
|
+
}
|
|
152
|
+
else if (item.options?.style == 'bold') {
|
|
153
|
+
return `**${item.value}**`;
|
|
154
|
+
}
|
|
155
|
+
else if (item.options?.style == 'strikethrough') {
|
|
156
|
+
return `~~${item.value}~~`;
|
|
157
|
+
}
|
|
158
|
+
return item.value;
|
|
159
|
+
}
|
|
160
|
+
})
|
|
161
|
+
.join('');
|
|
162
|
+
if (content) {
|
|
163
|
+
return Promise.all([content].map(item => client.channelsMessages(channel_id, {
|
|
164
|
+
content: item
|
|
165
|
+
})));
|
|
166
|
+
}
|
|
167
|
+
const images = val.filter(item => item.type == 'Image' || item.type == 'ImageURL' || item.type == 'ImageFile');
|
|
168
|
+
if (images && images.length > 0) {
|
|
169
|
+
return Promise.all(images.map(async (item) => {
|
|
170
|
+
if (item.type == 'Image') {
|
|
171
|
+
return client.channelsMessagesImage(channel_id, item.value);
|
|
172
|
+
}
|
|
173
|
+
else if (item.type == 'ImageURL') {
|
|
174
|
+
return client.channelsMessagesImage(channel_id, ImageURLToBuffer(item.value));
|
|
175
|
+
}
|
|
176
|
+
else if (item.type == 'ImageFile') {
|
|
177
|
+
const data = readFileSync(item.value);
|
|
178
|
+
return client.channelsMessagesImage(channel_id, data);
|
|
179
|
+
}
|
|
180
|
+
}));
|
|
181
|
+
}
|
|
182
|
+
// buttons
|
|
183
|
+
const buttons = val.filter(item => item.type == 'BT.group');
|
|
184
|
+
if (buttons && buttons.length > 0) {
|
|
185
|
+
return Promise.all(buttons.map(async (item) => {
|
|
186
|
+
const rows = item.value;
|
|
187
|
+
// 构造成按钮
|
|
188
|
+
const data = createButtonsData(rows);
|
|
189
|
+
// console.log("data", data)
|
|
190
|
+
const res = await client.channelsMessages(channel_id, {
|
|
191
|
+
content: '',
|
|
192
|
+
components: data
|
|
193
|
+
});
|
|
194
|
+
return createResult(ResultCode.Ok, 'client.groupOpenMessages', {
|
|
195
|
+
id: res.id
|
|
196
|
+
});
|
|
197
|
+
})).catch(err => [
|
|
198
|
+
createResult(ResultCode.Fail, err?.response?.data ?? err?.message ?? err, null)
|
|
199
|
+
]);
|
|
200
|
+
}
|
|
201
|
+
return Promise.all([]);
|
|
202
|
+
};
|
|
203
|
+
|
|
204
|
+
export { sendchannel, senduser };
|