@discordeno/rest 19.0.0-next.dea9d1d → 19.0.0-next.dfbee47
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/invalidBucket.d.ts +6 -7
- package/dist/invalidBucket.d.ts.map +1 -1
- package/dist/invalidBucket.js +23 -25
- package/dist/invalidBucket.js.map +1 -1
- package/dist/manager.d.ts +9 -0
- package/dist/manager.d.ts.map +1 -1
- package/dist/manager.js +220 -685
- package/dist/manager.js.map +1 -1
- package/dist/queue.js +1 -1
- package/dist/queue.js.map +1 -1
- package/dist/routes.d.ts +3 -0
- package/dist/routes.d.ts.map +1 -0
- package/dist/routes.js +487 -0
- package/dist/routes.js.map +1 -0
- package/dist/types.d.ts +106 -47
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js.map +1 -1
- package/dist/typings/routes.d.ts +0 -2
- package/dist/typings/routes.d.ts.map +1 -1
- package/dist/typings/routes.js.map +1 -1
- package/package.json +4 -5
package/dist/manager.js
CHANGED
|
@@ -1,510 +1,40 @@
|
|
|
1
|
-
/* eslint-disable @typescript-eslint/restrict-template-expressions */ /* eslint-disable no-const-assign */ import {
|
|
2
|
-
import { calculateBits, camelize, camelToSnakeCase, delay, encode, getBotIdFromToken, isGetMessagesAfter, isGetMessagesAround, isGetMessagesBefore, isGetMessagesLimit, logger, processReactionString, urlToBase64 } from '@discordeno/utils';
|
|
3
|
-
import fetch from 'node-fetch';
|
|
1
|
+
/* eslint-disable @typescript-eslint/restrict-template-expressions */ /* eslint-disable no-const-assign */ import { calculateBits, camelToSnakeCase, camelize, delay, getBotIdFromToken, logger, processReactionString, urlToBase64 } from '@discordeno/utils';
|
|
4
2
|
import { createInvalidRequestBucket } from './invalidBucket.js';
|
|
5
3
|
import { Queue } from './queue.js';
|
|
4
|
+
import { InteractionResponseTypes } from '@discordeno/types';
|
|
5
|
+
import { createRoutes } from './routes.js';
|
|
6
6
|
// TODO: make dynamic based on package.json file
|
|
7
7
|
const version = '19.0.0-alpha.1';
|
|
8
|
+
export const DISCORD_API_VERSION = 10;
|
|
9
|
+
export const DISCORD_API_URL = 'https://discord.com/api';
|
|
10
|
+
export const AUDIT_LOG_REASON_HEADER = 'x-audit-log-reason';
|
|
11
|
+
export const RATE_LIMIT_REMAINING_HEADER = 'x-ratelimit-remaining';
|
|
12
|
+
export const RATE_LIMIT_RESET_AFTER_HEADER = 'x-ratelimit-reset-after';
|
|
13
|
+
export const RATE_LIMIT_GLOBAL_HEADER = 'x-ratelimit-global';
|
|
14
|
+
export const RATE_LIMIT_BUCKET_HEADER = 'x-ratelimit-bucket';
|
|
15
|
+
export const RATE_LIMIT_LIMIT_HEADER = 'x-ratelimit-limit';
|
|
16
|
+
export const RATE_LIMIT_SCOPE_HEADER = 'x-ratelimit-scope';
|
|
8
17
|
export function createRestManager(options) {
|
|
9
|
-
|
|
10
|
-
if (!
|
|
18
|
+
const applicationId = options.applicationId ? BigInt(options.applicationId) : options.token ? getBotIdFromToken(options.token) : undefined;
|
|
19
|
+
if (!applicationId) {
|
|
20
|
+
throw new Error('`applicationId` was not provided and was not able to extract the id from the bots token. Please explicitly pass `applicationId` to the rest manager.');
|
|
21
|
+
}
|
|
22
|
+
const baseUrl = options.proxy?.baseUrl ?? DISCORD_API_URL;
|
|
11
23
|
const rest = {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
maxRetryCount: Infinity,
|
|
24
|
+
applicationId,
|
|
25
|
+
authorization: options.proxy?.authorization,
|
|
26
|
+
baseUrl,
|
|
27
|
+
deleteQueueDelay: 60000,
|
|
17
28
|
globallyRateLimited: false,
|
|
29
|
+
invalidBucket: createInvalidRequestBucket({}),
|
|
30
|
+
isProxied: !baseUrl.startsWith(DISCORD_API_URL),
|
|
31
|
+
maxRetryCount: Infinity,
|
|
18
32
|
processingRateLimitedPaths: false,
|
|
19
|
-
deleteQueueDelay: 60000,
|
|
20
33
|
queues: new Map(),
|
|
21
34
|
rateLimitedPaths: new Map(),
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
routes:
|
|
25
|
-
webhooks: {
|
|
26
|
-
id: (webhookId)=>{
|
|
27
|
-
return `/webhooks/${webhookId}`;
|
|
28
|
-
},
|
|
29
|
-
message: (webhookId, token, messageId, options)=>{
|
|
30
|
-
let url = `/webhooks/${webhookId}/${token}/messages/${messageId}?`;
|
|
31
|
-
if (options) {
|
|
32
|
-
if (options.threadId) url += `thread_id=${options.threadId}`;
|
|
33
|
-
}
|
|
34
|
-
return url;
|
|
35
|
-
},
|
|
36
|
-
original: (webhookId, token, options)=>{
|
|
37
|
-
let url = `/webhooks/${webhookId}/${token}/messages/@original?`;
|
|
38
|
-
if (options) {
|
|
39
|
-
if (options.threadId) url += `thread_id=${options.threadId}`;
|
|
40
|
-
}
|
|
41
|
-
return url;
|
|
42
|
-
},
|
|
43
|
-
webhook: (webhookId, token, options)=>{
|
|
44
|
-
let url = `/webhooks/${webhookId}/${token}?`;
|
|
45
|
-
if (options) {
|
|
46
|
-
if (options?.wait !== undefined) url += `wait=${options.wait.toString()}`;
|
|
47
|
-
if (options.threadId) url += `thread_id=${options.threadId}`;
|
|
48
|
-
}
|
|
49
|
-
return url;
|
|
50
|
-
}
|
|
51
|
-
},
|
|
52
|
-
// Miscellaneous Endpoints
|
|
53
|
-
sessionInfo: ()=>rest.routes.gatewayBot(),
|
|
54
|
-
// Channel Endpoints
|
|
55
|
-
channels: {
|
|
56
|
-
bulk: (channelId)=>{
|
|
57
|
-
return `/channels/${channelId}/messages/bulk-delete`;
|
|
58
|
-
},
|
|
59
|
-
dm: ()=>{
|
|
60
|
-
return '/users/@me/channels';
|
|
61
|
-
},
|
|
62
|
-
pin: (channelId, messageId)=>{
|
|
63
|
-
return `/channels/${channelId}/pins/${messageId}`;
|
|
64
|
-
},
|
|
65
|
-
pins: (channelId)=>{
|
|
66
|
-
return `/channels/${channelId}/pins`;
|
|
67
|
-
},
|
|
68
|
-
reactions: {
|
|
69
|
-
bot: (channelId, messageId, emoji)=>{
|
|
70
|
-
return `/channels/${channelId}/messages/${messageId}/reactions/${encodeURIComponent(emoji)}/@me`;
|
|
71
|
-
},
|
|
72
|
-
user: (channelId, messageId, emoji, userId)=>{
|
|
73
|
-
return `/channels/${channelId}/messages/${messageId}/reactions/${encodeURIComponent(emoji)}/${userId}`;
|
|
74
|
-
},
|
|
75
|
-
all: (channelId, messageId)=>{
|
|
76
|
-
return `/channels/${channelId}/messages/${messageId}/reactions`;
|
|
77
|
-
},
|
|
78
|
-
emoji: (channelId, messageId, emoji, options)=>{
|
|
79
|
-
let url = `/channels/${channelId}/messages/${messageId}/reactions/${encodeURIComponent(emoji)}?`;
|
|
80
|
-
if (options) {
|
|
81
|
-
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions
|
|
82
|
-
if (options.after) url += `after=${options.after}`;
|
|
83
|
-
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions
|
|
84
|
-
if (options.limit) url += `&limit=${options.limit}`;
|
|
85
|
-
}
|
|
86
|
-
return url;
|
|
87
|
-
},
|
|
88
|
-
message: (channelId, messageId, emoji, options)=>{
|
|
89
|
-
let url = `/channels/${channelId}/messages/${messageId}/reactions/${encodeURIComponent(emoji)}?`;
|
|
90
|
-
if (options) {
|
|
91
|
-
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions
|
|
92
|
-
if (options.after) url += `after=${options.after}`;
|
|
93
|
-
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions
|
|
94
|
-
if (options.limit) url += `&limit=${options.limit}`;
|
|
95
|
-
}
|
|
96
|
-
return url;
|
|
97
|
-
}
|
|
98
|
-
},
|
|
99
|
-
webhooks: (channelId)=>{
|
|
100
|
-
return `/channels/${channelId}/webhooks`;
|
|
101
|
-
},
|
|
102
|
-
channel: (channelId)=>{
|
|
103
|
-
return `/channels/${channelId}`;
|
|
104
|
-
},
|
|
105
|
-
follow: (channelId)=>{
|
|
106
|
-
return `/channels/${channelId}/followers`;
|
|
107
|
-
},
|
|
108
|
-
forum: (channelId)=>{
|
|
109
|
-
return `/channels/${channelId}/threads?has_message=true`;
|
|
110
|
-
},
|
|
111
|
-
invites: (channelId)=>{
|
|
112
|
-
return `/channels/${channelId}/invites`;
|
|
113
|
-
},
|
|
114
|
-
message: (channelId, messageId)=>{
|
|
115
|
-
return `/channels/${channelId}/messages/${messageId}`;
|
|
116
|
-
},
|
|
117
|
-
messages: (channelId, options)=>{
|
|
118
|
-
let url = `/channels/${channelId}/messages?`;
|
|
119
|
-
if (options) {
|
|
120
|
-
if (isGetMessagesAfter(options) && options.after) {
|
|
121
|
-
url += `after=${options.after}`;
|
|
122
|
-
}
|
|
123
|
-
if (isGetMessagesBefore(options) && options.before) {
|
|
124
|
-
url += `&before=${options.before}`;
|
|
125
|
-
}
|
|
126
|
-
if (isGetMessagesAround(options) && options.around) {
|
|
127
|
-
url += `&around=${options.around}`;
|
|
128
|
-
}
|
|
129
|
-
if (isGetMessagesLimit(options) && options.limit) {
|
|
130
|
-
url += `&limit=${options.limit}`;
|
|
131
|
-
}
|
|
132
|
-
}
|
|
133
|
-
return url;
|
|
134
|
-
},
|
|
135
|
-
overwrite: (channelId, overwriteId)=>{
|
|
136
|
-
return `/channels/${channelId}/permissions/${overwriteId}`;
|
|
137
|
-
},
|
|
138
|
-
crosspost: (channelId, messageId)=>{
|
|
139
|
-
return `/channels/${channelId}/messages/${messageId}/crosspost`;
|
|
140
|
-
},
|
|
141
|
-
stages: ()=>{
|
|
142
|
-
return '/stage-instances';
|
|
143
|
-
},
|
|
144
|
-
stage: (channelId)=>{
|
|
145
|
-
return `/stage-instances/${channelId}`;
|
|
146
|
-
},
|
|
147
|
-
// Thread Endpoints
|
|
148
|
-
threads: {
|
|
149
|
-
message: (channelId, messageId)=>{
|
|
150
|
-
return `/channels/${channelId}/messages/${messageId}/threads`;
|
|
151
|
-
},
|
|
152
|
-
all: (channelId)=>{
|
|
153
|
-
return `/channels/${channelId}/threads`;
|
|
154
|
-
},
|
|
155
|
-
active: (guildId)=>{
|
|
156
|
-
return `/guilds/${guildId}/threads/active`;
|
|
157
|
-
},
|
|
158
|
-
members: (channelId)=>{
|
|
159
|
-
return `/channels/${channelId}/thread-members`;
|
|
160
|
-
},
|
|
161
|
-
me: (channelId)=>{
|
|
162
|
-
return `/channels/${channelId}/thread-members/@me`;
|
|
163
|
-
},
|
|
164
|
-
user: (channelId, userId)=>{
|
|
165
|
-
return `/channels/${channelId}/thread-members/${userId}`;
|
|
166
|
-
},
|
|
167
|
-
archived: (channelId)=>{
|
|
168
|
-
return `/channels/${channelId}/threads/archived`;
|
|
169
|
-
},
|
|
170
|
-
public: (channelId, options)=>{
|
|
171
|
-
let url = `/channels/${channelId}/threads/archived/public?`;
|
|
172
|
-
if (options) {
|
|
173
|
-
if (options.before) {
|
|
174
|
-
url += `before=${new Date(options.before).toISOString()}`;
|
|
175
|
-
}
|
|
176
|
-
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions
|
|
177
|
-
if (options.limit) url += `&limit=${options.limit}`;
|
|
178
|
-
}
|
|
179
|
-
return url;
|
|
180
|
-
},
|
|
181
|
-
private: (channelId, options)=>{
|
|
182
|
-
let url = `/channels/${channelId}/threads/archived/private?`;
|
|
183
|
-
if (options) {
|
|
184
|
-
if (options.before) {
|
|
185
|
-
url += `before=${new Date(options.before).toISOString()}`;
|
|
186
|
-
}
|
|
187
|
-
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions
|
|
188
|
-
if (options.limit) url += `&limit=${options.limit}`;
|
|
189
|
-
}
|
|
190
|
-
return url;
|
|
191
|
-
},
|
|
192
|
-
joined: (channelId, options)=>{
|
|
193
|
-
let url = `/channels/${channelId}/users/@me/threads/archived/private?`;
|
|
194
|
-
if (options) {
|
|
195
|
-
if (options.before) {
|
|
196
|
-
url += `before=${new Date(options.before).toISOString()}`;
|
|
197
|
-
}
|
|
198
|
-
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions
|
|
199
|
-
if (options.limit) url += `&limit=${options.limit}`;
|
|
200
|
-
}
|
|
201
|
-
return url;
|
|
202
|
-
}
|
|
203
|
-
},
|
|
204
|
-
typing: (channelId)=>{
|
|
205
|
-
return `/channels/${channelId}/typing`;
|
|
206
|
-
}
|
|
207
|
-
},
|
|
208
|
-
// Guild Endpoints
|
|
209
|
-
guilds: {
|
|
210
|
-
all: ()=>{
|
|
211
|
-
return '/guilds';
|
|
212
|
-
},
|
|
213
|
-
auditlogs: (guildId, options)=>{
|
|
214
|
-
let url = `/guilds/${guildId}/audit-logs?`;
|
|
215
|
-
if (options) {
|
|
216
|
-
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions
|
|
217
|
-
if (options.actionType) url += `action_type=${options.actionType}`;
|
|
218
|
-
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions
|
|
219
|
-
if (options.before) url += `&before=${options.before}`;
|
|
220
|
-
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions
|
|
221
|
-
if (options.after) url += `&after=${options.after}`;
|
|
222
|
-
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions
|
|
223
|
-
if (options.limit) url += `&limit=${options.limit}`;
|
|
224
|
-
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions
|
|
225
|
-
if (options.userId) url += `&user_id=${options.userId}`;
|
|
226
|
-
}
|
|
227
|
-
return url;
|
|
228
|
-
},
|
|
229
|
-
automod: {
|
|
230
|
-
rule: (guildId, ruleId)=>{
|
|
231
|
-
return `/guilds/${guildId}/auto-moderation/rules/${ruleId}`;
|
|
232
|
-
},
|
|
233
|
-
rules: (guildId)=>{
|
|
234
|
-
return `/guilds/${guildId}/auto-moderation/rules`;
|
|
235
|
-
}
|
|
236
|
-
},
|
|
237
|
-
channels: (guildId)=>{
|
|
238
|
-
return `/guilds/${guildId}/channels`;
|
|
239
|
-
},
|
|
240
|
-
emoji: (guildId, emojiId)=>{
|
|
241
|
-
return `/guilds/${guildId}/emojis/${emojiId}`;
|
|
242
|
-
},
|
|
243
|
-
emojis: (guildId)=>{
|
|
244
|
-
return `/guilds/${guildId}/emojis`;
|
|
245
|
-
},
|
|
246
|
-
events: {
|
|
247
|
-
events: (guildId, withUserCount)=>{
|
|
248
|
-
let url = `/guilds/${guildId}/scheduled-events?`;
|
|
249
|
-
if (withUserCount !== undefined) {
|
|
250
|
-
url += `with_user_count=${withUserCount.toString()}`;
|
|
251
|
-
}
|
|
252
|
-
return url;
|
|
253
|
-
},
|
|
254
|
-
event: (guildId, eventId, withUserCount)=>{
|
|
255
|
-
let url = `/guilds/${guildId}/scheduled-events/${eventId}`;
|
|
256
|
-
if (withUserCount !== undefined) {
|
|
257
|
-
url += `with_user_count=${withUserCount.toString()}`;
|
|
258
|
-
}
|
|
259
|
-
return url;
|
|
260
|
-
},
|
|
261
|
-
users: (guildId, eventId, options)=>{
|
|
262
|
-
let url = `/guilds/${guildId}/scheduled-events/${eventId}/users?`;
|
|
263
|
-
if (options) {
|
|
264
|
-
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions
|
|
265
|
-
if (options.limit !== undefined) url += `limit=${options.limit}`;
|
|
266
|
-
if (options.withMember !== undefined) {
|
|
267
|
-
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions
|
|
268
|
-
url += `&with_member=${options.withMember.toString()}`;
|
|
269
|
-
}
|
|
270
|
-
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions
|
|
271
|
-
if (options.after !== undefined) url += `&after=${options.after}`;
|
|
272
|
-
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions
|
|
273
|
-
if (options.before !== undefined) url += `&before=${options.before}`;
|
|
274
|
-
}
|
|
275
|
-
return url;
|
|
276
|
-
}
|
|
277
|
-
},
|
|
278
|
-
guild (guildId, withCounts) {
|
|
279
|
-
let url = `/guilds/${guildId}?`;
|
|
280
|
-
if (withCounts !== undefined) {
|
|
281
|
-
url += `with_counts=${withCounts.toString()}`;
|
|
282
|
-
}
|
|
283
|
-
return url;
|
|
284
|
-
},
|
|
285
|
-
integration (guildId, integrationId) {
|
|
286
|
-
return `/guilds/${guildId}/integrations/${integrationId}`;
|
|
287
|
-
},
|
|
288
|
-
integrations: (guildId)=>{
|
|
289
|
-
return `/guilds/${guildId}/integrations?include_applications=true`;
|
|
290
|
-
},
|
|
291
|
-
invite (inviteCode, options) {
|
|
292
|
-
let url = `/invites/${inviteCode}?`;
|
|
293
|
-
if (options) {
|
|
294
|
-
if (options.withCounts !== undefined) {
|
|
295
|
-
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions
|
|
296
|
-
url += `with_counts=${options.withCounts.toString()}`;
|
|
297
|
-
}
|
|
298
|
-
if (options.withExpiration !== undefined) {
|
|
299
|
-
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions
|
|
300
|
-
url += `&with_expiration=${options.withExpiration.toString()}`;
|
|
301
|
-
}
|
|
302
|
-
if (options.scheduledEventId) {
|
|
303
|
-
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions
|
|
304
|
-
url += `&guild_scheduled_event_id=${options.scheduledEventId}`;
|
|
305
|
-
}
|
|
306
|
-
}
|
|
307
|
-
return url;
|
|
308
|
-
},
|
|
309
|
-
invites: (guildId)=>{
|
|
310
|
-
return `/guilds/${guildId}/invites`;
|
|
311
|
-
},
|
|
312
|
-
leave: (guildId)=>{
|
|
313
|
-
return `/users/@me/guilds/${guildId}`;
|
|
314
|
-
},
|
|
315
|
-
members: {
|
|
316
|
-
ban: (guildId, userId)=>{
|
|
317
|
-
return `/guilds/${guildId}/bans/${userId}`;
|
|
318
|
-
},
|
|
319
|
-
bans: (guildId, options)=>{
|
|
320
|
-
let url = `/guilds/${guildId}/bans?`;
|
|
321
|
-
if (options) {
|
|
322
|
-
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions
|
|
323
|
-
if (options.limit) url += `limit=${options.limit}`;
|
|
324
|
-
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions
|
|
325
|
-
if (options.after) url += `&after=${options.after}`;
|
|
326
|
-
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions
|
|
327
|
-
if (options.before) url += `&before=${options.before}`;
|
|
328
|
-
}
|
|
329
|
-
return url;
|
|
330
|
-
},
|
|
331
|
-
bot: (guildId)=>{
|
|
332
|
-
return `/guilds/${guildId}/members/@me`;
|
|
333
|
-
},
|
|
334
|
-
member: (guildId, userId)=>{
|
|
335
|
-
return `/guilds/${guildId}/members/${userId}`;
|
|
336
|
-
},
|
|
337
|
-
members: (guildId, options)=>{
|
|
338
|
-
let url = `/guilds/${guildId}/members?`;
|
|
339
|
-
if (options !== undefined) {
|
|
340
|
-
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions
|
|
341
|
-
if (options.limit) url += `limit=${options.limit}`;
|
|
342
|
-
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions
|
|
343
|
-
if (options.after) url += `&after=${options.after}`;
|
|
344
|
-
}
|
|
345
|
-
return url;
|
|
346
|
-
},
|
|
347
|
-
search: (guildId, query, options)=>{
|
|
348
|
-
let url = `/guilds/${guildId}/members/search?query=${encodeURIComponent(query)}`;
|
|
349
|
-
if (options) {
|
|
350
|
-
if (options.limit !== undefined) url += `&limit=${options.limit}`;
|
|
351
|
-
}
|
|
352
|
-
return url;
|
|
353
|
-
},
|
|
354
|
-
prune: (guildId, options)=>{
|
|
355
|
-
let url = `/guilds/${guildId}/prune?`;
|
|
356
|
-
if (options) {
|
|
357
|
-
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions
|
|
358
|
-
if (options.days) url += `days=${options.days}`;
|
|
359
|
-
if (Array.isArray(options.includeRoles)) {
|
|
360
|
-
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions
|
|
361
|
-
url += `&include_roles=${options.includeRoles.join(',')}`;
|
|
362
|
-
} else if (options.includeRoles) {
|
|
363
|
-
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions
|
|
364
|
-
url += `&include_roles=${options.includeRoles}`;
|
|
365
|
-
}
|
|
366
|
-
}
|
|
367
|
-
return url;
|
|
368
|
-
}
|
|
369
|
-
},
|
|
370
|
-
mfa: (guildId)=>`/guilds/${guildId}/mfa`,
|
|
371
|
-
preview: (guildId)=>{
|
|
372
|
-
return `/guilds/${guildId}/preview`;
|
|
373
|
-
},
|
|
374
|
-
prune: (guildId, options)=>{
|
|
375
|
-
let url = `/guilds/${guildId}/prune?`;
|
|
376
|
-
if (options) {
|
|
377
|
-
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions
|
|
378
|
-
if (options.days) url += `days=${options.days}`;
|
|
379
|
-
if (Array.isArray(options.includeRoles)) {
|
|
380
|
-
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions
|
|
381
|
-
url += `&include_roles=${options.includeRoles.join(',')}`;
|
|
382
|
-
} else if (options.includeRoles) {
|
|
383
|
-
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions
|
|
384
|
-
url += `&include_roles=${options.includeRoles}`;
|
|
385
|
-
}
|
|
386
|
-
}
|
|
387
|
-
return url;
|
|
388
|
-
},
|
|
389
|
-
roles: {
|
|
390
|
-
one: (guildId, roleId)=>{
|
|
391
|
-
return `/guilds/${guildId}/roles/${roleId}`;
|
|
392
|
-
},
|
|
393
|
-
all: (guildId)=>{
|
|
394
|
-
return `/guilds/${guildId}/roles`;
|
|
395
|
-
},
|
|
396
|
-
member: (guildId, memberId, roleId)=>{
|
|
397
|
-
return `/guilds/${guildId}/members/${memberId}/roles/${roleId}`;
|
|
398
|
-
}
|
|
399
|
-
},
|
|
400
|
-
stickers: (guildId)=>{
|
|
401
|
-
return `/guilds/${guildId}/stickers`;
|
|
402
|
-
},
|
|
403
|
-
sticker: (guildId, stickerId)=>{
|
|
404
|
-
return `/guilds/${guildId}/stickers/${stickerId}`;
|
|
405
|
-
},
|
|
406
|
-
voice: (guildId, userId)=>{
|
|
407
|
-
return `/guilds/${guildId}/voice-states/${userId ?? '@me'}`;
|
|
408
|
-
},
|
|
409
|
-
templates: {
|
|
410
|
-
code: (code)=>{
|
|
411
|
-
return `/guilds/templates/${code}`;
|
|
412
|
-
},
|
|
413
|
-
guild: (guildId, code)=>{
|
|
414
|
-
return `/guilds/${guildId}/templates/${code}`;
|
|
415
|
-
},
|
|
416
|
-
all: (guildId)=>{
|
|
417
|
-
return `/guilds/${guildId}/templates`;
|
|
418
|
-
}
|
|
419
|
-
},
|
|
420
|
-
vanity: (guildId)=>{
|
|
421
|
-
return `/guilds/${guildId}/vanity-url`;
|
|
422
|
-
},
|
|
423
|
-
regions: (guildId)=>{
|
|
424
|
-
return `/guilds/${guildId}/regions`;
|
|
425
|
-
},
|
|
426
|
-
webhooks: (guildId)=>{
|
|
427
|
-
return `/guilds/${guildId}/webhooks`;
|
|
428
|
-
},
|
|
429
|
-
welcome: (guildId)=>{
|
|
430
|
-
return `/guilds/${guildId}/welcome-screen`;
|
|
431
|
-
},
|
|
432
|
-
widget: (guildId)=>{
|
|
433
|
-
return `/guilds/${guildId}/widget`;
|
|
434
|
-
},
|
|
435
|
-
widgetJson: (guildId)=>{
|
|
436
|
-
return `/guilds/${guildId}/widget.json`;
|
|
437
|
-
}
|
|
438
|
-
},
|
|
439
|
-
sticker: (stickerId)=>{
|
|
440
|
-
return `/stickers/${stickerId}`;
|
|
441
|
-
},
|
|
442
|
-
regions: ()=>{
|
|
443
|
-
return '/voice/regions';
|
|
444
|
-
},
|
|
445
|
-
// Interaction Endpoints
|
|
446
|
-
interactions: {
|
|
447
|
-
commands: {
|
|
448
|
-
// Application Endpoints
|
|
449
|
-
commands: (applicationId)=>{
|
|
450
|
-
return `/applications/${applicationId}/commands`;
|
|
451
|
-
},
|
|
452
|
-
guilds: {
|
|
453
|
-
all (applicationId, guildId) {
|
|
454
|
-
return `/applications/${applicationId}/guilds/${guildId}/commands`;
|
|
455
|
-
},
|
|
456
|
-
one (applicationId, guildId, commandId, withLocalizations) {
|
|
457
|
-
let url = `/applications/${applicationId}/guilds/${guildId}/commands/${commandId}?`;
|
|
458
|
-
if (withLocalizations !== undefined) {
|
|
459
|
-
url += `with_localizations=${withLocalizations.toString()}`;
|
|
460
|
-
}
|
|
461
|
-
return url;
|
|
462
|
-
}
|
|
463
|
-
},
|
|
464
|
-
permissions: (applicationId, guildId)=>{
|
|
465
|
-
return `/applications/${applicationId}/guilds/${guildId}/commands/permissions`;
|
|
466
|
-
},
|
|
467
|
-
permission: (applicationId, guildId, commandId)=>{
|
|
468
|
-
return `/applications/${applicationId}/guilds/${guildId}/commands/${commandId}/permissions`;
|
|
469
|
-
},
|
|
470
|
-
command: (applicationId, commandId, withLocalizations)=>{
|
|
471
|
-
let url = `/applications/${applicationId}/commands/${commandId}?`;
|
|
472
|
-
if (withLocalizations !== undefined) {
|
|
473
|
-
url += `withLocalizations=${withLocalizations.toString()}`;
|
|
474
|
-
}
|
|
475
|
-
return url;
|
|
476
|
-
}
|
|
477
|
-
},
|
|
478
|
-
responses: {
|
|
479
|
-
// Interaction Endpoints
|
|
480
|
-
callback: (interactionId, token)=>{
|
|
481
|
-
return `/interactions/${interactionId}/${token}/callback`;
|
|
482
|
-
},
|
|
483
|
-
original: (interactionId, token)=>{
|
|
484
|
-
return `/webhooks/${interactionId}/${token}/messages/@original`;
|
|
485
|
-
},
|
|
486
|
-
message: (applicationId, token, messageId)=>{
|
|
487
|
-
return `/webhooks/${applicationId}/${token}/messages/${messageId}`;
|
|
488
|
-
}
|
|
489
|
-
}
|
|
490
|
-
},
|
|
491
|
-
// User endpoints
|
|
492
|
-
user (userId) {
|
|
493
|
-
return `/users/${userId}`;
|
|
494
|
-
},
|
|
495
|
-
userBot () {
|
|
496
|
-
return '/users/@me';
|
|
497
|
-
},
|
|
498
|
-
oauth2Application () {
|
|
499
|
-
return 'oauth2/applications/@me';
|
|
500
|
-
},
|
|
501
|
-
gatewayBot () {
|
|
502
|
-
return '/gateway/bot';
|
|
503
|
-
},
|
|
504
|
-
nitroStickerPacks () {
|
|
505
|
-
return '/sticker-packs';
|
|
506
|
-
}
|
|
507
|
-
},
|
|
35
|
+
token: options.token,
|
|
36
|
+
version: options.version ?? DISCORD_API_VERSION,
|
|
37
|
+
routes: createRoutes(),
|
|
508
38
|
checkRateLimits (url) {
|
|
509
39
|
const ratelimited = rest.rateLimitedPaths.get(url);
|
|
510
40
|
const global = rest.rateLimitedPaths.get('global');
|
|
@@ -530,11 +60,11 @@ export function createRestManager(options) {
|
|
|
530
60
|
'permissions',
|
|
531
61
|
'allow',
|
|
532
62
|
'deny'
|
|
533
|
-
].includes(key)) {
|
|
63
|
+
].includes(key) && obj[key] !== undefined) {
|
|
534
64
|
newObj[key] = calculateBits(obj[key]);
|
|
535
65
|
continue;
|
|
536
66
|
}
|
|
537
|
-
if (key === 'defaultMemberPermissions') {
|
|
67
|
+
if (key === 'defaultMemberPermissions' && obj[key] !== undefined) {
|
|
538
68
|
newObj.default_member_permissions = calculateBits(obj[key]);
|
|
539
69
|
continue;
|
|
540
70
|
}
|
|
@@ -549,10 +79,10 @@ export function createRestManager(options) {
|
|
|
549
79
|
const headers = {
|
|
550
80
|
'user-agent': `DiscordBot (https://github.com/discordeno/discordeno, v${version})`
|
|
551
81
|
};
|
|
552
|
-
if (
|
|
82
|
+
if (options?.unauthorized !== false) headers.authorization = `Bot ${rest.token}`;
|
|
553
83
|
// IF A REASON IS PROVIDED ENCODE IT IN HEADERS
|
|
554
84
|
if (options?.reason !== undefined) {
|
|
555
|
-
headers[
|
|
85
|
+
headers[AUDIT_LOG_REASON_HEADER] = encodeURIComponent(options?.reason);
|
|
556
86
|
}
|
|
557
87
|
let body;
|
|
558
88
|
// TODO: check if we need to add specific check for GET method
|
|
@@ -618,13 +148,13 @@ export function createRestManager(options) {
|
|
|
618
148
|
/** Processes the rate limit headers and determines if it needs to be rate limited and returns the bucket id if available */ processHeaders (url, headers) {
|
|
619
149
|
let rateLimited = false;
|
|
620
150
|
// GET ALL NECESSARY HEADERS
|
|
621
|
-
const remaining = headers.get(
|
|
622
|
-
const retryAfter = headers.get(
|
|
151
|
+
const remaining = headers.get(RATE_LIMIT_REMAINING_HEADER);
|
|
152
|
+
const retryAfter = headers.get(RATE_LIMIT_RESET_AFTER_HEADER);
|
|
623
153
|
const reset = Date.now() + Number(retryAfter) * 1000;
|
|
624
|
-
const global = headers.get(
|
|
154
|
+
const global = headers.get(RATE_LIMIT_GLOBAL_HEADER);
|
|
625
155
|
// undefined override null needed for typings
|
|
626
|
-
const bucketId = headers.get(
|
|
627
|
-
const limit = headers.get(
|
|
156
|
+
const bucketId = headers.get(RATE_LIMIT_BUCKET_HEADER) ?? undefined;
|
|
157
|
+
const limit = headers.get(RATE_LIMIT_LIMIT_HEADER);
|
|
628
158
|
rest.queues.get(url)?.handleCompletedRequest({
|
|
629
159
|
remaining: remaining ? Number(remaining) : undefined,
|
|
630
160
|
interval: retryAfter ? Number(retryAfter) * 1000 : undefined,
|
|
@@ -679,7 +209,7 @@ export function createRestManager(options) {
|
|
|
679
209
|
return rateLimited ? bucketId : undefined;
|
|
680
210
|
},
|
|
681
211
|
async sendRequest (options) {
|
|
682
|
-
const url =
|
|
212
|
+
const url = `${rest.baseUrl}/v${rest.version}${options.route}`;
|
|
683
213
|
const payload = rest.createRequestBody(options.method, options.requestBodyOptions);
|
|
684
214
|
logger.debug(`sending request to ${url}`, 'with payload:', {
|
|
685
215
|
...payload,
|
|
@@ -688,49 +218,57 @@ export function createRestManager(options) {
|
|
|
688
218
|
authorization: 'Bot tokenhere'
|
|
689
219
|
}
|
|
690
220
|
});
|
|
691
|
-
const response = await fetch(url, payload)
|
|
221
|
+
const response = await fetch(url, payload).catch(async (error)=>{
|
|
222
|
+
logger.error(error);
|
|
223
|
+
// Mark request and completed
|
|
224
|
+
rest.invalidBucket.handleCompletedRequest(999, false);
|
|
225
|
+
options.reject({
|
|
226
|
+
ok: false,
|
|
227
|
+
status: 999,
|
|
228
|
+
error: 'Possible network or request shape issue occurred. If this is rare, its a network glitch. If it occurs a lot something is wrong.'
|
|
229
|
+
});
|
|
230
|
+
throw error;
|
|
231
|
+
});
|
|
692
232
|
logger.debug(`request fetched from ${url} with status ${response.status} & ${response.statusText}`);
|
|
233
|
+
// Mark request and completed
|
|
234
|
+
rest.invalidBucket.handleCompletedRequest(response.status, response.headers.get(RATE_LIMIT_SCOPE_HEADER) === 'shared');
|
|
693
235
|
// Set the bucket id if it was available on the headers
|
|
694
|
-
const bucketId = rest.processHeaders(rest.simplifyUrl(options.
|
|
236
|
+
const bucketId = rest.processHeaders(rest.simplifyUrl(options.route, options.method), response.headers);
|
|
695
237
|
if (bucketId) options.bucketId = bucketId;
|
|
696
238
|
if (response.status < 200 || response.status >= 400) {
|
|
697
239
|
logger.debug(`Request to ${url} failed.`);
|
|
698
|
-
if (response.status
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
options.reject({
|
|
706
|
-
ok: false,
|
|
707
|
-
status: response.status,
|
|
708
|
-
error: 'The options was rate limited and it maxed out the retries limit.'
|
|
709
|
-
});
|
|
710
|
-
return;
|
|
711
|
-
}
|
|
712
|
-
// Rate limited, add back to queue
|
|
713
|
-
rest.invalidBucket.handleCompletedRequest(response.status, response.headers.get('X-RateLimit-Scope') === 'shared');
|
|
714
|
-
const resetAfter = response.headers.get('x-ratelimit-reset-after');
|
|
715
|
-
if (resetAfter) await delay(Number(resetAfter) * 1000);
|
|
716
|
-
// process the response to prevent mem leak
|
|
717
|
-
await response.json();
|
|
718
|
-
return await options.retryRequest?.(options);
|
|
240
|
+
if (response.status !== 429) {
|
|
241
|
+
options.reject({
|
|
242
|
+
ok: false,
|
|
243
|
+
status: response.status,
|
|
244
|
+
body: await response.text()
|
|
245
|
+
});
|
|
246
|
+
return;
|
|
719
247
|
}
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
248
|
+
logger.debug(`Request to ${url} was ratelimited.`);
|
|
249
|
+
// Too many attempts, get rid of request from queue.
|
|
250
|
+
if (options.retryCount >= rest.maxRetryCount) {
|
|
251
|
+
logger.debug(`Request to ${url} exceeded the maximum allowed retries.`, 'with payload:', payload);
|
|
252
|
+
// rest.debug(`[REST - RetriesMaxed] ${JSON.stringify(options)}`)
|
|
253
|
+
options.reject({
|
|
254
|
+
ok: false,
|
|
255
|
+
status: response.status,
|
|
256
|
+
error: 'The request was rate limited and it maxed out the retries limit.'
|
|
257
|
+
});
|
|
258
|
+
return;
|
|
259
|
+
}
|
|
260
|
+
options.retryCount += 1;
|
|
261
|
+
const resetAfter = response.headers.get(RATE_LIMIT_RESET_AFTER_HEADER);
|
|
262
|
+
if (resetAfter) await delay(Number(resetAfter) * 1000);
|
|
263
|
+
// process the response to prevent mem leak
|
|
264
|
+
await response.arrayBuffer();
|
|
265
|
+
return await options.retryRequest?.(options);
|
|
726
266
|
}
|
|
727
|
-
|
|
728
|
-
const json = is204 ? undefined : await response.json();
|
|
729
|
-
// Discord sometimes sends no response with 204 code
|
|
267
|
+
// Discord sometimes sends no response with no content.
|
|
730
268
|
options.resolve({
|
|
731
269
|
ok: true,
|
|
732
270
|
status: response.status,
|
|
733
|
-
body:
|
|
271
|
+
body: response.status === 204 ? undefined : await response.text()
|
|
734
272
|
});
|
|
735
273
|
},
|
|
736
274
|
simplifyUrl (url, method) {
|
|
@@ -754,16 +292,12 @@ export function createRestManager(options) {
|
|
|
754
292
|
}
|
|
755
293
|
return parts.join('/');
|
|
756
294
|
},
|
|
757
|
-
processRequest (request) {
|
|
758
|
-
const
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
if (parts[0]?.startsWith('v')) parts.shift();
|
|
764
|
-
// Set the full url to discord api in case it was recieved in a proxy rest
|
|
765
|
-
request.url = `${rest.baseUrl}/v${rest.version}/${parts.join('/')}`;
|
|
766
|
-
const url = rest.simplifyUrl(request.url, request.method);
|
|
295
|
+
async processRequest (request) {
|
|
296
|
+
const url = rest.simplifyUrl(request.route, request.method);
|
|
297
|
+
if (request.runThroughQueue === false) {
|
|
298
|
+
await rest.sendRequest(request);
|
|
299
|
+
return;
|
|
300
|
+
}
|
|
767
301
|
const queue = rest.queues.get(url);
|
|
768
302
|
if (queue !== undefined) {
|
|
769
303
|
queue.makeRequest(request);
|
|
@@ -779,36 +313,14 @@ export function createRestManager(options) {
|
|
|
779
313
|
rest.queues.set(url, bucketQueue);
|
|
780
314
|
}
|
|
781
315
|
},
|
|
782
|
-
async makeRequest (method,
|
|
783
|
-
if (
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
options.body.file = [
|
|
789
|
-
options.body.file
|
|
790
|
-
];
|
|
791
|
-
}
|
|
792
|
-
// convert blobs to string before sending to proxy
|
|
793
|
-
options.body.file = await Promise.all(options.body.file.map(async (f)=>{
|
|
794
|
-
const url = encode(await f.blob.arrayBuffer());
|
|
795
|
-
return {
|
|
796
|
-
name: f.name,
|
|
797
|
-
blob: `data:${f.blob.type};base64,${url}`
|
|
798
|
-
};
|
|
799
|
-
}));
|
|
800
|
-
}
|
|
801
|
-
const headers = {
|
|
802
|
-
Authorization: rest.authorization ?? ''
|
|
803
|
-
};
|
|
804
|
-
if (options?.body) {
|
|
805
|
-
headers['Content-Type'] = 'application/json';
|
|
316
|
+
async makeRequest (method, route, options) {
|
|
317
|
+
if (rest.isProxied) {
|
|
318
|
+
if (rest.authorization !== undefined) {
|
|
319
|
+
options ??= {};
|
|
320
|
+
options.headers ??= {};
|
|
321
|
+
options.headers.authorization = rest.authorization;
|
|
806
322
|
}
|
|
807
|
-
const result = await fetch(`${rest.baseUrl}${
|
|
808
|
-
body: options?.body ? JSON.stringify(options.body) : undefined,
|
|
809
|
-
headers,
|
|
810
|
-
method
|
|
811
|
-
});
|
|
323
|
+
const result = await fetch(`${rest.baseUrl}/v${rest.version}${route}`, rest.createRequestBody(method, options));
|
|
812
324
|
if (!result.ok) {
|
|
813
325
|
const err = await result.json().catch(()=>{});
|
|
814
326
|
// Legacy Handling to not break old code or when body is missing
|
|
@@ -817,21 +329,23 @@ export function createRestManager(options) {
|
|
|
817
329
|
}
|
|
818
330
|
return result.status !== 204 ? await result.json() : undefined;
|
|
819
331
|
}
|
|
820
|
-
|
|
332
|
+
// eslint-disable-next-line no-async-promise-executor
|
|
333
|
+
return await new Promise(async (resolve, reject)=>{
|
|
821
334
|
const payload = {
|
|
822
|
-
|
|
335
|
+
route,
|
|
823
336
|
method,
|
|
824
337
|
requestBodyOptions: options,
|
|
825
338
|
retryCount: 0,
|
|
826
339
|
retryRequest: async function(payload) {
|
|
827
|
-
rest.processRequest(payload);
|
|
340
|
+
await rest.processRequest(payload);
|
|
828
341
|
},
|
|
829
342
|
resolve: (data)=>{
|
|
830
343
|
resolve(data.status !== 204 ? JSON.parse(data.body ?? '{}') : undefined);
|
|
831
344
|
},
|
|
832
|
-
reject
|
|
345
|
+
reject,
|
|
346
|
+
runThroughQueue: options?.runThroughQueue
|
|
833
347
|
};
|
|
834
|
-
rest.processRequest(payload);
|
|
348
|
+
await rest.processRequest(payload);
|
|
835
349
|
});
|
|
836
350
|
},
|
|
837
351
|
async get (url, options) {
|
|
@@ -872,19 +386,22 @@ export function createRestManager(options) {
|
|
|
872
386
|
async addThreadMember (channelId, userId) {
|
|
873
387
|
await rest.put(rest.routes.channels.threads.user(channelId, userId));
|
|
874
388
|
},
|
|
875
|
-
async createAutomodRule (guildId, body) {
|
|
389
|
+
async createAutomodRule (guildId, body, reason) {
|
|
876
390
|
return await rest.post(rest.routes.guilds.automod.rules(guildId), {
|
|
877
|
-
body
|
|
391
|
+
body,
|
|
392
|
+
reason
|
|
878
393
|
});
|
|
879
394
|
},
|
|
880
|
-
async createChannel (guildId, body) {
|
|
395
|
+
async createChannel (guildId, body, reason) {
|
|
881
396
|
return await rest.post(rest.routes.guilds.channels(guildId), {
|
|
882
|
-
body
|
|
397
|
+
body,
|
|
398
|
+
reason
|
|
883
399
|
});
|
|
884
400
|
},
|
|
885
|
-
async createEmoji (guildId, body) {
|
|
401
|
+
async createEmoji (guildId, body, reason) {
|
|
886
402
|
return await rest.post(rest.routes.guilds.emojis(guildId), {
|
|
887
|
-
body
|
|
403
|
+
body,
|
|
404
|
+
reason
|
|
888
405
|
});
|
|
889
406
|
},
|
|
890
407
|
async createGlobalApplicationCommand (body) {
|
|
@@ -910,14 +427,15 @@ export function createRestManager(options) {
|
|
|
910
427
|
body
|
|
911
428
|
});
|
|
912
429
|
},
|
|
913
|
-
async createGuildSticker (guildId, options) {
|
|
430
|
+
async createGuildSticker (guildId, options, reason) {
|
|
914
431
|
const form = new FormData();
|
|
915
432
|
form.append('file', options.file.blob, options.file.name);
|
|
916
433
|
form.append('name', options.name);
|
|
917
434
|
form.append('description', options.description);
|
|
918
435
|
form.append('tags', options.tags);
|
|
919
436
|
return await rest.post(rest.routes.guilds.stickers(guildId), {
|
|
920
|
-
body: form
|
|
437
|
+
body: form,
|
|
438
|
+
reason
|
|
921
439
|
});
|
|
922
440
|
},
|
|
923
441
|
async createGuildTemplate (guildId, body) {
|
|
@@ -925,15 +443,17 @@ export function createRestManager(options) {
|
|
|
925
443
|
body
|
|
926
444
|
});
|
|
927
445
|
},
|
|
928
|
-
async createForumThread (channelId, body) {
|
|
446
|
+
async createForumThread (channelId, body, reason) {
|
|
929
447
|
return await rest.post(rest.routes.channels.forum(channelId), {
|
|
930
448
|
body,
|
|
931
|
-
files: body.files
|
|
449
|
+
files: body.files,
|
|
450
|
+
reason
|
|
932
451
|
});
|
|
933
452
|
},
|
|
934
|
-
async createInvite (channelId, body = {}) {
|
|
453
|
+
async createInvite (channelId, body = {}, reason) {
|
|
935
454
|
return await rest.post(rest.routes.channels.invites(channelId), {
|
|
936
|
-
body
|
|
455
|
+
body,
|
|
456
|
+
reason
|
|
937
457
|
});
|
|
938
458
|
},
|
|
939
459
|
async createRole (guildId, body, reason) {
|
|
@@ -942,14 +462,16 @@ export function createRestManager(options) {
|
|
|
942
462
|
reason
|
|
943
463
|
});
|
|
944
464
|
},
|
|
945
|
-
async createScheduledEvent (guildId, body) {
|
|
465
|
+
async createScheduledEvent (guildId, body, reason) {
|
|
946
466
|
return await rest.post(rest.routes.guilds.events.events(guildId), {
|
|
947
|
-
body
|
|
467
|
+
body,
|
|
468
|
+
reason
|
|
948
469
|
});
|
|
949
470
|
},
|
|
950
|
-
async createStageInstance (body) {
|
|
471
|
+
async createStageInstance (body, reason) {
|
|
951
472
|
return await rest.post(rest.routes.channels.stages(), {
|
|
952
|
-
body
|
|
473
|
+
body,
|
|
474
|
+
reason
|
|
953
475
|
});
|
|
954
476
|
},
|
|
955
477
|
async createWebhook (channelId, options, reason) {
|
|
@@ -982,7 +504,9 @@ export function createRestManager(options) {
|
|
|
982
504
|
});
|
|
983
505
|
},
|
|
984
506
|
async deleteFollowupMessage (token, messageId) {
|
|
985
|
-
await rest.delete(rest.routes.interactions.responses.message(rest.applicationId, token, messageId)
|
|
507
|
+
await rest.delete(rest.routes.interactions.responses.message(rest.applicationId, token, messageId), {
|
|
508
|
+
unauthorized: true
|
|
509
|
+
});
|
|
986
510
|
},
|
|
987
511
|
async deleteGlobalApplicationCommand (commandId) {
|
|
988
512
|
await rest.delete(rest.routes.interactions.commands.command(rest.applicationId, commandId));
|
|
@@ -1001,8 +525,10 @@ export function createRestManager(options) {
|
|
|
1001
525
|
async deleteGuildTemplate (guildId, templateCode) {
|
|
1002
526
|
await rest.delete(rest.routes.guilds.templates.guild(guildId, templateCode));
|
|
1003
527
|
},
|
|
1004
|
-
async deleteIntegration (guildId, integrationId) {
|
|
1005
|
-
await rest.delete(rest.routes.guilds.integration(guildId, integrationId)
|
|
528
|
+
async deleteIntegration (guildId, integrationId, reason) {
|
|
529
|
+
await rest.delete(rest.routes.guilds.integration(guildId, integrationId), {
|
|
530
|
+
reason
|
|
531
|
+
});
|
|
1006
532
|
},
|
|
1007
533
|
async deleteInvite (inviteCode, reason) {
|
|
1008
534
|
await rest.delete(rest.routes.guilds.invite(inviteCode), {
|
|
@@ -1023,7 +549,9 @@ export function createRestManager(options) {
|
|
|
1023
549
|
});
|
|
1024
550
|
},
|
|
1025
551
|
async deleteOriginalInteractionResponse (token) {
|
|
1026
|
-
await rest.delete(rest.routes.interactions.responses.original(rest.applicationId, token)
|
|
552
|
+
await rest.delete(rest.routes.interactions.responses.original(rest.applicationId, token), {
|
|
553
|
+
unauthorized: true
|
|
554
|
+
});
|
|
1027
555
|
},
|
|
1028
556
|
async deleteOwnReaction (channelId, messageId, reaction) {
|
|
1029
557
|
reaction = processReactionString(reaction);
|
|
@@ -1036,8 +564,10 @@ export function createRestManager(options) {
|
|
|
1036
564
|
reaction = processReactionString(reaction);
|
|
1037
565
|
await rest.delete(rest.routes.channels.reactions.emoji(channelId, messageId, reaction));
|
|
1038
566
|
},
|
|
1039
|
-
async deleteRole (guildId, roleId) {
|
|
1040
|
-
await rest.delete(rest.routes.guilds.roles.one(guildId, roleId)
|
|
567
|
+
async deleteRole (guildId, roleId, reason) {
|
|
568
|
+
await rest.delete(rest.routes.guilds.roles.one(guildId, roleId), {
|
|
569
|
+
reason
|
|
570
|
+
});
|
|
1041
571
|
},
|
|
1042
572
|
async deleteScheduledEvent (guildId, eventId) {
|
|
1043
573
|
await rest.delete(rest.routes.guilds.events.event(guildId, eventId));
|
|
@@ -1072,9 +602,10 @@ export function createRestManager(options) {
|
|
|
1072
602
|
}
|
|
1073
603
|
});
|
|
1074
604
|
},
|
|
1075
|
-
async editAutomodRule (guildId, ruleId, body) {
|
|
605
|
+
async editAutomodRule (guildId, ruleId, body, reason) {
|
|
1076
606
|
return await rest.patch(rest.routes.guilds.automod.rule(guildId, ruleId), {
|
|
1077
|
-
body
|
|
607
|
+
body,
|
|
608
|
+
reason
|
|
1078
609
|
});
|
|
1079
610
|
},
|
|
1080
611
|
async editBotProfile (options) {
|
|
@@ -1086,14 +617,16 @@ export function createRestManager(options) {
|
|
|
1086
617
|
}
|
|
1087
618
|
});
|
|
1088
619
|
},
|
|
1089
|
-
async editChannel (channelId, body) {
|
|
620
|
+
async editChannel (channelId, body, reason) {
|
|
1090
621
|
return await rest.patch(rest.routes.channels.channel(channelId), {
|
|
1091
|
-
body
|
|
622
|
+
body,
|
|
623
|
+
reason
|
|
1092
624
|
});
|
|
1093
625
|
},
|
|
1094
|
-
async editChannelPermissionOverrides (channelId, body) {
|
|
626
|
+
async editChannelPermissionOverrides (channelId, body, reason) {
|
|
1095
627
|
await rest.put(rest.routes.channels.overwrite(channelId, body.id), {
|
|
1096
|
-
body
|
|
628
|
+
body,
|
|
629
|
+
reason
|
|
1097
630
|
});
|
|
1098
631
|
},
|
|
1099
632
|
async editChannelPositions (guildId, body) {
|
|
@@ -1101,15 +634,17 @@ export function createRestManager(options) {
|
|
|
1101
634
|
body
|
|
1102
635
|
});
|
|
1103
636
|
},
|
|
1104
|
-
async editEmoji (guildId, id, body) {
|
|
637
|
+
async editEmoji (guildId, id, body, reason) {
|
|
1105
638
|
return await rest.patch(rest.routes.guilds.emoji(guildId, id), {
|
|
1106
|
-
body
|
|
639
|
+
body,
|
|
640
|
+
reason
|
|
1107
641
|
});
|
|
1108
642
|
},
|
|
1109
643
|
async editFollowupMessage (token, messageId, body) {
|
|
1110
644
|
return await rest.patch(rest.routes.interactions.responses.message(rest.applicationId, token, messageId), {
|
|
1111
645
|
body,
|
|
1112
|
-
files: body.files
|
|
646
|
+
files: body.files,
|
|
647
|
+
unauthorized: true
|
|
1113
648
|
});
|
|
1114
649
|
},
|
|
1115
650
|
async editGlobalApplicationCommand (commandId, body) {
|
|
@@ -1117,9 +652,10 @@ export function createRestManager(options) {
|
|
|
1117
652
|
body
|
|
1118
653
|
});
|
|
1119
654
|
},
|
|
1120
|
-
async editGuild (guildId, body) {
|
|
655
|
+
async editGuild (guildId, body, reason) {
|
|
1121
656
|
return await rest.patch(rest.routes.guilds.guild(guildId), {
|
|
1122
|
-
body
|
|
657
|
+
body,
|
|
658
|
+
reason
|
|
1123
659
|
});
|
|
1124
660
|
},
|
|
1125
661
|
async editGuildApplicationCommand (commandId, guildId, body) {
|
|
@@ -1135,9 +671,10 @@ export function createRestManager(options) {
|
|
|
1135
671
|
reason
|
|
1136
672
|
});
|
|
1137
673
|
},
|
|
1138
|
-
async editGuildSticker (guildId, stickerId, body) {
|
|
674
|
+
async editGuildSticker (guildId, stickerId, body, reason) {
|
|
1139
675
|
return await rest.patch(rest.routes.guilds.sticker(guildId, stickerId), {
|
|
1140
|
-
body
|
|
676
|
+
body,
|
|
677
|
+
reason
|
|
1141
678
|
});
|
|
1142
679
|
},
|
|
1143
680
|
async editGuildTemplate (guildId, templateCode, body) {
|
|
@@ -1162,7 +699,8 @@ export function createRestManager(options) {
|
|
|
1162
699
|
type: InteractionResponseTypes.UpdateMessage,
|
|
1163
700
|
data: options
|
|
1164
701
|
},
|
|
1165
|
-
files: options.files
|
|
702
|
+
files: options.files,
|
|
703
|
+
unauthorized: true
|
|
1166
704
|
});
|
|
1167
705
|
},
|
|
1168
706
|
async editOwnVoiceState (guildId, options) {
|
|
@@ -1173,19 +711,22 @@ export function createRestManager(options) {
|
|
|
1173
711
|
}
|
|
1174
712
|
});
|
|
1175
713
|
},
|
|
1176
|
-
async editScheduledEvent (guildId, eventId, body) {
|
|
714
|
+
async editScheduledEvent (guildId, eventId, body, reason) {
|
|
1177
715
|
return await rest.patch(rest.routes.guilds.events.event(guildId, eventId), {
|
|
1178
|
-
body
|
|
716
|
+
body,
|
|
717
|
+
reason
|
|
1179
718
|
});
|
|
1180
719
|
},
|
|
1181
|
-
async editRole (guildId, roleId, body) {
|
|
720
|
+
async editRole (guildId, roleId, body, reason) {
|
|
1182
721
|
return await rest.patch(rest.routes.guilds.roles.one(guildId, roleId), {
|
|
1183
|
-
body
|
|
722
|
+
body,
|
|
723
|
+
reason
|
|
1184
724
|
});
|
|
1185
725
|
},
|
|
1186
|
-
async editRolePositions (guildId, body) {
|
|
726
|
+
async editRolePositions (guildId, body, reason) {
|
|
1187
727
|
return await rest.patch(rest.routes.guilds.roles.all(guildId), {
|
|
1188
|
-
body
|
|
728
|
+
body,
|
|
729
|
+
reason
|
|
1189
730
|
});
|
|
1190
731
|
},
|
|
1191
732
|
async editStageInstance (channelId, topic, reason) {
|
|
@@ -1201,9 +742,10 @@ export function createRestManager(options) {
|
|
|
1201
742
|
body: options
|
|
1202
743
|
});
|
|
1203
744
|
},
|
|
1204
|
-
async editWebhook (webhookId, body) {
|
|
745
|
+
async editWebhook (webhookId, body, reason) {
|
|
1205
746
|
return await rest.patch(rest.routes.webhooks.id(webhookId), {
|
|
1206
|
-
body
|
|
747
|
+
body,
|
|
748
|
+
reason
|
|
1207
749
|
});
|
|
1208
750
|
},
|
|
1209
751
|
async editWebhookMessage (webhookId, token, messageId, options) {
|
|
@@ -1217,14 +759,16 @@ export function createRestManager(options) {
|
|
|
1217
759
|
body
|
|
1218
760
|
});
|
|
1219
761
|
},
|
|
1220
|
-
async editWelcomeScreen (guildId, body) {
|
|
762
|
+
async editWelcomeScreen (guildId, body, reason) {
|
|
1221
763
|
return await rest.patch(rest.routes.guilds.welcome(guildId), {
|
|
1222
|
-
body
|
|
764
|
+
body,
|
|
765
|
+
reason
|
|
1223
766
|
});
|
|
1224
767
|
},
|
|
1225
|
-
async editWidgetSettings (guildId, body) {
|
|
768
|
+
async editWidgetSettings (guildId, body, reason) {
|
|
1226
769
|
return await rest.patch(rest.routes.guilds.widget(guildId), {
|
|
1227
|
-
body
|
|
770
|
+
body,
|
|
771
|
+
reason
|
|
1228
772
|
});
|
|
1229
773
|
},
|
|
1230
774
|
async executeWebhook (webhookId, token, options) {
|
|
@@ -1295,7 +839,9 @@ export function createRestManager(options) {
|
|
|
1295
839
|
return await rest.get(rest.routes.guilds.emojis(guildId));
|
|
1296
840
|
},
|
|
1297
841
|
async getFollowupMessage (token, messageId) {
|
|
1298
|
-
return await rest.get(rest.routes.interactions.responses.message(rest.applicationId, token, messageId)
|
|
842
|
+
return await rest.get(rest.routes.interactions.responses.message(rest.applicationId, token, messageId), {
|
|
843
|
+
unauthorized: true
|
|
844
|
+
});
|
|
1299
845
|
},
|
|
1300
846
|
async getGatewayBot () {
|
|
1301
847
|
return await rest.get(rest.routes.gatewayBot());
|
|
@@ -1348,7 +894,9 @@ export function createRestManager(options) {
|
|
|
1348
894
|
return await rest.get(rest.routes.nitroStickerPacks());
|
|
1349
895
|
},
|
|
1350
896
|
async getOriginalInteractionResponse (token) {
|
|
1351
|
-
return await rest.get(rest.routes.interactions.responses.original(rest.applicationId, token)
|
|
897
|
+
return await rest.get(rest.routes.interactions.responses.original(rest.applicationId, token), {
|
|
898
|
+
unauthorized: true
|
|
899
|
+
});
|
|
1352
900
|
},
|
|
1353
901
|
async getPinnedMessages (channelId) {
|
|
1354
902
|
return await rest.get(rest.routes.channels.pins(channelId));
|
|
@@ -1448,47 +996,19 @@ export function createRestManager(options) {
|
|
|
1448
996
|
async removeThreadMember (channelId, userId) {
|
|
1449
997
|
await rest.delete(rest.routes.channels.threads.user(channelId, userId));
|
|
1450
998
|
},
|
|
1451
|
-
// TODO: why that
|
|
1452
999
|
async sendFollowupMessage (token, options) {
|
|
1453
|
-
return await
|
|
1454
|
-
|
|
1455
|
-
|
|
1456
|
-
|
|
1457
|
-
requestBodyOptions: {
|
|
1458
|
-
body: options,
|
|
1459
|
-
files: options.files
|
|
1460
|
-
},
|
|
1461
|
-
retryCount: 0,
|
|
1462
|
-
retryRequest: async function(options) {
|
|
1463
|
-
// TODO: should change to reprocess queue item
|
|
1464
|
-
await rest.sendRequest(options);
|
|
1465
|
-
},
|
|
1466
|
-
resolve: (data)=>{
|
|
1467
|
-
resolve(data.status !== 204 ? JSON.parse(data.body ?? '{}') : undefined);
|
|
1468
|
-
},
|
|
1469
|
-
reject
|
|
1470
|
-
});
|
|
1000
|
+
return await rest.post(rest.routes.webhooks.webhook(rest.applicationId, token), {
|
|
1001
|
+
body: options,
|
|
1002
|
+
files: options.files,
|
|
1003
|
+
unauthorized: true
|
|
1471
1004
|
});
|
|
1472
1005
|
},
|
|
1473
|
-
// TODO: why that
|
|
1474
1006
|
async sendInteractionResponse (interactionId, token, options) {
|
|
1475
|
-
await
|
|
1476
|
-
|
|
1477
|
-
|
|
1478
|
-
|
|
1479
|
-
|
|
1480
|
-
body: options
|
|
1481
|
-
},
|
|
1482
|
-
retryCount: 0,
|
|
1483
|
-
retryRequest: async function(options) {
|
|
1484
|
-
// TODO: should change to reprocess queue item
|
|
1485
|
-
await rest.sendRequest(options);
|
|
1486
|
-
},
|
|
1487
|
-
resolve: (data)=>{
|
|
1488
|
-
resolve(data.status !== 204 ? JSON.parse(data.body ?? '{}') : undefined);
|
|
1489
|
-
},
|
|
1490
|
-
reject
|
|
1491
|
-
});
|
|
1007
|
+
return await rest.post(rest.routes.interactions.responses.callback(interactionId, token), {
|
|
1008
|
+
body: options,
|
|
1009
|
+
files: options.data?.files,
|
|
1010
|
+
runThroughQueue: false,
|
|
1011
|
+
unauthorized: true
|
|
1492
1012
|
});
|
|
1493
1013
|
},
|
|
1494
1014
|
async sendMessage (channelId, body) {
|
|
@@ -1497,32 +1017,37 @@ export function createRestManager(options) {
|
|
|
1497
1017
|
files: body.files
|
|
1498
1018
|
});
|
|
1499
1019
|
},
|
|
1500
|
-
async startThreadWithMessage (channelId, messageId, body) {
|
|
1020
|
+
async startThreadWithMessage (channelId, messageId, body, reason) {
|
|
1501
1021
|
return await rest.post(rest.routes.channels.threads.message(channelId, messageId), {
|
|
1502
|
-
body
|
|
1022
|
+
body,
|
|
1023
|
+
reason
|
|
1503
1024
|
});
|
|
1504
1025
|
},
|
|
1505
|
-
async startThreadWithoutMessage (channelId, body) {
|
|
1026
|
+
async startThreadWithoutMessage (channelId, body, reason) {
|
|
1506
1027
|
return await rest.post(rest.routes.channels.threads.all(channelId), {
|
|
1507
|
-
body
|
|
1028
|
+
body,
|
|
1029
|
+
reason
|
|
1508
1030
|
});
|
|
1509
1031
|
},
|
|
1510
1032
|
async syncGuildTemplate (guildId) {
|
|
1511
1033
|
return await rest.put(rest.routes.guilds.templates.all(guildId));
|
|
1512
1034
|
},
|
|
1513
|
-
async banMember (guildId, userId, body) {
|
|
1035
|
+
async banMember (guildId, userId, body, reason) {
|
|
1514
1036
|
await rest.put(rest.routes.guilds.members.ban(guildId, userId), {
|
|
1515
|
-
body
|
|
1037
|
+
body,
|
|
1038
|
+
reason
|
|
1516
1039
|
});
|
|
1517
1040
|
},
|
|
1518
|
-
async editBotMember (guildId, body) {
|
|
1041
|
+
async editBotMember (guildId, body, reason) {
|
|
1519
1042
|
return await rest.patch(rest.routes.guilds.members.bot(guildId), {
|
|
1520
|
-
body
|
|
1043
|
+
body,
|
|
1044
|
+
reason
|
|
1521
1045
|
});
|
|
1522
1046
|
},
|
|
1523
|
-
async editMember (guildId, userId, body) {
|
|
1047
|
+
async editMember (guildId, userId, body, reason) {
|
|
1524
1048
|
return await rest.patch(rest.routes.guilds.members.member(guildId, userId), {
|
|
1525
|
-
body
|
|
1049
|
+
body,
|
|
1050
|
+
reason
|
|
1526
1051
|
});
|
|
1527
1052
|
},
|
|
1528
1053
|
async getMember (guildId, userId) {
|
|
@@ -1541,16 +1066,19 @@ export function createRestManager(options) {
|
|
|
1541
1066
|
reason
|
|
1542
1067
|
});
|
|
1543
1068
|
},
|
|
1544
|
-
async pruneMembers (guildId, body) {
|
|
1069
|
+
async pruneMembers (guildId, body, reason) {
|
|
1545
1070
|
return await rest.post(rest.routes.guilds.members.prune(guildId), {
|
|
1546
|
-
body
|
|
1071
|
+
body,
|
|
1072
|
+
reason
|
|
1547
1073
|
});
|
|
1548
1074
|
},
|
|
1549
1075
|
async searchMembers (guildId, query, options) {
|
|
1550
1076
|
return await rest.get(rest.routes.guilds.members.search(guildId, query, options));
|
|
1551
1077
|
},
|
|
1552
|
-
async unbanMember (guildId, userId) {
|
|
1553
|
-
await rest.delete(rest.routes.guilds.members.ban(guildId, userId)
|
|
1078
|
+
async unbanMember (guildId, userId, reason) {
|
|
1079
|
+
await rest.delete(rest.routes.guilds.members.ban(guildId, userId), {
|
|
1080
|
+
reason
|
|
1081
|
+
});
|
|
1554
1082
|
},
|
|
1555
1083
|
async unpinMessage (channelId, messageId, reason) {
|
|
1556
1084
|
await rest.delete(rest.routes.channels.pin(channelId, messageId), {
|
|
@@ -1573,5 +1101,12 @@ export function createRestManager(options) {
|
|
|
1573
1101
|
};
|
|
1574
1102
|
return rest;
|
|
1575
1103
|
}
|
|
1104
|
+
var HttpResponseCode;
|
|
1105
|
+
(function(HttpResponseCode) {
|
|
1106
|
+
HttpResponseCode[HttpResponseCode[/** Minimum value of a code in oder to consider that it was successful. */ "Success"] = 200] = "Success";
|
|
1107
|
+
HttpResponseCode[HttpResponseCode[/** Request completed successfully, but Discord returned an empty body. */ "NoContent"] = 204] = "NoContent";
|
|
1108
|
+
HttpResponseCode[HttpResponseCode[/** Minimum value of a code in order to consider that something went wrong. */ "Error"] = 400] = "Error";
|
|
1109
|
+
HttpResponseCode[HttpResponseCode[/** This request got rate limited. */ "TooManyRequests"] = 429] = "TooManyRequests";
|
|
1110
|
+
})(HttpResponseCode || (HttpResponseCode = {}));
|
|
1576
1111
|
|
|
1577
1112
|
//# sourceMappingURL=manager.js.map
|