Files
discord.js-selfbot/src/client/actions/GuildDelete.js

66 lines
1.8 KiB
JavaScript
Raw Normal View History

2022-03-19 17:37:45 +07:00
'use strict';
const { setTimeout } = require('node:timers');
2022-03-19 17:37:45 +07:00
const Action = require('./Action');
const { deletedGuilds } = require('../../structures/Guild');
const { Events } = require('../../util/Constants');
2022-03-19 17:37:45 +07:00
class GuildDeleteAction extends Action {
constructor(client) {
super(client);
this.deleted = new Map();
}
2022-03-19 17:37:45 +07:00
handle(data) {
const client = this.client;
let guild = client.guilds.cache.get(data.id);
if (guild) {
if (data.unavailable) {
// Guild is unavailable
guild.available = false;
/**
* Emitted whenever a guild becomes unavailable, likely due to a server outage.
* @event Client#guildUnavailable
* @param {Guild} guild The guild that has become unavailable
*/
client.emit(Events.GUILD_UNAVAILABLE, guild);
2022-03-19 17:37:45 +07:00
// Stops the GuildDelete packet thinking a guild was actually deleted,
// handles emitting of event itself
return {
guild: null,
};
2022-03-19 17:37:45 +07:00
}
for (const channel of guild.channels.cache.values()) this.client.channels._remove(channel.id);
client.voice.adapters.get(data.id)?.destroy();
// Delete guild
client.guilds.cache.delete(guild.id);
deletedGuilds.add(guild);
2022-03-19 17:37:45 +07:00
/**
* Emitted whenever a guild kicks the client or the guild is deleted/left.
* @event Client#guildDelete
* @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;
2022-03-19 17:37:45 +07:00
}
return { guild };
}
scheduleForDeletion(id) {
setTimeout(() => this.deleted.delete(id), this.client.options.restWsBridgeTimeout).unref();
2022-03-19 17:37:45 +07:00
}
}
module.exports = GuildDeleteAction;