@impulsedev/chameleon 1.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/LICENSE +21 -0
- package/README.md +23 -0
- package/dist/index.d.ts +2797 -0
- package/dist/index.js +3814 -0
- package/package.json +49 -0
package/dist/index.js
ADDED
|
@@ -0,0 +1,3814 @@
|
|
|
1
|
+
// src/types/user/index.ts
|
|
2
|
+
var UserFlag = {
|
|
3
|
+
STAFF: 1 << 0,
|
|
4
|
+
PARTNER: 1 << 1,
|
|
5
|
+
HYPESQUAD: 1 << 2,
|
|
6
|
+
BUG_HUNTER_LEVEL_1: 1 << 3,
|
|
7
|
+
HYPESQUAD_ONLINE_HOUSE_1: 1 << 6,
|
|
8
|
+
HYPESQUAD_ONLINE_HOUSE_2: 1 << 7,
|
|
9
|
+
HYPESQUAD_ONLINE_HOUSE_3: 1 << 8,
|
|
10
|
+
PREMIUM_EARLY_SUPPORTER: 1 << 9,
|
|
11
|
+
TEAM_PSEUDO_USER: 1 << 10,
|
|
12
|
+
BUG_HUNTER_LEVEL_2: 1 << 14,
|
|
13
|
+
VERIFIED_BOT: 1 << 16,
|
|
14
|
+
VERIFIED_DEVELOPER: 1 << 17,
|
|
15
|
+
CERTIFIED_MODERATOR: 1 << 18,
|
|
16
|
+
BOT_HTTP_INTERACTIONS: 1 << 19
|
|
17
|
+
};
|
|
18
|
+
var PremiumType = {
|
|
19
|
+
NONE: 0,
|
|
20
|
+
NITRO_CLASSIC: 1,
|
|
21
|
+
// older users have it / user that got a classic sub, nowdays not used
|
|
22
|
+
NITRO: 2,
|
|
23
|
+
NITRO_BASIC: 3
|
|
24
|
+
};
|
|
25
|
+
var VisibilityType = {
|
|
26
|
+
NONE: 0,
|
|
27
|
+
EVERYONE: 1
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
// src/types/guild/index.ts
|
|
31
|
+
var DefaultMessageNotificationLevel = {
|
|
32
|
+
ALL_MESSAGES: 0,
|
|
33
|
+
ONLY_MENTIONS: 1
|
|
34
|
+
};
|
|
35
|
+
var ExplicitContentFilterLevel = {
|
|
36
|
+
DISABLED: 0,
|
|
37
|
+
MEMBERS_WITHOUT_ROLES: 1,
|
|
38
|
+
ALL_MEMBERS: 2
|
|
39
|
+
};
|
|
40
|
+
var MFALevel = {
|
|
41
|
+
NONE: 0,
|
|
42
|
+
ELEVATED: 1
|
|
43
|
+
};
|
|
44
|
+
var VerificationLevel = {
|
|
45
|
+
NONE: 0,
|
|
46
|
+
LOW: 1,
|
|
47
|
+
MEDIUM: 2,
|
|
48
|
+
HIGH: 3,
|
|
49
|
+
VERY_HIGH: 4
|
|
50
|
+
};
|
|
51
|
+
var GuildNSFWLevel = {
|
|
52
|
+
DEFAULT: 0,
|
|
53
|
+
EXPLICIT: 1,
|
|
54
|
+
SAFE: 2,
|
|
55
|
+
AGE_RESTRICTED: 3
|
|
56
|
+
};
|
|
57
|
+
var PremiumTier = {
|
|
58
|
+
NONE: 0,
|
|
59
|
+
TIER_1: 1,
|
|
60
|
+
TIER_2: 2,
|
|
61
|
+
TIER_3: 3
|
|
62
|
+
};
|
|
63
|
+
var SystemChannelFlag = {
|
|
64
|
+
SUPPRESS_JOIN_NOTIFICATIONS: 1 << 0,
|
|
65
|
+
SUPPRESS_PREMIUM_SUBSCRIPTIONS: 1 << 1,
|
|
66
|
+
SUPPRESS_GUILD_REMINDER_NOTIFICATIONS: 1 << 2,
|
|
67
|
+
SUPPRESS_JOIN_NOTIFICATION_REPLIES: 1 << 3,
|
|
68
|
+
SUPPRESS_ROLE_SUBSCRIPTION_PURCHASE_NOTIFICATIONS: 1 << 4,
|
|
69
|
+
SUPPRESS_ROLE_SUBSCRIPTION_PURCHASE_NOTIFICATION_REPLIES: 1 << 5
|
|
70
|
+
};
|
|
71
|
+
var GuildMemberFlag = {
|
|
72
|
+
DID_REJOIN: 1 << 0,
|
|
73
|
+
COMPLETED_ONBOARDING: 1 << 1,
|
|
74
|
+
BYPASSES_VERIFICATION: 1 << 2,
|
|
75
|
+
STARTED_ONBOARDING: 1 << 3,
|
|
76
|
+
IS_GUEST: 1 << 4,
|
|
77
|
+
STARTED_HOME_ACTIONS: 1 << 5,
|
|
78
|
+
COMPLETED_HOME_ACTIONS: 1 << 6,
|
|
79
|
+
AUTOMOD_QUARANTINED_USERNAME: 1 << 7,
|
|
80
|
+
DM_SETTINGS_UPSELL_ACKNOWLEDGED: 1 << 9,
|
|
81
|
+
AUTOMOD_QUARANTINED_GUILD_TAG: 1 << 10
|
|
82
|
+
};
|
|
83
|
+
|
|
84
|
+
// src/types/channel/index.ts
|
|
85
|
+
var ChannelType = {
|
|
86
|
+
GUILD_TEXT: 0,
|
|
87
|
+
DM: 1,
|
|
88
|
+
GUILD_VOICE: 2,
|
|
89
|
+
GROUP_DM: 3,
|
|
90
|
+
GUILD_CATEGORY: 4,
|
|
91
|
+
GUILD_ANNOUNCEMENT: 5,
|
|
92
|
+
ANNOUNCEMENT_THREAD: 10,
|
|
93
|
+
PUBLIC_THREAD: 11,
|
|
94
|
+
PRIVATE_THREAD: 12,
|
|
95
|
+
GUILD_STAGE_VOICE: 13,
|
|
96
|
+
GUILD_DIRECTORY: 14,
|
|
97
|
+
GUILD_FORUM: 15,
|
|
98
|
+
GUILD_MEDIA: 16
|
|
99
|
+
};
|
|
100
|
+
var VideoQualityMode = {
|
|
101
|
+
AUTO: 1,
|
|
102
|
+
FULL: 2
|
|
103
|
+
};
|
|
104
|
+
var ChannelFlag = {
|
|
105
|
+
PINNED: 1 << 1,
|
|
106
|
+
REQUIRE_TAG: 1 << 4,
|
|
107
|
+
HIDE_MEDIA_DOWNLOAD_OPTIONS: 1 << 15
|
|
108
|
+
};
|
|
109
|
+
var SortOrderType = {
|
|
110
|
+
LATEST_ACTIVITY: 0,
|
|
111
|
+
CREATION_DATE: 1
|
|
112
|
+
};
|
|
113
|
+
var ForumLayoutType = {
|
|
114
|
+
NOT_SET: 0,
|
|
115
|
+
LIST_VIEW: 1,
|
|
116
|
+
GALLERY_VIEW: 2
|
|
117
|
+
};
|
|
118
|
+
|
|
119
|
+
// src/types/message/index.ts
|
|
120
|
+
var MessageType = {
|
|
121
|
+
DEFAULT: 0,
|
|
122
|
+
RECIPIENT_ADD: 1,
|
|
123
|
+
RECIPIENT_REMOVE: 2,
|
|
124
|
+
CALL: 3,
|
|
125
|
+
CHANNEL_NAME_CHANGE: 4,
|
|
126
|
+
CHANNEL_ICON_CHANGE: 5,
|
|
127
|
+
CHANNEL_PINNED_MESSAGE: 6,
|
|
128
|
+
USER_JOIN: 7,
|
|
129
|
+
GUILD_BOOST: 8,
|
|
130
|
+
GUILD_BOOST_TIER_1: 9,
|
|
131
|
+
GUILD_BOOST_TIER_2: 10,
|
|
132
|
+
GUILD_BOOST_TIER_3: 11,
|
|
133
|
+
CHANNEL_FOLLOW_ADD: 12,
|
|
134
|
+
GUILD_DISCOVERY_DISQUALIFIED: 14,
|
|
135
|
+
GUILD_DISCOVERY_REQUALIFIED: 15,
|
|
136
|
+
GUILD_DISCOVERY_GRACE_PERIOD_INITIAL_WARNING: 16,
|
|
137
|
+
GUILD_DISCOVERY_GRACE_PERIOD_FINAL_WARNING: 17,
|
|
138
|
+
THREAD_CREATED: 18,
|
|
139
|
+
REPLY: 19,
|
|
140
|
+
CHAT_INPUT_COMMAND: 20,
|
|
141
|
+
THREAD_STARTER_MESSAGE: 21,
|
|
142
|
+
GUILD_INVITE_REMINDER: 22,
|
|
143
|
+
CONTEXT_MENU_COMMAND: 23,
|
|
144
|
+
AUTO_MODERATION_ACTION: 24,
|
|
145
|
+
ROLE_SUBSCRIPTION_PURCHASE: 25,
|
|
146
|
+
INTERACTION_PREMIUM_UPSELL: 26,
|
|
147
|
+
STAGE_START: 27,
|
|
148
|
+
STAGE_END: 28,
|
|
149
|
+
STAGE_SPEAKER: 29,
|
|
150
|
+
STAGE_TOPIC: 31,
|
|
151
|
+
GUILD_APPLICATION_PREMIUM_SUBSCRIPTION: 32,
|
|
152
|
+
GUILD_INCIDENT_ALERT_MODE_ENABLED: 36,
|
|
153
|
+
GUILD_INCIDENT_ALERT_MODE_DISABLED: 37,
|
|
154
|
+
GUILD_INCIDENT_REPORT_RAID: 38,
|
|
155
|
+
GUILD_INCIDENT_REPORT_FALSE_ALARM: 39,
|
|
156
|
+
PURCHASE_NOTIFICATION: 44,
|
|
157
|
+
POLL_RESULT: 46
|
|
158
|
+
};
|
|
159
|
+
var MessageActivityType = {
|
|
160
|
+
JOIN: 1,
|
|
161
|
+
SPECTATE: 2,
|
|
162
|
+
LISTEN: 3,
|
|
163
|
+
JOIN_REQUEST: 5
|
|
164
|
+
};
|
|
165
|
+
var MessageFlag = {
|
|
166
|
+
CROSSPOSTED: 1 << 0,
|
|
167
|
+
IS_CROSSPOST: 1 << 1,
|
|
168
|
+
SUPPRESS_EMBEDS: 1 << 2,
|
|
169
|
+
SOURCE_MESSAGE_DELETED: 1 << 3,
|
|
170
|
+
URGENT: 1 << 4,
|
|
171
|
+
HAS_THREAD: 1 << 5,
|
|
172
|
+
EPHEMERAL: 1 << 6,
|
|
173
|
+
LOADING: 1 << 7,
|
|
174
|
+
FAILED_TO_MENTION_SOME_ROLES_IN_THREAD: 1 << 8,
|
|
175
|
+
SUPPRESS_NOTIFICATIONS: 1 << 12,
|
|
176
|
+
IS_VOICE_MESSAGE: 1 << 13,
|
|
177
|
+
HAS_SNAPSHOT: 1 << 14,
|
|
178
|
+
IS_COMPONENTS_V2: 1 << 15
|
|
179
|
+
};
|
|
180
|
+
var MessageReferenceType = {
|
|
181
|
+
DEFAULT: 0,
|
|
182
|
+
FORWARD: 1
|
|
183
|
+
};
|
|
184
|
+
var EmbedType = {
|
|
185
|
+
RICH: "rich",
|
|
186
|
+
IMAGE: "image",
|
|
187
|
+
VIDEO: "video",
|
|
188
|
+
GIFV: "gifv",
|
|
189
|
+
ARTICLE: "article",
|
|
190
|
+
LINK: "link",
|
|
191
|
+
POLL_RESULT: "poll_result"
|
|
192
|
+
};
|
|
193
|
+
var AttachmentFlag = {
|
|
194
|
+
IS_CLIP: 1 << 0,
|
|
195
|
+
IS_THUMBNAIL: 1 << 1,
|
|
196
|
+
IS_REMIX: 1 << 2,
|
|
197
|
+
IS_SPOILER: 1 << 3,
|
|
198
|
+
IS_ANIMATED: 1 << 5
|
|
199
|
+
};
|
|
200
|
+
|
|
201
|
+
// src/types/application/index.ts
|
|
202
|
+
var ApplicationFlag = {
|
|
203
|
+
APPLICATION_AUTO_MODERATION_RULE_CREATE_BADGE: 1 << 6,
|
|
204
|
+
GATEWAY_PRESENCE: 1 << 12,
|
|
205
|
+
GATEWAY_PRESENCE_LIMITED: 1 << 13,
|
|
206
|
+
GATEWAY_GUILD_MEMBERS: 1 << 14,
|
|
207
|
+
GATEWAY_GUILD_MEMBERS_LIMITED: 1 << 15,
|
|
208
|
+
VERIFICATION_PENDING_GUILD_LIMIT: 1 << 16,
|
|
209
|
+
EMBEDDED: 1 << 17,
|
|
210
|
+
GATEWAY_MESSAGE_CONTENT: 1 << 18,
|
|
211
|
+
GATEWAY_MESSAGE_CONTENT_LIMITED: 1 << 19,
|
|
212
|
+
APPLICATION_COMMAND_BADGE: 1 << 23
|
|
213
|
+
};
|
|
214
|
+
var ApplicationIntegrationType = {
|
|
215
|
+
GUILD_INSTALL: 0,
|
|
216
|
+
USER_INSTALL: 1
|
|
217
|
+
};
|
|
218
|
+
var ApplicationEventWebhookStatus = {
|
|
219
|
+
DISABLED: 1,
|
|
220
|
+
ENABLED: 2,
|
|
221
|
+
DISABLED_BY_DISCORD: 3
|
|
222
|
+
};
|
|
223
|
+
var ActivityLocationKind = {
|
|
224
|
+
GUILD_CHANNEL: "gc",
|
|
225
|
+
PRIVATE_CHANNEL: "pc"
|
|
226
|
+
};
|
|
227
|
+
var ApplicationRoleConnectionMetadataType = {
|
|
228
|
+
INTEGER_LESS_THAN_OR_EQUAL: 1,
|
|
229
|
+
INTEGER_GREATER_THAN_OR_EQUAL: 2,
|
|
230
|
+
INTEGER_EQUAL: 3,
|
|
231
|
+
INTEGER_NOT_EQUAL: 4,
|
|
232
|
+
DATETIME_LESS_THAN_OR_EQUAL: 5,
|
|
233
|
+
DATETIME_GREATER_THAN_OR_EQUAL: 6,
|
|
234
|
+
BOOLEAN_EQUAL: 7,
|
|
235
|
+
BOOLEAN_NOT_EQUAL: 8
|
|
236
|
+
};
|
|
237
|
+
var ApplicationCommandType = {
|
|
238
|
+
CHAT_INPUT: 1,
|
|
239
|
+
USER: 2,
|
|
240
|
+
MESSAGE: 3,
|
|
241
|
+
PRIMARY_ENTRY_POINT: 4
|
|
242
|
+
};
|
|
243
|
+
var ApplicationCommandOptionType = {
|
|
244
|
+
SUB_COMMAND: 1,
|
|
245
|
+
SUB_COMMAND_GROUP: 2,
|
|
246
|
+
STRING: 3,
|
|
247
|
+
INTEGER: 4,
|
|
248
|
+
BOOLEAN: 5,
|
|
249
|
+
USER: 6,
|
|
250
|
+
CHANNEL: 7,
|
|
251
|
+
ROLE: 8,
|
|
252
|
+
MENTIONABLE: 9,
|
|
253
|
+
NUMBER: 10,
|
|
254
|
+
ATTACHMENT: 11
|
|
255
|
+
};
|
|
256
|
+
|
|
257
|
+
// src/types/types.ts
|
|
258
|
+
var IntentBits = {
|
|
259
|
+
Guilds: 1 << 0,
|
|
260
|
+
GuildMembers: 1 << 1,
|
|
261
|
+
GuildModeration: 1 << 2,
|
|
262
|
+
GuildEmojisAndStickers: 1 << 3,
|
|
263
|
+
GuildIntegrations: 1 << 4,
|
|
264
|
+
GuildWebhooks: 1 << 5,
|
|
265
|
+
GuildInvites: 1 << 6,
|
|
266
|
+
GuildVoiceStates: 1 << 7,
|
|
267
|
+
GuildPresences: 1 << 8,
|
|
268
|
+
GuildMessages: 1 << 9,
|
|
269
|
+
GuildMessageReactions: 1 << 10,
|
|
270
|
+
GuildMessageTyping: 1 << 11,
|
|
271
|
+
DirectMessages: 1 << 12,
|
|
272
|
+
DirectMessageReactions: 1 << 13,
|
|
273
|
+
DirectMessageTyping: 1 << 14,
|
|
274
|
+
MessageContent: 1 << 15,
|
|
275
|
+
GuildScheduledEvents: 1 << 16,
|
|
276
|
+
AutoModerationConfiguration: 1 << 20,
|
|
277
|
+
AutoModerationExecution: 1 << 21,
|
|
278
|
+
GuildMessagePolls: 1 << 24,
|
|
279
|
+
DirectMessagePolls: 1 << 25
|
|
280
|
+
};
|
|
281
|
+
var Intents = {
|
|
282
|
+
...IntentBits,
|
|
283
|
+
Moderation: [
|
|
284
|
+
IntentBits.GuildModeration,
|
|
285
|
+
IntentBits.AutoModerationConfiguration,
|
|
286
|
+
IntentBits.AutoModerationExecution
|
|
287
|
+
// todo: add rest
|
|
288
|
+
]
|
|
289
|
+
};
|
|
290
|
+
var DISCORD_GATEWAY_OPCODES = /* @__PURE__ */ ((DISCORD_GATEWAY_OPCODES2) => {
|
|
291
|
+
DISCORD_GATEWAY_OPCODES2[DISCORD_GATEWAY_OPCODES2["DISPATCH"] = 0] = "DISPATCH";
|
|
292
|
+
DISCORD_GATEWAY_OPCODES2[DISCORD_GATEWAY_OPCODES2["HEARTBEAT"] = 1] = "HEARTBEAT";
|
|
293
|
+
DISCORD_GATEWAY_OPCODES2[DISCORD_GATEWAY_OPCODES2["IDENTIFY"] = 2] = "IDENTIFY";
|
|
294
|
+
DISCORD_GATEWAY_OPCODES2[DISCORD_GATEWAY_OPCODES2["PRESENCE_UPDATE"] = 3] = "PRESENCE_UPDATE";
|
|
295
|
+
DISCORD_GATEWAY_OPCODES2[DISCORD_GATEWAY_OPCODES2["VOICE_STATE_UPDATE"] = 4] = "VOICE_STATE_UPDATE";
|
|
296
|
+
DISCORD_GATEWAY_OPCODES2[DISCORD_GATEWAY_OPCODES2["RESUME"] = 6] = "RESUME";
|
|
297
|
+
DISCORD_GATEWAY_OPCODES2[DISCORD_GATEWAY_OPCODES2["RECONNECT"] = 7] = "RECONNECT";
|
|
298
|
+
DISCORD_GATEWAY_OPCODES2[DISCORD_GATEWAY_OPCODES2["REQUEST_GUILD_MEMBERS"] = 8] = "REQUEST_GUILD_MEMBERS";
|
|
299
|
+
DISCORD_GATEWAY_OPCODES2[DISCORD_GATEWAY_OPCODES2["INVALID_SESSION"] = 9] = "INVALID_SESSION";
|
|
300
|
+
DISCORD_GATEWAY_OPCODES2[DISCORD_GATEWAY_OPCODES2["HELLO"] = 10] = "HELLO";
|
|
301
|
+
DISCORD_GATEWAY_OPCODES2[DISCORD_GATEWAY_OPCODES2["HEARTBEAT_ACK"] = 11] = "HEARTBEAT_ACK";
|
|
302
|
+
DISCORD_GATEWAY_OPCODES2[DISCORD_GATEWAY_OPCODES2["REQUEST_SOUNDBOARD_SOUNDS"] = 31] = "REQUEST_SOUNDBOARD_SOUNDS";
|
|
303
|
+
DISCORD_GATEWAY_OPCODES2[DISCORD_GATEWAY_OPCODES2["REQUEST_CHANNEL_INFO"] = 43] = "REQUEST_CHANNEL_INFO";
|
|
304
|
+
return DISCORD_GATEWAY_OPCODES2;
|
|
305
|
+
})(DISCORD_GATEWAY_OPCODES || {});
|
|
306
|
+
var DISCORD_PERMISSIONS = {
|
|
307
|
+
CREATE_INSTANT_INVITE: 1n << 0n,
|
|
308
|
+
KICK_MEMBERS: 1n << 1n,
|
|
309
|
+
BAN_MEMBERS: 1n << 2n,
|
|
310
|
+
ADMINISTRATOR: 1n << 3n,
|
|
311
|
+
MANAGE_CHANNELS: 1n << 4n,
|
|
312
|
+
MANAGE_GUILD: 1n << 5n,
|
|
313
|
+
ADD_REACTIONS: 1n << 6n,
|
|
314
|
+
VIEW_AUDIT_LOG: 1n << 7n,
|
|
315
|
+
PRIORITY_SPEAKER: 1n << 8n,
|
|
316
|
+
STREAM: 1n << 9n,
|
|
317
|
+
VIEW_CHANNEL: 1n << 10n,
|
|
318
|
+
SEND_MESSAGES: 1n << 11n,
|
|
319
|
+
SEND_TTS_MESSAGES: 1n << 12n,
|
|
320
|
+
MANAGE_MESSAGES: 1n << 13n,
|
|
321
|
+
EMBED_LINKS: 1n << 14n,
|
|
322
|
+
ATTACH_FILES: 1n << 15n,
|
|
323
|
+
READ_MESSAGE_HISTORY: 1n << 16n,
|
|
324
|
+
MENTION_EVERYONE: 1n << 17n,
|
|
325
|
+
USE_EXTERNAL_EMOJIS: 1n << 18n,
|
|
326
|
+
VIEW_GUILD_INSIGHTS: 1n << 19n,
|
|
327
|
+
CONNECT: 1n << 20n,
|
|
328
|
+
SPEAK: 1n << 21n,
|
|
329
|
+
MUTE_MEMBERS: 1n << 22n,
|
|
330
|
+
DEAFEN_MEMBERS: 1n << 23n,
|
|
331
|
+
MOVE_MEMBERS: 1n << 24n,
|
|
332
|
+
USE_VAD: 1n << 25n,
|
|
333
|
+
CHANGE_NICKNAME: 1n << 26n,
|
|
334
|
+
MANAGE_NICKNAMES: 1n << 27n,
|
|
335
|
+
MANAGE_ROLES: 1n << 28n,
|
|
336
|
+
MANAGE_WEBHOOKS: 1n << 29n,
|
|
337
|
+
MANAGE_GUILD_EXPRESSIONS: 1n << 30n,
|
|
338
|
+
USE_APPLICATION_COMMANDS: 1n << 31n,
|
|
339
|
+
REQUEST_TO_SPEAK: 1n << 32n,
|
|
340
|
+
MANAGE_EVENTS: 1n << 33n,
|
|
341
|
+
MANAGE_THREADS: 1n << 34n,
|
|
342
|
+
CREATE_PUBLIC_THREADS: 1n << 35n,
|
|
343
|
+
CREATE_PRIVATE_THREADS: 1n << 36n,
|
|
344
|
+
USE_EXTERNAL_STICKERS: 1n << 37n,
|
|
345
|
+
SEND_MESSAGES_IN_THREADS: 1n << 38n,
|
|
346
|
+
USE_EMBEDDED_ACTIVITIES: 1n << 39n,
|
|
347
|
+
MODERATE_MEMBERS: 1n << 40n,
|
|
348
|
+
VIEW_CREATOR_MONETIZATION_ANALYTICS: 1n << 41n,
|
|
349
|
+
USE_SOUNDBOARD: 1n << 42n,
|
|
350
|
+
CREATE_GUILD_EXPRESSIONS: 1n << 43n,
|
|
351
|
+
CREATE_EVENTS: 1n << 44n,
|
|
352
|
+
USE_EXTERNAL_SOUNDS: 1n << 45n,
|
|
353
|
+
SEND_VOICE_MESSAGES: 1n << 46n,
|
|
354
|
+
SET_VOICE_CHANNEL_STATUS: 1n << 48n,
|
|
355
|
+
SEND_POLLS: 1n << 49n,
|
|
356
|
+
USE_EXTERNAL_APPS: 1n << 50n,
|
|
357
|
+
PIN_MESSAGES: 1n << 51n,
|
|
358
|
+
BYPASS_SLOWMODE: 1n << 52n
|
|
359
|
+
};
|
|
360
|
+
var AUDIT_LOG_EVENT_TYPES = {
|
|
361
|
+
GUILD_UPDATE: 1,
|
|
362
|
+
CHANNEL_CREATE: 10,
|
|
363
|
+
CHANNEL_UPDATE: 11,
|
|
364
|
+
CHANNEL_DELETE: 12,
|
|
365
|
+
CHANNEL_OVERWRITE_CREATE: 13,
|
|
366
|
+
CHANNEL_OVERWRITE_UPDATE: 14,
|
|
367
|
+
CHANNEL_OVERWRITE_DELETE: 15,
|
|
368
|
+
MEMBER_KICK: 20,
|
|
369
|
+
MEMBER_PRUNE: 21,
|
|
370
|
+
MEMBER_BAN_ADD: 22,
|
|
371
|
+
MEMBER_BAN_REMOVE: 23,
|
|
372
|
+
MEMBER_UPDATE: 24,
|
|
373
|
+
MEMBER_ROLE_UPDATE: 25,
|
|
374
|
+
MEMBER_MOVE: 26,
|
|
375
|
+
MEMBER_DISCONNECT: 27,
|
|
376
|
+
BOT_ADD: 28,
|
|
377
|
+
ROLE_CREATE: 30,
|
|
378
|
+
ROLE_UPDATE: 31,
|
|
379
|
+
ROLE_DELETE: 32,
|
|
380
|
+
INVITE_CREATE: 40,
|
|
381
|
+
INVITE_UPDATE: 41,
|
|
382
|
+
INVITE_DELETE: 42,
|
|
383
|
+
WEBHOOK_CREATE: 50,
|
|
384
|
+
WEBHOOK_UPDATE: 51,
|
|
385
|
+
WEBHOOK_DELETE: 52,
|
|
386
|
+
EMOJI_CREATE: 60,
|
|
387
|
+
EMOJI_UPDATE: 61,
|
|
388
|
+
EMOJI_DELETE: 62,
|
|
389
|
+
MESSAGE_DELETE: 72,
|
|
390
|
+
MESSAGE_BULK_DELETE: 73,
|
|
391
|
+
MESSAGE_PIN: 74,
|
|
392
|
+
MESSAGE_UNPIN: 75,
|
|
393
|
+
INTEGRATION_CREATE: 80,
|
|
394
|
+
INTEGRATION_UPDATE: 81,
|
|
395
|
+
INTEGRATION_DELETE: 82,
|
|
396
|
+
STAGE_INSTANCE_CREATE: 83,
|
|
397
|
+
STAGE_INSTANCE_UPDATE: 84,
|
|
398
|
+
STAGE_INSTANCE_DELETE: 85,
|
|
399
|
+
STICKER_CREATE: 90,
|
|
400
|
+
STICKER_UPDATE: 91,
|
|
401
|
+
STICKER_DELETE: 92,
|
|
402
|
+
GUILD_SCHEDULED_EVENT_CREATE: 100,
|
|
403
|
+
GUILD_SCHEDULED_EVENT_UPDATE: 101,
|
|
404
|
+
GUILD_SCHEDULED_EVENT_DELETE: 102,
|
|
405
|
+
THREAD_CREATE: 110,
|
|
406
|
+
THREAD_UPDATE: 111,
|
|
407
|
+
THREAD_DELETE: 112,
|
|
408
|
+
APPLICATION_COMMAND_PERMISSION_UPDATE: 121,
|
|
409
|
+
SOUNDBOARD_SOUND_CREATE: 130,
|
|
410
|
+
SOUNDBOARD_SOUND_UPDATE: 131,
|
|
411
|
+
SOUNDBOARD_SOUND_DELETE: 132,
|
|
412
|
+
AUTO_MODERATION_RULE_CREATE: 140,
|
|
413
|
+
AUTO_MODERATION_RULE_UPDATE: 141,
|
|
414
|
+
AUTO_MODERATION_RULE_DELETE: 142,
|
|
415
|
+
AUTO_MODERATION_BLOCK_MESSAGE: 143,
|
|
416
|
+
AUTO_MODERATION_FLAG_TO_CHANNEL: 144,
|
|
417
|
+
AUTO_MODERATION_USER_COMMUNICATION_DISABLED: 145,
|
|
418
|
+
AUTO_MODERATION_QUARANTINE_USER: 146,
|
|
419
|
+
CREATOR_MONETIZATION_REQUEST_CREATED: 150,
|
|
420
|
+
CREATOR_MONETIZATION_TERMS_ACCEPTED: 151,
|
|
421
|
+
ONBOARDING_PROMPT_CREATE: 163,
|
|
422
|
+
ONBOARDING_PROMPT_UPDATE: 164,
|
|
423
|
+
ONBOARDING_PROMPT_DELETE: 165,
|
|
424
|
+
ONBOARDING_CREATE: 166,
|
|
425
|
+
ONBOARDING_UPDATE: 167,
|
|
426
|
+
HOME_SETTINGS_CREATE: 190,
|
|
427
|
+
HOME_SETTINGS_UPDATE: 191,
|
|
428
|
+
VOICE_CHANNEL_STATUS_UPDATE: 192,
|
|
429
|
+
VOICE_CHANNEL_STATUS_DELETE: 193
|
|
430
|
+
};
|
|
431
|
+
var Activity = /* @__PURE__ */ ((Activity2) => {
|
|
432
|
+
Activity2[Activity2["PLAYING"] = 0] = "PLAYING";
|
|
433
|
+
Activity2[Activity2["STREAMING"] = 1] = "STREAMING";
|
|
434
|
+
Activity2[Activity2["LISTENING"] = 2] = "LISTENING";
|
|
435
|
+
Activity2[Activity2["WATCHING"] = 3] = "WATCHING";
|
|
436
|
+
Activity2[Activity2["CUSTOM"] = 4] = "CUSTOM";
|
|
437
|
+
Activity2[Activity2["COMPETING"] = 5] = "COMPETING";
|
|
438
|
+
return Activity2;
|
|
439
|
+
})(Activity || {});
|
|
440
|
+
|
|
441
|
+
// src/types/automod/index.ts
|
|
442
|
+
var AutoModerationEventType = {
|
|
443
|
+
MESSAGE_SEND: 1,
|
|
444
|
+
MEMBER_UPDATE: 2
|
|
445
|
+
};
|
|
446
|
+
var AutoModerationTriggerType = {
|
|
447
|
+
KEYWORD: 1,
|
|
448
|
+
SPAM: 3,
|
|
449
|
+
KEYWORD_PRESET: 4,
|
|
450
|
+
MENTION_SPAM: 5,
|
|
451
|
+
MEMBER_PROFILE: 6
|
|
452
|
+
};
|
|
453
|
+
var AutoModerationKeywordPresetType = {
|
|
454
|
+
PROFANITY: 1,
|
|
455
|
+
SEXUAL_CONTENT: 2,
|
|
456
|
+
SLURS: 3
|
|
457
|
+
};
|
|
458
|
+
var AutoModerationActionType = {
|
|
459
|
+
BLOCK_MESSAGE: 1,
|
|
460
|
+
SEND_ALERT_MESSAGE: 2,
|
|
461
|
+
TIMEOUT: 3,
|
|
462
|
+
BLOCK_MEMBER_INTERACTION: 4
|
|
463
|
+
};
|
|
464
|
+
|
|
465
|
+
// src/types/components/index.ts
|
|
466
|
+
var ComponentType = {
|
|
467
|
+
ACTION_ROW: 1,
|
|
468
|
+
BUTTON: 2,
|
|
469
|
+
STRING_SELECT: 3,
|
|
470
|
+
TEXT_INPUT: 4,
|
|
471
|
+
USER_SELECT: 5,
|
|
472
|
+
ROLE_SELECT: 6,
|
|
473
|
+
MENTIONABLE_SELECT: 7,
|
|
474
|
+
CHANNEL_SELECT: 8
|
|
475
|
+
};
|
|
476
|
+
var ButtonStyle = {
|
|
477
|
+
PRIMARY: 1,
|
|
478
|
+
SECONDARY: 2,
|
|
479
|
+
SUCCESS: 3,
|
|
480
|
+
DANGER: 4,
|
|
481
|
+
LINK: 5,
|
|
482
|
+
PREMIUM: 6
|
|
483
|
+
};
|
|
484
|
+
|
|
485
|
+
// src/types/entitlement/index.ts
|
|
486
|
+
var EntitlementType = {
|
|
487
|
+
PURCHASE: 1,
|
|
488
|
+
PREMIUM_SUBSCRIPTION: 2,
|
|
489
|
+
DEVELOPER_GIFT: 3,
|
|
490
|
+
TEST_MODE_PURCHASE: 4,
|
|
491
|
+
FREE_PURCHASE: 5,
|
|
492
|
+
USER_GIFT: 6,
|
|
493
|
+
PREMIUM_PURCHASE: 7,
|
|
494
|
+
APPLICATION_SUBSCRIPTION: 8
|
|
495
|
+
};
|
|
496
|
+
|
|
497
|
+
// src/types/expressions/index.ts
|
|
498
|
+
var StickerType = {
|
|
499
|
+
STANDARD: 1,
|
|
500
|
+
GUILD: 2
|
|
501
|
+
};
|
|
502
|
+
var StickerFormatType = {
|
|
503
|
+
PNG: 1,
|
|
504
|
+
APNG: 2,
|
|
505
|
+
LOTTIE: 3,
|
|
506
|
+
GIF: 4
|
|
507
|
+
};
|
|
508
|
+
|
|
509
|
+
// src/types/integration/index.ts
|
|
510
|
+
var IntegrationExpireBehavior = {
|
|
511
|
+
REMOVE_ROLE: 0,
|
|
512
|
+
KICK: 1
|
|
513
|
+
};
|
|
514
|
+
|
|
515
|
+
// src/types/invite/index.ts
|
|
516
|
+
var InviteType = {
|
|
517
|
+
GUILD: 0,
|
|
518
|
+
GROUP_DM: 1,
|
|
519
|
+
FRIEND: 2
|
|
520
|
+
};
|
|
521
|
+
var InviteTargetType = {
|
|
522
|
+
STREAM: 1,
|
|
523
|
+
EMBEDDED_APPLICATION: 2
|
|
524
|
+
};
|
|
525
|
+
var GuildInviteFlag = {
|
|
526
|
+
IS_GUEST_INVITE: 1 << 0
|
|
527
|
+
};
|
|
528
|
+
|
|
529
|
+
// src/types/lobby/index.ts
|
|
530
|
+
var LobbyMemberFlag = {
|
|
531
|
+
CAN_LINK_LOBBY: 1 << 0
|
|
532
|
+
};
|
|
533
|
+
|
|
534
|
+
// src/types/scheduled/index.ts
|
|
535
|
+
var GuildScheduledEventPrivacyLevel = {
|
|
536
|
+
GUILD_ONLY: 2
|
|
537
|
+
};
|
|
538
|
+
var GuildScheduledEventStatus = {
|
|
539
|
+
SCHEDULED: 1,
|
|
540
|
+
ACTIVE: 2,
|
|
541
|
+
COMPLETED: 3,
|
|
542
|
+
CANCELED: 4
|
|
543
|
+
};
|
|
544
|
+
var GuildScheduledEventEntityType = {
|
|
545
|
+
STAGE_INSTANCE: 1,
|
|
546
|
+
VOICE: 2,
|
|
547
|
+
EXTERNAL: 3
|
|
548
|
+
};
|
|
549
|
+
|
|
550
|
+
// src/types/sku/index.ts
|
|
551
|
+
var SkuType = {
|
|
552
|
+
DURABLE: 2,
|
|
553
|
+
CONSUMABLE: 3,
|
|
554
|
+
SUBSCRIPTION: 5,
|
|
555
|
+
SUBSCRIPTION_GROUP: 6
|
|
556
|
+
};
|
|
557
|
+
var SkuFlag = {
|
|
558
|
+
AVAILABLE: 1 << 2,
|
|
559
|
+
GUILD_SUBSCRIPTION: 1 << 7,
|
|
560
|
+
USER_SUBSCRIPTION: 1 << 8
|
|
561
|
+
};
|
|
562
|
+
|
|
563
|
+
// src/types/stage/index.ts
|
|
564
|
+
var StagePrivacyLevel = {
|
|
565
|
+
PUBLIC: 1,
|
|
566
|
+
GUILD_ONLY: 2
|
|
567
|
+
};
|
|
568
|
+
|
|
569
|
+
// src/types/subscription/index.ts
|
|
570
|
+
var SubscriptionStatus = {
|
|
571
|
+
ACTIVE: 0,
|
|
572
|
+
ENDING: 1,
|
|
573
|
+
INACTIVE: 2
|
|
574
|
+
};
|
|
575
|
+
|
|
576
|
+
// src/types/voice/index.ts
|
|
577
|
+
var CHAMELEON_SELF_MAP = {
|
|
578
|
+
selfMute: "userMuted",
|
|
579
|
+
selfDeaf: "userDeafened",
|
|
580
|
+
selfStream: "userStreaming",
|
|
581
|
+
selfVideo: "userVideo"
|
|
582
|
+
};
|
|
583
|
+
|
|
584
|
+
// src/types/webhook/index.ts
|
|
585
|
+
var WebhookType = {
|
|
586
|
+
INCOMING: 1,
|
|
587
|
+
CHANNEL_FOLLOWER: 2,
|
|
588
|
+
APPLICATION: 3
|
|
589
|
+
};
|
|
590
|
+
|
|
591
|
+
// src/utils/tongue.ts
|
|
592
|
+
var Tongue = class {
|
|
593
|
+
map;
|
|
594
|
+
max;
|
|
595
|
+
constructor(maxSize = Infinity) {
|
|
596
|
+
this.map = /* @__PURE__ */ new Map();
|
|
597
|
+
this.max = maxSize;
|
|
598
|
+
}
|
|
599
|
+
get(key) {
|
|
600
|
+
if (!this.map.has(key)) return void 0;
|
|
601
|
+
const val = this.map.get(key);
|
|
602
|
+
this.map.delete(key);
|
|
603
|
+
this.map.set(key, val);
|
|
604
|
+
return val;
|
|
605
|
+
}
|
|
606
|
+
set(key, val) {
|
|
607
|
+
if (this.map.has(key)) {
|
|
608
|
+
this.map.delete(key);
|
|
609
|
+
} else if (this.map.size >= this.max) {
|
|
610
|
+
const firstKey = this.map.keys().next().value;
|
|
611
|
+
if (firstKey !== void 0) this.map.delete(firstKey);
|
|
612
|
+
}
|
|
613
|
+
this.map.set(key, val);
|
|
614
|
+
return this;
|
|
615
|
+
}
|
|
616
|
+
has(key) {
|
|
617
|
+
return this.map.has(key);
|
|
618
|
+
}
|
|
619
|
+
delete(key) {
|
|
620
|
+
return this.map.delete(key);
|
|
621
|
+
}
|
|
622
|
+
clear() {
|
|
623
|
+
this.map.clear();
|
|
624
|
+
}
|
|
625
|
+
get size() {
|
|
626
|
+
return this.map.size;
|
|
627
|
+
}
|
|
628
|
+
values() {
|
|
629
|
+
return this.map.values();
|
|
630
|
+
}
|
|
631
|
+
keys() {
|
|
632
|
+
return this.map.keys();
|
|
633
|
+
}
|
|
634
|
+
};
|
|
635
|
+
|
|
636
|
+
// src/client/store.ts
|
|
637
|
+
var TongueStore = class {
|
|
638
|
+
guilds;
|
|
639
|
+
roles;
|
|
640
|
+
channels;
|
|
641
|
+
users;
|
|
642
|
+
members;
|
|
643
|
+
messages;
|
|
644
|
+
emojis;
|
|
645
|
+
stickers;
|
|
646
|
+
stageInstances;
|
|
647
|
+
scheduledEvents;
|
|
648
|
+
autoModRules;
|
|
649
|
+
integrations;
|
|
650
|
+
constructor(options) {
|
|
651
|
+
this.guilds = new Tongue(options?.guilds ?? Infinity);
|
|
652
|
+
this.roles = new Tongue(options?.roles ?? Infinity);
|
|
653
|
+
this.channels = new Tongue(options?.channels ?? Infinity);
|
|
654
|
+
this.members = new Tongue(options?.members ?? 1e3);
|
|
655
|
+
this.messages = new Tongue(options?.messages ?? 100);
|
|
656
|
+
this.users = new Tongue(options?.users ?? Infinity);
|
|
657
|
+
this.emojis = new Tongue(options?.emojis ?? Infinity);
|
|
658
|
+
this.stickers = new Tongue(options?.stickers ?? Infinity);
|
|
659
|
+
this.stageInstances = new Tongue(options?.stageInstances ?? Infinity);
|
|
660
|
+
this.scheduledEvents = new Tongue(options?.scheduledEvents ?? Infinity);
|
|
661
|
+
this.autoModRules = new Tongue(options?.autoModRules ?? Infinity);
|
|
662
|
+
this.integrations = new Tongue(options?.integrations ?? Infinity);
|
|
663
|
+
}
|
|
664
|
+
static memberKey(guildId, userId) {
|
|
665
|
+
return `${guildId}_${userId}`;
|
|
666
|
+
}
|
|
667
|
+
};
|
|
668
|
+
|
|
669
|
+
// src/rest/rates.ts
|
|
670
|
+
var RateLimitError = class extends Error {
|
|
671
|
+
constructor(delay, global) {
|
|
672
|
+
super("Rate limited");
|
|
673
|
+
this.delay = delay;
|
|
674
|
+
this.global = global;
|
|
675
|
+
}
|
|
676
|
+
delay;
|
|
677
|
+
global;
|
|
678
|
+
};
|
|
679
|
+
var Bucket = class {
|
|
680
|
+
remaining = 1;
|
|
681
|
+
resetTimestamp = 0;
|
|
682
|
+
promiseQueue = Promise.resolve();
|
|
683
|
+
async queue(fn) {
|
|
684
|
+
return new Promise((resolve2, reject) => {
|
|
685
|
+
this.promiseQueue = this.promiseQueue.then(async () => {
|
|
686
|
+
while (true) {
|
|
687
|
+
if (this.remaining <= 0 && Date.now() < this.resetTimestamp) {
|
|
688
|
+
await new Promise((r) => setTimeout(r, this.resetTimestamp - Date.now()));
|
|
689
|
+
}
|
|
690
|
+
this.remaining--;
|
|
691
|
+
try {
|
|
692
|
+
const res = await fn();
|
|
693
|
+
resolve2(res);
|
|
694
|
+
break;
|
|
695
|
+
} catch (e) {
|
|
696
|
+
if (e instanceof RateLimitError) {
|
|
697
|
+
await new Promise((r) => setTimeout(r, e.delay));
|
|
698
|
+
continue;
|
|
699
|
+
}
|
|
700
|
+
reject(e);
|
|
701
|
+
break;
|
|
702
|
+
}
|
|
703
|
+
}
|
|
704
|
+
});
|
|
705
|
+
});
|
|
706
|
+
}
|
|
707
|
+
};
|
|
708
|
+
var RateLimiter = class {
|
|
709
|
+
globalReset = 0;
|
|
710
|
+
routeToBucket = /* @__PURE__ */ new Map();
|
|
711
|
+
buckets = /* @__PURE__ */ new Map();
|
|
712
|
+
getRoute(method, endpoint) {
|
|
713
|
+
const path2 = endpoint.replace(/\/([a-z-]+)\/(?:[0-9]{17,19})/g, (match, p1) => {
|
|
714
|
+
if (["channels", "guilds", "webhooks"].includes(p1)) {
|
|
715
|
+
return match;
|
|
716
|
+
}
|
|
717
|
+
return `/${p1}/:id`;
|
|
718
|
+
});
|
|
719
|
+
const reactionRoute = path2.replace(/\/reactions\/[^/]+\/?(@me|[0-9]{17,19})?/g, "/reactions/:emoji/:id");
|
|
720
|
+
return `${method} ${reactionRoute}`;
|
|
721
|
+
}
|
|
722
|
+
async execute(method, endpoint, requestFn) {
|
|
723
|
+
const route = this.getRoute(method, endpoint);
|
|
724
|
+
const bucketId = this.routeToBucket.get(route) ?? route;
|
|
725
|
+
let bucket = this.buckets.get(bucketId);
|
|
726
|
+
if (!bucket) {
|
|
727
|
+
bucket = new Bucket();
|
|
728
|
+
this.buckets.set(bucketId, bucket);
|
|
729
|
+
}
|
|
730
|
+
const initialBucket = bucket;
|
|
731
|
+
return initialBucket.queue(async () => {
|
|
732
|
+
if (Date.now() < this.globalReset) {
|
|
733
|
+
await new Promise((r) => setTimeout(r, this.globalReset - Date.now()));
|
|
734
|
+
}
|
|
735
|
+
const response = await requestFn();
|
|
736
|
+
const global = response.headers.get("x-ratelimit-global") === "true";
|
|
737
|
+
const retryAfter = response.headers.get("retry-after");
|
|
738
|
+
if (response.status === 429) {
|
|
739
|
+
const delay = retryAfter ? parseFloat(retryAfter) * 1e3 : 5e3;
|
|
740
|
+
if (global) {
|
|
741
|
+
this.globalReset = Date.now() + delay;
|
|
742
|
+
}
|
|
743
|
+
throw new RateLimitError(delay, global);
|
|
744
|
+
}
|
|
745
|
+
const hash = response.headers.get("x-ratelimit-bucket");
|
|
746
|
+
const remaining = response.headers.get("x-ratelimit-remaining");
|
|
747
|
+
const resetAfter = response.headers.get("x-ratelimit-reset-after");
|
|
748
|
+
let targetBucket = initialBucket;
|
|
749
|
+
if (hash) {
|
|
750
|
+
if (hash !== bucketId) {
|
|
751
|
+
this.routeToBucket.set(route, hash);
|
|
752
|
+
if (!this.buckets.has(hash)) {
|
|
753
|
+
this.buckets.set(hash, initialBucket);
|
|
754
|
+
} else {
|
|
755
|
+
targetBucket = this.buckets.get(hash);
|
|
756
|
+
}
|
|
757
|
+
}
|
|
758
|
+
}
|
|
759
|
+
if (remaining !== null) {
|
|
760
|
+
targetBucket.remaining = parseInt(remaining, 10);
|
|
761
|
+
}
|
|
762
|
+
if (resetAfter !== null) {
|
|
763
|
+
targetBucket.resetTimestamp = Date.now() + parseFloat(resetAfter) * 1e3;
|
|
764
|
+
}
|
|
765
|
+
return response;
|
|
766
|
+
});
|
|
767
|
+
}
|
|
768
|
+
};
|
|
769
|
+
|
|
770
|
+
// src/rest/index.ts
|
|
771
|
+
var ChameleonREST = class {
|
|
772
|
+
token;
|
|
773
|
+
version;
|
|
774
|
+
baseUrl;
|
|
775
|
+
limiter;
|
|
776
|
+
constructor(options) {
|
|
777
|
+
this.token = options.token;
|
|
778
|
+
this.version = options.version ?? 10;
|
|
779
|
+
this.baseUrl = `https://discord.com/api/v${this.version}`;
|
|
780
|
+
this.limiter = new RateLimiter();
|
|
781
|
+
}
|
|
782
|
+
/**
|
|
783
|
+
* Internal generic request handler that doesn't throw, returning `{ ok: boolean, ... }` shape
|
|
784
|
+
*/
|
|
785
|
+
async request(method, endpoint, body, headers) {
|
|
786
|
+
const path2 = endpoint.startsWith("/") ? endpoint : `/${endpoint}`;
|
|
787
|
+
const url = `${this.baseUrl}${path2}`;
|
|
788
|
+
const reqHeaders = {
|
|
789
|
+
"Authorization": `Bot ${this.token}`,
|
|
790
|
+
"User-Agent": "Chameleon (https://github.com/impulsedoes/chameleon)",
|
|
791
|
+
...headers
|
|
792
|
+
};
|
|
793
|
+
let reqBody = void 0;
|
|
794
|
+
if (body) {
|
|
795
|
+
reqHeaders["Content-Type"] = "application/json";
|
|
796
|
+
reqBody = JSON.stringify(body);
|
|
797
|
+
}
|
|
798
|
+
try {
|
|
799
|
+
const response = await this.limiter.execute(method, path2, () => fetch(url, {
|
|
800
|
+
method,
|
|
801
|
+
headers: reqHeaders,
|
|
802
|
+
...reqBody !== void 0 ? { body: reqBody } : {}
|
|
803
|
+
}));
|
|
804
|
+
let data = null;
|
|
805
|
+
if (response.status !== 204) {
|
|
806
|
+
const text = await response.text();
|
|
807
|
+
if (text) {
|
|
808
|
+
try {
|
|
809
|
+
data = JSON.parse(text);
|
|
810
|
+
} catch {
|
|
811
|
+
data = text;
|
|
812
|
+
}
|
|
813
|
+
}
|
|
814
|
+
}
|
|
815
|
+
if (response.ok) {
|
|
816
|
+
return { ok: true, data };
|
|
817
|
+
}
|
|
818
|
+
const errData = data;
|
|
819
|
+
return {
|
|
820
|
+
ok: false,
|
|
821
|
+
status: response.status,
|
|
822
|
+
...typeof errData?.code === "number" ? { code: errData.code } : {},
|
|
823
|
+
message: typeof errData?.message === "string" ? errData.message : response.statusText,
|
|
824
|
+
raw: data
|
|
825
|
+
};
|
|
826
|
+
} catch (error) {
|
|
827
|
+
return {
|
|
828
|
+
ok: false,
|
|
829
|
+
status: 0,
|
|
830
|
+
message: error instanceof Error ? error.message : "Unknown network error"
|
|
831
|
+
};
|
|
832
|
+
}
|
|
833
|
+
}
|
|
834
|
+
get(endpoint, headers) {
|
|
835
|
+
return this.request("GET", endpoint, void 0, headers);
|
|
836
|
+
}
|
|
837
|
+
post(endpoint, body, headers) {
|
|
838
|
+
return this.request("POST", endpoint, body, headers);
|
|
839
|
+
}
|
|
840
|
+
put(endpoint, body, headers) {
|
|
841
|
+
return this.request("PUT", endpoint, body, headers);
|
|
842
|
+
}
|
|
843
|
+
patch(endpoint, body, headers) {
|
|
844
|
+
return this.request("PATCH", endpoint, body, headers);
|
|
845
|
+
}
|
|
846
|
+
delete(endpoint, headers) {
|
|
847
|
+
return this.request("DELETE", endpoint, void 0, headers);
|
|
848
|
+
}
|
|
849
|
+
};
|
|
850
|
+
|
|
851
|
+
// src/gateway/index.ts
|
|
852
|
+
var FATAL_CLOSE_CODES = /* @__PURE__ */ new Set([
|
|
853
|
+
4004,
|
|
854
|
+
// Authentication failed
|
|
855
|
+
4010,
|
|
856
|
+
// Invalid shard
|
|
857
|
+
4011,
|
|
858
|
+
// Sharding required
|
|
859
|
+
4012,
|
|
860
|
+
// Invalid API version
|
|
861
|
+
4013,
|
|
862
|
+
// Invalid intent(s)
|
|
863
|
+
4014
|
|
864
|
+
// Disallowed intent(s)
|
|
865
|
+
]);
|
|
866
|
+
var NO_RESUME_CLOSE_CODES = /* @__PURE__ */ new Set([
|
|
867
|
+
4007,
|
|
868
|
+
// Invalid seq
|
|
869
|
+
4009
|
|
870
|
+
// Session timed out
|
|
871
|
+
]);
|
|
872
|
+
var ChameleonGateway = class {
|
|
873
|
+
token;
|
|
874
|
+
intents;
|
|
875
|
+
version;
|
|
876
|
+
ms = -1;
|
|
877
|
+
encoding;
|
|
878
|
+
largeThreshold;
|
|
879
|
+
shard;
|
|
880
|
+
status = "idle";
|
|
881
|
+
ws = null;
|
|
882
|
+
heartbeatTimer = null;
|
|
883
|
+
heartbeatIntervalMs = 45e3;
|
|
884
|
+
heartbeatAcked = true;
|
|
885
|
+
seq = null;
|
|
886
|
+
sessionId = null;
|
|
887
|
+
baseUrl;
|
|
888
|
+
resumeUrl = null;
|
|
889
|
+
reconnectAttempts = 0;
|
|
890
|
+
reconnectTimer = null;
|
|
891
|
+
_lastHeartbeatSend = 0;
|
|
892
|
+
listeners = /* @__PURE__ */ new Map();
|
|
893
|
+
constructor(options) {
|
|
894
|
+
this.token = options.token;
|
|
895
|
+
this.intents = options.intents;
|
|
896
|
+
this.version = options.version ?? 10;
|
|
897
|
+
this.encoding = options.encoding ?? "json";
|
|
898
|
+
this.largeThreshold = options.largeThreshold ?? 50;
|
|
899
|
+
this.baseUrl = `wss://gateway.discord.gg/?v=${this.version}&encoding=${this.encoding}`;
|
|
900
|
+
if (options.shard !== void 0) this.shard = options.shard;
|
|
901
|
+
}
|
|
902
|
+
/**
|
|
903
|
+
* Open a new WebSocket connection to the Gateway,
|
|
904
|
+
* if resuming, uses the resume_gateway_url, otherwise uses the base URL
|
|
905
|
+
*/
|
|
906
|
+
connect() {
|
|
907
|
+
if (this.ws && (this.ws.readyState === WebSocket.OPEN || this.ws.readyState === WebSocket.CONNECTING)) {
|
|
908
|
+
return;
|
|
909
|
+
}
|
|
910
|
+
this.clearReconnectTimer();
|
|
911
|
+
const isResuming = this.canResume();
|
|
912
|
+
const url = isResuming && this.resumeUrl ? `${this.resumeUrl}?v=${this.version}&encoding=${this.encoding}` : this.baseUrl;
|
|
913
|
+
this.status = isResuming ? "resuming" : "connecting";
|
|
914
|
+
this.emit("debug", `[GATEWAY] Connecting to ${url} (resume=${isResuming})`);
|
|
915
|
+
this.ws = new WebSocket(url);
|
|
916
|
+
this.ws.onopen = this.onOpen.bind(this);
|
|
917
|
+
this.ws.onmessage = this.onMessage.bind(this);
|
|
918
|
+
this.ws.onclose = this.onClose.bind(this);
|
|
919
|
+
this.ws.onerror = this.onError.bind(this);
|
|
920
|
+
}
|
|
921
|
+
/**
|
|
922
|
+
* Gracefully close the connection
|
|
923
|
+
* code 1000/1001 invalidates the session
|
|
924
|
+
* any other code keeps the session alive for resume
|
|
925
|
+
*/
|
|
926
|
+
disconnect(code = 1e3, reason) {
|
|
927
|
+
this.stopHeartbeat();
|
|
928
|
+
this.clearReconnectTimer();
|
|
929
|
+
if (code === 1e3 || code === 1001) {
|
|
930
|
+
this.sessionId = null;
|
|
931
|
+
this.seq = null;
|
|
932
|
+
this.resumeUrl = null;
|
|
933
|
+
}
|
|
934
|
+
if (this.ws) {
|
|
935
|
+
try {
|
|
936
|
+
this.ws.close(code, reason);
|
|
937
|
+
} catch {
|
|
938
|
+
}
|
|
939
|
+
this.ws = null;
|
|
940
|
+
}
|
|
941
|
+
this.status = "disconnected";
|
|
942
|
+
}
|
|
943
|
+
/**
|
|
944
|
+
* Send a payload to the Gateway.
|
|
945
|
+
*/
|
|
946
|
+
send(op, d) {
|
|
947
|
+
if (!this.ws || this.ws.readyState !== WebSocket.OPEN) return;
|
|
948
|
+
this.ws.send(JSON.stringify({ op, d }));
|
|
949
|
+
}
|
|
950
|
+
pendingPresence = null;
|
|
951
|
+
/**
|
|
952
|
+
* Update the presence/status for this shard
|
|
953
|
+
*/
|
|
954
|
+
updatePresence(options) {
|
|
955
|
+
const payload = {
|
|
956
|
+
since: options.since ?? null,
|
|
957
|
+
activities: options.activities?.map((activity) => {
|
|
958
|
+
if (activity.type === 4 /* CUSTOM */ && !activity.state) {
|
|
959
|
+
return {
|
|
960
|
+
...activity,
|
|
961
|
+
name: "CS",
|
|
962
|
+
state: activity.name
|
|
963
|
+
};
|
|
964
|
+
}
|
|
965
|
+
if (activity.type === 1 /* STREAMING */ && !activity.url) {
|
|
966
|
+
return {
|
|
967
|
+
...activity,
|
|
968
|
+
url: "https://twitch.tv/discord"
|
|
969
|
+
};
|
|
970
|
+
}
|
|
971
|
+
return activity;
|
|
972
|
+
}) ?? [],
|
|
973
|
+
status: options.status ?? "online",
|
|
974
|
+
afk: options.afk ?? false
|
|
975
|
+
};
|
|
976
|
+
if (!this.ws || this.ws.readyState !== WebSocket.OPEN) {
|
|
977
|
+
this.pendingPresence = payload;
|
|
978
|
+
return;
|
|
979
|
+
}
|
|
980
|
+
this.send(3 /* PRESENCE_UPDATE */, payload);
|
|
981
|
+
}
|
|
982
|
+
/**
|
|
983
|
+
* request offline/large guild members from the Gateway
|
|
984
|
+
* this is used to lazy-load members into the cache via GUILD_MEMBERS_CHUNK events
|
|
985
|
+
*/
|
|
986
|
+
requestGuildMembers(options) {
|
|
987
|
+
if (!this.ws || this.ws.readyState !== WebSocket.OPEN) {
|
|
988
|
+
throw new Error("[GATEWAY] Cannot request guild members while disconnected");
|
|
989
|
+
}
|
|
990
|
+
const payload = {
|
|
991
|
+
guild_id: options.guildId,
|
|
992
|
+
limit: options.limit
|
|
993
|
+
};
|
|
994
|
+
if (options.query !== void 0) payload.query = options.query;
|
|
995
|
+
if (options.presences !== void 0) payload.presences = options.presences;
|
|
996
|
+
if (options.userIds !== void 0) payload.user_ids = options.userIds;
|
|
997
|
+
if (options.nonce !== void 0) payload.nonce = options.nonce;
|
|
998
|
+
this.send(8 /* REQUEST_GUILD_MEMBERS */, payload);
|
|
999
|
+
}
|
|
1000
|
+
/**
|
|
1001
|
+
* Register an event listener.
|
|
1002
|
+
*/
|
|
1003
|
+
on(event, listener) {
|
|
1004
|
+
if (!this.listeners.has(event)) {
|
|
1005
|
+
this.listeners.set(event, []);
|
|
1006
|
+
}
|
|
1007
|
+
this.listeners.get(event).push(listener);
|
|
1008
|
+
}
|
|
1009
|
+
/**
|
|
1010
|
+
* Remove all listeners for a specific event, or all listeners entirely.
|
|
1011
|
+
*/
|
|
1012
|
+
removeAllListeners(event) {
|
|
1013
|
+
if (event) {
|
|
1014
|
+
this.listeners.delete(event);
|
|
1015
|
+
} else {
|
|
1016
|
+
this.listeners.clear();
|
|
1017
|
+
}
|
|
1018
|
+
}
|
|
1019
|
+
emit(event, data) {
|
|
1020
|
+
const handlers = this.listeners.get(event);
|
|
1021
|
+
if (!handlers) return;
|
|
1022
|
+
for (const handler of handlers) {
|
|
1023
|
+
handler(data);
|
|
1024
|
+
}
|
|
1025
|
+
}
|
|
1026
|
+
onOpen() {
|
|
1027
|
+
this.emit("debug", "[GATEWAY] WebSocket connection opened");
|
|
1028
|
+
}
|
|
1029
|
+
onMessage(event) {
|
|
1030
|
+
let payload;
|
|
1031
|
+
try {
|
|
1032
|
+
payload = JSON.parse(event.data);
|
|
1033
|
+
} catch (err) {
|
|
1034
|
+
this.emit("debug", `[GATEWAY] Failed to parse payload: ${err}`);
|
|
1035
|
+
return;
|
|
1036
|
+
}
|
|
1037
|
+
if (payload.s !== null && payload.s !== void 0) {
|
|
1038
|
+
this.seq = payload.s;
|
|
1039
|
+
}
|
|
1040
|
+
switch (payload.op) {
|
|
1041
|
+
case 10 /* HELLO */: {
|
|
1042
|
+
const hello = payload.d;
|
|
1043
|
+
this.heartbeatIntervalMs = hello.heartbeat_interval;
|
|
1044
|
+
this.heartbeatAcked = true;
|
|
1045
|
+
this.startHeartbeat();
|
|
1046
|
+
this.identify();
|
|
1047
|
+
break;
|
|
1048
|
+
}
|
|
1049
|
+
case 11 /* HEARTBEAT_ACK */: {
|
|
1050
|
+
this.heartbeatAcked = true;
|
|
1051
|
+
this.ms = Date.now() - this._lastHeartbeatSend;
|
|
1052
|
+
this.emit("heartbeatAck");
|
|
1053
|
+
break;
|
|
1054
|
+
}
|
|
1055
|
+
case 1 /* HEARTBEAT */: {
|
|
1056
|
+
this.sendHeartbeat();
|
|
1057
|
+
break;
|
|
1058
|
+
}
|
|
1059
|
+
case 0 /* DISPATCH */: {
|
|
1060
|
+
this.handleDispatch(payload);
|
|
1061
|
+
break;
|
|
1062
|
+
}
|
|
1063
|
+
case 7 /* RECONNECT */: {
|
|
1064
|
+
this.emit("debug", "[GATEWAY] Received Reconnect, reconnecting...");
|
|
1065
|
+
this.scheduleReconnect();
|
|
1066
|
+
break;
|
|
1067
|
+
}
|
|
1068
|
+
case 9 /* INVALID_SESSION */: {
|
|
1069
|
+
const resumable = payload.d;
|
|
1070
|
+
this.emit("debug", `[GATEWAY] Invalid Session (resumable=${resumable})`);
|
|
1071
|
+
if (!resumable) {
|
|
1072
|
+
this.sessionId = null;
|
|
1073
|
+
this.seq = null;
|
|
1074
|
+
this.resumeUrl = null;
|
|
1075
|
+
}
|
|
1076
|
+
const delay = 1e3 + Math.random() * 4e3;
|
|
1077
|
+
this.disconnect(4900, "Invalid session");
|
|
1078
|
+
setTimeout(() => this.connect(), delay);
|
|
1079
|
+
break;
|
|
1080
|
+
}
|
|
1081
|
+
}
|
|
1082
|
+
}
|
|
1083
|
+
onClose(event) {
|
|
1084
|
+
const { code, reason } = event;
|
|
1085
|
+
this.stopHeartbeat();
|
|
1086
|
+
this.emit("debug", `[GATEWAY] Connection closed (code=${code}, reason=${reason || "none"})`);
|
|
1087
|
+
this.emit("disconnected", { code, reason });
|
|
1088
|
+
if (FATAL_CLOSE_CODES.has(code)) {
|
|
1089
|
+
this.status = "disconnected";
|
|
1090
|
+
this.emit("error", new Error(`[GATEWAY] Fatal close code ${code}: ${reason}`));
|
|
1091
|
+
return;
|
|
1092
|
+
}
|
|
1093
|
+
if (NO_RESUME_CLOSE_CODES.has(code)) {
|
|
1094
|
+
this.sessionId = null;
|
|
1095
|
+
this.seq = null;
|
|
1096
|
+
this.resumeUrl = null;
|
|
1097
|
+
}
|
|
1098
|
+
this.status = "disconnected";
|
|
1099
|
+
this.scheduleReconnect();
|
|
1100
|
+
}
|
|
1101
|
+
onError(event) {
|
|
1102
|
+
this.emit("debug", `[GATEWAY] WebSocket error`);
|
|
1103
|
+
this.emit("error", event);
|
|
1104
|
+
}
|
|
1105
|
+
handleDispatch(payload) {
|
|
1106
|
+
const { t, d } = payload;
|
|
1107
|
+
if (t === "READY") {
|
|
1108
|
+
const ready = d;
|
|
1109
|
+
this.sessionId = ready.session_id;
|
|
1110
|
+
this.resumeUrl = ready.resume_gateway_url;
|
|
1111
|
+
this.status = "connected";
|
|
1112
|
+
this.reconnectAttempts = 0;
|
|
1113
|
+
this.emit("debug", `[GATEWAY] READY (session=${this.sessionId})`);
|
|
1114
|
+
}
|
|
1115
|
+
if (t === "RESUMED") {
|
|
1116
|
+
this.status = "connected";
|
|
1117
|
+
this.reconnectAttempts = 0;
|
|
1118
|
+
this.emit("debug", "[GATEWAY] Session resumed successfully");
|
|
1119
|
+
}
|
|
1120
|
+
this.emit("dispatch", payload);
|
|
1121
|
+
}
|
|
1122
|
+
/**
|
|
1123
|
+
* Start the heartbeat loop
|
|
1124
|
+
* first heartbeat is sent after interval * jitter
|
|
1125
|
+
* subsequent heartbeats are sent every interval ms
|
|
1126
|
+
*/
|
|
1127
|
+
startHeartbeat() {
|
|
1128
|
+
this.stopHeartbeat();
|
|
1129
|
+
const jitter = Math.random();
|
|
1130
|
+
const firstDelay = Math.floor(this.heartbeatIntervalMs * jitter);
|
|
1131
|
+
this.emit("debug", `[GATEWAY] Starting heartbeat (interval=${this.heartbeatIntervalMs}ms, firstDelay=${firstDelay}ms)`);
|
|
1132
|
+
this.heartbeatTimer = setTimeout(() => {
|
|
1133
|
+
this.sendHeartbeat();
|
|
1134
|
+
this.heartbeatTimer = setInterval(() => {
|
|
1135
|
+
this.sendHeartbeat();
|
|
1136
|
+
}, this.heartbeatIntervalMs);
|
|
1137
|
+
}, firstDelay);
|
|
1138
|
+
}
|
|
1139
|
+
/**
|
|
1140
|
+
* send a single heartbeat, if the previous one was not ACKed,
|
|
1141
|
+
* we close and reconnect
|
|
1142
|
+
*/
|
|
1143
|
+
sendHeartbeat() {
|
|
1144
|
+
if (!this.heartbeatAcked) {
|
|
1145
|
+
this.emit("debug", "[GATEWAY] Heartbeat ACK not received, reconnecting...");
|
|
1146
|
+
this.disconnect(4900, "Zombie connection (no heartbeat ACK)");
|
|
1147
|
+
this.scheduleReconnect();
|
|
1148
|
+
return;
|
|
1149
|
+
}
|
|
1150
|
+
this.heartbeatAcked = false;
|
|
1151
|
+
this._lastHeartbeatSend = Date.now();
|
|
1152
|
+
this.send(1 /* HEARTBEAT */, this.seq);
|
|
1153
|
+
}
|
|
1154
|
+
stopHeartbeat() {
|
|
1155
|
+
if (this.heartbeatTimer) {
|
|
1156
|
+
clearTimeout(this.heartbeatTimer);
|
|
1157
|
+
clearInterval(this.heartbeatTimer);
|
|
1158
|
+
this.heartbeatTimer = null;
|
|
1159
|
+
}
|
|
1160
|
+
}
|
|
1161
|
+
canResume() {
|
|
1162
|
+
return this.sessionId !== null && this.seq !== null;
|
|
1163
|
+
}
|
|
1164
|
+
/**
|
|
1165
|
+
* send Identify or Resume depending on whether we have an active session
|
|
1166
|
+
*/
|
|
1167
|
+
identify() {
|
|
1168
|
+
if (this.canResume()) {
|
|
1169
|
+
this.emit("debug", `[GATEWAY] Resuming session ${this.sessionId} at seq ${this.seq}`);
|
|
1170
|
+
this.send(6 /* RESUME */, {
|
|
1171
|
+
token: this.token,
|
|
1172
|
+
session_id: this.sessionId,
|
|
1173
|
+
seq: this.seq
|
|
1174
|
+
});
|
|
1175
|
+
} else {
|
|
1176
|
+
this.emit("debug", "[GATEWAY] Identifying as new session");
|
|
1177
|
+
this.send(2 /* IDENTIFY */, {
|
|
1178
|
+
token: this.token,
|
|
1179
|
+
intents: this.intents,
|
|
1180
|
+
properties: {
|
|
1181
|
+
os: process.platform ?? "linux",
|
|
1182
|
+
browser: "chameleon",
|
|
1183
|
+
device: "chameleon"
|
|
1184
|
+
},
|
|
1185
|
+
large_threshold: this.largeThreshold,
|
|
1186
|
+
...this.shard ? { shard: this.shard } : {},
|
|
1187
|
+
...this.pendingPresence ? { presence: this.pendingPresence } : {}
|
|
1188
|
+
});
|
|
1189
|
+
}
|
|
1190
|
+
}
|
|
1191
|
+
/**
|
|
1192
|
+
* schedule a reconnect with exponential backoff
|
|
1193
|
+
* delay: min(1s * 2^attempt, 30s) + jitter
|
|
1194
|
+
*/
|
|
1195
|
+
scheduleReconnect() {
|
|
1196
|
+
this.clearReconnectTimer();
|
|
1197
|
+
const baseDelay = Math.min(1e3 * Math.pow(2, this.reconnectAttempts), 3e4);
|
|
1198
|
+
const jitter = Math.random() * 1e3;
|
|
1199
|
+
const delay = baseDelay + jitter;
|
|
1200
|
+
this.reconnectAttempts++;
|
|
1201
|
+
this.emit("debug", `[GATEWAY] Reconnecting in ${Math.round(delay)}ms (attempt #${this.reconnectAttempts})`);
|
|
1202
|
+
this.reconnectTimer = setTimeout(() => {
|
|
1203
|
+
this.reconnectTimer = null;
|
|
1204
|
+
this.connect();
|
|
1205
|
+
}, delay);
|
|
1206
|
+
}
|
|
1207
|
+
clearReconnectTimer() {
|
|
1208
|
+
if (this.reconnectTimer) {
|
|
1209
|
+
clearTimeout(this.reconnectTimer);
|
|
1210
|
+
this.reconnectTimer = null;
|
|
1211
|
+
}
|
|
1212
|
+
}
|
|
1213
|
+
};
|
|
1214
|
+
|
|
1215
|
+
// package.json
|
|
1216
|
+
var package_default = {
|
|
1217
|
+
name: "chameleon",
|
|
1218
|
+
version: "1.1.0",
|
|
1219
|
+
description: "highly optimized, memory-efficient, and fully type-safe Discord API library",
|
|
1220
|
+
main: "dist/index.js",
|
|
1221
|
+
types: "dist/index.d.ts",
|
|
1222
|
+
scripts: {
|
|
1223
|
+
test: "vitest",
|
|
1224
|
+
docs: "typedoc",
|
|
1225
|
+
lint: "eslint src example",
|
|
1226
|
+
"lint:fix": "eslint src example --fix",
|
|
1227
|
+
prepare: "husky",
|
|
1228
|
+
typecheck: "tsc --noEmit",
|
|
1229
|
+
build: "npm run typecheck && tsup src/index.ts --format esm --dts --clean"
|
|
1230
|
+
},
|
|
1231
|
+
exports: {
|
|
1232
|
+
".": {
|
|
1233
|
+
import: "./dist/index.js",
|
|
1234
|
+
types: "./dist/index.d.ts"
|
|
1235
|
+
}
|
|
1236
|
+
},
|
|
1237
|
+
keywords: [
|
|
1238
|
+
"api",
|
|
1239
|
+
"chameleon",
|
|
1240
|
+
"discord",
|
|
1241
|
+
"library",
|
|
1242
|
+
"typescript"
|
|
1243
|
+
],
|
|
1244
|
+
author: "impulsedoes",
|
|
1245
|
+
license: "MIT",
|
|
1246
|
+
type: "module",
|
|
1247
|
+
devDependencies: {
|
|
1248
|
+
"@eslint/js": "^10.0.1",
|
|
1249
|
+
"@types/node": "^25.9.1",
|
|
1250
|
+
"@vitest/coverage-v8": "^4.1.7",
|
|
1251
|
+
eslint: "^10.4.0",
|
|
1252
|
+
husky: "^9.1.7",
|
|
1253
|
+
"lint-staged": "^17.0.5",
|
|
1254
|
+
tsup: "^8.5.1",
|
|
1255
|
+
tsx: "^4.22.3",
|
|
1256
|
+
typedoc: "^0.28.19",
|
|
1257
|
+
typescript: "^6.0.3",
|
|
1258
|
+
"typescript-eslint": "^8.59.4",
|
|
1259
|
+
vitest: "^4.1.7"
|
|
1260
|
+
},
|
|
1261
|
+
"lint-staged": {
|
|
1262
|
+
"*.ts": "eslint --fix"
|
|
1263
|
+
}
|
|
1264
|
+
};
|
|
1265
|
+
|
|
1266
|
+
// src/utils/constants.ts
|
|
1267
|
+
var MESSAGE_FLAGS = {
|
|
1268
|
+
CROSSPOSTED: 1 << 0,
|
|
1269
|
+
IS_CROSSPOST: 1 << 1,
|
|
1270
|
+
SUPPRESS_EMBEDS: 1 << 2,
|
|
1271
|
+
SOURCE_MESSAGE_DELETED: 1 << 3,
|
|
1272
|
+
URGENT: 1 << 4,
|
|
1273
|
+
HAS_THREAD: 1 << 5,
|
|
1274
|
+
EPHEMERAL: 1 << 6,
|
|
1275
|
+
LOADING: 1 << 7,
|
|
1276
|
+
FAILED_TO_MENTION_SOME_ROLES_IN_THREAD: 1 << 8,
|
|
1277
|
+
SUPPRESS_NOTIFICATIONS: 1 << 12,
|
|
1278
|
+
IS_VOICE_MESSAGE: 1 << 13,
|
|
1279
|
+
HAS_SNAPSHOT: 1 << 14,
|
|
1280
|
+
IS_COMPONENTS_V2: 1 << 15
|
|
1281
|
+
};
|
|
1282
|
+
var CHAMELEON_VERSION = package_default.version;
|
|
1283
|
+
var CHAMELEON = package_default.name;
|
|
1284
|
+
|
|
1285
|
+
// src/builders/embed.ts
|
|
1286
|
+
var Colors = {
|
|
1287
|
+
Blue: 2003199,
|
|
1288
|
+
Purple: 10181046,
|
|
1289
|
+
Orange: 16744272,
|
|
1290
|
+
Pink: 16739201,
|
|
1291
|
+
White: 16777215,
|
|
1292
|
+
Blurple: 5793266,
|
|
1293
|
+
Green: 5763719,
|
|
1294
|
+
Yellow: 16705372,
|
|
1295
|
+
Fuchsia: 15418782,
|
|
1296
|
+
Red: 15548997,
|
|
1297
|
+
Black: 2303786,
|
|
1298
|
+
Transparent: 3092790
|
|
1299
|
+
};
|
|
1300
|
+
var EmbedBuilder = class {
|
|
1301
|
+
data;
|
|
1302
|
+
constructor(data) {
|
|
1303
|
+
this.data = {};
|
|
1304
|
+
if (!data) return;
|
|
1305
|
+
if ("title" in data) this.data.title = data.title;
|
|
1306
|
+
if ("description" in data) this.data.description = data.description;
|
|
1307
|
+
if ("color" in data) this.data.color = data.color;
|
|
1308
|
+
if ("url" in data) this.data.url = data.url;
|
|
1309
|
+
if ("timestamp" in data && data.timestamp) {
|
|
1310
|
+
this.data.timestamp = new Date(data.timestamp).getTime();
|
|
1311
|
+
}
|
|
1312
|
+
if (data.author) {
|
|
1313
|
+
const author = data.author;
|
|
1314
|
+
this.data.author = {
|
|
1315
|
+
name: author.name,
|
|
1316
|
+
url: author.url,
|
|
1317
|
+
iconUrl: author.iconUrl ?? author.icon_url,
|
|
1318
|
+
proxyIconUrl: author.proxyIconUrl ?? author.proxy_icon_url
|
|
1319
|
+
};
|
|
1320
|
+
}
|
|
1321
|
+
if (data.footer) {
|
|
1322
|
+
const footer = data.footer;
|
|
1323
|
+
this.data.footer = {
|
|
1324
|
+
text: footer.text,
|
|
1325
|
+
iconUrl: footer.iconUrl ?? footer.icon_url,
|
|
1326
|
+
proxyIconUrl: footer.proxyIconUrl ?? footer.proxy_icon_url
|
|
1327
|
+
};
|
|
1328
|
+
}
|
|
1329
|
+
if (data.image) {
|
|
1330
|
+
const image = data.image;
|
|
1331
|
+
this.data.image = {
|
|
1332
|
+
url: image.url,
|
|
1333
|
+
proxyUrl: image.proxyUrl ?? image.proxy_url,
|
|
1334
|
+
height: image.height,
|
|
1335
|
+
width: image.width
|
|
1336
|
+
};
|
|
1337
|
+
}
|
|
1338
|
+
if (data.thumbnail) {
|
|
1339
|
+
const thumbnail = data.thumbnail;
|
|
1340
|
+
this.data.thumbnail = {
|
|
1341
|
+
url: thumbnail.url,
|
|
1342
|
+
proxyUrl: thumbnail.proxyUrl ?? thumbnail.proxy_url,
|
|
1343
|
+
height: thumbnail.height,
|
|
1344
|
+
width: thumbnail.width
|
|
1345
|
+
};
|
|
1346
|
+
}
|
|
1347
|
+
if (Array.isArray(data.fields)) {
|
|
1348
|
+
this.data.fields = data.fields.map((f) => ({
|
|
1349
|
+
name: f.name,
|
|
1350
|
+
value: f.value,
|
|
1351
|
+
inline: f.inline ?? false
|
|
1352
|
+
}));
|
|
1353
|
+
}
|
|
1354
|
+
}
|
|
1355
|
+
setTitle(title) {
|
|
1356
|
+
this.data.title = title;
|
|
1357
|
+
return this;
|
|
1358
|
+
}
|
|
1359
|
+
setDescription(description) {
|
|
1360
|
+
this.data.description = description;
|
|
1361
|
+
return this;
|
|
1362
|
+
}
|
|
1363
|
+
setColor(color) {
|
|
1364
|
+
this.data.color = color;
|
|
1365
|
+
return this;
|
|
1366
|
+
}
|
|
1367
|
+
setURL(url) {
|
|
1368
|
+
this.data.url = url;
|
|
1369
|
+
return this;
|
|
1370
|
+
}
|
|
1371
|
+
setTimestamp(ts) {
|
|
1372
|
+
this.data.timestamp = ts instanceof Date ? ts.getTime() : ts ?? Date.now();
|
|
1373
|
+
return this;
|
|
1374
|
+
}
|
|
1375
|
+
setFooter(text, iconUrl) {
|
|
1376
|
+
this.data.footer = { text, ...iconUrl ? { iconUrl } : {} };
|
|
1377
|
+
return this;
|
|
1378
|
+
}
|
|
1379
|
+
setAuthor(name, iconUrl, url) {
|
|
1380
|
+
this.data.author = { name, ...iconUrl ? { iconUrl } : {}, ...url ? { url } : {} };
|
|
1381
|
+
return this;
|
|
1382
|
+
}
|
|
1383
|
+
setImage(url) {
|
|
1384
|
+
this.data.image = { url };
|
|
1385
|
+
return this;
|
|
1386
|
+
}
|
|
1387
|
+
setThumbnail(url) {
|
|
1388
|
+
this.data.thumbnail = { url };
|
|
1389
|
+
return this;
|
|
1390
|
+
}
|
|
1391
|
+
addField(name, value, inline = false) {
|
|
1392
|
+
if (!this.data.fields) this.data.fields = [];
|
|
1393
|
+
this.data.fields.push({ name, value, inline });
|
|
1394
|
+
return this;
|
|
1395
|
+
}
|
|
1396
|
+
addFields(...fields) {
|
|
1397
|
+
if (!this.data.fields) this.data.fields = [];
|
|
1398
|
+
this.data.fields.push(...fields);
|
|
1399
|
+
return this;
|
|
1400
|
+
}
|
|
1401
|
+
build() {
|
|
1402
|
+
return { ...this.data };
|
|
1403
|
+
}
|
|
1404
|
+
toJSON() {
|
|
1405
|
+
const payload = {
|
|
1406
|
+
...this.data,
|
|
1407
|
+
timestamp: this.data.timestamp ? new Date(this.data.timestamp).toISOString() : void 0
|
|
1408
|
+
};
|
|
1409
|
+
if (this.data.author) {
|
|
1410
|
+
payload.author = {
|
|
1411
|
+
name: this.data.author.name,
|
|
1412
|
+
url: this.data.author.url,
|
|
1413
|
+
icon_url: this.data.author.iconUrl,
|
|
1414
|
+
proxy_icon_url: this.data.author.proxyIconUrl
|
|
1415
|
+
};
|
|
1416
|
+
}
|
|
1417
|
+
if (this.data.footer) {
|
|
1418
|
+
payload.footer = {
|
|
1419
|
+
text: this.data.footer.text,
|
|
1420
|
+
icon_url: this.data.footer.iconUrl,
|
|
1421
|
+
proxy_icon_url: this.data.footer.proxyIconUrl
|
|
1422
|
+
};
|
|
1423
|
+
}
|
|
1424
|
+
if (this.data.image) {
|
|
1425
|
+
payload.image = {
|
|
1426
|
+
url: this.data.image.url,
|
|
1427
|
+
proxy_url: this.data.image.proxyUrl,
|
|
1428
|
+
height: this.data.image.height,
|
|
1429
|
+
width: this.data.image.width
|
|
1430
|
+
};
|
|
1431
|
+
}
|
|
1432
|
+
if (this.data.thumbnail) {
|
|
1433
|
+
payload.thumbnail = {
|
|
1434
|
+
url: this.data.thumbnail.url,
|
|
1435
|
+
proxy_url: this.data.thumbnail.proxyUrl,
|
|
1436
|
+
height: this.data.thumbnail.height,
|
|
1437
|
+
width: this.data.thumbnail.width
|
|
1438
|
+
};
|
|
1439
|
+
}
|
|
1440
|
+
return payload;
|
|
1441
|
+
}
|
|
1442
|
+
};
|
|
1443
|
+
|
|
1444
|
+
// src/builders/components.ts
|
|
1445
|
+
var ButtonBuilder = class {
|
|
1446
|
+
data = { type: ComponentType.BUTTON };
|
|
1447
|
+
setCustomId(id) {
|
|
1448
|
+
this.data.customId = id;
|
|
1449
|
+
return this;
|
|
1450
|
+
}
|
|
1451
|
+
setLabel(label) {
|
|
1452
|
+
this.data.label = label;
|
|
1453
|
+
return this;
|
|
1454
|
+
}
|
|
1455
|
+
setStyle(style) {
|
|
1456
|
+
this.data.style = style;
|
|
1457
|
+
return this;
|
|
1458
|
+
}
|
|
1459
|
+
setEmoji(emoji) {
|
|
1460
|
+
this.data.emoji = emoji;
|
|
1461
|
+
return this;
|
|
1462
|
+
}
|
|
1463
|
+
setDisabled(disabled = true) {
|
|
1464
|
+
this.data.disabled = disabled;
|
|
1465
|
+
return this;
|
|
1466
|
+
}
|
|
1467
|
+
setURL(url) {
|
|
1468
|
+
this.data.url = url;
|
|
1469
|
+
this.data.style = ButtonStyle.LINK;
|
|
1470
|
+
return this;
|
|
1471
|
+
}
|
|
1472
|
+
build() {
|
|
1473
|
+
return { ...this.data };
|
|
1474
|
+
}
|
|
1475
|
+
toJSON() {
|
|
1476
|
+
return this.build();
|
|
1477
|
+
}
|
|
1478
|
+
};
|
|
1479
|
+
var SelectMenuBuilder = class {
|
|
1480
|
+
data = { type: ComponentType.STRING_SELECT };
|
|
1481
|
+
setCustomId(id) {
|
|
1482
|
+
this.data.customId = id;
|
|
1483
|
+
return this;
|
|
1484
|
+
}
|
|
1485
|
+
setPlaceholder(placeholder) {
|
|
1486
|
+
this.data.placeholder = placeholder;
|
|
1487
|
+
return this;
|
|
1488
|
+
}
|
|
1489
|
+
setMinValues(min) {
|
|
1490
|
+
this.data.minValues = min;
|
|
1491
|
+
return this;
|
|
1492
|
+
}
|
|
1493
|
+
setMaxValues(max) {
|
|
1494
|
+
this.data.maxValues = max;
|
|
1495
|
+
return this;
|
|
1496
|
+
}
|
|
1497
|
+
setDisabled(disabled = true) {
|
|
1498
|
+
this.data.disabled = disabled;
|
|
1499
|
+
return this;
|
|
1500
|
+
}
|
|
1501
|
+
addOption(option) {
|
|
1502
|
+
if (!this.data.options) this.data.options = [];
|
|
1503
|
+
this.data.options.push(option);
|
|
1504
|
+
return this;
|
|
1505
|
+
}
|
|
1506
|
+
addOptions(...options) {
|
|
1507
|
+
if (!this.data.options) this.data.options = [];
|
|
1508
|
+
this.data.options.push(...options);
|
|
1509
|
+
return this;
|
|
1510
|
+
}
|
|
1511
|
+
setType(type) {
|
|
1512
|
+
this.data.type = type;
|
|
1513
|
+
return this;
|
|
1514
|
+
}
|
|
1515
|
+
build() {
|
|
1516
|
+
return { ...this.data };
|
|
1517
|
+
}
|
|
1518
|
+
toJSON() {
|
|
1519
|
+
return this.build();
|
|
1520
|
+
}
|
|
1521
|
+
};
|
|
1522
|
+
var TextInputBuilder = class {
|
|
1523
|
+
data = { type: ComponentType.TEXT_INPUT };
|
|
1524
|
+
setCustomId(id) {
|
|
1525
|
+
this.data.customId = id;
|
|
1526
|
+
return this;
|
|
1527
|
+
}
|
|
1528
|
+
setLabel(label) {
|
|
1529
|
+
this.data.label = label;
|
|
1530
|
+
return this;
|
|
1531
|
+
}
|
|
1532
|
+
setStyle(style) {
|
|
1533
|
+
this.data.style = style;
|
|
1534
|
+
return this;
|
|
1535
|
+
}
|
|
1536
|
+
setPlaceholder(placeholder) {
|
|
1537
|
+
this.data.placeholder = placeholder;
|
|
1538
|
+
return this;
|
|
1539
|
+
}
|
|
1540
|
+
_minLength;
|
|
1541
|
+
_maxLength;
|
|
1542
|
+
_required;
|
|
1543
|
+
_value;
|
|
1544
|
+
setMinLength(length) {
|
|
1545
|
+
this._minLength = length;
|
|
1546
|
+
return this;
|
|
1547
|
+
}
|
|
1548
|
+
setMaxLength(length) {
|
|
1549
|
+
this._maxLength = length;
|
|
1550
|
+
return this;
|
|
1551
|
+
}
|
|
1552
|
+
setRequired(required = true) {
|
|
1553
|
+
this._required = required;
|
|
1554
|
+
return this;
|
|
1555
|
+
}
|
|
1556
|
+
setValue(value) {
|
|
1557
|
+
this._value = value;
|
|
1558
|
+
return this;
|
|
1559
|
+
}
|
|
1560
|
+
build() {
|
|
1561
|
+
return {
|
|
1562
|
+
...this.data,
|
|
1563
|
+
minLength: this._minLength,
|
|
1564
|
+
maxLength: this._maxLength,
|
|
1565
|
+
required: this._required,
|
|
1566
|
+
value: this._value
|
|
1567
|
+
};
|
|
1568
|
+
}
|
|
1569
|
+
toJSON() {
|
|
1570
|
+
return {
|
|
1571
|
+
type: ComponentType.TEXT_INPUT,
|
|
1572
|
+
custom_id: this.data.customId,
|
|
1573
|
+
style: this.data.style,
|
|
1574
|
+
label: this.data.label,
|
|
1575
|
+
placeholder: this.data.placeholder,
|
|
1576
|
+
min_length: this._minLength,
|
|
1577
|
+
max_length: this._maxLength,
|
|
1578
|
+
required: this._required,
|
|
1579
|
+
value: this._value
|
|
1580
|
+
};
|
|
1581
|
+
}
|
|
1582
|
+
};
|
|
1583
|
+
var ActionRowBuilder = class {
|
|
1584
|
+
data = { type: ComponentType.ACTION_ROW, components: [] };
|
|
1585
|
+
addComponent(component) {
|
|
1586
|
+
const built = "build" in component && typeof component.build === "function" ? component.build() : component;
|
|
1587
|
+
this.data.components.push(built);
|
|
1588
|
+
return this;
|
|
1589
|
+
}
|
|
1590
|
+
addComponents(...components) {
|
|
1591
|
+
for (const c of components) this.addComponent(c);
|
|
1592
|
+
return this;
|
|
1593
|
+
}
|
|
1594
|
+
build() {
|
|
1595
|
+
return { ...this.data, components: [...this.data.components] };
|
|
1596
|
+
}
|
|
1597
|
+
toJSON() {
|
|
1598
|
+
return this.build();
|
|
1599
|
+
}
|
|
1600
|
+
};
|
|
1601
|
+
var ModalBuilder = class {
|
|
1602
|
+
_title = "";
|
|
1603
|
+
_customId = "";
|
|
1604
|
+
_components = [];
|
|
1605
|
+
setTitle(title) {
|
|
1606
|
+
this._title = title;
|
|
1607
|
+
return this;
|
|
1608
|
+
}
|
|
1609
|
+
setCustomId(id) {
|
|
1610
|
+
this._customId = id;
|
|
1611
|
+
return this;
|
|
1612
|
+
}
|
|
1613
|
+
addComponent(row) {
|
|
1614
|
+
const built = "build" in row && typeof row.build === "function" ? row.build() : row;
|
|
1615
|
+
this._components.push(built);
|
|
1616
|
+
return this;
|
|
1617
|
+
}
|
|
1618
|
+
addComponents(...rows) {
|
|
1619
|
+
for (const r of rows) this.addComponent(r);
|
|
1620
|
+
return this;
|
|
1621
|
+
}
|
|
1622
|
+
build() {
|
|
1623
|
+
return {
|
|
1624
|
+
title: this._title,
|
|
1625
|
+
custom_id: this._customId,
|
|
1626
|
+
components: [...this._components]
|
|
1627
|
+
};
|
|
1628
|
+
}
|
|
1629
|
+
toJSON() {
|
|
1630
|
+
return this.build();
|
|
1631
|
+
}
|
|
1632
|
+
};
|
|
1633
|
+
|
|
1634
|
+
// src/builders/index.ts
|
|
1635
|
+
function buildUser(raw) {
|
|
1636
|
+
return {
|
|
1637
|
+
id: raw.id,
|
|
1638
|
+
username: raw.username,
|
|
1639
|
+
discriminator: raw.discriminator,
|
|
1640
|
+
globalName: raw.global_name ?? null,
|
|
1641
|
+
avatar: raw.avatar ?? null,
|
|
1642
|
+
bot: raw.bot ?? false,
|
|
1643
|
+
system: raw.system ?? false,
|
|
1644
|
+
mfaEnabled: raw.mfa_enabled ?? false,
|
|
1645
|
+
banner: raw.banner ?? null,
|
|
1646
|
+
accentColor: raw.accent_color ?? null,
|
|
1647
|
+
locale: raw.locale ?? void 0,
|
|
1648
|
+
flags: raw.flags ?? 0,
|
|
1649
|
+
premiumType: raw.premium_type ?? 0,
|
|
1650
|
+
publicFlags: raw.public_flags ?? 0
|
|
1651
|
+
};
|
|
1652
|
+
}
|
|
1653
|
+
function buildChannel(raw, guildId) {
|
|
1654
|
+
return {
|
|
1655
|
+
id: raw.id,
|
|
1656
|
+
type: raw.type,
|
|
1657
|
+
guildId: raw.guild_id ?? guildId ?? void 0,
|
|
1658
|
+
name: raw.name ?? null,
|
|
1659
|
+
position: raw.position ?? 0,
|
|
1660
|
+
parentId: raw.parent_id ?? null,
|
|
1661
|
+
topic: raw.topic ?? null,
|
|
1662
|
+
nsfw: raw.nsfw ?? false,
|
|
1663
|
+
lastMessageId: raw.last_message_id ?? null,
|
|
1664
|
+
bitrate: raw.bitrate ?? void 0,
|
|
1665
|
+
userLimit: raw.user_limit ?? void 0,
|
|
1666
|
+
rateLimitPerUser: raw.rate_limit_per_user ?? 0,
|
|
1667
|
+
permissionOverwrites: raw.permission_overwrites ?? []
|
|
1668
|
+
};
|
|
1669
|
+
}
|
|
1670
|
+
function buildGuild(raw) {
|
|
1671
|
+
return {
|
|
1672
|
+
id: raw.id,
|
|
1673
|
+
name: raw.name,
|
|
1674
|
+
icon: raw.icon ?? null,
|
|
1675
|
+
splash: raw.splash ?? null,
|
|
1676
|
+
discoverySplash: raw.discovery_splash ?? null,
|
|
1677
|
+
ownerId: raw.owner_id,
|
|
1678
|
+
afkChannelId: raw.afk_channel_id ?? null,
|
|
1679
|
+
afkTimeout: raw.afk_timeout ?? 0,
|
|
1680
|
+
verificationLevel: raw.verification_level ?? 0,
|
|
1681
|
+
defaultMessageNotifications: raw.default_message_notifications ?? 0,
|
|
1682
|
+
explicitContentFilter: raw.explicit_content_filter ?? 0,
|
|
1683
|
+
features: raw.features ?? [],
|
|
1684
|
+
mfaLevel: raw.mfa_level ?? 0,
|
|
1685
|
+
systemChannelId: raw.system_channel_id ?? null,
|
|
1686
|
+
systemChannelFlags: raw.system_channel_flags ?? 0,
|
|
1687
|
+
rulesChannelId: raw.rules_channel_id ?? null,
|
|
1688
|
+
memberCount: raw.member_count ?? 0,
|
|
1689
|
+
vanityUrlCode: raw.vanity_url_code ?? null,
|
|
1690
|
+
description: raw.description ?? null,
|
|
1691
|
+
banner: raw.banner ?? null,
|
|
1692
|
+
premiumTier: raw.premium_tier ?? 0,
|
|
1693
|
+
premiumSubscriptionCount: raw.premium_subscription_count ?? 0,
|
|
1694
|
+
preferredLocale: raw.preferred_locale ?? "en-US",
|
|
1695
|
+
publicUpdatesChannelId: raw.public_updates_channel_id ?? null,
|
|
1696
|
+
nsfwLevel: raw.nsfw_level ?? 0,
|
|
1697
|
+
premiumProgressBarEnabled: raw.premium_progress_bar_enabled ?? false,
|
|
1698
|
+
roles: Array.isArray(raw.roles) ? raw.roles.map((r) => buildRole(r)) : [],
|
|
1699
|
+
emojis: raw.emojis ?? [],
|
|
1700
|
+
applicationId: raw.application_id ?? null,
|
|
1701
|
+
large: raw.large ?? false
|
|
1702
|
+
};
|
|
1703
|
+
}
|
|
1704
|
+
function buildRole(raw) {
|
|
1705
|
+
return {
|
|
1706
|
+
id: raw.id,
|
|
1707
|
+
name: raw.name,
|
|
1708
|
+
color: raw.color ?? 0,
|
|
1709
|
+
hoist: raw.hoist ?? false,
|
|
1710
|
+
position: raw.position ?? 0,
|
|
1711
|
+
permissions: raw.permissions,
|
|
1712
|
+
managed: raw.managed ?? false,
|
|
1713
|
+
mentionable: raw.mentionable ?? false,
|
|
1714
|
+
icon: raw.icon ?? null,
|
|
1715
|
+
unicodeEmoji: raw.unicode_emoji ?? null,
|
|
1716
|
+
flags: raw.flags ?? 0
|
|
1717
|
+
};
|
|
1718
|
+
}
|
|
1719
|
+
function buildMember(raw, guildId, cache) {
|
|
1720
|
+
let userObj;
|
|
1721
|
+
if (raw.user) {
|
|
1722
|
+
const user = buildUser(raw.user);
|
|
1723
|
+
cache.users.set(user.id, user);
|
|
1724
|
+
userObj = user;
|
|
1725
|
+
}
|
|
1726
|
+
return {
|
|
1727
|
+
...userObj ? { user: userObj } : {},
|
|
1728
|
+
nick: raw.nick ?? null,
|
|
1729
|
+
avatar: raw.avatar ?? null,
|
|
1730
|
+
roles: raw.roles ?? [],
|
|
1731
|
+
joinedAt: raw.joined_at ? Date.parse(raw.joined_at) : 0,
|
|
1732
|
+
premiumSince: raw.premium_since ? Date.parse(raw.premium_since) : null,
|
|
1733
|
+
deaf: raw.deaf ?? false,
|
|
1734
|
+
mute: raw.mute ?? false,
|
|
1735
|
+
pending: raw.pending ?? false,
|
|
1736
|
+
flags: raw.flags ?? 0,
|
|
1737
|
+
communicationDisabledUntil: raw.communication_disabled_until ? Date.parse(raw.communication_disabled_until) : null
|
|
1738
|
+
};
|
|
1739
|
+
}
|
|
1740
|
+
function buildMessage(raw, cache, oldMessage) {
|
|
1741
|
+
const authorRaw = raw.author;
|
|
1742
|
+
const author = authorRaw ? buildUser(authorRaw) : oldMessage?.author ?? {};
|
|
1743
|
+
if (authorRaw && author.id) {
|
|
1744
|
+
cache.users.set(author.id, author);
|
|
1745
|
+
}
|
|
1746
|
+
const msgId = raw.id ?? oldMessage?.id;
|
|
1747
|
+
const channelId = raw.channel_id ?? oldMessage?.channelId;
|
|
1748
|
+
const guildId = raw.guild_id ? raw.guild_id : oldMessage?.guildId;
|
|
1749
|
+
const msg = {
|
|
1750
|
+
id: msgId,
|
|
1751
|
+
channelId,
|
|
1752
|
+
author,
|
|
1753
|
+
...guildId ? { guildId } : {},
|
|
1754
|
+
url: `https://discord.com/channels/${guildId ?? "@me"}/${channelId}/${msgId}`,
|
|
1755
|
+
content: raw.content ?? oldMessage?.content ?? "",
|
|
1756
|
+
timestamp: raw.timestamp ? Date.parse(raw.timestamp) : oldMessage?.timestamp ?? Date.now(),
|
|
1757
|
+
editedTimestamp: raw.edited_timestamp ? Date.parse(raw.edited_timestamp) : oldMessage?.editedTimestamp ?? null,
|
|
1758
|
+
tts: raw.tts ?? oldMessage?.tts ?? false,
|
|
1759
|
+
mentionEveryone: raw.mention_everyone ?? oldMessage?.mentionEveryone ?? false,
|
|
1760
|
+
mentions: raw.mentions ? raw.mentions.map((m) => buildUser(m)) : oldMessage?.mentions ?? [],
|
|
1761
|
+
mentionRoles: raw.mention_roles ?? oldMessage?.mentionRoles ?? [],
|
|
1762
|
+
attachments: raw.attachments ?? oldMessage?.attachments ?? [],
|
|
1763
|
+
embeds: raw.embeds ?? oldMessage?.embeds ?? [],
|
|
1764
|
+
pinned: raw.pinned ?? oldMessage?.pinned ?? false,
|
|
1765
|
+
type: raw.type ?? oldMessage?.type ?? 0
|
|
1766
|
+
};
|
|
1767
|
+
return msg;
|
|
1768
|
+
}
|
|
1769
|
+
function resolveChannel(channelId, cache) {
|
|
1770
|
+
return cache.channels.get(channelId) ?? { id: channelId };
|
|
1771
|
+
}
|
|
1772
|
+
function resolveGuild(guildId, cache) {
|
|
1773
|
+
return cache.guilds.get(guildId) ?? { id: guildId };
|
|
1774
|
+
}
|
|
1775
|
+
function resolveUser(userId, cache) {
|
|
1776
|
+
return cache.users.get(userId) ?? { id: userId };
|
|
1777
|
+
}
|
|
1778
|
+
function resolveRole(roleId, cache) {
|
|
1779
|
+
return cache.roles.get(roleId) ?? { id: roleId };
|
|
1780
|
+
}
|
|
1781
|
+
|
|
1782
|
+
// src/commands/options.ts
|
|
1783
|
+
var opt = {
|
|
1784
|
+
string: (description, options) => ({
|
|
1785
|
+
type: "string",
|
|
1786
|
+
description,
|
|
1787
|
+
required: options?.required ?? false,
|
|
1788
|
+
...options
|
|
1789
|
+
}),
|
|
1790
|
+
integer: (description, options) => ({
|
|
1791
|
+
type: "integer",
|
|
1792
|
+
description,
|
|
1793
|
+
required: options?.required ?? false,
|
|
1794
|
+
...options
|
|
1795
|
+
}),
|
|
1796
|
+
number: (description, options) => ({
|
|
1797
|
+
type: "number",
|
|
1798
|
+
description,
|
|
1799
|
+
required: options?.required ?? false,
|
|
1800
|
+
...options
|
|
1801
|
+
}),
|
|
1802
|
+
boolean: (description, options) => ({
|
|
1803
|
+
type: "boolean",
|
|
1804
|
+
description,
|
|
1805
|
+
required: options?.required ?? false
|
|
1806
|
+
}),
|
|
1807
|
+
user: (description, options) => ({
|
|
1808
|
+
type: "user",
|
|
1809
|
+
description,
|
|
1810
|
+
required: options?.required ?? false
|
|
1811
|
+
}),
|
|
1812
|
+
channel: (description, options) => ({
|
|
1813
|
+
type: "channel",
|
|
1814
|
+
description,
|
|
1815
|
+
required: options?.required ?? false
|
|
1816
|
+
}),
|
|
1817
|
+
role: (description, options) => ({
|
|
1818
|
+
type: "role",
|
|
1819
|
+
description,
|
|
1820
|
+
required: options?.required ?? false
|
|
1821
|
+
})
|
|
1822
|
+
};
|
|
1823
|
+
|
|
1824
|
+
// src/commands/context.ts
|
|
1825
|
+
var CommandContext = class {
|
|
1826
|
+
options;
|
|
1827
|
+
user;
|
|
1828
|
+
guild;
|
|
1829
|
+
channel;
|
|
1830
|
+
interactionId;
|
|
1831
|
+
interactionToken;
|
|
1832
|
+
_client;
|
|
1833
|
+
_deferred = false;
|
|
1834
|
+
_replied = false;
|
|
1835
|
+
constructor(client, rawInteraction, parsedOptions, user, guild, channel) {
|
|
1836
|
+
this._client = client;
|
|
1837
|
+
this.interactionId = rawInteraction.id;
|
|
1838
|
+
this.interactionToken = rawInteraction.token;
|
|
1839
|
+
this.options = parsedOptions;
|
|
1840
|
+
this.user = user;
|
|
1841
|
+
this.guild = guild;
|
|
1842
|
+
this.channel = channel;
|
|
1843
|
+
}
|
|
1844
|
+
get replied() {
|
|
1845
|
+
return this._replied;
|
|
1846
|
+
}
|
|
1847
|
+
get deferred() {
|
|
1848
|
+
return this._deferred;
|
|
1849
|
+
}
|
|
1850
|
+
async reply(payload) {
|
|
1851
|
+
if (this._replied || this._deferred) throw new Error("Interaction already acknowledged.");
|
|
1852
|
+
const data = typeof payload === "string" ? { content: payload } : { ...payload };
|
|
1853
|
+
if (typeof payload === "object" && payload.ephemeral) data.flags = 64;
|
|
1854
|
+
await this._client.rest.post(`/interactions/${this.interactionId}/${this.interactionToken}/callback`, {
|
|
1855
|
+
type: 4 /* CHANNEL_MESSAGE_WITH_SOURCE */,
|
|
1856
|
+
data
|
|
1857
|
+
});
|
|
1858
|
+
this._replied = true;
|
|
1859
|
+
}
|
|
1860
|
+
async defer(options) {
|
|
1861
|
+
if (this._replied || this._deferred) throw new Error("Interaction already acknowledged.");
|
|
1862
|
+
await this._client.rest.post(`/interactions/${this.interactionId}/${this.interactionToken}/callback`, {
|
|
1863
|
+
type: 5 /* DEFERRED_CHANNEL_MESSAGE_WITH_SOURCE */,
|
|
1864
|
+
data: {
|
|
1865
|
+
flags: options?.ephemeral ? 64 : 0
|
|
1866
|
+
}
|
|
1867
|
+
});
|
|
1868
|
+
this._deferred = true;
|
|
1869
|
+
}
|
|
1870
|
+
async followUp(payload) {
|
|
1871
|
+
if (!this._deferred && !this._replied) throw new Error("Interaction not acknowledged. Use reply or defer first.");
|
|
1872
|
+
const data = typeof payload === "string" ? { content: payload } : { ...payload };
|
|
1873
|
+
if (typeof payload === "object" && payload.ephemeral) data.flags = 64;
|
|
1874
|
+
await this._client.rest.post(`/webhooks/${this._client.user?.id}/${this.interactionToken}`, data);
|
|
1875
|
+
}
|
|
1876
|
+
async showModal(modal) {
|
|
1877
|
+
if (this._replied || this._deferred) throw new Error("Interaction already acknowledged.");
|
|
1878
|
+
const payload = modal.type === "modal" ? {
|
|
1879
|
+
custom_id: modal.customId,
|
|
1880
|
+
title: modal.title,
|
|
1881
|
+
components: modal.fields.map((f) => ({
|
|
1882
|
+
type: 1 /* ACTION_ROW */,
|
|
1883
|
+
components: [{
|
|
1884
|
+
type: 4 /* TEXT_INPUT */,
|
|
1885
|
+
custom_id: f.id,
|
|
1886
|
+
style: f.type,
|
|
1887
|
+
// 1 short, 2 paragraph
|
|
1888
|
+
label: f.label,
|
|
1889
|
+
required: f.required,
|
|
1890
|
+
min_length: f.minLength,
|
|
1891
|
+
max_length: f.maxLength,
|
|
1892
|
+
placeholder: f.placeholder,
|
|
1893
|
+
value: f.value
|
|
1894
|
+
}]
|
|
1895
|
+
}))
|
|
1896
|
+
} : modal;
|
|
1897
|
+
await this._client.rest.post(`/interactions/${this.interactionId}/${this.interactionToken}/callback`, {
|
|
1898
|
+
type: 9 /* MODAL */,
|
|
1899
|
+
data: payload
|
|
1900
|
+
});
|
|
1901
|
+
this._replied = true;
|
|
1902
|
+
}
|
|
1903
|
+
};
|
|
1904
|
+
|
|
1905
|
+
// src/commands/command.ts
|
|
1906
|
+
function defineSubcommand(def) {
|
|
1907
|
+
return def;
|
|
1908
|
+
}
|
|
1909
|
+
function defineCommand(def) {
|
|
1910
|
+
if (!def.execute && (!def.subcommands || Object.keys(def.subcommands).length === 0)) {
|
|
1911
|
+
throw new Error(`Command ${def.name} must have an execute function or subcommands.`);
|
|
1912
|
+
}
|
|
1913
|
+
return def;
|
|
1914
|
+
}
|
|
1915
|
+
|
|
1916
|
+
// src/commands/interactions.ts
|
|
1917
|
+
var ComponentContext = class {
|
|
1918
|
+
customId;
|
|
1919
|
+
user;
|
|
1920
|
+
guild;
|
|
1921
|
+
channel;
|
|
1922
|
+
message;
|
|
1923
|
+
interactionId;
|
|
1924
|
+
interactionToken;
|
|
1925
|
+
_client;
|
|
1926
|
+
_deferred = false;
|
|
1927
|
+
_replied = false;
|
|
1928
|
+
constructor(client, raw, user, guild, channel) {
|
|
1929
|
+
this._client = client;
|
|
1930
|
+
this.interactionId = raw.id;
|
|
1931
|
+
this.interactionToken = raw.token;
|
|
1932
|
+
this.customId = raw.data?.custom_id ?? "";
|
|
1933
|
+
this.message = raw.message;
|
|
1934
|
+
this.user = user;
|
|
1935
|
+
this.guild = guild;
|
|
1936
|
+
this.channel = channel;
|
|
1937
|
+
}
|
|
1938
|
+
get replied() {
|
|
1939
|
+
return this._replied;
|
|
1940
|
+
}
|
|
1941
|
+
get deferred() {
|
|
1942
|
+
return this._deferred;
|
|
1943
|
+
}
|
|
1944
|
+
/** Values from a select menu interaction */
|
|
1945
|
+
get values() {
|
|
1946
|
+
return this._values ?? [];
|
|
1947
|
+
}
|
|
1948
|
+
async reply(payload) {
|
|
1949
|
+
if (this._replied || this._deferred) throw new Error("Interaction already acknowledged.");
|
|
1950
|
+
const data = typeof payload === "string" ? { content: payload } : { ...payload };
|
|
1951
|
+
if (typeof payload === "object" && payload.ephemeral) data.flags = 64;
|
|
1952
|
+
await this._client.rest.post(`/interactions/${this.interactionId}/${this.interactionToken}/callback`, {
|
|
1953
|
+
type: 4 /* CHANNEL_MESSAGE_WITH_SOURCE */,
|
|
1954
|
+
data
|
|
1955
|
+
});
|
|
1956
|
+
this._replied = true;
|
|
1957
|
+
}
|
|
1958
|
+
async deferUpdate() {
|
|
1959
|
+
if (this._replied || this._deferred) throw new Error("Interaction already acknowledged.");
|
|
1960
|
+
await this._client.rest.post(`/interactions/${this.interactionId}/${this.interactionToken}/callback`, {
|
|
1961
|
+
type: 6 /* DEFERRED_UPDATE_MESSAGE */
|
|
1962
|
+
});
|
|
1963
|
+
this._deferred = true;
|
|
1964
|
+
}
|
|
1965
|
+
async update(payload) {
|
|
1966
|
+
if (this._replied || this._deferred) throw new Error("Interaction already acknowledged.");
|
|
1967
|
+
const data = typeof payload === "string" ? { content: payload } : { ...payload };
|
|
1968
|
+
if (typeof payload === "object" && payload.ephemeral) data.flags = 64;
|
|
1969
|
+
await this._client.rest.post(`/interactions/${this.interactionId}/${this.interactionToken}/callback`, {
|
|
1970
|
+
type: 7 /* UPDATE_MESSAGE */,
|
|
1971
|
+
data
|
|
1972
|
+
});
|
|
1973
|
+
this._replied = true;
|
|
1974
|
+
}
|
|
1975
|
+
async followUp(payload) {
|
|
1976
|
+
if (!this._deferred && !this._replied) throw new Error("Interaction not acknowledged.");
|
|
1977
|
+
const data = typeof payload === "string" ? { content: payload } : { ...payload };
|
|
1978
|
+
if (typeof payload === "object" && payload.ephemeral) data.flags = 64;
|
|
1979
|
+
await this._client.rest.post(`/webhooks/${this._client.user?.id}/${this.interactionToken}`, data);
|
|
1980
|
+
}
|
|
1981
|
+
};
|
|
1982
|
+
var ModalContext = class {
|
|
1983
|
+
customId;
|
|
1984
|
+
user;
|
|
1985
|
+
guild;
|
|
1986
|
+
channel;
|
|
1987
|
+
interactionId;
|
|
1988
|
+
interactionToken;
|
|
1989
|
+
_fields = /* @__PURE__ */ new Map();
|
|
1990
|
+
_client;
|
|
1991
|
+
_replied = false;
|
|
1992
|
+
_deferred = false;
|
|
1993
|
+
constructor(client, raw, user, guild, channel) {
|
|
1994
|
+
this._client = client;
|
|
1995
|
+
this.interactionId = raw.id;
|
|
1996
|
+
this.interactionToken = raw.token;
|
|
1997
|
+
this.customId = raw.data?.custom_id ?? "";
|
|
1998
|
+
this.user = user;
|
|
1999
|
+
this.guild = guild;
|
|
2000
|
+
this.channel = channel;
|
|
2001
|
+
const rows = raw.data?.components ?? [];
|
|
2002
|
+
for (const row of rows) {
|
|
2003
|
+
for (const comp of row.components ?? []) {
|
|
2004
|
+
if (comp.custom_id && comp.value !== void 0) {
|
|
2005
|
+
this._fields.set(comp.custom_id, comp.value);
|
|
2006
|
+
}
|
|
2007
|
+
}
|
|
2008
|
+
}
|
|
2009
|
+
}
|
|
2010
|
+
get replied() {
|
|
2011
|
+
return this._replied;
|
|
2012
|
+
}
|
|
2013
|
+
get deferred() {
|
|
2014
|
+
return this._deferred;
|
|
2015
|
+
}
|
|
2016
|
+
/** Get a text input value by its customId */
|
|
2017
|
+
getField(customId) {
|
|
2018
|
+
return this._fields.get(customId);
|
|
2019
|
+
}
|
|
2020
|
+
/** Get all field values as a plain object */
|
|
2021
|
+
get fields() {
|
|
2022
|
+
return Object.fromEntries(this._fields);
|
|
2023
|
+
}
|
|
2024
|
+
async reply(payload) {
|
|
2025
|
+
if (this._replied || this._deferred) throw new Error("Interaction already acknowledged.");
|
|
2026
|
+
const data = typeof payload === "string" ? { content: payload } : { ...payload };
|
|
2027
|
+
if (typeof payload === "object" && payload.ephemeral) data.flags = 64;
|
|
2028
|
+
await this._client.rest.post(`/interactions/${this.interactionId}/${this.interactionToken}/callback`, {
|
|
2029
|
+
type: 4 /* CHANNEL_MESSAGE_WITH_SOURCE */,
|
|
2030
|
+
data
|
|
2031
|
+
});
|
|
2032
|
+
this._replied = true;
|
|
2033
|
+
}
|
|
2034
|
+
async defer(options) {
|
|
2035
|
+
if (this._replied || this._deferred) throw new Error("Interaction already acknowledged.");
|
|
2036
|
+
await this._client.rest.post(`/interactions/${this.interactionId}/${this.interactionToken}/callback`, {
|
|
2037
|
+
type: 5 /* DEFERRED_CHANNEL_MESSAGE_WITH_SOURCE */,
|
|
2038
|
+
data: { flags: options?.ephemeral ? 64 : 0 }
|
|
2039
|
+
});
|
|
2040
|
+
this._deferred = true;
|
|
2041
|
+
}
|
|
2042
|
+
async followUp(payload) {
|
|
2043
|
+
if (!this._deferred && !this._replied) throw new Error("Interaction not acknowledged.");
|
|
2044
|
+
const data = typeof payload === "string" ? { content: payload } : { ...payload };
|
|
2045
|
+
if (typeof payload === "object" && payload.ephemeral) data.flags = 64;
|
|
2046
|
+
await this._client.rest.post(`/webhooks/${this._client.user?.id}/${this.interactionToken}`, data);
|
|
2047
|
+
}
|
|
2048
|
+
};
|
|
2049
|
+
|
|
2050
|
+
// src/commands/manager.ts
|
|
2051
|
+
import * as fs from "fs";
|
|
2052
|
+
import * as path from "path";
|
|
2053
|
+
var CommandManager = class {
|
|
2054
|
+
_commands = /* @__PURE__ */ new Map();
|
|
2055
|
+
_components = [];
|
|
2056
|
+
_modals = [];
|
|
2057
|
+
_client;
|
|
2058
|
+
constructor(client) {
|
|
2059
|
+
this._client = client;
|
|
2060
|
+
}
|
|
2061
|
+
register(...commands) {
|
|
2062
|
+
for (const cmd of commands) {
|
|
2063
|
+
this._commands.set(cmd.name, cmd);
|
|
2064
|
+
}
|
|
2065
|
+
this._deployCommands(commands).catch(console.error);
|
|
2066
|
+
}
|
|
2067
|
+
registerComponent(handler) {
|
|
2068
|
+
this._components.push(handler);
|
|
2069
|
+
}
|
|
2070
|
+
registerModal(handler) {
|
|
2071
|
+
this._modals.push(handler);
|
|
2072
|
+
}
|
|
2073
|
+
async load(directory) {
|
|
2074
|
+
const fullPath = path.resolve(process.cwd(), directory);
|
|
2075
|
+
if (!fs.existsSync(fullPath)) {
|
|
2076
|
+
console.error(`[Chameleon] Command directory ${directory} does not exist.`);
|
|
2077
|
+
return;
|
|
2078
|
+
}
|
|
2079
|
+
const files = fs.readdirSync(fullPath).filter((f) => f.endsWith(".js") || f.endsWith(".ts"));
|
|
2080
|
+
const commands = [];
|
|
2081
|
+
for (const file of files) {
|
|
2082
|
+
const filePath = path.join(fullPath, file);
|
|
2083
|
+
try {
|
|
2084
|
+
const module = await import(`file://${filePath}`);
|
|
2085
|
+
const command = module.default;
|
|
2086
|
+
if (command && typeof command.name === "string") {
|
|
2087
|
+
commands.push(command);
|
|
2088
|
+
}
|
|
2089
|
+
} catch (err) {
|
|
2090
|
+
console.error(`[Chameleon] Failed to load command from ${file}:`, err);
|
|
2091
|
+
}
|
|
2092
|
+
}
|
|
2093
|
+
if (commands.length > 0) {
|
|
2094
|
+
this.register(...commands);
|
|
2095
|
+
}
|
|
2096
|
+
}
|
|
2097
|
+
async _deployCommands(commands) {
|
|
2098
|
+
const payload = commands.map((c) => this._transformCommand(c));
|
|
2099
|
+
if (this._client.user?.id) {
|
|
2100
|
+
await this._client.rest.put(`/applications/${this._client.user.id}/commands`, payload);
|
|
2101
|
+
} else {
|
|
2102
|
+
this._client.on("READY", async () => {
|
|
2103
|
+
await this._client.rest.put(`/applications/${this._client.user.id}/commands`, payload);
|
|
2104
|
+
});
|
|
2105
|
+
}
|
|
2106
|
+
}
|
|
2107
|
+
_transformCommand(cmd) {
|
|
2108
|
+
const mapType = (t) => {
|
|
2109
|
+
switch (t) {
|
|
2110
|
+
case "string":
|
|
2111
|
+
return 3;
|
|
2112
|
+
case "integer":
|
|
2113
|
+
return 4;
|
|
2114
|
+
case "boolean":
|
|
2115
|
+
return 5;
|
|
2116
|
+
case "user":
|
|
2117
|
+
return 6;
|
|
2118
|
+
case "channel":
|
|
2119
|
+
return 7;
|
|
2120
|
+
case "role":
|
|
2121
|
+
return 8;
|
|
2122
|
+
case "number":
|
|
2123
|
+
return 10;
|
|
2124
|
+
default:
|
|
2125
|
+
return 3;
|
|
2126
|
+
}
|
|
2127
|
+
};
|
|
2128
|
+
const options = [];
|
|
2129
|
+
if (cmd.subcommands) {
|
|
2130
|
+
for (const [subName, subDefRaw] of Object.entries(cmd.subcommands)) {
|
|
2131
|
+
const subDef = subDefRaw;
|
|
2132
|
+
const subOpts = [];
|
|
2133
|
+
if (subDef.options) {
|
|
2134
|
+
for (const [optName, optDef] of Object.entries(subDef.options)) {
|
|
2135
|
+
subOpts.push({
|
|
2136
|
+
type: mapType(optDef.type),
|
|
2137
|
+
name: optName,
|
|
2138
|
+
description: optDef.description,
|
|
2139
|
+
required: optDef.required,
|
|
2140
|
+
choices: optDef.choices,
|
|
2141
|
+
min_value: optDef.min,
|
|
2142
|
+
max_value: optDef.max
|
|
2143
|
+
});
|
|
2144
|
+
}
|
|
2145
|
+
}
|
|
2146
|
+
options.push({
|
|
2147
|
+
type: 1 /* SUB_COMMAND */,
|
|
2148
|
+
name: subName,
|
|
2149
|
+
description: subDef.description,
|
|
2150
|
+
options: subOpts
|
|
2151
|
+
});
|
|
2152
|
+
}
|
|
2153
|
+
} else if (cmd.options) {
|
|
2154
|
+
for (const [optName, optDef] of Object.entries(cmd.options)) {
|
|
2155
|
+
options.push({
|
|
2156
|
+
type: mapType(optDef.type),
|
|
2157
|
+
name: optName,
|
|
2158
|
+
description: optDef.description,
|
|
2159
|
+
required: optDef.required,
|
|
2160
|
+
choices: optDef.choices,
|
|
2161
|
+
min_value: optDef.min,
|
|
2162
|
+
max_value: optDef.max
|
|
2163
|
+
});
|
|
2164
|
+
}
|
|
2165
|
+
}
|
|
2166
|
+
return {
|
|
2167
|
+
name: cmd.name,
|
|
2168
|
+
description: cmd.description,
|
|
2169
|
+
options: options.length ? options : void 0
|
|
2170
|
+
};
|
|
2171
|
+
}
|
|
2172
|
+
async handleInteraction(raw) {
|
|
2173
|
+
if (raw.type === 3 /* MESSAGE_COMPONENT */) return this._handleComponentInteraction(raw);
|
|
2174
|
+
if (raw.type === 5 /* MODAL_SUBMIT */) return this._handleModalInteraction(raw);
|
|
2175
|
+
if (raw.type !== 2 /* APPLICATION_COMMAND */) return;
|
|
2176
|
+
const name = raw.data.name;
|
|
2177
|
+
const command = this._commands.get(name);
|
|
2178
|
+
if (!command) return;
|
|
2179
|
+
const parsedOptions = {};
|
|
2180
|
+
let targetExecute = command.execute;
|
|
2181
|
+
const rawOptions = raw.data.options || [];
|
|
2182
|
+
let actualOptions = rawOptions;
|
|
2183
|
+
if (rawOptions.length > 0 && rawOptions[0].type === 1 /* SUB_COMMAND */) {
|
|
2184
|
+
const subcommandName = rawOptions[0].name;
|
|
2185
|
+
actualOptions = rawOptions[0].options || [];
|
|
2186
|
+
if (command.subcommands && command.subcommands[subcommandName]) {
|
|
2187
|
+
targetExecute = command.subcommands[subcommandName].execute;
|
|
2188
|
+
}
|
|
2189
|
+
}
|
|
2190
|
+
for (const opt2 of actualOptions) {
|
|
2191
|
+
if (opt2.type === 6 /* USER */ && raw.data.resolved?.users?.[opt2.value]) {
|
|
2192
|
+
parsedOptions[opt2.name] = resolveUser(opt2.value, this._client.cache);
|
|
2193
|
+
} else if (opt2.type === 7 /* CHANNEL */ && raw.data.resolved?.channels?.[opt2.value]) {
|
|
2194
|
+
parsedOptions[opt2.name] = resolveChannel(opt2.value, this._client.cache);
|
|
2195
|
+
} else if (opt2.type === 8 /* ROLE */ && raw.data.resolved?.roles?.[opt2.value]) {
|
|
2196
|
+
parsedOptions[opt2.name] = resolveRole(opt2.value, this._client.cache);
|
|
2197
|
+
} else {
|
|
2198
|
+
parsedOptions[opt2.name] = opt2.value;
|
|
2199
|
+
}
|
|
2200
|
+
}
|
|
2201
|
+
const member = raw.member || {};
|
|
2202
|
+
const userRaw = member.user || raw.user;
|
|
2203
|
+
const user = buildUser(userRaw);
|
|
2204
|
+
const ctx = new CommandContext(
|
|
2205
|
+
this._client,
|
|
2206
|
+
raw,
|
|
2207
|
+
parsedOptions,
|
|
2208
|
+
user,
|
|
2209
|
+
raw.guild_id ? resolveGuild(raw.guild_id, this._client.cache) : void 0,
|
|
2210
|
+
raw.channel_id ? resolveChannel(raw.channel_id, this._client.cache) : void 0
|
|
2211
|
+
);
|
|
2212
|
+
if (targetExecute) {
|
|
2213
|
+
try {
|
|
2214
|
+
await targetExecute(ctx);
|
|
2215
|
+
} catch (err) {
|
|
2216
|
+
console.error(`[Chameleon] Error executing command ${name}:`, err);
|
|
2217
|
+
}
|
|
2218
|
+
}
|
|
2219
|
+
}
|
|
2220
|
+
async _handleComponentInteraction(raw) {
|
|
2221
|
+
const customId = raw.data.custom_id;
|
|
2222
|
+
const handler = this._components.find(
|
|
2223
|
+
(h) => typeof h.customId === "string" ? h.customId === customId : h.customId.test(customId)
|
|
2224
|
+
);
|
|
2225
|
+
if (!handler) return;
|
|
2226
|
+
const userRaw = raw.member?.user || raw.user;
|
|
2227
|
+
const user = buildUser(userRaw);
|
|
2228
|
+
const ctx = new ComponentContext(
|
|
2229
|
+
this._client,
|
|
2230
|
+
raw,
|
|
2231
|
+
user,
|
|
2232
|
+
raw.guild_id ? resolveGuild(raw.guild_id, this._client.cache) : void 0,
|
|
2233
|
+
raw.channel_id ? resolveChannel(raw.channel_id, this._client.cache) : void 0
|
|
2234
|
+
);
|
|
2235
|
+
if (raw.data.component_type === 3 /* STRING_SELECT */ || raw.data.component_type === 5 /* USER_SELECT */ || raw.data.component_type === 6 /* ROLE_SELECT */ || raw.data.component_type === 7 /* MENTIONABLE_SELECT */ || raw.data.component_type === 8 /* CHANNEL_SELECT */) {
|
|
2236
|
+
ctx._values = raw.data.values || [];
|
|
2237
|
+
}
|
|
2238
|
+
try {
|
|
2239
|
+
await handler.execute(ctx);
|
|
2240
|
+
} catch (err) {
|
|
2241
|
+
console.error(`[Chameleon] Error executing component ${customId}:`, err);
|
|
2242
|
+
}
|
|
2243
|
+
}
|
|
2244
|
+
async _handleModalInteraction(raw) {
|
|
2245
|
+
const customId = raw.data.custom_id;
|
|
2246
|
+
const handler = this._modals.find(
|
|
2247
|
+
(h) => typeof h.customId === "string" ? h.customId === customId : h.customId.test(customId)
|
|
2248
|
+
);
|
|
2249
|
+
if (!handler) return;
|
|
2250
|
+
const userRaw = raw.member?.user || raw.user;
|
|
2251
|
+
const user = buildUser(userRaw);
|
|
2252
|
+
const ctx = new ModalContext(
|
|
2253
|
+
this._client,
|
|
2254
|
+
raw,
|
|
2255
|
+
user,
|
|
2256
|
+
raw.guild_id ? resolveGuild(raw.guild_id, this._client.cache) : void 0,
|
|
2257
|
+
raw.channel_id ? resolveChannel(raw.channel_id, this._client.cache) : void 0
|
|
2258
|
+
);
|
|
2259
|
+
try {
|
|
2260
|
+
await handler.execute(ctx);
|
|
2261
|
+
} catch (err) {
|
|
2262
|
+
console.error(`[Chameleon] Error executing modal ${customId}:`, err);
|
|
2263
|
+
}
|
|
2264
|
+
}
|
|
2265
|
+
};
|
|
2266
|
+
|
|
2267
|
+
// src/components/context.ts
|
|
2268
|
+
var ComponentContext2 = class {
|
|
2269
|
+
user;
|
|
2270
|
+
guild;
|
|
2271
|
+
channel;
|
|
2272
|
+
interactionId;
|
|
2273
|
+
interactionToken;
|
|
2274
|
+
customId;
|
|
2275
|
+
values;
|
|
2276
|
+
fields;
|
|
2277
|
+
_client;
|
|
2278
|
+
_deferred = false;
|
|
2279
|
+
_replied = false;
|
|
2280
|
+
constructor(client, rawInteraction, user, guild, channel) {
|
|
2281
|
+
this._client = client;
|
|
2282
|
+
this.interactionId = rawInteraction.id;
|
|
2283
|
+
this.interactionToken = rawInteraction.token;
|
|
2284
|
+
this.customId = rawInteraction.data?.custom_id;
|
|
2285
|
+
this.user = user;
|
|
2286
|
+
this.guild = guild;
|
|
2287
|
+
this.channel = channel;
|
|
2288
|
+
this.values = rawInteraction.data?.values ?? [];
|
|
2289
|
+
const fields = {};
|
|
2290
|
+
if (rawInteraction.data?.components) {
|
|
2291
|
+
for (const row of rawInteraction.data.components) {
|
|
2292
|
+
for (const comp of row.components) {
|
|
2293
|
+
fields[comp.custom_id] = comp.value;
|
|
2294
|
+
}
|
|
2295
|
+
}
|
|
2296
|
+
}
|
|
2297
|
+
this.fields = fields;
|
|
2298
|
+
}
|
|
2299
|
+
get replied() {
|
|
2300
|
+
return this._replied;
|
|
2301
|
+
}
|
|
2302
|
+
get deferred() {
|
|
2303
|
+
return this._deferred;
|
|
2304
|
+
}
|
|
2305
|
+
async reply(payload) {
|
|
2306
|
+
if (this._replied || this._deferred) throw new Error("Interaction already acknowledged.");
|
|
2307
|
+
const data = typeof payload === "string" ? { content: payload } : { ...payload };
|
|
2308
|
+
if (typeof payload === "object" && payload.ephemeral) data.flags = 64;
|
|
2309
|
+
await this._client.rest.post(`/interactions/${this.interactionId}/${this.interactionToken}/callback`, {
|
|
2310
|
+
type: 4 /* CHANNEL_MESSAGE_WITH_SOURCE */,
|
|
2311
|
+
data
|
|
2312
|
+
});
|
|
2313
|
+
this._replied = true;
|
|
2314
|
+
}
|
|
2315
|
+
async defer(options) {
|
|
2316
|
+
if (this._replied || this._deferred) throw new Error("Interaction already acknowledged.");
|
|
2317
|
+
await this._client.rest.post(`/interactions/${this.interactionId}/${this.interactionToken}/callback`, {
|
|
2318
|
+
type: 5 /* DEFERRED_CHANNEL_MESSAGE_WITH_SOURCE */,
|
|
2319
|
+
data: {
|
|
2320
|
+
flags: options?.ephemeral ? 64 : 0
|
|
2321
|
+
}
|
|
2322
|
+
});
|
|
2323
|
+
this._deferred = true;
|
|
2324
|
+
}
|
|
2325
|
+
async update(payload) {
|
|
2326
|
+
if (this._replied || this._deferred) throw new Error("Interaction already acknowledged.");
|
|
2327
|
+
const data = typeof payload === "string" ? { content: payload } : { ...payload };
|
|
2328
|
+
await this._client.rest.post(`/interactions/${this.interactionId}/${this.interactionToken}/callback`, {
|
|
2329
|
+
type: 7 /* UPDATE_MESSAGE */,
|
|
2330
|
+
data
|
|
2331
|
+
});
|
|
2332
|
+
this._replied = true;
|
|
2333
|
+
}
|
|
2334
|
+
async deferUpdate() {
|
|
2335
|
+
if (this._replied || this._deferred) throw new Error("Interaction already acknowledged.");
|
|
2336
|
+
await this._client.rest.post(`/interactions/${this.interactionId}/${this.interactionToken}/callback`, {
|
|
2337
|
+
type: 6 /* DEFERRED_UPDATE_MESSAGE */
|
|
2338
|
+
});
|
|
2339
|
+
this._deferred = true;
|
|
2340
|
+
}
|
|
2341
|
+
async followUp(payload) {
|
|
2342
|
+
if (!this._deferred && !this._replied) throw new Error("Interaction not acknowledged. Use reply or defer first.");
|
|
2343
|
+
const data = typeof payload === "string" ? { content: payload } : { ...payload };
|
|
2344
|
+
if (typeof payload === "object" && payload.ephemeral) data.flags = 64;
|
|
2345
|
+
await this._client.rest.post(`/webhooks/${this._client.user?.id}/${this.interactionToken}`, data);
|
|
2346
|
+
}
|
|
2347
|
+
async showModal(modal) {
|
|
2348
|
+
if (this._replied || this._deferred) throw new Error("Interaction already acknowledged.");
|
|
2349
|
+
await this._client.rest.post(`/interactions/${this.interactionId}/${this.interactionToken}/callback`, {
|
|
2350
|
+
type: 9 /* MODAL */,
|
|
2351
|
+
data: modal.type === "modal" ? buildModalPayload(modal) : modal
|
|
2352
|
+
});
|
|
2353
|
+
this._replied = true;
|
|
2354
|
+
}
|
|
2355
|
+
};
|
|
2356
|
+
function buildModalPayload(def) {
|
|
2357
|
+
return {
|
|
2358
|
+
custom_id: def.customId,
|
|
2359
|
+
title: def.title,
|
|
2360
|
+
components: def.fields.map((f) => ({
|
|
2361
|
+
type: 1 /* ACTION_ROW */,
|
|
2362
|
+
components: [{
|
|
2363
|
+
type: 4 /* TEXT_INPUT */,
|
|
2364
|
+
custom_id: f.id,
|
|
2365
|
+
style: f.type,
|
|
2366
|
+
// 1 short, 2 paragraph
|
|
2367
|
+
label: f.label,
|
|
2368
|
+
required: f.required,
|
|
2369
|
+
min_length: f.minLength,
|
|
2370
|
+
max_length: f.maxLength,
|
|
2371
|
+
placeholder: f.placeholder,
|
|
2372
|
+
value: f.value
|
|
2373
|
+
}]
|
|
2374
|
+
}))
|
|
2375
|
+
};
|
|
2376
|
+
}
|
|
2377
|
+
|
|
2378
|
+
// src/components/define.ts
|
|
2379
|
+
function resolveButtonStyle(style) {
|
|
2380
|
+
if (typeof style === "number") return style;
|
|
2381
|
+
const map = { primary: 1, secondary: 2, success: 3, danger: 4, link: 5, premium: 6 };
|
|
2382
|
+
return map[style] ?? 1;
|
|
2383
|
+
}
|
|
2384
|
+
function defineButton(def) {
|
|
2385
|
+
return { ...def, type: "button" };
|
|
2386
|
+
}
|
|
2387
|
+
function defineStringSelect(def) {
|
|
2388
|
+
return { ...def, type: "string_select" };
|
|
2389
|
+
}
|
|
2390
|
+
function defineUserSelect(def) {
|
|
2391
|
+
return { ...def, type: "user_select" };
|
|
2392
|
+
}
|
|
2393
|
+
function defineRoleSelect(def) {
|
|
2394
|
+
return { ...def, type: "role_select" };
|
|
2395
|
+
}
|
|
2396
|
+
function defineChannelSelect(def) {
|
|
2397
|
+
return { ...def, type: "channel_select" };
|
|
2398
|
+
}
|
|
2399
|
+
function defineMentionableSelect(def) {
|
|
2400
|
+
return { ...def, type: "mentionable_select" };
|
|
2401
|
+
}
|
|
2402
|
+
var field = {
|
|
2403
|
+
short: (id, label, options) => ({
|
|
2404
|
+
id,
|
|
2405
|
+
type: 1 /* SHORT */,
|
|
2406
|
+
label,
|
|
2407
|
+
required: options?.required ?? true,
|
|
2408
|
+
...options
|
|
2409
|
+
}),
|
|
2410
|
+
paragraph: (id, label, options) => ({
|
|
2411
|
+
id,
|
|
2412
|
+
type: 2 /* PARAGRAPH */,
|
|
2413
|
+
label,
|
|
2414
|
+
required: options?.required ?? true,
|
|
2415
|
+
...options
|
|
2416
|
+
})
|
|
2417
|
+
};
|
|
2418
|
+
function defineModal(def) {
|
|
2419
|
+
return { ...def, type: "modal" };
|
|
2420
|
+
}
|
|
2421
|
+
|
|
2422
|
+
// src/components/actionRow.ts
|
|
2423
|
+
var ActionRow = {
|
|
2424
|
+
of: (...components) => {
|
|
2425
|
+
return {
|
|
2426
|
+
type: 1 /* ACTION_ROW */,
|
|
2427
|
+
components: components.map((c) => {
|
|
2428
|
+
if (c.type === "button") {
|
|
2429
|
+
return {
|
|
2430
|
+
type: 2 /* BUTTON */,
|
|
2431
|
+
custom_id: c.customId,
|
|
2432
|
+
url: c.url,
|
|
2433
|
+
label: c.label,
|
|
2434
|
+
style: resolveButtonStyle(c.style),
|
|
2435
|
+
disabled: c.disabled,
|
|
2436
|
+
emoji: c.emoji,
|
|
2437
|
+
sku_id: c.skuId
|
|
2438
|
+
};
|
|
2439
|
+
}
|
|
2440
|
+
if (c.type === "string_select") {
|
|
2441
|
+
return {
|
|
2442
|
+
type: 3 /* STRING_SELECT */,
|
|
2443
|
+
custom_id: c.customId,
|
|
2444
|
+
options: c.options,
|
|
2445
|
+
placeholder: c.placeholder,
|
|
2446
|
+
min_values: c.minValues,
|
|
2447
|
+
max_values: c.maxValues,
|
|
2448
|
+
disabled: c.disabled
|
|
2449
|
+
};
|
|
2450
|
+
}
|
|
2451
|
+
if (c.type === "user_select") {
|
|
2452
|
+
return { type: 5 /* USER_SELECT */, custom_id: c.customId, placeholder: c.placeholder, min_values: c.minValues, max_values: c.maxValues, disabled: c.disabled };
|
|
2453
|
+
}
|
|
2454
|
+
if (c.type === "role_select") {
|
|
2455
|
+
return { type: 6 /* ROLE_SELECT */, custom_id: c.customId, placeholder: c.placeholder, min_values: c.minValues, max_values: c.maxValues, disabled: c.disabled };
|
|
2456
|
+
}
|
|
2457
|
+
if (c.type === "mentionable_select") {
|
|
2458
|
+
return { type: 7 /* MENTIONABLE_SELECT */, custom_id: c.customId, placeholder: c.placeholder, min_values: c.minValues, max_values: c.maxValues, disabled: c.disabled };
|
|
2459
|
+
}
|
|
2460
|
+
if (c.type === "channel_select") {
|
|
2461
|
+
return { type: 8 /* CHANNEL_SELECT */, custom_id: c.customId, channel_types: c.channelTypes, placeholder: c.placeholder, min_values: c.minValues, max_values: c.maxValues, disabled: c.disabled };
|
|
2462
|
+
}
|
|
2463
|
+
if (c.type === 1 /* SHORT */ || c.type === 2 /* PARAGRAPH */) {
|
|
2464
|
+
return {
|
|
2465
|
+
type: 4 /* TEXT_INPUT */,
|
|
2466
|
+
custom_id: c.id,
|
|
2467
|
+
style: c.type,
|
|
2468
|
+
label: c.label,
|
|
2469
|
+
required: c.required,
|
|
2470
|
+
min_length: c.minLength,
|
|
2471
|
+
max_length: c.maxLength,
|
|
2472
|
+
placeholder: c.placeholder,
|
|
2473
|
+
value: c.value
|
|
2474
|
+
};
|
|
2475
|
+
}
|
|
2476
|
+
return c;
|
|
2477
|
+
}).map((obj) => {
|
|
2478
|
+
const clean = {};
|
|
2479
|
+
for (const [k, v] of Object.entries(obj)) {
|
|
2480
|
+
if (v !== void 0) clean[k] = v;
|
|
2481
|
+
}
|
|
2482
|
+
return clean;
|
|
2483
|
+
})
|
|
2484
|
+
};
|
|
2485
|
+
}
|
|
2486
|
+
};
|
|
2487
|
+
|
|
2488
|
+
// src/components/manager.ts
|
|
2489
|
+
var ComponentManager = class {
|
|
2490
|
+
constructor(client) {
|
|
2491
|
+
this.client = client;
|
|
2492
|
+
}
|
|
2493
|
+
client;
|
|
2494
|
+
handlers = /* @__PURE__ */ new Map();
|
|
2495
|
+
register(...components) {
|
|
2496
|
+
for (const comp of components) {
|
|
2497
|
+
if (comp.customId) {
|
|
2498
|
+
this.handlers.set(comp.customId, comp);
|
|
2499
|
+
}
|
|
2500
|
+
}
|
|
2501
|
+
}
|
|
2502
|
+
async handleInteraction(raw) {
|
|
2503
|
+
const data = raw.data;
|
|
2504
|
+
const customId = data.custom_id;
|
|
2505
|
+
if (!customId) return;
|
|
2506
|
+
const handler = this.handlers.get(customId);
|
|
2507
|
+
if (!handler || !handler.execute) return;
|
|
2508
|
+
const user = buildUser(raw.user ?? raw.member?.user);
|
|
2509
|
+
let guild;
|
|
2510
|
+
if (raw.guild_id) {
|
|
2511
|
+
guild = this.client.cache.guilds.get(raw.guild_id) ?? { id: raw.guild_id };
|
|
2512
|
+
}
|
|
2513
|
+
let channel;
|
|
2514
|
+
if (raw.channel_id) {
|
|
2515
|
+
channel = resolveChannel(raw.channel_id, this.client.cache) ?? { id: raw.channel_id };
|
|
2516
|
+
}
|
|
2517
|
+
if (data.resolved?.members && data.resolved?.users && raw.guild_id) {
|
|
2518
|
+
for (const [id, memberData] of Object.entries(data.resolved.members)) {
|
|
2519
|
+
const userData = data.resolved.users[id];
|
|
2520
|
+
if (userData) {
|
|
2521
|
+
const mergedMember = { ...memberData, user: userData };
|
|
2522
|
+
const u = buildUser(userData);
|
|
2523
|
+
this.client.cache.users.set(u.id, u);
|
|
2524
|
+
}
|
|
2525
|
+
}
|
|
2526
|
+
}
|
|
2527
|
+
const ctx = new ComponentContext2(this.client, raw, user, guild, channel);
|
|
2528
|
+
if (handler.type === "user_select" && data.resolved?.users) {
|
|
2529
|
+
ctx.values = ctx.values.map((id) => {
|
|
2530
|
+
const uData = data.resolved.users[id];
|
|
2531
|
+
return uData ? buildUser(uData) : { id };
|
|
2532
|
+
});
|
|
2533
|
+
} else if (handler.type === "channel_select" && data.resolved?.channels) {
|
|
2534
|
+
ctx.values = ctx.values.map((id) => {
|
|
2535
|
+
const cData = data.resolved.channels[id];
|
|
2536
|
+
return cData ? buildChannel(cData, raw.guild_id) : { id };
|
|
2537
|
+
});
|
|
2538
|
+
}
|
|
2539
|
+
try {
|
|
2540
|
+
await handler.execute(ctx);
|
|
2541
|
+
} catch (err) {
|
|
2542
|
+
console.error(`[COMPONENTS] Error executing component ${customId}:`, err);
|
|
2543
|
+
}
|
|
2544
|
+
}
|
|
2545
|
+
};
|
|
2546
|
+
|
|
2547
|
+
// src/managers/base.ts
|
|
2548
|
+
var BaseManager = class {
|
|
2549
|
+
constructor(rest, store) {
|
|
2550
|
+
this.rest = rest;
|
|
2551
|
+
this.store = store;
|
|
2552
|
+
}
|
|
2553
|
+
rest;
|
|
2554
|
+
store;
|
|
2555
|
+
async fetch(id, force = false) {
|
|
2556
|
+
if (!force) {
|
|
2557
|
+
const tongue2 = this.store[this.storeKey];
|
|
2558
|
+
const cached = tongue2.get(id);
|
|
2559
|
+
if (cached) return { ok: true, data: cached };
|
|
2560
|
+
}
|
|
2561
|
+
const result = await this.rest.get(this.endpoint(id));
|
|
2562
|
+
if (!result.ok) return result;
|
|
2563
|
+
const entity = this.build(result.data);
|
|
2564
|
+
const tongue = this.store[this.storeKey];
|
|
2565
|
+
tongue.set(id, entity);
|
|
2566
|
+
return { ok: true, data: entity };
|
|
2567
|
+
}
|
|
2568
|
+
};
|
|
2569
|
+
|
|
2570
|
+
// src/managers/user.ts
|
|
2571
|
+
var UserManager = class extends BaseManager {
|
|
2572
|
+
storeKey = "users";
|
|
2573
|
+
endpoint(id) {
|
|
2574
|
+
return `/users/${id}`;
|
|
2575
|
+
}
|
|
2576
|
+
build = buildUser;
|
|
2577
|
+
};
|
|
2578
|
+
|
|
2579
|
+
// src/managers/guild.ts
|
|
2580
|
+
var GuildManager = class extends BaseManager {
|
|
2581
|
+
storeKey = "guilds";
|
|
2582
|
+
endpoint(id) {
|
|
2583
|
+
return `/guilds/${id}`;
|
|
2584
|
+
}
|
|
2585
|
+
build = buildGuild;
|
|
2586
|
+
async fetchChannels(guildId) {
|
|
2587
|
+
const result = await this.rest.get(`/guilds/${guildId}/channels`);
|
|
2588
|
+
if (!result.ok) return result;
|
|
2589
|
+
const channels = result.data.map((raw) => buildChannel(raw, guildId));
|
|
2590
|
+
for (const c of channels) {
|
|
2591
|
+
this.store.channels.set(c.id, c);
|
|
2592
|
+
}
|
|
2593
|
+
return { ok: true, data: channels };
|
|
2594
|
+
}
|
|
2595
|
+
async ban(guildId, userId, options) {
|
|
2596
|
+
const payload = {};
|
|
2597
|
+
if (options?.deleteMessageSeconds !== void 0) payload.delete_message_seconds = options.deleteMessageSeconds;
|
|
2598
|
+
const headers = {};
|
|
2599
|
+
if (options?.reason) headers["X-Audit-Log-Reason"] = encodeURIComponent(options.reason);
|
|
2600
|
+
const result = await this.rest.put(`/guilds/${guildId}/bans/${userId}`, payload, headers);
|
|
2601
|
+
return result;
|
|
2602
|
+
}
|
|
2603
|
+
async unban(guildId, userId, reason) {
|
|
2604
|
+
const headers = {};
|
|
2605
|
+
if (reason) headers["X-Audit-Log-Reason"] = encodeURIComponent(reason);
|
|
2606
|
+
const result = await this.rest.delete(`/guilds/${guildId}/bans/${userId}`, headers);
|
|
2607
|
+
return result;
|
|
2608
|
+
}
|
|
2609
|
+
async kick(guildId, userId, reason) {
|
|
2610
|
+
const headers = {};
|
|
2611
|
+
if (reason) headers["X-Audit-Log-Reason"] = encodeURIComponent(reason);
|
|
2612
|
+
const result = await this.rest.delete(`/guilds/${guildId}/members/${userId}`, headers);
|
|
2613
|
+
if (result.ok) {
|
|
2614
|
+
this.store.members.delete(TongueStore.memberKey(guildId, userId));
|
|
2615
|
+
}
|
|
2616
|
+
return result;
|
|
2617
|
+
}
|
|
2618
|
+
};
|
|
2619
|
+
|
|
2620
|
+
// src/managers/channel.ts
|
|
2621
|
+
var ChannelManager = class extends BaseManager {
|
|
2622
|
+
storeKey = "channels";
|
|
2623
|
+
endpoint(id) {
|
|
2624
|
+
return `/channels/${id}`;
|
|
2625
|
+
}
|
|
2626
|
+
build = buildChannel;
|
|
2627
|
+
};
|
|
2628
|
+
|
|
2629
|
+
// src/managers/member.ts
|
|
2630
|
+
var MemberManager = class {
|
|
2631
|
+
constructor(rest, store, guildId) {
|
|
2632
|
+
this.rest = rest;
|
|
2633
|
+
this.store = store;
|
|
2634
|
+
this.guildId = guildId;
|
|
2635
|
+
}
|
|
2636
|
+
rest;
|
|
2637
|
+
store;
|
|
2638
|
+
guildId;
|
|
2639
|
+
async fetch(userId, force = false) {
|
|
2640
|
+
const cacheKey = TongueStore.memberKey(this.guildId, userId);
|
|
2641
|
+
if (!force) {
|
|
2642
|
+
const cached = this.store.members.get(cacheKey);
|
|
2643
|
+
if (cached) return { ok: true, data: cached };
|
|
2644
|
+
}
|
|
2645
|
+
const result = await this.rest.get(`/guilds/${this.guildId}/members/${userId}`);
|
|
2646
|
+
if (!result.ok) return result;
|
|
2647
|
+
const member = buildMember(result.data, this.guildId, this.store);
|
|
2648
|
+
this.store.members.set(cacheKey, member);
|
|
2649
|
+
return { ok: true, data: member };
|
|
2650
|
+
}
|
|
2651
|
+
};
|
|
2652
|
+
|
|
2653
|
+
// src/managers/message.ts
|
|
2654
|
+
var MessageManager = class {
|
|
2655
|
+
constructor(rest, store) {
|
|
2656
|
+
this.rest = rest;
|
|
2657
|
+
this.store = store;
|
|
2658
|
+
}
|
|
2659
|
+
rest;
|
|
2660
|
+
store;
|
|
2661
|
+
async fetch(channelId, messageId, force = false) {
|
|
2662
|
+
if (!force) {
|
|
2663
|
+
const cached = this.store.messages.get(messageId);
|
|
2664
|
+
if (cached) return { ok: true, data: cached };
|
|
2665
|
+
}
|
|
2666
|
+
const result = await this.rest.get(`/channels/${channelId}/messages/${messageId}`);
|
|
2667
|
+
if (!result.ok) return result;
|
|
2668
|
+
const message = buildMessage(result.data, this.store);
|
|
2669
|
+
this.store.messages.set(message.id, message);
|
|
2670
|
+
return { ok: true, data: message };
|
|
2671
|
+
}
|
|
2672
|
+
async send(channelId, payload) {
|
|
2673
|
+
const data = typeof payload === "string" ? { content: payload } : payload;
|
|
2674
|
+
const result = await this.rest.post(`/channels/${channelId}/messages`, data);
|
|
2675
|
+
if (!result.ok) return result;
|
|
2676
|
+
const message = buildMessage(result.data, this.store);
|
|
2677
|
+
this.store.messages.set(message.id, message);
|
|
2678
|
+
return { ok: true, data: message };
|
|
2679
|
+
}
|
|
2680
|
+
async edit(channelId, messageId, payload) {
|
|
2681
|
+
const data = typeof payload === "string" ? { content: payload } : payload;
|
|
2682
|
+
const result = await this.rest.patch(`/channels/${channelId}/messages/${messageId}`, data);
|
|
2683
|
+
if (!result.ok) return result;
|
|
2684
|
+
const oldMsg = this.store.messages.get(messageId);
|
|
2685
|
+
const message = buildMessage(result.data, this.store, oldMsg);
|
|
2686
|
+
this.store.messages.set(message.id, message);
|
|
2687
|
+
return { ok: true, data: message };
|
|
2688
|
+
}
|
|
2689
|
+
async delete(channelId, messageId) {
|
|
2690
|
+
const result = await this.rest.delete(`/channels/${channelId}/messages/${messageId}`);
|
|
2691
|
+
if (result.ok) {
|
|
2692
|
+
this.store.messages.delete(messageId);
|
|
2693
|
+
}
|
|
2694
|
+
return result;
|
|
2695
|
+
}
|
|
2696
|
+
};
|
|
2697
|
+
|
|
2698
|
+
// src/managers/collector.ts
|
|
2699
|
+
var CollectorManager = class {
|
|
2700
|
+
constructor(client) {
|
|
2701
|
+
this.client = client;
|
|
2702
|
+
}
|
|
2703
|
+
client;
|
|
2704
|
+
/**
|
|
2705
|
+
* Waits for a specified number of messages in a given channel that pass the filter, if the time limit
|
|
2706
|
+
* is reached, resolves with the messages collected so far
|
|
2707
|
+
*/
|
|
2708
|
+
async awaitMessages(channelId, options = {}) {
|
|
2709
|
+
const { filter, max = 1, time = 15e3 } = options;
|
|
2710
|
+
return new Promise((resolve2) => {
|
|
2711
|
+
const messages = [];
|
|
2712
|
+
let timeoutId = null;
|
|
2713
|
+
const handler = (data) => {
|
|
2714
|
+
const msg = data.message;
|
|
2715
|
+
if (msg.channelId !== channelId) return;
|
|
2716
|
+
if (filter && !filter(msg)) return;
|
|
2717
|
+
messages.push(msg);
|
|
2718
|
+
if (messages.length >= max) {
|
|
2719
|
+
cleanup();
|
|
2720
|
+
resolve2(messages);
|
|
2721
|
+
}
|
|
2722
|
+
};
|
|
2723
|
+
const cleanup = () => {
|
|
2724
|
+
if (timeoutId) clearTimeout(timeoutId);
|
|
2725
|
+
this.client.off("MESSAGE_CREATE", handler);
|
|
2726
|
+
};
|
|
2727
|
+
this.client.on("MESSAGE_CREATE", handler);
|
|
2728
|
+
if (time > 0) {
|
|
2729
|
+
timeoutId = setTimeout(() => {
|
|
2730
|
+
cleanup();
|
|
2731
|
+
resolve2(messages);
|
|
2732
|
+
}, time);
|
|
2733
|
+
}
|
|
2734
|
+
});
|
|
2735
|
+
}
|
|
2736
|
+
/**
|
|
2737
|
+
* waits for a single component interaction on a specific message,
|
|
2738
|
+
* resolves with the ComponentContext if successful, or null if it timed out
|
|
2739
|
+
*/
|
|
2740
|
+
async awaitComponent(messageId, options = {}) {
|
|
2741
|
+
const { filter, time = 15e3 } = options;
|
|
2742
|
+
return new Promise((resolve2) => {
|
|
2743
|
+
let timeoutId = null;
|
|
2744
|
+
const handler = (data) => {
|
|
2745
|
+
const raw = data.interaction;
|
|
2746
|
+
if (raw.type !== 3 /* MESSAGE_COMPONENT */) return;
|
|
2747
|
+
if (raw.message?.id !== messageId) return;
|
|
2748
|
+
const userRaw = raw.member?.user || raw.user;
|
|
2749
|
+
const user = buildUser(userRaw);
|
|
2750
|
+
const ctx = new ComponentContext(
|
|
2751
|
+
this.client,
|
|
2752
|
+
raw,
|
|
2753
|
+
user,
|
|
2754
|
+
raw.guild_id ? resolveGuild(raw.guild_id, this.client.cache) : void 0,
|
|
2755
|
+
raw.channel_id ? resolveChannel(raw.channel_id, this.client.cache) : void 0
|
|
2756
|
+
);
|
|
2757
|
+
if (raw.data.component_type === 3 /* STRING_SELECT */ || raw.data.component_type === 5 /* USER_SELECT */ || raw.data.component_type === 6 /* ROLE_SELECT */ || raw.data.component_type === 7 /* MENTIONABLE_SELECT */ || raw.data.component_type === 8 /* CHANNEL_SELECT */) {
|
|
2758
|
+
ctx._values = raw.data.values || [];
|
|
2759
|
+
}
|
|
2760
|
+
if (filter && !filter(ctx)) return;
|
|
2761
|
+
cleanup();
|
|
2762
|
+
resolve2(ctx);
|
|
2763
|
+
};
|
|
2764
|
+
const cleanup = () => {
|
|
2765
|
+
if (timeoutId) clearTimeout(timeoutId);
|
|
2766
|
+
this.client.off("INTERACTION_CREATE", handler);
|
|
2767
|
+
};
|
|
2768
|
+
this.client.on("INTERACTION_CREATE", handler);
|
|
2769
|
+
if (time > 0) {
|
|
2770
|
+
timeoutId = setTimeout(() => {
|
|
2771
|
+
cleanup();
|
|
2772
|
+
resolve2(null);
|
|
2773
|
+
}, time);
|
|
2774
|
+
}
|
|
2775
|
+
});
|
|
2776
|
+
}
|
|
2777
|
+
};
|
|
2778
|
+
|
|
2779
|
+
// src/client/client.ts
|
|
2780
|
+
var Client = class {
|
|
2781
|
+
token;
|
|
2782
|
+
intents;
|
|
2783
|
+
cache;
|
|
2784
|
+
rest;
|
|
2785
|
+
gateways = /* @__PURE__ */ new Map();
|
|
2786
|
+
totalShards = 1;
|
|
2787
|
+
gateway;
|
|
2788
|
+
user = null;
|
|
2789
|
+
unavailableGuilds = /* @__PURE__ */ new Set();
|
|
2790
|
+
outageGuilds = /* @__PURE__ */ new Set();
|
|
2791
|
+
pendingChunks = /* @__PURE__ */ new Map();
|
|
2792
|
+
debug;
|
|
2793
|
+
commands;
|
|
2794
|
+
components;
|
|
2795
|
+
users;
|
|
2796
|
+
guilds;
|
|
2797
|
+
channels;
|
|
2798
|
+
messages;
|
|
2799
|
+
collectors;
|
|
2800
|
+
listeners = /* @__PURE__ */ new Map();
|
|
2801
|
+
middlewares = [];
|
|
2802
|
+
constructor(options) {
|
|
2803
|
+
this.token = options.token;
|
|
2804
|
+
this.intents = this.resolveIntents(options.intents);
|
|
2805
|
+
this.debug = options.debug ?? false;
|
|
2806
|
+
this.cache = new TongueStore(options.cache);
|
|
2807
|
+
this.rest = new ChameleonREST({ token: this.token });
|
|
2808
|
+
this.commands = new CommandManager(this);
|
|
2809
|
+
this.components = new ComponentManager(this);
|
|
2810
|
+
this.users = new UserManager(this.rest, this.cache);
|
|
2811
|
+
this.guilds = new GuildManager(this.rest, this.cache);
|
|
2812
|
+
this.channels = new ChannelManager(this.rest, this.cache);
|
|
2813
|
+
this.messages = new MessageManager(this.rest, this.cache);
|
|
2814
|
+
this.collectors = new CollectorManager(this);
|
|
2815
|
+
let shards = [0];
|
|
2816
|
+
let totalShards = 1;
|
|
2817
|
+
if (options.sharding === "auto") {
|
|
2818
|
+
if (process.env.SHARD_LIST && process.env.TOTAL_SHARDS) {
|
|
2819
|
+
shards = process.env.SHARD_LIST.split(",").map(Number);
|
|
2820
|
+
totalShards = Number(process.env.TOTAL_SHARDS);
|
|
2821
|
+
} else if (process.env.SHARD_ID !== void 0 && process.env.SHARD_COUNT !== void 0) {
|
|
2822
|
+
shards = [Number(process.env.SHARD_ID)];
|
|
2823
|
+
totalShards = Number(process.env.SHARD_COUNT);
|
|
2824
|
+
}
|
|
2825
|
+
} else if (typeof options.sharding === "object") {
|
|
2826
|
+
shards = options.sharding.shards;
|
|
2827
|
+
totalShards = options.sharding.total;
|
|
2828
|
+
}
|
|
2829
|
+
this.totalShards = totalShards;
|
|
2830
|
+
for (const shardId of shards) {
|
|
2831
|
+
const gatewayOptions = {
|
|
2832
|
+
token: this.token,
|
|
2833
|
+
intents: this.intents,
|
|
2834
|
+
...options.sharding ? { shard: [shardId, totalShards] } : {}
|
|
2835
|
+
};
|
|
2836
|
+
if (options.largeThreshold !== void 0) {
|
|
2837
|
+
gatewayOptions.largeThreshold = options.largeThreshold;
|
|
2838
|
+
}
|
|
2839
|
+
const gw = new ChameleonGateway(gatewayOptions);
|
|
2840
|
+
this.gateways.set(shardId, gw);
|
|
2841
|
+
}
|
|
2842
|
+
this.gateway = this.gateways.get(shards[0]);
|
|
2843
|
+
this.setupGateway();
|
|
2844
|
+
}
|
|
2845
|
+
resolveIntents(intents) {
|
|
2846
|
+
if (!Array.isArray(intents)) {
|
|
2847
|
+
intents = [intents];
|
|
2848
|
+
}
|
|
2849
|
+
let resolved = 0;
|
|
2850
|
+
for (const intent of intents) {
|
|
2851
|
+
if (typeof intent === "number") {
|
|
2852
|
+
resolved |= intent;
|
|
2853
|
+
} else if (typeof intent === "string") {
|
|
2854
|
+
const bit = IntentBits[intent];
|
|
2855
|
+
if (bit !== void 0) {
|
|
2856
|
+
resolved |= bit;
|
|
2857
|
+
}
|
|
2858
|
+
} else if (Array.isArray(intent)) {
|
|
2859
|
+
resolved |= this.resolveIntents(intent);
|
|
2860
|
+
}
|
|
2861
|
+
}
|
|
2862
|
+
return resolved;
|
|
2863
|
+
}
|
|
2864
|
+
/**
|
|
2865
|
+
* register an event listener with full type-safety via discriminated unions
|
|
2866
|
+
*/
|
|
2867
|
+
on(event, listener) {
|
|
2868
|
+
if (!this.listeners.has(event)) {
|
|
2869
|
+
this.listeners.set(event, []);
|
|
2870
|
+
}
|
|
2871
|
+
this.listeners.get(event).push(listener);
|
|
2872
|
+
return this;
|
|
2873
|
+
}
|
|
2874
|
+
/**
|
|
2875
|
+
* remove an event listener
|
|
2876
|
+
*/
|
|
2877
|
+
off(event, listener) {
|
|
2878
|
+
const handlers = this.listeners.get(event);
|
|
2879
|
+
if (!handlers) return this;
|
|
2880
|
+
const index = handlers.indexOf(listener);
|
|
2881
|
+
if (index !== -1) {
|
|
2882
|
+
handlers.splice(index, 1);
|
|
2883
|
+
}
|
|
2884
|
+
return this;
|
|
2885
|
+
}
|
|
2886
|
+
/**
|
|
2887
|
+
* register middleware that runs between dispatch and event handlers
|
|
2888
|
+
*/
|
|
2889
|
+
use(fn) {
|
|
2890
|
+
this.middlewares.push(fn);
|
|
2891
|
+
return this;
|
|
2892
|
+
}
|
|
2893
|
+
getShardForGuild(guildId) {
|
|
2894
|
+
return Number(BigInt(guildId) >> 22n) % this.totalShards;
|
|
2895
|
+
}
|
|
2896
|
+
/**
|
|
2897
|
+
* request offline/large guild members from the Gateway.
|
|
2898
|
+
* This is used to lazy-load members into the cache or search for specific members
|
|
2899
|
+
*/
|
|
2900
|
+
requestGuildMembers(options) {
|
|
2901
|
+
const guildId = Array.isArray(options.guildId) ? options.guildId[0] : options.guildId;
|
|
2902
|
+
if (!guildId) return;
|
|
2903
|
+
const shardId = this.getShardForGuild(guildId);
|
|
2904
|
+
const gw = this.gateways.get(shardId) ?? this.gateway;
|
|
2905
|
+
if (gw) {
|
|
2906
|
+
gw.requestGuildMembers(options);
|
|
2907
|
+
}
|
|
2908
|
+
}
|
|
2909
|
+
/**
|
|
2910
|
+
* Connect to all Gateways
|
|
2911
|
+
*/
|
|
2912
|
+
async login() {
|
|
2913
|
+
for (const gw of this.gateways.values()) {
|
|
2914
|
+
gw.connect();
|
|
2915
|
+
await new Promise((r) => setTimeout(r, 5e3));
|
|
2916
|
+
}
|
|
2917
|
+
}
|
|
2918
|
+
/**
|
|
2919
|
+
* Gracefully disconnect from all Gateways
|
|
2920
|
+
*/
|
|
2921
|
+
destroy() {
|
|
2922
|
+
for (const gw of this.gateways.values()) {
|
|
2923
|
+
gw.disconnect(1e3, "Client destroyed");
|
|
2924
|
+
}
|
|
2925
|
+
}
|
|
2926
|
+
/**
|
|
2927
|
+
* Update presence/status across all shards
|
|
2928
|
+
*/
|
|
2929
|
+
presence(options) {
|
|
2930
|
+
for (const gw of this.gateways.values()) {
|
|
2931
|
+
gw.updatePresence(options);
|
|
2932
|
+
}
|
|
2933
|
+
}
|
|
2934
|
+
/**
|
|
2935
|
+
* dispatch an event through the middleware pipeline, then to listeners
|
|
2936
|
+
*/
|
|
2937
|
+
dispatch(event, data) {
|
|
2938
|
+
if (this.middlewares.length === 0) {
|
|
2939
|
+
this.emit(event, data);
|
|
2940
|
+
return;
|
|
2941
|
+
}
|
|
2942
|
+
let index = 0;
|
|
2943
|
+
const next = () => {
|
|
2944
|
+
index++;
|
|
2945
|
+
if (index >= this.middlewares.length) {
|
|
2946
|
+
this.emit(event, data);
|
|
2947
|
+
return;
|
|
2948
|
+
}
|
|
2949
|
+
const mw = this.middlewares[index];
|
|
2950
|
+
if (mw) mw(data, next);
|
|
2951
|
+
};
|
|
2952
|
+
const first = this.middlewares[0];
|
|
2953
|
+
if (first) first(data, next);
|
|
2954
|
+
}
|
|
2955
|
+
/**
|
|
2956
|
+
* emit to registered listeners
|
|
2957
|
+
*/
|
|
2958
|
+
emit(event, data) {
|
|
2959
|
+
const handlers = this.listeners.get(event);
|
|
2960
|
+
if (!handlers) return;
|
|
2961
|
+
for (const handler of handlers) {
|
|
2962
|
+
handler(data);
|
|
2963
|
+
}
|
|
2964
|
+
}
|
|
2965
|
+
setupGateway() {
|
|
2966
|
+
for (const gw of this.gateways.values()) {
|
|
2967
|
+
gw.on("dispatch", (payload) => {
|
|
2968
|
+
this.handleDispatch(payload);
|
|
2969
|
+
});
|
|
2970
|
+
}
|
|
2971
|
+
}
|
|
2972
|
+
handleDispatch(payload) {
|
|
2973
|
+
const { t } = payload;
|
|
2974
|
+
const d = payload.d;
|
|
2975
|
+
if (!t || !d) return;
|
|
2976
|
+
switch (t) {
|
|
2977
|
+
case "READY": {
|
|
2978
|
+
if (d.user) {
|
|
2979
|
+
this.user = buildUser(d.user);
|
|
2980
|
+
this.cache.users.set(this.user.id, this.user);
|
|
2981
|
+
}
|
|
2982
|
+
if (Array.isArray(d.guilds)) {
|
|
2983
|
+
for (const raw of d.guilds) {
|
|
2984
|
+
if (raw.unavailable && typeof raw.id === "string") {
|
|
2985
|
+
this.unavailableGuilds.add(raw.id);
|
|
2986
|
+
}
|
|
2987
|
+
}
|
|
2988
|
+
}
|
|
2989
|
+
this.dispatch("READY", { type: "READY" });
|
|
2990
|
+
break;
|
|
2991
|
+
}
|
|
2992
|
+
case "RESUMED": {
|
|
2993
|
+
this.dispatch("RESUMED", { type: "RESUMED" });
|
|
2994
|
+
break;
|
|
2995
|
+
}
|
|
2996
|
+
case "GUILD_CREATE": {
|
|
2997
|
+
const guild = buildGuild(d);
|
|
2998
|
+
let reason = null;
|
|
2999
|
+
if (this.unavailableGuilds.has(guild.id)) {
|
|
3000
|
+
this.unavailableGuilds.delete(guild.id);
|
|
3001
|
+
reason = "hydration";
|
|
3002
|
+
} else if (this.outageGuilds.has(guild.id)) {
|
|
3003
|
+
this.outageGuilds.delete(guild.id);
|
|
3004
|
+
reason = "outage";
|
|
3005
|
+
}
|
|
3006
|
+
this.cache.guilds.set(guild.id, guild);
|
|
3007
|
+
if (Array.isArray(d.channels)) {
|
|
3008
|
+
for (const raw of d.channels) {
|
|
3009
|
+
const ch = buildChannel(raw, guild.id);
|
|
3010
|
+
this.cache.channels.set(ch.id, ch);
|
|
3011
|
+
}
|
|
3012
|
+
}
|
|
3013
|
+
if (Array.isArray(d.roles)) {
|
|
3014
|
+
for (const raw of d.roles) {
|
|
3015
|
+
const role = buildRole(raw);
|
|
3016
|
+
this.cache.roles.set(role.id, role);
|
|
3017
|
+
}
|
|
3018
|
+
}
|
|
3019
|
+
if (Array.isArray(d.members)) {
|
|
3020
|
+
for (const raw of d.members) {
|
|
3021
|
+
const member = buildMember(raw, guild.id, this.cache);
|
|
3022
|
+
if (member.user?.id) {
|
|
3023
|
+
this.cache.members.set(TongueStore.memberKey(guild.id, member.user.id), member);
|
|
3024
|
+
}
|
|
3025
|
+
}
|
|
3026
|
+
}
|
|
3027
|
+
if (Array.isArray(d.emojis)) {
|
|
3028
|
+
for (const raw of d.emojis) {
|
|
3029
|
+
this.cache.emojis.set(raw.id, raw);
|
|
3030
|
+
}
|
|
3031
|
+
}
|
|
3032
|
+
if (Array.isArray(d.stickers)) {
|
|
3033
|
+
for (const raw of d.stickers) {
|
|
3034
|
+
this.cache.stickers.set(raw.id, raw);
|
|
3035
|
+
}
|
|
3036
|
+
}
|
|
3037
|
+
if (Array.isArray(d.stage_instances)) {
|
|
3038
|
+
for (const raw of d.stage_instances) {
|
|
3039
|
+
this.cache.stageInstances.set(raw.id, raw);
|
|
3040
|
+
}
|
|
3041
|
+
}
|
|
3042
|
+
if (Array.isArray(d.guild_scheduled_events)) {
|
|
3043
|
+
for (const raw of d.guild_scheduled_events) {
|
|
3044
|
+
this.cache.scheduledEvents.set(raw.id, raw);
|
|
3045
|
+
}
|
|
3046
|
+
}
|
|
3047
|
+
if (guild.large) {
|
|
3048
|
+
this.pendingChunks.set(guild.id, {
|
|
3049
|
+
received: 0,
|
|
3050
|
+
total: -1,
|
|
3051
|
+
reason,
|
|
3052
|
+
guild,
|
|
3053
|
+
timeout: setTimeout(() => {
|
|
3054
|
+
if (this.pendingChunks.has(guild.id)) {
|
|
3055
|
+
this.pendingChunks.delete(guild.id);
|
|
3056
|
+
if (reason) {
|
|
3057
|
+
this.dispatch("GUILD_AVAILABLE", { type: "GUILD_AVAILABLE", guild, reason, partial: true });
|
|
3058
|
+
} else {
|
|
3059
|
+
this.dispatch("GUILD_CREATE", { type: "GUILD_CREATE", guild, partial: true });
|
|
3060
|
+
}
|
|
3061
|
+
}
|
|
3062
|
+
}, 15e3)
|
|
3063
|
+
});
|
|
3064
|
+
const shardId = this.getShardForGuild(guild.id);
|
|
3065
|
+
const gw = this.gateways.get(shardId) ?? this.gateway;
|
|
3066
|
+
if (gw) {
|
|
3067
|
+
gw.requestGuildMembers({
|
|
3068
|
+
guildId: guild.id,
|
|
3069
|
+
query: "",
|
|
3070
|
+
limit: 0
|
|
3071
|
+
});
|
|
3072
|
+
}
|
|
3073
|
+
} else {
|
|
3074
|
+
if (reason) {
|
|
3075
|
+
this.dispatch("GUILD_AVAILABLE", { type: "GUILD_AVAILABLE", guild, reason });
|
|
3076
|
+
} else {
|
|
3077
|
+
this.dispatch("GUILD_CREATE", { type: "GUILD_CREATE", guild });
|
|
3078
|
+
}
|
|
3079
|
+
}
|
|
3080
|
+
break;
|
|
3081
|
+
}
|
|
3082
|
+
case "GUILD_UPDATE": {
|
|
3083
|
+
const oldGuild = this.cache.guilds.get(d.id);
|
|
3084
|
+
const guild = buildGuild(d);
|
|
3085
|
+
this.cache.guilds.set(guild.id, guild);
|
|
3086
|
+
this.dispatch("GUILD_UPDATE", { type: "GUILD_UPDATE", guild, ...oldGuild ? { oldGuild } : {} });
|
|
3087
|
+
break;
|
|
3088
|
+
}
|
|
3089
|
+
case "GUILD_DELETE": {
|
|
3090
|
+
const guildId = d.id;
|
|
3091
|
+
const unavailable = d.unavailable;
|
|
3092
|
+
if (unavailable) {
|
|
3093
|
+
this.outageGuilds.add(guildId);
|
|
3094
|
+
this.dispatch("GUILD_UNAVAILABLE", { type: "GUILD_UNAVAILABLE", guildId });
|
|
3095
|
+
} else {
|
|
3096
|
+
this.cache.guilds.delete(guildId);
|
|
3097
|
+
this.dispatch("GUILD_DELETE", { type: "GUILD_DELETE", guildId });
|
|
3098
|
+
}
|
|
3099
|
+
break;
|
|
3100
|
+
}
|
|
3101
|
+
case "CHANNEL_CREATE": {
|
|
3102
|
+
const channel = buildChannel(d);
|
|
3103
|
+
this.cache.channels.set(channel.id, channel);
|
|
3104
|
+
this.dispatch("CHANNEL_CREATE", { type: "CHANNEL_CREATE", channel, ...d.guild_id ? { guild: { id: d.guild_id } } : {} });
|
|
3105
|
+
break;
|
|
3106
|
+
}
|
|
3107
|
+
case "CHANNEL_UPDATE": {
|
|
3108
|
+
const oldChannel = this.cache.channels.get(d.id);
|
|
3109
|
+
const channel = buildChannel(d);
|
|
3110
|
+
this.cache.channels.set(channel.id, channel);
|
|
3111
|
+
this.dispatch("CHANNEL_UPDATE", { type: "CHANNEL_UPDATE", channel, ...oldChannel ? { oldChannel } : {}, ...d.guild_id ? { guild: { id: d.guild_id } } : {} });
|
|
3112
|
+
break;
|
|
3113
|
+
}
|
|
3114
|
+
case "CHANNEL_DELETE": {
|
|
3115
|
+
const channelId = d.id;
|
|
3116
|
+
this.cache.channels.delete(channelId);
|
|
3117
|
+
this.dispatch("CHANNEL_DELETE", { type: "CHANNEL_DELETE", channelId, ...d.guild_id ? { guild: { id: d.guild_id } } : {} });
|
|
3118
|
+
break;
|
|
3119
|
+
}
|
|
3120
|
+
case "CHANNEL_PINS_UPDATE": {
|
|
3121
|
+
this.dispatch("CHANNEL_PINS_UPDATE", {
|
|
3122
|
+
type: "CHANNEL_PINS_UPDATE",
|
|
3123
|
+
channelId: d.channel_id,
|
|
3124
|
+
...d.guild_id ? { guildId: d.guild_id } : {},
|
|
3125
|
+
...d.last_pin_timestamp !== void 0 ? { lastPinTimestamp: d.last_pin_timestamp ? Date.parse(d.last_pin_timestamp) : null } : {}
|
|
3126
|
+
});
|
|
3127
|
+
break;
|
|
3128
|
+
}
|
|
3129
|
+
case "THREAD_CREATE": {
|
|
3130
|
+
const channel = buildChannel(d);
|
|
3131
|
+
this.cache.channels.set(channel.id, channel);
|
|
3132
|
+
this.dispatch("THREAD_CREATE", { type: "THREAD_CREATE", channel });
|
|
3133
|
+
break;
|
|
3134
|
+
}
|
|
3135
|
+
case "THREAD_UPDATE": {
|
|
3136
|
+
const oldChannel = this.cache.channels.get(d.id);
|
|
3137
|
+
const channel = buildChannel(d);
|
|
3138
|
+
this.cache.channels.set(channel.id, channel);
|
|
3139
|
+
this.dispatch("THREAD_UPDATE", { type: "THREAD_UPDATE", channel, ...oldChannel ? { oldChannel } : {} });
|
|
3140
|
+
break;
|
|
3141
|
+
}
|
|
3142
|
+
case "THREAD_DELETE": {
|
|
3143
|
+
const id = d.id;
|
|
3144
|
+
this.cache.channels.delete(id);
|
|
3145
|
+
this.dispatch("THREAD_DELETE", {
|
|
3146
|
+
type: "THREAD_DELETE",
|
|
3147
|
+
id,
|
|
3148
|
+
guildId: d.guild_id,
|
|
3149
|
+
parentId: d.parent_id,
|
|
3150
|
+
channelType: d.type
|
|
3151
|
+
});
|
|
3152
|
+
break;
|
|
3153
|
+
}
|
|
3154
|
+
case "GUILD_MEMBER_ADD": {
|
|
3155
|
+
const guildId = d.guild_id;
|
|
3156
|
+
const member = buildMember(d, guildId, this.cache);
|
|
3157
|
+
if (member.user?.id) {
|
|
3158
|
+
this.cache.members.set(TongueStore.memberKey(guildId, member.user.id), member);
|
|
3159
|
+
}
|
|
3160
|
+
this.dispatch("GUILD_MEMBER_ADD", { type: "GUILD_MEMBER_ADD", member, guildId });
|
|
3161
|
+
break;
|
|
3162
|
+
}
|
|
3163
|
+
case "GUILD_MEMBER_UPDATE": {
|
|
3164
|
+
const guildId = d.guild_id;
|
|
3165
|
+
const rawUser = d.user;
|
|
3166
|
+
const user = buildUser(rawUser);
|
|
3167
|
+
this.cache.users.set(user.id, user);
|
|
3168
|
+
const memberKey = TongueStore.memberKey(guildId, user.id);
|
|
3169
|
+
const oldMember = this.cache.members.get(memberKey);
|
|
3170
|
+
const updatedMember = buildMember(d, guildId, this.cache);
|
|
3171
|
+
this.cache.members.set(memberKey, updatedMember);
|
|
3172
|
+
this.dispatch("GUILD_MEMBER_UPDATE", {
|
|
3173
|
+
type: "GUILD_MEMBER_UPDATE",
|
|
3174
|
+
guildId,
|
|
3175
|
+
user,
|
|
3176
|
+
roles: d.roles,
|
|
3177
|
+
...oldMember ? { oldMember } : {},
|
|
3178
|
+
...d.nick !== void 0 ? { nick: d.nick ?? null } : {},
|
|
3179
|
+
...d.joined_at !== void 0 ? { joinedAt: d.joined_at ? Date.parse(d.joined_at) : null } : {}
|
|
3180
|
+
});
|
|
3181
|
+
break;
|
|
3182
|
+
}
|
|
3183
|
+
case "GUILD_MEMBER_REMOVE": {
|
|
3184
|
+
const guildId = d.guild_id;
|
|
3185
|
+
const rawUser = d.user;
|
|
3186
|
+
const user = buildUser(rawUser);
|
|
3187
|
+
this.cache.members.delete(TongueStore.memberKey(guildId, user.id));
|
|
3188
|
+
this.dispatch("GUILD_MEMBER_REMOVE", { type: "GUILD_MEMBER_REMOVE", user, guildId });
|
|
3189
|
+
break;
|
|
3190
|
+
}
|
|
3191
|
+
case "GUILD_ROLE_CREATE": {
|
|
3192
|
+
const role = buildRole(d.role);
|
|
3193
|
+
this.cache.roles.set(role.id, role);
|
|
3194
|
+
this.dispatch("GUILD_ROLE_CREATE", { type: "GUILD_ROLE_CREATE", guildId: d.guild_id, role });
|
|
3195
|
+
break;
|
|
3196
|
+
}
|
|
3197
|
+
case "GUILD_ROLE_UPDATE": {
|
|
3198
|
+
const rolePayload = d.role;
|
|
3199
|
+
const oldRole = this.cache.roles.get(rolePayload.id);
|
|
3200
|
+
const role = buildRole(rolePayload);
|
|
3201
|
+
this.cache.roles.set(role.id, role);
|
|
3202
|
+
this.dispatch("GUILD_ROLE_UPDATE", { type: "GUILD_ROLE_UPDATE", guildId: d.guild_id, role, ...oldRole ? { oldRole } : {} });
|
|
3203
|
+
break;
|
|
3204
|
+
}
|
|
3205
|
+
case "GUILD_ROLE_DELETE": {
|
|
3206
|
+
const roleId = d.role_id;
|
|
3207
|
+
this.cache.roles.delete(roleId);
|
|
3208
|
+
this.dispatch("GUILD_ROLE_DELETE", { type: "GUILD_ROLE_DELETE", guildId: d.guild_id, roleId });
|
|
3209
|
+
break;
|
|
3210
|
+
}
|
|
3211
|
+
case "GUILD_BAN_ADD": {
|
|
3212
|
+
const user = buildUser(d.user);
|
|
3213
|
+
this.cache.users.set(user.id, user);
|
|
3214
|
+
this.dispatch("GUILD_BAN_ADD", { type: "GUILD_BAN_ADD", guildId: d.guild_id, user });
|
|
3215
|
+
break;
|
|
3216
|
+
}
|
|
3217
|
+
case "GUILD_BAN_REMOVE": {
|
|
3218
|
+
const user = buildUser(d.user);
|
|
3219
|
+
this.cache.users.set(user.id, user);
|
|
3220
|
+
this.dispatch("GUILD_BAN_REMOVE", { type: "GUILD_BAN_REMOVE", guildId: d.guild_id, user });
|
|
3221
|
+
break;
|
|
3222
|
+
}
|
|
3223
|
+
case "MESSAGE_CREATE": {
|
|
3224
|
+
const message = buildMessage(d, this.cache);
|
|
3225
|
+
this.cache.messages.set(message.id, message);
|
|
3226
|
+
this.dispatch("MESSAGE_CREATE", {
|
|
3227
|
+
type: "MESSAGE_CREATE",
|
|
3228
|
+
message,
|
|
3229
|
+
channel: resolveChannel(message.channelId, this.cache)
|
|
3230
|
+
});
|
|
3231
|
+
break;
|
|
3232
|
+
}
|
|
3233
|
+
case "MESSAGE_UPDATE": {
|
|
3234
|
+
const oldMessage = this.cache.messages.get(d.id);
|
|
3235
|
+
const message = buildMessage(d, this.cache, oldMessage);
|
|
3236
|
+
this.cache.messages.set(message.id, message);
|
|
3237
|
+
this.dispatch("MESSAGE_UPDATE", {
|
|
3238
|
+
type: "MESSAGE_UPDATE",
|
|
3239
|
+
message,
|
|
3240
|
+
channel: resolveChannel(message.channelId, this.cache),
|
|
3241
|
+
...oldMessage ? { oldMessage } : {}
|
|
3242
|
+
});
|
|
3243
|
+
break;
|
|
3244
|
+
}
|
|
3245
|
+
case "MESSAGE_DELETE": {
|
|
3246
|
+
const messageId = d.id;
|
|
3247
|
+
const message = this.cache.messages.get(messageId);
|
|
3248
|
+
this.cache.messages.delete(messageId);
|
|
3249
|
+
this.dispatch("MESSAGE_DELETE", {
|
|
3250
|
+
type: "MESSAGE_DELETE",
|
|
3251
|
+
messageId,
|
|
3252
|
+
channelId: d.channel_id,
|
|
3253
|
+
...d.guild_id ? { guildId: d.guild_id } : {},
|
|
3254
|
+
...message ? { message } : {}
|
|
3255
|
+
});
|
|
3256
|
+
break;
|
|
3257
|
+
}
|
|
3258
|
+
case "MESSAGE_DELETE_BULK": {
|
|
3259
|
+
const ids = d.ids;
|
|
3260
|
+
const messages = [];
|
|
3261
|
+
for (const id of ids) {
|
|
3262
|
+
const msg = this.cache.messages.get(id);
|
|
3263
|
+
if (msg) messages.push(msg);
|
|
3264
|
+
this.cache.messages.delete(id);
|
|
3265
|
+
}
|
|
3266
|
+
this.dispatch("MESSAGE_DELETE_BULK", {
|
|
3267
|
+
type: "MESSAGE_DELETE_BULK",
|
|
3268
|
+
messageIds: ids,
|
|
3269
|
+
channelId: d.channel_id,
|
|
3270
|
+
...d.guild_id ? { guildId: d.guild_id } : {},
|
|
3271
|
+
...messages.length > 0 ? { messages } : {}
|
|
3272
|
+
});
|
|
3273
|
+
break;
|
|
3274
|
+
}
|
|
3275
|
+
case "MESSAGE_REACTION_ADD": {
|
|
3276
|
+
let reactionMember;
|
|
3277
|
+
if (d.member && d.guild_id) {
|
|
3278
|
+
reactionMember = buildMember(d.member, d.guild_id, this.cache);
|
|
3279
|
+
if (reactionMember.user?.id) {
|
|
3280
|
+
this.cache.users.set(reactionMember.user.id, reactionMember.user);
|
|
3281
|
+
this.cache.members.set(TongueStore.memberKey(d.guild_id, reactionMember.user.id), reactionMember);
|
|
3282
|
+
}
|
|
3283
|
+
}
|
|
3284
|
+
this.dispatch("MESSAGE_REACTION_ADD", {
|
|
3285
|
+
type: "MESSAGE_REACTION_ADD",
|
|
3286
|
+
userId: d.user_id,
|
|
3287
|
+
channelId: d.channel_id,
|
|
3288
|
+
messageId: d.message_id,
|
|
3289
|
+
...d.guild_id ? { guildId: d.guild_id } : {},
|
|
3290
|
+
emoji: d.emoji,
|
|
3291
|
+
...reactionMember ? { member: reactionMember } : {}
|
|
3292
|
+
});
|
|
3293
|
+
break;
|
|
3294
|
+
}
|
|
3295
|
+
case "MESSAGE_REACTION_REMOVE": {
|
|
3296
|
+
this.dispatch("MESSAGE_REACTION_REMOVE", {
|
|
3297
|
+
type: "MESSAGE_REACTION_REMOVE",
|
|
3298
|
+
userId: d.user_id,
|
|
3299
|
+
channelId: d.channel_id,
|
|
3300
|
+
messageId: d.message_id,
|
|
3301
|
+
...d.guild_id ? { guildId: d.guild_id } : {},
|
|
3302
|
+
emoji: d.emoji
|
|
3303
|
+
});
|
|
3304
|
+
break;
|
|
3305
|
+
}
|
|
3306
|
+
case "MESSAGE_REACTION_REMOVE_ALL": {
|
|
3307
|
+
this.dispatch("MESSAGE_REACTION_REMOVE_ALL", {
|
|
3308
|
+
type: "MESSAGE_REACTION_REMOVE_ALL",
|
|
3309
|
+
channelId: d.channel_id,
|
|
3310
|
+
messageId: d.message_id,
|
|
3311
|
+
...d.guild_id ? { guildId: d.guild_id } : {}
|
|
3312
|
+
});
|
|
3313
|
+
break;
|
|
3314
|
+
}
|
|
3315
|
+
case "MESSAGE_REACTION_REMOVE_EMOJI": {
|
|
3316
|
+
this.dispatch("MESSAGE_REACTION_REMOVE_EMOJI", {
|
|
3317
|
+
type: "MESSAGE_REACTION_REMOVE_EMOJI",
|
|
3318
|
+
channelId: d.channel_id,
|
|
3319
|
+
messageId: d.message_id,
|
|
3320
|
+
...d.guild_id ? { guildId: d.guild_id } : {},
|
|
3321
|
+
emoji: d.emoji
|
|
3322
|
+
});
|
|
3323
|
+
break;
|
|
3324
|
+
}
|
|
3325
|
+
case "INTERACTION_CREATE": {
|
|
3326
|
+
if (d.type === 2 /* APPLICATION_COMMAND */ || d.type === 4 /* APPLICATION_COMMAND_AUTOCOMPLETE */) {
|
|
3327
|
+
this.commands.handleInteraction(d).catch(console.error);
|
|
3328
|
+
} else if (d.type === 3 /* MESSAGE_COMPONENT */ || d.type === 5 /* MODAL_SUBMIT */) {
|
|
3329
|
+
this.components.handleInteraction(d).catch(console.error);
|
|
3330
|
+
}
|
|
3331
|
+
this.dispatch("INTERACTION_CREATE", {
|
|
3332
|
+
type: "INTERACTION_CREATE",
|
|
3333
|
+
interaction: d
|
|
3334
|
+
});
|
|
3335
|
+
break;
|
|
3336
|
+
}
|
|
3337
|
+
case "VOICE_STATE_UPDATE": {
|
|
3338
|
+
this.dispatch("VOICE_STATE_UPDATE", {
|
|
3339
|
+
type: "VOICE_STATE_UPDATE",
|
|
3340
|
+
voiceState: d
|
|
3341
|
+
});
|
|
3342
|
+
break;
|
|
3343
|
+
}
|
|
3344
|
+
case "VOICE_SERVER_UPDATE": {
|
|
3345
|
+
this.dispatch("VOICE_SERVER_UPDATE", {
|
|
3346
|
+
type: "VOICE_SERVER_UPDATE",
|
|
3347
|
+
token: d.token,
|
|
3348
|
+
guildId: d.guild_id,
|
|
3349
|
+
endpoint: d.endpoint
|
|
3350
|
+
});
|
|
3351
|
+
break;
|
|
3352
|
+
}
|
|
3353
|
+
case "INVITE_CREATE": {
|
|
3354
|
+
let inviter;
|
|
3355
|
+
if (d.inviter) {
|
|
3356
|
+
inviter = buildUser(d.inviter);
|
|
3357
|
+
this.cache.users.set(inviter.id, inviter);
|
|
3358
|
+
}
|
|
3359
|
+
this.dispatch("INVITE_CREATE", {
|
|
3360
|
+
type: "INVITE_CREATE",
|
|
3361
|
+
channelId: d.channel_id,
|
|
3362
|
+
code: d.code,
|
|
3363
|
+
...d.guild_id ? { guildId: d.guild_id } : {},
|
|
3364
|
+
...inviter ? { inviter } : {},
|
|
3365
|
+
maxAge: d.max_age,
|
|
3366
|
+
maxUses: d.max_uses,
|
|
3367
|
+
temporary: d.temporary
|
|
3368
|
+
});
|
|
3369
|
+
break;
|
|
3370
|
+
}
|
|
3371
|
+
case "INVITE_DELETE": {
|
|
3372
|
+
this.dispatch("INVITE_DELETE", {
|
|
3373
|
+
type: "INVITE_DELETE",
|
|
3374
|
+
channelId: d.channel_id,
|
|
3375
|
+
code: d.code,
|
|
3376
|
+
...d.guild_id ? { guildId: d.guild_id } : {}
|
|
3377
|
+
});
|
|
3378
|
+
break;
|
|
3379
|
+
}
|
|
3380
|
+
case "GUILD_INTEGRATIONS_UPDATE": {
|
|
3381
|
+
this.dispatch("GUILD_INTEGRATIONS_UPDATE", {
|
|
3382
|
+
type: "GUILD_INTEGRATIONS_UPDATE",
|
|
3383
|
+
guildId: d.guild_id
|
|
3384
|
+
});
|
|
3385
|
+
break;
|
|
3386
|
+
}
|
|
3387
|
+
case "ENTITLEMENT_CREATE": {
|
|
3388
|
+
this.dispatch("ENTITLEMENT_CREATE", { type: "ENTITLEMENT_CREATE", entitlement: d });
|
|
3389
|
+
break;
|
|
3390
|
+
}
|
|
3391
|
+
case "ENTITLEMENT_UPDATE": {
|
|
3392
|
+
this.dispatch("ENTITLEMENT_UPDATE", { type: "ENTITLEMENT_UPDATE", entitlement: d });
|
|
3393
|
+
break;
|
|
3394
|
+
}
|
|
3395
|
+
case "ENTITLEMENT_DELETE": {
|
|
3396
|
+
this.dispatch("ENTITLEMENT_DELETE", { type: "ENTITLEMENT_DELETE", entitlement: d });
|
|
3397
|
+
break;
|
|
3398
|
+
}
|
|
3399
|
+
case "PRESENCE_UPDATE": {
|
|
3400
|
+
this.dispatch("PRESENCE_UPDATE", {
|
|
3401
|
+
type: "PRESENCE_UPDATE",
|
|
3402
|
+
user: d.user,
|
|
3403
|
+
guildId: d.guild_id,
|
|
3404
|
+
status: d.status,
|
|
3405
|
+
activities: d.activities,
|
|
3406
|
+
clientStatus: d.client_status
|
|
3407
|
+
});
|
|
3408
|
+
break;
|
|
3409
|
+
}
|
|
3410
|
+
case "TYPING_START": {
|
|
3411
|
+
let typingMember;
|
|
3412
|
+
if (d.member && d.guild_id) {
|
|
3413
|
+
typingMember = buildMember(d.member, d.guild_id, this.cache);
|
|
3414
|
+
if (typingMember.user?.id) {
|
|
3415
|
+
this.cache.users.set(typingMember.user.id, typingMember.user);
|
|
3416
|
+
this.cache.members.set(TongueStore.memberKey(d.guild_id, typingMember.user.id), typingMember);
|
|
3417
|
+
}
|
|
3418
|
+
}
|
|
3419
|
+
this.dispatch("TYPING_START", {
|
|
3420
|
+
type: "TYPING_START",
|
|
3421
|
+
channelId: d.channel_id,
|
|
3422
|
+
...d.guild_id ? { guildId: d.guild_id } : {},
|
|
3423
|
+
userId: d.user_id,
|
|
3424
|
+
timestamp: d.timestamp,
|
|
3425
|
+
...typingMember ? { member: typingMember } : {}
|
|
3426
|
+
});
|
|
3427
|
+
break;
|
|
3428
|
+
}
|
|
3429
|
+
case "USER_UPDATE": {
|
|
3430
|
+
const oldUser = this.cache.users.get(d.id);
|
|
3431
|
+
const user = buildUser(d);
|
|
3432
|
+
this.cache.users.set(user.id, user);
|
|
3433
|
+
if (this.user && user.id === this.user.id) {
|
|
3434
|
+
this.user = user;
|
|
3435
|
+
}
|
|
3436
|
+
this.dispatch("USER_UPDATE", { type: "USER_UPDATE", user, ...oldUser ? { oldUser } : {} });
|
|
3437
|
+
break;
|
|
3438
|
+
}
|
|
3439
|
+
case "WEBHOOKS_UPDATE": {
|
|
3440
|
+
this.dispatch("WEBHOOKS_UPDATE", {
|
|
3441
|
+
type: "WEBHOOKS_UPDATE",
|
|
3442
|
+
guildId: d.guild_id,
|
|
3443
|
+
channelId: d.channel_id
|
|
3444
|
+
});
|
|
3445
|
+
break;
|
|
3446
|
+
}
|
|
3447
|
+
case "MESSAGE_POLL_VOTE_ADD": {
|
|
3448
|
+
this.dispatch("MESSAGE_POLL_VOTE_ADD", {
|
|
3449
|
+
type: "MESSAGE_POLL_VOTE_ADD",
|
|
3450
|
+
userId: d.user_id,
|
|
3451
|
+
channelId: d.channel_id,
|
|
3452
|
+
messageId: d.message_id,
|
|
3453
|
+
...d.guild_id ? { guildId: d.guild_id } : {},
|
|
3454
|
+
answerId: d.answer_id
|
|
3455
|
+
});
|
|
3456
|
+
break;
|
|
3457
|
+
}
|
|
3458
|
+
case "MESSAGE_POLL_VOTE_REMOVE": {
|
|
3459
|
+
this.dispatch("MESSAGE_POLL_VOTE_REMOVE", {
|
|
3460
|
+
type: "MESSAGE_POLL_VOTE_REMOVE",
|
|
3461
|
+
userId: d.user_id,
|
|
3462
|
+
channelId: d.channel_id,
|
|
3463
|
+
messageId: d.message_id,
|
|
3464
|
+
...d.guild_id ? { guildId: d.guild_id } : {},
|
|
3465
|
+
answerId: d.answer_id
|
|
3466
|
+
});
|
|
3467
|
+
break;
|
|
3468
|
+
}
|
|
3469
|
+
case "GUILD_MEMBERS_CHUNK": {
|
|
3470
|
+
const guildId = d.guild_id;
|
|
3471
|
+
const members = [];
|
|
3472
|
+
if (Array.isArray(d.members)) {
|
|
3473
|
+
for (const raw of d.members) {
|
|
3474
|
+
const member = buildMember(raw, guildId, this.cache);
|
|
3475
|
+
if (member.user?.id) {
|
|
3476
|
+
this.cache.users.set(member.user.id, member.user);
|
|
3477
|
+
this.cache.members.set(TongueStore.memberKey(guildId, member.user.id), member);
|
|
3478
|
+
}
|
|
3479
|
+
members.push(member);
|
|
3480
|
+
}
|
|
3481
|
+
}
|
|
3482
|
+
const chunkCount = d.chunk_count;
|
|
3483
|
+
const state = this.pendingChunks.get(guildId);
|
|
3484
|
+
if (state) {
|
|
3485
|
+
state.total = chunkCount;
|
|
3486
|
+
state.received++;
|
|
3487
|
+
if (state.received >= state.total) {
|
|
3488
|
+
clearTimeout(state.timeout);
|
|
3489
|
+
this.pendingChunks.delete(guildId);
|
|
3490
|
+
if (state.reason) {
|
|
3491
|
+
this.dispatch("GUILD_AVAILABLE", { type: "GUILD_AVAILABLE", guild: state.guild, reason: state.reason });
|
|
3492
|
+
} else {
|
|
3493
|
+
this.dispatch("GUILD_CREATE", { type: "GUILD_CREATE", guild: state.guild });
|
|
3494
|
+
}
|
|
3495
|
+
}
|
|
3496
|
+
}
|
|
3497
|
+
this.dispatch("GUILD_MEMBERS_CHUNK", {
|
|
3498
|
+
type: "GUILD_MEMBERS_CHUNK",
|
|
3499
|
+
guildId,
|
|
3500
|
+
members,
|
|
3501
|
+
chunkIndex: d.chunk_index,
|
|
3502
|
+
chunkCount: d.chunk_count,
|
|
3503
|
+
...d.not_found ? { notFound: d.not_found } : {},
|
|
3504
|
+
...d.nonce ? { nonce: d.nonce } : {}
|
|
3505
|
+
});
|
|
3506
|
+
break;
|
|
3507
|
+
}
|
|
3508
|
+
case "THREAD_LIST_SYNC": {
|
|
3509
|
+
const guildId = d.guild_id;
|
|
3510
|
+
const threads = [];
|
|
3511
|
+
if (Array.isArray(d.threads)) {
|
|
3512
|
+
for (const raw of d.threads) {
|
|
3513
|
+
const ch = buildChannel(raw, guildId);
|
|
3514
|
+
this.cache.channels.set(ch.id, ch);
|
|
3515
|
+
threads.push(ch);
|
|
3516
|
+
}
|
|
3517
|
+
}
|
|
3518
|
+
this.dispatch("THREAD_LIST_SYNC", {
|
|
3519
|
+
type: "THREAD_LIST_SYNC",
|
|
3520
|
+
guildId,
|
|
3521
|
+
...d.channel_ids ? { channelIds: d.channel_ids } : {},
|
|
3522
|
+
threads,
|
|
3523
|
+
members: d.members
|
|
3524
|
+
});
|
|
3525
|
+
break;
|
|
3526
|
+
}
|
|
3527
|
+
case "GUILD_EMOJIS_UPDATE": {
|
|
3528
|
+
const emojis = d.emojis;
|
|
3529
|
+
for (const emoji of emojis) {
|
|
3530
|
+
if (emoji.id) this.cache.emojis.set(emoji.id, emoji);
|
|
3531
|
+
}
|
|
3532
|
+
this.dispatch("GUILD_EMOJIS_UPDATE", {
|
|
3533
|
+
type: "GUILD_EMOJIS_UPDATE",
|
|
3534
|
+
guildId: d.guild_id,
|
|
3535
|
+
emojis
|
|
3536
|
+
});
|
|
3537
|
+
break;
|
|
3538
|
+
}
|
|
3539
|
+
case "GUILD_STICKERS_UPDATE": {
|
|
3540
|
+
const stickers = d.stickers;
|
|
3541
|
+
for (const sticker of stickers) {
|
|
3542
|
+
this.cache.stickers.set(sticker.id, sticker);
|
|
3543
|
+
}
|
|
3544
|
+
this.dispatch("GUILD_STICKERS_UPDATE", {
|
|
3545
|
+
type: "GUILD_STICKERS_UPDATE",
|
|
3546
|
+
guildId: d.guild_id,
|
|
3547
|
+
stickers
|
|
3548
|
+
});
|
|
3549
|
+
break;
|
|
3550
|
+
}
|
|
3551
|
+
case "STAGE_INSTANCE_CREATE": {
|
|
3552
|
+
const stageInstance = d;
|
|
3553
|
+
this.cache.stageInstances.set(stageInstance.id, stageInstance);
|
|
3554
|
+
this.dispatch("STAGE_INSTANCE_CREATE", { type: "STAGE_INSTANCE_CREATE", stageInstance });
|
|
3555
|
+
break;
|
|
3556
|
+
}
|
|
3557
|
+
case "STAGE_INSTANCE_UPDATE": {
|
|
3558
|
+
const stageInstance = d;
|
|
3559
|
+
this.cache.stageInstances.set(stageInstance.id, stageInstance);
|
|
3560
|
+
this.dispatch("STAGE_INSTANCE_UPDATE", { type: "STAGE_INSTANCE_UPDATE", stageInstance });
|
|
3561
|
+
break;
|
|
3562
|
+
}
|
|
3563
|
+
case "STAGE_INSTANCE_DELETE": {
|
|
3564
|
+
const stageInstance = d;
|
|
3565
|
+
this.cache.stageInstances.delete(stageInstance.id);
|
|
3566
|
+
this.dispatch("STAGE_INSTANCE_DELETE", { type: "STAGE_INSTANCE_DELETE", stageInstance });
|
|
3567
|
+
break;
|
|
3568
|
+
}
|
|
3569
|
+
case "GUILD_SCHEDULED_EVENT_CREATE": {
|
|
3570
|
+
const scheduledEvent = d;
|
|
3571
|
+
this.cache.scheduledEvents.set(scheduledEvent.id, scheduledEvent);
|
|
3572
|
+
this.dispatch("GUILD_SCHEDULED_EVENT_CREATE", { type: "GUILD_SCHEDULED_EVENT_CREATE", scheduledEvent });
|
|
3573
|
+
break;
|
|
3574
|
+
}
|
|
3575
|
+
case "GUILD_SCHEDULED_EVENT_UPDATE": {
|
|
3576
|
+
const scheduledEvent = d;
|
|
3577
|
+
this.cache.scheduledEvents.set(scheduledEvent.id, scheduledEvent);
|
|
3578
|
+
this.dispatch("GUILD_SCHEDULED_EVENT_UPDATE", { type: "GUILD_SCHEDULED_EVENT_UPDATE", scheduledEvent });
|
|
3579
|
+
break;
|
|
3580
|
+
}
|
|
3581
|
+
case "GUILD_SCHEDULED_EVENT_DELETE": {
|
|
3582
|
+
const scheduledEvent = d;
|
|
3583
|
+
this.cache.scheduledEvents.delete(scheduledEvent.id);
|
|
3584
|
+
this.dispatch("GUILD_SCHEDULED_EVENT_DELETE", { type: "GUILD_SCHEDULED_EVENT_DELETE", scheduledEvent });
|
|
3585
|
+
break;
|
|
3586
|
+
}
|
|
3587
|
+
case "GUILD_SCHEDULED_EVENT_USER_ADD": {
|
|
3588
|
+
this.dispatch("GUILD_SCHEDULED_EVENT_USER_ADD", { type: "GUILD_SCHEDULED_EVENT_USER_ADD", guildScheduledEventId: d.guild_scheduled_event_id, userId: d.user_id, guildId: d.guild_id });
|
|
3589
|
+
break;
|
|
3590
|
+
}
|
|
3591
|
+
case "GUILD_SCHEDULED_EVENT_USER_REMOVE": {
|
|
3592
|
+
this.dispatch("GUILD_SCHEDULED_EVENT_USER_REMOVE", { type: "GUILD_SCHEDULED_EVENT_USER_REMOVE", guildScheduledEventId: d.guild_scheduled_event_id, userId: d.user_id, guildId: d.guild_id });
|
|
3593
|
+
break;
|
|
3594
|
+
}
|
|
3595
|
+
case "AUTO_MODERATION_RULE_CREATE": {
|
|
3596
|
+
const rule = d;
|
|
3597
|
+
this.cache.autoModRules.set(rule.id, rule);
|
|
3598
|
+
this.dispatch("AUTO_MODERATION_RULE_CREATE", { type: "AUTO_MODERATION_RULE_CREATE", rule });
|
|
3599
|
+
break;
|
|
3600
|
+
}
|
|
3601
|
+
case "AUTO_MODERATION_RULE_UPDATE": {
|
|
3602
|
+
const rule = d;
|
|
3603
|
+
this.cache.autoModRules.set(rule.id, rule);
|
|
3604
|
+
this.dispatch("AUTO_MODERATION_RULE_UPDATE", { type: "AUTO_MODERATION_RULE_UPDATE", rule });
|
|
3605
|
+
break;
|
|
3606
|
+
}
|
|
3607
|
+
case "AUTO_MODERATION_RULE_DELETE": {
|
|
3608
|
+
const rule = d;
|
|
3609
|
+
this.cache.autoModRules.delete(rule.id);
|
|
3610
|
+
this.dispatch("AUTO_MODERATION_RULE_DELETE", { type: "AUTO_MODERATION_RULE_DELETE", rule });
|
|
3611
|
+
break;
|
|
3612
|
+
}
|
|
3613
|
+
case "AUTO_MODERATION_ACTION_EXECUTION": {
|
|
3614
|
+
this.dispatch("AUTO_MODERATION_ACTION_EXECUTION", {
|
|
3615
|
+
type: "AUTO_MODERATION_ACTION_EXECUTION",
|
|
3616
|
+
guildId: d.guild_id,
|
|
3617
|
+
action: d.action,
|
|
3618
|
+
ruleId: d.rule_id,
|
|
3619
|
+
ruleTriggerType: d.rule_trigger_type,
|
|
3620
|
+
userId: d.user_id,
|
|
3621
|
+
...d.channel_id ? { channelId: d.channel_id } : {},
|
|
3622
|
+
...d.message_id ? { messageId: d.message_id } : {},
|
|
3623
|
+
...d.content !== void 0 ? { content: d.content } : {},
|
|
3624
|
+
...d.matched_keyword !== void 0 ? { matchedKeyword: d.matched_keyword } : {},
|
|
3625
|
+
...d.matched_content !== void 0 ? { matchedContent: d.matched_content } : {}
|
|
3626
|
+
});
|
|
3627
|
+
break;
|
|
3628
|
+
}
|
|
3629
|
+
case "INTEGRATION_CREATE": {
|
|
3630
|
+
const integration = d;
|
|
3631
|
+
this.cache.integrations.set(integration.id, integration);
|
|
3632
|
+
this.dispatch("INTEGRATION_CREATE", { type: "INTEGRATION_CREATE", guildId: d.guild_id, integration });
|
|
3633
|
+
break;
|
|
3634
|
+
}
|
|
3635
|
+
case "INTEGRATION_UPDATE": {
|
|
3636
|
+
const integration = d;
|
|
3637
|
+
this.cache.integrations.set(integration.id, integration);
|
|
3638
|
+
this.dispatch("INTEGRATION_UPDATE", { type: "INTEGRATION_UPDATE", guildId: d.guild_id, integration });
|
|
3639
|
+
break;
|
|
3640
|
+
}
|
|
3641
|
+
case "INTEGRATION_DELETE": {
|
|
3642
|
+
this.cache.integrations.delete(d.id);
|
|
3643
|
+
this.dispatch("INTEGRATION_DELETE", {
|
|
3644
|
+
type: "INTEGRATION_DELETE",
|
|
3645
|
+
id: d.id,
|
|
3646
|
+
guildId: d.guild_id,
|
|
3647
|
+
...d.application_id ? { applicationId: d.application_id } : {}
|
|
3648
|
+
});
|
|
3649
|
+
break;
|
|
3650
|
+
}
|
|
3651
|
+
}
|
|
3652
|
+
}
|
|
3653
|
+
};
|
|
3654
|
+
|
|
3655
|
+
// src/utils/permissions.ts
|
|
3656
|
+
function hasPermission(permissions, flag) {
|
|
3657
|
+
const bits = typeof permissions === "string" ? BigInt(permissions) : permissions;
|
|
3658
|
+
return (bits & flag) === flag;
|
|
3659
|
+
}
|
|
3660
|
+
function hasAllPermissions(permissions, ...flags) {
|
|
3661
|
+
const bits = typeof permissions === "string" ? BigInt(permissions) : permissions;
|
|
3662
|
+
for (const flag of flags) {
|
|
3663
|
+
if ((bits & flag) !== flag) return false;
|
|
3664
|
+
}
|
|
3665
|
+
return true;
|
|
3666
|
+
}
|
|
3667
|
+
function hasAnyPermission(permissions, ...flags) {
|
|
3668
|
+
const bits = typeof permissions === "string" ? BigInt(permissions) : permissions;
|
|
3669
|
+
for (const flag of flags) {
|
|
3670
|
+
if ((bits & flag) === flag) return true;
|
|
3671
|
+
}
|
|
3672
|
+
return false;
|
|
3673
|
+
}
|
|
3674
|
+
function combinePermissions(...flags) {
|
|
3675
|
+
let result = 0n;
|
|
3676
|
+
for (const flag of flags) result |= flag;
|
|
3677
|
+
return result;
|
|
3678
|
+
}
|
|
3679
|
+
function listPermissions(permissions) {
|
|
3680
|
+
const bits = typeof permissions === "string" ? BigInt(permissions) : permissions;
|
|
3681
|
+
const result = [];
|
|
3682
|
+
for (const [name, flag] of Object.entries(DISCORD_PERMISSIONS)) {
|
|
3683
|
+
if ((bits & flag) === flag) result.push(name);
|
|
3684
|
+
}
|
|
3685
|
+
return result;
|
|
3686
|
+
}
|
|
3687
|
+
|
|
3688
|
+
// src/utils/chameleon.ts
|
|
3689
|
+
import os from "os";
|
|
3690
|
+
var Chameleon = class {
|
|
3691
|
+
static get lifespan() {
|
|
3692
|
+
return {
|
|
3693
|
+
get ram() {
|
|
3694
|
+
return Math.round(process.memoryUsage().rss / 1024 / 1024);
|
|
3695
|
+
},
|
|
3696
|
+
get cpu() {
|
|
3697
|
+
return os.loadavg()[0];
|
|
3698
|
+
}
|
|
3699
|
+
};
|
|
3700
|
+
}
|
|
3701
|
+
};
|
|
3702
|
+
export {
|
|
3703
|
+
AUDIT_LOG_EVENT_TYPES,
|
|
3704
|
+
ActionRow,
|
|
3705
|
+
ActionRowBuilder,
|
|
3706
|
+
Activity,
|
|
3707
|
+
ActivityLocationKind,
|
|
3708
|
+
ApplicationCommandOptionType,
|
|
3709
|
+
ApplicationCommandType,
|
|
3710
|
+
ApplicationEventWebhookStatus,
|
|
3711
|
+
ApplicationFlag,
|
|
3712
|
+
ApplicationIntegrationType,
|
|
3713
|
+
ApplicationRoleConnectionMetadataType,
|
|
3714
|
+
AttachmentFlag,
|
|
3715
|
+
AutoModerationActionType,
|
|
3716
|
+
AutoModerationEventType,
|
|
3717
|
+
AutoModerationKeywordPresetType,
|
|
3718
|
+
AutoModerationTriggerType,
|
|
3719
|
+
BaseManager,
|
|
3720
|
+
ButtonBuilder,
|
|
3721
|
+
ButtonStyle,
|
|
3722
|
+
CHAMELEON_SELF_MAP,
|
|
3723
|
+
Chameleon,
|
|
3724
|
+
ChameleonGateway,
|
|
3725
|
+
ChameleonREST,
|
|
3726
|
+
ChannelFlag,
|
|
3727
|
+
ChannelManager,
|
|
3728
|
+
ChannelType,
|
|
3729
|
+
Client,
|
|
3730
|
+
CollectorManager,
|
|
3731
|
+
Colors,
|
|
3732
|
+
CommandContext,
|
|
3733
|
+
CommandManager,
|
|
3734
|
+
ComponentContext2 as ComponentContext,
|
|
3735
|
+
ComponentManager,
|
|
3736
|
+
ComponentType,
|
|
3737
|
+
DISCORD_GATEWAY_OPCODES,
|
|
3738
|
+
DISCORD_PERMISSIONS,
|
|
3739
|
+
DefaultMessageNotificationLevel,
|
|
3740
|
+
EmbedBuilder,
|
|
3741
|
+
EmbedType,
|
|
3742
|
+
EntitlementType,
|
|
3743
|
+
ExplicitContentFilterLevel,
|
|
3744
|
+
ForumLayoutType,
|
|
3745
|
+
GuildInviteFlag,
|
|
3746
|
+
GuildManager,
|
|
3747
|
+
GuildMemberFlag,
|
|
3748
|
+
GuildNSFWLevel,
|
|
3749
|
+
GuildScheduledEventEntityType,
|
|
3750
|
+
GuildScheduledEventPrivacyLevel,
|
|
3751
|
+
GuildScheduledEventStatus,
|
|
3752
|
+
IntegrationExpireBehavior,
|
|
3753
|
+
IntentBits,
|
|
3754
|
+
Intents,
|
|
3755
|
+
InviteTargetType,
|
|
3756
|
+
InviteType,
|
|
3757
|
+
LobbyMemberFlag,
|
|
3758
|
+
MFALevel,
|
|
3759
|
+
MemberManager,
|
|
3760
|
+
MessageActivityType,
|
|
3761
|
+
MessageFlag,
|
|
3762
|
+
MessageManager,
|
|
3763
|
+
MessageReferenceType,
|
|
3764
|
+
MessageType,
|
|
3765
|
+
ModalBuilder,
|
|
3766
|
+
PremiumTier,
|
|
3767
|
+
PremiumType,
|
|
3768
|
+
SelectMenuBuilder,
|
|
3769
|
+
SkuFlag,
|
|
3770
|
+
SkuType,
|
|
3771
|
+
SortOrderType,
|
|
3772
|
+
StagePrivacyLevel,
|
|
3773
|
+
StickerFormatType,
|
|
3774
|
+
StickerType,
|
|
3775
|
+
SubscriptionStatus,
|
|
3776
|
+
SystemChannelFlag,
|
|
3777
|
+
TextInputBuilder,
|
|
3778
|
+
Tongue,
|
|
3779
|
+
TongueStore,
|
|
3780
|
+
UserFlag,
|
|
3781
|
+
UserManager,
|
|
3782
|
+
VerificationLevel,
|
|
3783
|
+
VideoQualityMode,
|
|
3784
|
+
VisibilityType,
|
|
3785
|
+
WebhookType,
|
|
3786
|
+
buildChannel,
|
|
3787
|
+
buildGuild,
|
|
3788
|
+
buildMember,
|
|
3789
|
+
buildMessage,
|
|
3790
|
+
buildModalPayload,
|
|
3791
|
+
buildRole,
|
|
3792
|
+
buildUser,
|
|
3793
|
+
combinePermissions,
|
|
3794
|
+
defineButton,
|
|
3795
|
+
defineChannelSelect,
|
|
3796
|
+
defineCommand,
|
|
3797
|
+
defineMentionableSelect,
|
|
3798
|
+
defineModal,
|
|
3799
|
+
defineRoleSelect,
|
|
3800
|
+
defineStringSelect,
|
|
3801
|
+
defineSubcommand,
|
|
3802
|
+
defineUserSelect,
|
|
3803
|
+
field,
|
|
3804
|
+
hasAllPermissions,
|
|
3805
|
+
hasAnyPermission,
|
|
3806
|
+
hasPermission,
|
|
3807
|
+
listPermissions,
|
|
3808
|
+
opt,
|
|
3809
|
+
resolveButtonStyle,
|
|
3810
|
+
resolveChannel,
|
|
3811
|
+
resolveGuild,
|
|
3812
|
+
resolveRole,
|
|
3813
|
+
resolveUser
|
|
3814
|
+
};
|