Skip to content
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

refactor(Actions): remove deleted maps #7076

Merged
merged 2 commits into from
Jan 7, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions packages/discord.js/src/client/Client.js
Original file line number Diff line number Diff line change
Expand Up @@ -577,9 +577,6 @@ class Client extends BaseClient {
if (typeof options.waitGuildTimeout !== 'number' || isNaN(options.waitGuildTimeout)) {
throw new TypeError('CLIENT_INVALID_OPTION', 'waitGuildTimeout', 'a number');
}
if (typeof options.restWsBridgeTimeout !== 'number' || isNaN(options.restWsBridgeTimeout)) {
throw new TypeError('CLIENT_INVALID_OPTION', 'restWsBridgeTimeout', 'a number');
}
if (typeof options.restRequestTimeout !== 'number' || isNaN(options.restRequestTimeout)) {
throw new TypeError('CLIENT_INVALID_OPTION', 'restRequestTimeout', 'a number');
}
Expand Down
7 changes: 0 additions & 7 deletions packages/discord.js/src/client/actions/ChannelDelete.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,6 @@ const { deletedMessages } = require('../../structures/Message');
const { Events } = require('../../util/Constants');

class ChannelDeleteAction extends Action {
constructor(client) {
super(client);
this.deleted = new Map();
}

handle(data) {
const client = this.client;
const channel = client.channels.cache.get(data.id);
Expand All @@ -31,8 +26,6 @@ class ChannelDeleteAction extends Action {
*/
client.emit(Events.CHANNEL_DELETE, channel);
}

return { channel };
}
}

Expand Down
21 changes: 1 addition & 20 deletions packages/discord.js/src/client/actions/GuildDelete.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,10 @@
'use strict';

const { setTimeout } = require('node:timers');
const Action = require('./Action');
const { deletedGuilds } = require('../../structures/Guild');
const { Events } = require('../../util/Constants');

class GuildDeleteAction extends Action {
constructor(client) {
super(client);
this.deleted = new Map();
}

handle(data) {
const client = this.client;

Expand All @@ -29,9 +23,7 @@ class GuildDeleteAction extends Action {

// Stops the GuildDelete packet thinking a guild was actually deleted,
// handles emitting of event itself
return {
guild: null,
};
return;
}

for (const channel of guild.channels.cache.values()) this.client.channels._remove(channel.id);
Expand All @@ -47,18 +39,7 @@ class GuildDeleteAction extends Action {
* @param {Guild} guild The guild that was deleted
*/
client.emit(Events.GUILD_DELETE, guild);

this.deleted.set(guild.id, guild);
this.scheduleForDeletion(guild.id);
} else {
guild = this.deleted.get(data.id) ?? null;
}

return { guild };
}

scheduleForDeletion(id) {
setTimeout(() => this.deleted.delete(id), this.client.options.restWsBridgeTimeout).unref();
}
}

Expand Down
4 changes: 2 additions & 2 deletions packages/discord.js/src/structures/Guild.js
Original file line number Diff line number Diff line change
Expand Up @@ -1246,7 +1246,7 @@ class Guild extends AnonymousGuild {
async leave() {
if (this.ownerId === this.client.user.id) throw new Error('GUILD_OWNED');
await this.client.api.users('@me').guilds(this.id).delete();
return this.client.actions.GuildDelete.handle({ id: this.id }).guild;
return this;
}

/**
Expand All @@ -1260,7 +1260,7 @@ class Guild extends AnonymousGuild {
*/
async delete() {
await this.client.api.guilds(this.id).delete();
return this.client.actions.GuildDelete.handle({ id: this.id }).guild;
return this;
}

/**
Expand Down
3 changes: 0 additions & 3 deletions packages/discord.js/src/util/Options.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,6 @@ const process = require('node:process');
* they're missing all the data for a particular structure. See the "Partial Structures" topic on the
* [guide](https://discordjs.guide/popular-topics/partials.html) for some
* important usage information, as partials require you to put checks in place when handling data.
* @property {number} [restWsBridgeTimeout=5000] Maximum time permitted between REST responses and their
* corresponding WebSocket events
* @property {number} [restTimeOffset=500] Extra time in milliseconds to wait before continuing to make REST
* requests (higher values will reduce rate-limiting errors on bad connections)
* @property {number} [restRequestTimeout=15000] Time to wait before cancelling a REST request, in milliseconds
Expand Down Expand Up @@ -139,7 +137,6 @@ class Options extends null {
messageSweepInterval: 0,
invalidRequestWarningInterval: 0,
partials: [],
restWsBridgeTimeout: 5_000,
restRequestTimeout: 15_000,
restGlobalRateLimit: 0,
retryLimit: 1,
Expand Down
1 change: 0 additions & 1 deletion packages/discord.js/typings/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3988,7 +3988,6 @@ export interface ClientOptions {
allowedMentions?: MessageMentionOptions;
invalidRequestWarningInterval?: number;
partials?: PartialTypes[];
restWsBridgeTimeout?: number;
restTimeOffset?: number;
restRequestTimeout?: number;
restGlobalRateLimit?: number;
Expand Down