snowtransfer 0.4.3 → 0.5.2

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.
Files changed (44) hide show
  1. package/README.md +2 -1
  2. package/dist/Constants.d.ts +4 -0
  3. package/dist/Constants.js +4 -0
  4. package/dist/Endpoints.d.ts +78 -77
  5. package/dist/Endpoints.js +2 -1
  6. package/dist/{ratelimitBuckets/LocalBucket.d.ts → LocalBucket.d.ts} +15 -9
  7. package/dist/LocalBucket.js +88 -0
  8. package/dist/Ratelimiter.d.ts +24 -12
  9. package/dist/Ratelimiter.js +41 -24
  10. package/dist/RequestHandler.d.ts +1 -3
  11. package/dist/RequestHandler.js +23 -40
  12. package/dist/SnowTransfer.d.ts +2 -7
  13. package/dist/SnowTransfer.js +5 -5
  14. package/dist/index.d.ts +2 -0
  15. package/dist/index.js +1 -0
  16. package/dist/methods/AuditLog.d.ts +16 -4
  17. package/dist/methods/AuditLog.js +10 -0
  18. package/dist/methods/Bots.d.ts +5 -4
  19. package/dist/methods/Bots.js +5 -4
  20. package/dist/methods/Channels.d.ts +481 -261
  21. package/dist/methods/Channels.js +366 -265
  22. package/dist/methods/GuildAssets.d.ts +66 -11
  23. package/dist/methods/GuildAssets.js +61 -9
  24. package/dist/methods/GuildScheduledEvent.d.ts +90 -29
  25. package/dist/methods/GuildScheduledEvent.js +44 -16
  26. package/dist/methods/GuildTemplate.d.ts +29 -0
  27. package/dist/methods/GuildTemplate.js +29 -0
  28. package/dist/methods/Guilds.d.ts +383 -173
  29. package/dist/methods/Guilds.js +253 -138
  30. package/dist/methods/Interactions.d.ts +166 -75
  31. package/dist/methods/Interactions.js +159 -92
  32. package/dist/methods/Invites.d.ts +13 -2
  33. package/dist/methods/Invites.js +14 -4
  34. package/dist/methods/StageInstance.d.ts +21 -1
  35. package/dist/methods/StageInstance.js +20 -2
  36. package/dist/methods/Users.d.ts +41 -21
  37. package/dist/methods/Users.js +35 -21
  38. package/dist/methods/{Voices.d.ts → Voice.d.ts} +5 -0
  39. package/dist/methods/{Voices.js → Voice.js} +5 -0
  40. package/dist/methods/Webhooks.d.ts +80 -42
  41. package/dist/methods/Webhooks.js +38 -41
  42. package/dist/tsconfig.tsbuildinfo +1 -1
  43. package/package.json +7 -7
  44. package/dist/ratelimitBuckets/LocalBucket.js +0 -73
package/README.md CHANGED
@@ -6,12 +6,13 @@
6
6
  Part of the WeatherStack
7
7
 
8
8
  SnowTransfer is a small library specially made to **only** cover the REST/HTTP area of the discord api.
9
- It makes no assumptions about the rest of your stack, therefore you can use it anywhere as long as you use node 8 or higher.
9
+ It makes no assumptions about the rest of your stack, therefore you can use it anywhere as long as you use node 12 or higher.
10
10
 
11
11
  ### Some of the things that make SnowTransfer awesome:
12
12
  - No requirement for other components
13
13
  - Full coverage of the discord rest api
14
14
  - Well documented
15
+ - Supports both Bot and Bearer tokens (Bearer tokens will have much more limited access than Bot tokens)
15
16
 
16
17
  ### General Usecase:
17
18
  SnowTransfer is not your everyday library,
