refactor(Actions): remove deleted maps (#7076)

This commit is contained in:
Jan
2022-01-08 00:34:47 +01:00
committed by GitHub
parent fbe40031cf
commit 5022b14da0
6 changed files with 3 additions and 36 deletions

View File

@@ -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');
}

View File

@@ -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);
@@ -31,8 +26,6 @@ class ChannelDeleteAction extends Action {
*/
client.emit(Events.CHANNEL_DELETE, channel);
}
return { channel };
}
}

View File

@@ -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;
@@ -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);
@@ -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();
}
}

View File

@@ -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;
}
/**
@@ -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;
}
/**

View File

@@ -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
@@ -139,7 +137,6 @@ class Options extends null {
messageSweepInterval: 0,
invalidRequestWarningInterval: 0,
partials: [],
restWsBridgeTimeout: 5_000,
restRequestTimeout: 15_000,
restGlobalRateLimit: 0,
retryLimit: 1,

View File

@@ -3988,7 +3988,6 @@ export interface ClientOptions {
allowedMentions?: MessageMentionOptions;
invalidRequestWarningInterval?: number;
partials?: PartialTypes[];
restWsBridgeTimeout?: number;
restTimeOffset?: number;
restRequestTimeout?: number;
restGlobalRateLimit?: number;