mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-18 04:23:31 +01:00
refactor(Actions): remove deleted maps (#7076)
This commit is contained in:
@@ -577,9 +577,6 @@ class Client extends BaseClient {
|
|||||||
if (typeof options.waitGuildTimeout !== 'number' || isNaN(options.waitGuildTimeout)) {
|
if (typeof options.waitGuildTimeout !== 'number' || isNaN(options.waitGuildTimeout)) {
|
||||||
throw new TypeError('CLIENT_INVALID_OPTION', 'waitGuildTimeout', 'a number');
|
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)) {
|
if (typeof options.restRequestTimeout !== 'number' || isNaN(options.restRequestTimeout)) {
|
||||||
throw new TypeError('CLIENT_INVALID_OPTION', 'restRequestTimeout', 'a number');
|
throw new TypeError('CLIENT_INVALID_OPTION', 'restRequestTimeout', 'a number');
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,11 +7,6 @@ const { deletedMessages } = require('../../structures/Message');
|
|||||||
const { Events } = require('../../util/Constants');
|
const { Events } = require('../../util/Constants');
|
||||||
|
|
||||||
class ChannelDeleteAction extends Action {
|
class ChannelDeleteAction extends Action {
|
||||||
constructor(client) {
|
|
||||||
super(client);
|
|
||||||
this.deleted = new Map();
|
|
||||||
}
|
|
||||||
|
|
||||||
handle(data) {
|
handle(data) {
|
||||||
const client = this.client;
|
const client = this.client;
|
||||||
const channel = client.channels.cache.get(data.id);
|
const channel = client.channels.cache.get(data.id);
|
||||||
@@ -31,8 +26,6 @@ class ChannelDeleteAction extends Action {
|
|||||||
*/
|
*/
|
||||||
client.emit(Events.CHANNEL_DELETE, channel);
|
client.emit(Events.CHANNEL_DELETE, channel);
|
||||||
}
|
}
|
||||||
|
|
||||||
return { channel };
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,16 +1,10 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
const { setTimeout } = require('node:timers');
|
|
||||||
const Action = require('./Action');
|
const Action = require('./Action');
|
||||||
const { deletedGuilds } = require('../../structures/Guild');
|
const { deletedGuilds } = require('../../structures/Guild');
|
||||||
const { Events } = require('../../util/Constants');
|
const { Events } = require('../../util/Constants');
|
||||||
|
|
||||||
class GuildDeleteAction extends Action {
|
class GuildDeleteAction extends Action {
|
||||||
constructor(client) {
|
|
||||||
super(client);
|
|
||||||
this.deleted = new Map();
|
|
||||||
}
|
|
||||||
|
|
||||||
handle(data) {
|
handle(data) {
|
||||||
const client = this.client;
|
const client = this.client;
|
||||||
|
|
||||||
@@ -29,9 +23,7 @@ class GuildDeleteAction extends Action {
|
|||||||
|
|
||||||
// Stops the GuildDelete packet thinking a guild was actually deleted,
|
// Stops the GuildDelete packet thinking a guild was actually deleted,
|
||||||
// handles emitting of event itself
|
// handles emitting of event itself
|
||||||
return {
|
return;
|
||||||
guild: null,
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
for (const channel of guild.channels.cache.values()) this.client.channels._remove(channel.id);
|
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
|
* @param {Guild} guild The guild that was deleted
|
||||||
*/
|
*/
|
||||||
client.emit(Events.GUILD_DELETE, guild);
|
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();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1246,7 +1246,7 @@ class Guild extends AnonymousGuild {
|
|||||||
async leave() {
|
async leave() {
|
||||||
if (this.ownerId === this.client.user.id) throw new Error('GUILD_OWNED');
|
if (this.ownerId === this.client.user.id) throw new Error('GUILD_OWNED');
|
||||||
await this.client.api.users('@me').guilds(this.id).delete();
|
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() {
|
async delete() {
|
||||||
await this.client.api.guilds(this.id).delete();
|
await this.client.api.guilds(this.id).delete();
|
||||||
return this.client.actions.GuildDelete.handle({ id: this.id }).guild;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -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
|
* 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
|
* [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.
|
* 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
|
* @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)
|
* 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
|
* @property {number} [restRequestTimeout=15000] Time to wait before cancelling a REST request, in milliseconds
|
||||||
@@ -139,7 +137,6 @@ class Options extends null {
|
|||||||
messageSweepInterval: 0,
|
messageSweepInterval: 0,
|
||||||
invalidRequestWarningInterval: 0,
|
invalidRequestWarningInterval: 0,
|
||||||
partials: [],
|
partials: [],
|
||||||
restWsBridgeTimeout: 5_000,
|
|
||||||
restRequestTimeout: 15_000,
|
restRequestTimeout: 15_000,
|
||||||
restGlobalRateLimit: 0,
|
restGlobalRateLimit: 0,
|
||||||
retryLimit: 1,
|
retryLimit: 1,
|
||||||
|
|||||||
1
packages/discord.js/typings/index.d.ts
vendored
1
packages/discord.js/typings/index.d.ts
vendored
@@ -3988,7 +3988,6 @@ export interface ClientOptions {
|
|||||||
allowedMentions?: MessageMentionOptions;
|
allowedMentions?: MessageMentionOptions;
|
||||||
invalidRequestWarningInterval?: number;
|
invalidRequestWarningInterval?: number;
|
||||||
partials?: PartialTypes[];
|
partials?: PartialTypes[];
|
||||||
restWsBridgeTimeout?: number;
|
|
||||||
restTimeOffset?: number;
|
restTimeOffset?: number;
|
||||||
restRequestTimeout?: number;
|
restRequestTimeout?: number;
|
||||||
restGlobalRateLimit?: number;
|
restGlobalRateLimit?: number;
|
||||||
|
|||||||
Reference in New Issue
Block a user