-
-
Notifications
You must be signed in to change notification settings - Fork 4k
feat(GuildMemberManager): handle gateway request ratelimit #11252
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
didinele
wants to merge
9
commits into
main
Choose a base branch
from
feat/mainlib-fetch-g-member-limit
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+69
−23
Open
Changes from 7 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
d89eae9
feat(GuildMemberManager): handle gateway request ratelimit
didinele d0cba2e
chore: typo no one saw
didinele e2ce83d
fix: cleanup listener properly
didinele 2528a50
types: add error code
Jiralite d362a34
refactor: requested changes
didinele 655c169
fix: update emitted warning
didinele 9edfadb
chore: requested changes
didinele a0bad68
refactor: remove event
didinele 263f1e3
refactor: warning
didinele File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
67 changes: 67 additions & 0 deletions
67
packages/discord.js/src/client/websocket/handlers/RATE_LIMITED.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,67 @@ | ||
| 'use strict'; | ||
|
|
||
| const process = require('node:process'); | ||
| const { GatewayOpcodes } = require('discord-api-types/v10'); | ||
| const { Events } = require('../../../util/Events.js'); | ||
|
|
||
| let emittedWarning = false; | ||
|
|
||
| module.exports = (client, { d: data }) => { | ||
| /** | ||
| * Represents metadata for a gateway request guild member rate limit event | ||
| * | ||
| * @typedef {Object} GatewayRequestGuildMemberRateLimitMetaData | ||
| * @property {Guild} guild The guild related to the rate limited request | ||
| * @property {string} nonce The nonce used in the request that was rate limited | ||
| */ | ||
|
|
||
| /** | ||
| * Represents additional metadata for a gateway rate limited event | ||
| * | ||
| * @typedef {GatewayRequestGuildMemberRateLimitMetaData} GatewayRateLimitMetaData | ||
| */ | ||
|
|
||
| /** | ||
| * Represents the information provided by Discord when a gateway ratelimit is hit. | ||
| * | ||
| * @typedef {Object} GatewayRateLimitData | ||
| * @property {GatewayOpCodes} opcode The opcode of the event that triggered the rate limit | ||
| * @property {number} retryAfter The number of seconds to wait before submitting another request | ||
| * @property {GatewayRateLimitMetaData} [meta] Additional metadata for the event that was rate limited. Missing for unknown opcodes. | ||
| */ | ||
|
|
||
| let meta; | ||
| switch (data.opcode) { | ||
| case GatewayOpcodes.RequestGuildMembers: { | ||
| const guild = client.guilds.cache.get(data.meta.guild_id); | ||
|
|
||
| meta = { | ||
| guild, | ||
| nonce: data.nonce, | ||
| }; | ||
|
|
||
| break; | ||
| } | ||
|
|
||
| default: { | ||
| if (!emittedWarning && !client.listenerCount(Events.RateLimited)) { | ||
| process.emitWarning( | ||
| `Received a rate limit for an unknown opcode: ${data.opcode}. For additional information, listen to the Client#rateLimited event.`, | ||
| ); | ||
| emittedWarning = true; | ||
| } | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Emitted whenever a gateway rate limit is hit. | ||
| * | ||
| * @event Client#rateLimited | ||
| * @param {GatewayRateLimitData} rateLimitData The data related to the rate limit | ||
| */ | ||
| client.emit(Events.RateLimited, { | ||
| opcode: data.opcode, | ||
| retryAfter: data.retry_after, | ||
| meta, | ||
| }); | ||
| }; | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.