@@ -1,7 +1,11 @@
1
1
  declare const _default: {
2
2
  REST_API_VERSION: 10;
3
+ GET_CHANNEL_MESSAGES_MIN_RESULTS: 1;
3
4
  GET_CHANNEL_MESSAGES_MAX_RESULTS: 100;
5
+ GET_GUILD_SCHEDULED_EVENT_USERS_MIN_RESULTS: 1;
4
6
  GET_GUILD_SCHEDULED_EVENT_USERS_MAX_RESULTS: 100;
7
+ SEARCH_MEMBERS_MIN_RESULTS: 1;
8
+ SEARCH_MEMBERS_MAX_RESULTS: 1000;
5
9
  BULK_DELETE_MESSAGES_MIN: 2;
6
10
  BULK_DELETE_MESSAGES_MAX: 100;
7
11
  OK_STATUS_CODES: number[];
package/dist/Constants.js CHANGED
@@ -1,8 +1,12 @@
1
1
  "use strict";
2
2
  module.exports = {
3
3
  REST_API_VERSION: 10,
4
+ GET_CHANNEL_MESSAGES_MIN_RESULTS: 1,
4
5
  GET_CHANNEL_MESSAGES_MAX_RESULTS: 100,
6
+ GET_GUILD_SCHEDULED_EVENT_USERS_MIN_RESULTS: 1,
5
7
  GET_GUILD_SCHEDULED_EVENT_USERS_MAX_RESULTS: 100,
8
+ SEARCH_MEMBERS_MIN_RESULTS: 1,
9
+ SEARCH_MEMBERS_MAX_RESULTS: 1000,
6
10
  BULK_DELETE_MESSAGES_MIN: 2,
7
11
  BULK_DELETE_MESSAGES_MAX: 100,
8
12
  OK_STATUS_CODES: [200, 201, 204, 304]
@@ -7,89 +7,90 @@ declare const Endpoints: {
7
7
  BASE_URL: "/api/v10";
8
8
  BASE_HOST: "https://discord.com";
9
9
  CDN_URL: "https://cdn.discordapp.com";
10
- APPLICATION_COMMAND: (appID: string, cmdID: string) => "/applications/:app_id/commands/:cmd_id";
11
- APPLICATION_COMMANDS: (appID: string) => "/applications/:app_id/commands";
12
- APPLICATION_GUILD_COMMANDS_PERMISSIONS: (appID: string, guildID: string) => "/applications/:app_id/guilds/:guild_id/commands/permissions";
13
- APPLICATION_GUILD_COMMAND_PERMISSIONS: (appID: string, guildID: string, cmdID: string) => "/applications/:app_id/guilds/:guild_id/commands/permissions";
14
- APPLICATION_GUILD_COMMAND: (appID: string, guildID: string, cmdID: string) => "/applications/:app_id/guilds/:guild_id/commands/:cmd_id";
15
- APPLICATION_GUILD_COMMANDS: (appID: string, guildID: string) => "/applications/:app_id/guilds/:guild_id/commands";
16
- CHANNEL: (chanID: string) => "/channels/:channel_id";
17
- CHANNEL_BULK_DELETE: (chanID: string) => "/channels/:channel_id/messages/bulk-delete";
18
- CHANNEL_INVITES: (chanID: string) => "/channels/:channel_id/invites";
19
- CHANNEL_MESSAGE: (chanID: string, msgID: string) => "/channels/:channel_id/messages/:message_id";
20
- CHANNEL_MESSAGE_CROSSPOST: (chanID: string, msgID: string) => "/channels/:channel_id/messages/:message_id/crosspost";
21
- CHANNEL_MESSAGE_REACTION: (chanID: string, msgID: string, reaction: string) => "/channels/:channel_id/messages/:message_id/reactions/:reaction";
22
- CHANNEL_MESSAGE_REACTION_USER: (chanID: string, msgID: string, reaction: string, userID: string) => "/channels/:channel_id/messages/:message_id/reactions/:reaction/:user_id";
23
- CHANNEL_MESSAGE_REACTIONS: (chanID: string, msgID: string) => "/channels/:channel_id/messages/:message_id/reactions";
24
- CHANNEL_MESSAGE_THREADS: (chanID: string, msgID: string) => "/channels/:channel_id/messages/:message_id/threads";
25
- CHANNEL_MESSAGES: (chanID: string) => "/channels/:channel_id/messages";
26
- CHANNEL_PERMISSION: (chanID: string, permID: string) => "/channels/:channel_id/permissions/:perm_id";
27
- CHANNEL_PERMISSIONS: (chanID: string) => "/channels/:channel_id/permissions";
28
- CHANNEL_PIN: (chanID: string, msgID: string) => "/channels/:channel_id/pins/:message_id";
29
- CHANNEL_PINS: (chanID: string) => "/channels/:channel_id/pins";
30
- CHANNEL_RECIPIENT: (chanID: string, userID: string) => "/channels/:channel_id/recipients/:user_id";
31
- CHANNEL_THREADS: (chanID: string) => "/channels/:channel_id/threads";
32
- CHANNEL_THREAD_MEMBER: (chanID: string, memberID: string) => "/channels/:channel_id/thread-members/:member_id";
33
- CHANNEL_THREAD_MEMBERS: (chanID: string) => "/channels/:channel_id/thread-members";
34
- CHANNEL_THREADS_ARCHIVED_PRIVATE: (chanID: string) => "/channels/:channel_id/threads/archived/private";
35
- CHANNEL_THREADS_ARCHIVED_PRIVATE_USER: (chanID: string) => "/channels/:channel_id/users/@me/threads/archived/private";
36
- CHANNEL_THREADS_ARCHIVED_PUBLIC: (chanID: string) => "/channels/:channel_id/threads/archived/public";
37
- CHANNEL_TYPING: (chanID: string) => "/channels/:channel_id/typing";
38
- CHANNEL_WEBHOOKS: (chanID: string) => "/channels/:channel_id/webhooks";
10
+ APPLICATION_COMMAND: (appID: string, cmdID: string) => "/applications/{app_id}/commands/{cmd_id}";
11
+ APPLICATION_COMMANDS: (appID: string) => "/applications/{app_id}/commands";
12
+ APPLICATION_GUILD_COMMANDS_PERMISSIONS: (appID: string, guildID: string) => "/applications/{app_id}/guilds/{guild_id}/commands/permissions";
13
+ APPLICATION_GUILD_COMMAND_PERMISSIONS: (appID: string, guildID: string, cmdID: string) => "/applications/{app_id}/guilds/{guild_id}/commands/{cmd_id}/permissions";
14
+ APPLICATION_GUILD_COMMAND: (appID: string, guildID: string, cmdID: string) => "/applications/{app_id}/guilds/{guild_id}/commands/{cmd_id}";
15
+ APPLICATION_GUILD_COMMANDS: (appID: string, guildID: string) => "/applications/{app_id}/guilds/{guild_id}/commands";
16
+ CHANNEL: (chanID: string) => "/channels/{channel_id}";
17
+ CHANNEL_BULK_DELETE: (chanID: string) => "/channels/{channel_id}/messages/bulk-delete";
18
+ CHANNEL_FOLLOWERS: (chanID: string) => "/channels/{channel_id}/followers";
19
+ CHANNEL_INVITES: (chanID: string) => "/channels/{channel_id}/invites";
20
+ CHANNEL_MESSAGE: (chanID: string, msgID: string) => "/channels/{channel_id}/messages/{message_id}";
21
+ CHANNEL_MESSAGE_CROSSPOST: (chanID: string, msgID: string) => "/channels/{channel_id}/messages/{message_id}/crosspost";
22
+ CHANNEL_MESSAGE_REACTION: (chanID: string, msgID: string, reaction: string) => "/channels/{channel_id}/messages/{message_id}/reactions/{reaction}";
23
+ CHANNEL_MESSAGE_REACTION_USER: (chanID: string, msgID: string, reaction: string, userID: string) => "/channels/{channel_id}/messages/{message_id}/reactions/{reaction}/{user_id}";
24
+ CHANNEL_MESSAGE_REACTIONS: (chanID: string, msgID: string) => "/channels/{channel_id}/messages/{message_id}/reactions";
25
+ CHANNEL_MESSAGE_THREADS: (chanID: string, msgID: string) => "/channels/{channel_id}/messages/{message_id}/threads";
26
+ CHANNEL_MESSAGES: (chanID: string) => "/channels/{channel_id}/messages";
27
+ CHANNEL_PERMISSION: (chanID: string, permID: string) => "/channels/{channel_id}/permissions/{perm_id}";
28
+ CHANNEL_PERMISSIONS: (chanID: string) => "/channels/{channel_id}/permissions";
29
+ CHANNEL_PIN: (chanID: string, msgID: string) => "/channels/{channel_id}/pins/{message_id}";
30
+ CHANNEL_PINS: (chanID: string) => "/channels/{channel_id}/pins";
31
+ CHANNEL_RECIPIENT: (chanID: string, userID: string) => "/channels/{channel_id}/recipients/{user_id}";
32
+ CHANNEL_THREADS: (chanID: string) => "/channels/{channel_id}/threads";
33
+ CHANNEL_THREAD_MEMBER: (chanID: string, memberID: string) => "/channels/{channel_id}/thread-members/{member_id}";
34
+ CHANNEL_THREAD_MEMBERS: (chanID: string) => "/channels/{channel_id}/thread-members";
35
+ CHANNEL_THREADS_ARCHIVED_PRIVATE: (chanID: string) => "/channels/{channel_id}/threads/archived/private";
36
+ CHANNEL_THREADS_ARCHIVED_PRIVATE_USER: (chanID: string) => "/channels/{channel_id}/users/@me/threads/archived/private";
37
+ CHANNEL_THREADS_ARCHIVED_PUBLIC: (chanID: string) => "/channels/{channel_id}/threads/archived/public";
38
+ CHANNEL_TYPING: (chanID: string) => "/channels/{channel_id}/typing";
39
+ CHANNEL_WEBHOOKS: (chanID: string) => "/channels/{channel_id}/webhooks";
39
40
  CHANNELS: "/channels";
40
41
  GATEWAY: "/gateway";
41
42
  GATEWAY_BOT: "/gateway/bot";
42
- GUILD: (guildID: string) => "/guilds/:guild_id";
43
- GUILD_AUDIT_LOGS: (guildID: string) => "/guilds/:guild_id/audit-logs";
44
- GUILD_BAN: (guildID: string, memberID: string) => "/guilds/:guild_id/bans/:member_id";
45
- GUILD_BANS: (guildID: string) => "/guilds/:guild_id/bans";
46
- GUILD_CHANNELS: (guildID: string) => "/guilds/:guild_id/channels";
47
- GUILD_EMOJI: (guildID: string, emojiID: string) => "/guilds/:guild_id/emojis/:emoji_id";
48
- GUILD_EMOJIS: (guildID: string) => "/guilds/:guild_id/emojis";
49
- GUILD_INVITES: (guildID: string) => "/guilds/:guild_id/invites";
50
- GUILD_INTEGRATION: (guildID: string, integrationID: string) => "/guilds/:guild_id/integrations/:integration_id";
51
- GUILD_INTEGRATIONS: (guildID: string) => "/guilds/:guild_id/integrations";
52
- GUILD_MEMBER: (guildID: string, memberID: string) => "/guilds/:guild_id/members/:member_id";
53
- GUILD_MEMBER_ROLE: (guildID: string, memberID: string, roleID: string) => "/guilds/:guild_id/members/:member_id/roles/:role_id";
54
- GUILD_MEMBERS: (guildID: string) => "/guilds/:guild_id/members";
55
- GUILD_MEMBERS_SEARCH: (guildID: string) => "/guilds/:guild_id/members/search";
56
- GUILD_PREVIEW: (guildID: string) => "/guilds/:guild_id/preview";
57
- GUILD_PRUNE: (guildID: string) => "/guilds/:guild_id/prune";
58
- GUILD_ROLE: (guildID: string, roleID: string) => "/guilds/:guild_id/roles/:role_id";
59
- GUILD_ROLES: (guildID: string) => "/guilds/:guild_id/roles";
60
- GUILD_SCHEDULED_EVENTS: (guildID: string) => "/guilds/:guild_id/scheduled-events";
61
- GUILD_SCHEDULED_EVENT: (guildID: string, eventId: string) => "/guilds/:guild_id/scheduled-events/:event_id";
62
- GUILD_SCHEDULED_EVENT_USERS: (guildID: string, eventId: string) => "/guilds/:guild_id/scheduled-events/:event_id/users";
63
- GUILD_STICKER: (guildID: string, stickerID: string) => "/guilds/:guild_id/stickers/:sticker_id";
64
- GUILD_STICKERS: (guildID: string) => "/guilds/:guild_id/stickers";
65
- GUILD_TEMPLATE: (guildID: string, code: string) => "/guilds/:guild_id/templates/:code";
66
- GUILD_THREADS_ACTIVE: (guildID: string) => "/guilds/:guild_id/threads/active";
67
- GUILD_TEMPLATES: (guildID: string) => "/guilds/:guild_id/templates";
68
- GUILD_VANITY: (guildID: string) => "/guilds/:guild_id/vanity-url";
69
- GUILD_VOICE_REGIONS: (guildID: string) => "/guilds/:guild_id/regions";
70
- GUILD_VOICE_STATE_USER: (guildID: string, memberID: string) => "/guilds/:guild_id/voice-states/:member-id";
71
- GUILD_WEBHOOKS: (guildID: string) => "/guilds/:guild_id/webhooks";
72
- GUILD_WELCOME_SCREEN: (guildID: string) => "/guilds/:guild_id/welcome-screen";
73
- GUILD_WIDGET: (guildID: string) => "/guilds/:guild_id/widget.json";
74
- GUILD_WIDGET_SETTINGS: (guildID: string) => "/guilds/:guild_id/widget";
43
+ GUILD: (guildID: string) => "/guilds/{guild_id}";
44
+ GUILD_AUDIT_LOGS: (guildID: string) => "/guilds/{guild_id}/audit-logs";
45
+ GUILD_BAN: (guildID: string, memberID: string) => "/guilds/{guild_id}/bans/{member_id}";
46
+ GUILD_BANS: (guildID: string) => "/guilds/{guild_id}/bans";
47
+ GUILD_CHANNELS: (guildID: string) => "/guilds/{guild_id}/channels";
48
+ GUILD_EMOJI: (guildID: string, emojiID: string) => "/guilds/{guild_id}/emojis/{emoji_id}";
49
+ GUILD_EMOJIS: (guildID: string) => "/guilds/{guild_id}/emojis";
50
+ GUILD_INVITES: (guildID: string) => "/guilds/{guild_id}/invites";
51
+ GUILD_INTEGRATION: (guildID: string, integrationID: string) => "/guilds/{guild_id}/integrations/{integration_id}";
52
+ GUILD_INTEGRATIONS: (guildID: string) => "/guilds/{guild_id}/integrations";
53
+ GUILD_MEMBER: (guildID: string, memberID: string) => "/guilds/{guild_id}/members/{member_id}";
54
+ GUILD_MEMBER_ROLE: (guildID: string, memberID: string, roleID: string) => "/guilds/{guild_id}/members/{member_id}/roles/{role_id}";
55
+ GUILD_MEMBERS: (guildID: string) => "/guilds/{guild_id}/members";
56
+ GUILD_MEMBERS_SEARCH: (guildID: string) => "/guilds/{guild_id}/members/search";
57
+ GUILD_PREVIEW: (guildID: string) => "/guilds/{guild_id}/preview";
58
+ GUILD_PRUNE: (guildID: string) => "/guilds/{guild_id}/prune";
59
+ GUILD_ROLE: (guildID: string, roleID: string) => "/guilds/{guild_id}/roles/{role_id}";
60
+ GUILD_ROLES: (guildID: string) => "/guilds/{guild_id}/roles";
61
+ GUILD_SCHEDULED_EVENTS: (guildID: string) => "/guilds/{guild_id}/scheduled-events";
62
+ GUILD_SCHEDULED_EVENT: (guildID: string, eventId: string) => "/guilds/{guild_id}/scheduled-events/{event_id}";
63
+ GUILD_SCHEDULED_EVENT_USERS: (guildID: string, eventId: string) => "/guilds/{guild_id}/scheduled-events/{event_id}/users";
64
+ GUILD_STICKER: (guildID: string, stickerID: string) => "/guilds/{guild_id}/stickers/{sticker_id}";
65
+ GUILD_STICKERS: (guildID: string) => "/guilds/{guild_id}/stickers";
66
+ GUILD_TEMPLATE: (guildID: string, code: string) => "/guilds/{guild_id}/templates/{code}";
67
+ GUILD_THREADS_ACTIVE: (guildID: string) => "/guilds/{guild_id}/threads/active";
68
+ GUILD_TEMPLATES: (guildID: string) => "/guilds/{guild_id}/templates";
69
+ GUILD_VANITY: (guildID: string) => "/guilds/{guild_id}/vanity-url";
70
+ GUILD_VOICE_REGIONS: (guildID: string) => "/guilds/{guild_id}/regions";
71
+ GUILD_VOICE_STATE_USER: (guildID: string, memberID: string) => "/guilds/{guild_id}/voice-states/{member-id}";
72
+ GUILD_WEBHOOKS: (guildID: string) => "/guilds/{guild_id}/webhooks";
73
+ GUILD_WELCOME_SCREEN: (guildID: string) => "/guilds/{guild_id}/welcome-screen";
74
+ GUILD_WIDGET: (guildID: string) => "/guilds/{guild_id}/widget.json";
75
+ GUILD_WIDGET_SETTINGS: (guildID: string) => "/guilds/{guild_id}/widget";
75
76
  GUILDS: "/guilds";
76
- INTERACTION_CALLBACK: (interactionID: string, token: string) => "/interactions/:interaction_id/:token/callback";
77
- INVITE: (inviteID: string) => "/invites/:invite_id";
78
- OAUTH2_APPLICATION: (appID: string) => "/oauth2/applications/:app_id";
79
- STAGE_INSTANCE_CHANNEL: (chanID: string) => "/stage-instances/:channel_id";
77
+ INTERACTION_CALLBACK: (interactionID: string, token: string) => "/interactions/{interaction_id}/{token}/callback";
78
+ INVITES: (inviteID: string) => "/invites/{invite_id}";
79
+ OAUTH2_APPLICATION: (appID: string) => "/oauth2/applications/{app_id}";
80
+ STAGE_INSTANCE_CHANNEL: (chanID: string) => "/stage-instances/{channel_id}";
80
81
  STAGE_INSTANCES: "/stage-instances";
81
- STICKER: (stickerID: string) => "/stickers/:sticker_id";
82
- TEMPLATE: (code: string) => "/guilds/templates/:code";
83
- USER: (userID: string) => "/users/:user_id";
84
- USER_CHANNELS: (userID: string) => "/users/:user_id/channels";
85
- USER_GUILD: (userID: string, guildID: string) => any;
86
- USER_GUILDS: (userID: string) => "/users/:user_id/guilds";
82
+ STICKER: (stickerID: string) => "/stickers/{sticker_id}";
83
+ TEMPLATE: (code: string) => "/guilds/templates/{code}";
84
+ USER: (userID: string) => "/users/{user_id}";
85
+ USER_CHANNELS: (userID: string) => "/users/{user_id}/channels";
86
+ USER_GUILD: (userID: string, guildID: string) => "/users/{user_id}/guilds/{guild_id}";
87
+ USER_GUILDS: (userID: string) => "/users/{user_id}/guilds";
87
88
  USERS: "/users";
88
89
  VOICE_REGIONS: "/voice/regions";
89
- WEBHOOK: (hookID: string) => "/webhooks/:hook_id";
90
- WEBHOOK_TOKEN: (hookID: string, token: string) => "/webhooks/:hook_id/:token";
91
- WEBHOOK_TOKEN_GITHUB: (hookID: string, token: string) => "/webhooks/:hook_id/:token/github";
92
- WEBHOOK_TOKEN_MESSAGE: (hookID: string, token: string, msgID: string) => string;
93
- WEBHOOK_TOKEN_SLACK: (hookID: string, token: string) => "/webhooks/:hook_id/:token/slack";
90
+ WEBHOOK: (hookID: string) => "/webhooks/{hook_id}";
91
+ WEBHOOK_TOKEN: (hookID: string, token: string) => "/webhooks/{hook_id}/{token}";
92
+ WEBHOOK_TOKEN_GITHUB: (hookID: string, token: string) => "/webhooks/{hook_id}/{token}/github";
93
+ WEBHOOK_TOKEN_MESSAGE: (hookID: string, token: string, msgID: string) => "/webhooks/{hook_id}/{token}/messages/{message_id}";
94
+ WEBHOOK_TOKEN_SLACK: (hookID: string, token: string) => "/webhooks/{hook_id}/{token}/slack";
94
95
  };
95
96
  export = Endpoints;
package/dist/Endpoints.js CHANGED
@@ -20,6 +20,7 @@ const Endpoints = {
20
20
  APPLICATION_GUILD_COMMANDS: (appID, guildID) => `/applications/${appID}/guilds/${guildID}/commands`,
21
21
  CHANNEL: (chanID) => `${Endpoints.CHANNELS}/${chanID}`,
22
22
  CHANNEL_BULK_DELETE: (chanID) => `${Endpoints.CHANNEL_MESSAGES(chanID)}/bulk-delete`,
23
+ CHANNEL_FOLLOWERS: (chanID) => `${Endpoints.CHANNEL(chanID)}/followers`,
23
24
  CHANNEL_INVITES: (chanID) => `${Endpoints.CHANNEL(chanID)}/invites`,
24
25
  CHANNEL_MESSAGE: (chanID, msgID) => `${Endpoints.CHANNEL_MESSAGES(chanID)}/${msgID}`,
25
26
  CHANNEL_MESSAGE_CROSSPOST: (chanID, msgID) => `${Endpoints.CHANNEL_MESSAGE(chanID, msgID)}/crosspost`,
@@ -79,7 +80,7 @@ const Endpoints = {
79
80
  GUILD_WIDGET_SETTINGS: (guildID) => `${Endpoints.GUILD(guildID)}/widget`,
80
81
  GUILDS: "/guilds",
81
82
  INTERACTION_CALLBACK: (interactionID, token) => `/interactions/${interactionID}/${token}/callback`,
82
- INVITE: (inviteID) => `/invites/${inviteID}`,
83
+ INVITES: (inviteID) => `/invites/${inviteID}`,
83
84
  OAUTH2_APPLICATION: (appID) => `/oauth2/applications/${appID}`,
84
85
  STAGE_INSTANCE_CHANNEL: (chanID) => `${Endpoints.STAGE_INSTANCES}/${chanID}`,
85
86
  STAGE_INSTANCES: "/stage-instances",
@@ -1,5 +1,7 @@
1
+ /// <reference types="node" />
1
2
  /**
2
3
  * Bucket used for saving ratelimits
4
+ * @protected
3
5
  */
4
6
  declare class LocalBucket {
5
7
  /**
@@ -16,32 +18,36 @@ declare class LocalBucket {
16
18
  /**
17
19
  * Remaining amount of executions during the current timeframe
18
20
  */
19
- protected _remaining: number;
21
+ remaining: number;
20
22
  /**
21
23
  * Timeframe in milliseconds until the ratelimit resets
22
24
  */
23
25
  reset: number;
24
26
  /**
25
- * The Date time in which the bucket will reset
27
+ * Timeout that calls the reset function once the timeframe passed
26
28
  */
27
- resetAt: number | null;
29
+ resetTimeout: NodeJS.Timeout | null;
28
30
  /**
29
31
  * ratelimiter used for ratelimiting requests
30
32
  */
31
- ratelimiter: import("../Ratelimiter");
33
+ ratelimiter: import("./Ratelimiter");
34
+ /**
35
+ * Key used internally to routify requests
36
+ */
37
+ routeKey: string;
38
+ static readonly default: typeof LocalBucket;
32
39
  /**
33
40
  * Create a new bucket
34
41
  * @param ratelimiter ratelimiter used for ratelimiting requests
42
+ * @param routeKey Key used internally to routify requests. Assigned by ratelimiter
35
43
  */
36
- constructor(ratelimiter: import("../Ratelimiter"));
37
- get remaining(): number;
38
- set remaining(value: number);
44
+ constructor(ratelimiter: import("./Ratelimiter"), routeKey: string);
39
45
  /**
40
46
  * Queue a function to be executed
41
47
  * @param fn function to be executed
42
48
  * @returns Result of the function if any
43
49
  */
44
- queue(fn: (bucket: LocalBucket) => any | Promise<any>): Promise<any>;
50
+ queue<T>(fn: (bucket: LocalBucket) => T): Promise<T>;
45
51
  /**
46
52
  * Check if there are any functions in the queue that haven't been executed yet
47
53
  */
@@ -49,7 +55,7 @@ declare class LocalBucket {
49
55
  /**
50
56
  * Reset the remaining tokens to the base limit
51
57
  */
52
- resetRemaining(): void;
58
+ private resetRemaining;
53
59
  /**
54
60
  * Clear the current queue of events to be sent
55
61
  */
@@ -0,0 +1,88 @@
1
+ "use strict";
2
+ /**
3
+ * Bucket used for saving ratelimits
4
+ * @protected
5
+ */
6
+ class LocalBucket {
7
+ /**
8
+ * Create a new bucket
9
+ * @param ratelimiter ratelimiter used for ratelimiting requests
10
+ * @param routeKey Key used internally to routify requests. Assigned by ratelimiter
11
+ */
12
+ constructor(ratelimiter, routeKey) {
13
+ /**
14
+ * array of functions waiting to be executed
15
+ */
16
+ this.fnQueue = [];
17
+ /**
18
+ * Number of functions that may be executed during the timeframe set in limitReset
19
+ */
20
+ this.limit = 5;
21
+ /**
22
+ * Remaining amount of executions during the current timeframe
23
+ */
24
+ this.remaining = 1;
25
+ /**
26
+ * Timeframe in milliseconds until the ratelimit resets
27
+ */
28
+ this.reset = 5000;
29
+ /**
30
+ * Timeout that calls the reset function once the timeframe passed
31
+ */
32
+ this.resetTimeout = null;
33
+ this.ratelimiter = ratelimiter;
34
+ this.routeKey = routeKey;
35
+ }
36
+ /**
37
+ * Queue a function to be executed
38
+ * @param fn function to be executed
39
+ * @returns Result of the function if any
40
+ */
41
+ queue(fn) {
42
+ return new Promise(res => {
43
+ const wrapFn = () => {
44
+ this.remaining--;
45
+ if (!this.resetTimeout)
46
+ this.resetTimeout = setTimeout(() => this.resetRemaining(), this.reset);
47
+ if (this.remaining !== 0)
48
+ this.checkQueue();
49
+ return res(fn(this));
50
+ };
51
+ this.fnQueue.push({ fn, callback: wrapFn });
52
+ this.checkQueue();
53
+ });
54
+ }
55
+ /**
56
+ * Check if there are any functions in the queue that haven't been executed yet
57
+ */
58
+ checkQueue() {
59
+ if (this.ratelimiter.global)
60
+ return;
61
+ if (this.fnQueue.length && this.remaining !== 0) {
62
+ const queuedFunc = this.fnQueue.splice(0, 1)[0];
63
+ queuedFunc.callback();
64
+ }
65
+ }
66
+ /**
67
+ * Reset the remaining tokens to the base limit
68
+ */
69
+ resetRemaining() {
70
+ this.remaining = this.limit;
71
+ if (this.resetTimeout) {
72
+ clearTimeout(this.resetTimeout);
73
+ this.resetTimeout = null;
74
+ }
75
+ if (this.fnQueue.length)
76
+ this.checkQueue();
77
+ else
78
+ delete this.ratelimiter.buckets[this.routeKey];
79
+ }
80
+ /**
81
+ * Clear the current queue of events to be sent
82
+ */
83
+ dropQueue() {
84
+ this.fnQueue.length = 0;
85
+ }
86
+ }
87
+ LocalBucket.default = LocalBucket;
88
+ module.exports = LocalBucket;
@@ -1,25 +1,37 @@
1
1
  /// <reference types="node" />
2
- import LocalBucket from "./ratelimitBuckets/LocalBucket";
2
+ import LocalBucket from "./LocalBucket";
3
3
  /**
4
4
  * Ratelimiter used for handling the ratelimits imposed by the rest api
5
5
  * @protected
6
6
  */
7
7
  declare class Ratelimiter {
8
+ /**
9
+ * An object of Buckets that store rate limit info
10
+ */
8
11
  buckets: {
9
12
  [routeKey: string]: LocalBucket;
10
13
  };
11
- global: boolean;
12
- globalResetAt: number;
13
14
  /**
14
- * This is an interval to constantly check Buckets which should be reset or unreferenced from the RateLimiter to be swept by the garbage collector.
15
- * This 1 timeout is more performant as compared to potentially many more ticking timers to reset individual bucket remaining values.
16
- *
17
- * YOU SHOULD NEVER OVERRIDE THIS UNLESS YOU KNOW WHAT YOU'RE DOING. REQUESTS MAY POSSIBLY NEVER EXECUTE WITHOUT THIS AND/OR MEMORY MAY SLOWLY CLIMB OVER TIME.
15
+ * If you're being globally rate limited
16
+ */
17
+ private _global;
18
+ /**
19
+ * Timeframe in milliseconds until when the global rate limit resets
20
+ */
21
+ globalReset: number;
22
+ /**
23
+ * Timeout that resets the global ratelimit once the timeframe has passed
24
+ */
25
+ globalResetTimeout: NodeJS.Timeout | null;
26
+ static default: typeof Ratelimiter;
27
+ /**
28
+ * If you're being globally rate limited
29
+ */
30
+ get global(): boolean;
31
+ /**
32
+ * If you're being globally rate limited
18
33
  */
19
- protected _timeout: NodeJS.Timeout;
20
- protected _timeoutFN: () => void;
21
- protected _timeoutDuration: number;
22
- constructor();
34
+ set global(value: boolean);
23
35
  /**
24
36
  * Returns a key for saving ratelimits for routes
25
37
  * (Taken from https://github.com/abalabahaha/eris/blob/master/lib/rest/RequestHandler.js) -> I luv u abal <3
@@ -34,6 +46,6 @@ declare class Ratelimiter {
34
46
  * @param url Endpoint of the request
35
47
  * @param method Http method used by the request
36
48
  */
37
- queue(fn: (bucket: import("./ratelimitBuckets/LocalBucket")) => any, url: string, method: string): void;
49
+ queue(fn: (bucket: import("./LocalBucket")) => any, url: string, method: string): void;
38
50
  }
39
51
  export = Ratelimiter;
@@ -2,37 +2,53 @@
2
2
  var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
- const LocalBucket_1 = __importDefault(require("./ratelimitBuckets/LocalBucket"));
5
+ const LocalBucket_1 = __importDefault(require("./LocalBucket"));
6
6
  /**
7
7
  * Ratelimiter used for handling the ratelimits imposed by the rest api
8
8
  * @protected
9
9
  */
10
10
  class Ratelimiter {
11
11
  constructor() {
12
+ /**
13
+ * An object of Buckets that store rate limit info
14
+ */
12
15
  this.buckets = {};
13
- this.global = false;
14
- this.globalResetAt = 0;
15
- // eslint-disable-next-line @typescript-eslint/no-this-alias
16
- const limiter = this;
17
- this._timeoutFN = function () {
18
- for (const routeKey of Object.keys(limiter.buckets)) {
19
- const bkt = limiter.buckets[routeKey];
20
- if (bkt.resetAt && bkt.resetAt < Date.now()) {
21
- if (bkt.fnQueue.length)
22
- bkt.resetRemaining();
23
- else
24
- delete limiter.buckets[routeKey];
25
- }
26
- else if (!bkt.resetAt && limiter.global && limiter.globalResetAt < Date.now()) {
27
- if (bkt.fnQueue.length)
28
- bkt.checkQueue();
29
- else
30
- delete limiter.buckets[routeKey];
16
+ /**
17
+ * If you're being globally rate limited
18
+ */
19
+ this._global = false;
20
+ /**
21
+ * Timeframe in milliseconds until when the global rate limit resets
22
+ */
23
+ this.globalReset = 0;
24
+ /**
25
+ * Timeout that resets the global ratelimit once the timeframe has passed
26
+ */
27
+ this.globalResetTimeout = null;
28
+ }
29
+ /**
30
+ * If you're being globally rate limited
31
+ */
32
+ get global() {
33
+ return this._global;
34
+ }
35
+ /**
36
+ * If you're being globally rate limited
37
+ */
38
+ set global(value) {
39
+ if (value && this.globalReset) {
40
+ if (this.globalResetTimeout)
41
+ clearTimeout(this.globalResetTimeout);
42
+ this.globalResetTimeout = setTimeout(() => {
43
+ this.globalResetTimeout = null;
44
+ this.globalReset = 0;
45
+ this.global = false;
46
+ for (const bkt of Object.values(this.buckets)) {
47
+ bkt.checkQueue();
31
48
  }
32
- }
33
- };
34
- this._timeoutDuration = 1000;
35
- this._timeout = setInterval(() => { limiter._timeoutFN(); }, limiter._timeoutDuration);
49
+ }, this.globalReset);
50
+ }
51
+ this._global = value;
36
52
  }
37
53
  /**
38
54
  * Returns a key for saving ratelimits for routes
@@ -58,8 +74,9 @@ class Ratelimiter {
58
74
  queue(fn, url, method) {
59
75
  const routeKey = this.routify(url, method);
60
76
  if (!this.buckets[routeKey])
61
- this.buckets[routeKey] = new LocalBucket_1.default(this);
77
+ this.buckets[routeKey] = new LocalBucket_1.default(this, routeKey);
62
78
  this.buckets[routeKey].queue(fn);
63
79
  }
64
80
  }
81
+ Ratelimiter.default = Ratelimiter;
65
82
  module.exports = Ratelimiter;
@@ -73,10 +73,9 @@ declare class RequestHandler extends EventEmitter {
73
73
  * @param method http method to use
74
74
  * @param dataType type of the data being sent
75
75
  * @param data data to send, if any
76
- * @param amount amount of requests previously executed
77
76
  * @returns Result of the request
78
77
  */
79
- request(endpoint: string, method: HTTPMethod, dataType?: "json" | "multipart", data?: any | undefined, amount?: number): Promise<any>;
78
+ request(endpoint: string, method: HTTPMethod, dataType?: "json" | "multipart", data?: any | undefined): Promise<any>;
80
79
  /**
81
80
  * Apply the received ratelimit headers to the ratelimit bucket
82
81
  * @param bkt Ratelimit bucket to apply the headers to
@@ -88,7 +87,6 @@ declare class RequestHandler extends EventEmitter {
88
87
  * @param endpoint Endpoint to use
89
88
  * @param data Data to send
90
89
  * @param useParams Whether to send the data in the body or use query params
91
- * @param amount amount of requests previously executed
92
90
  * @returns Result of the request
93
91
  */
94
92
  private _request;