Added Guild Deletion

This commit is contained in:
hydrabolt
2016-05-01 14:51:46 +01:00
parent 3a0426482e
commit f95c588d87
12 changed files with 129 additions and 26 deletions

View File

@@ -0,0 +1,54 @@
'use strict';
const Action = require('./Action');
const Constants = require('../../util/Constants');
const Message = require('../../structures/Message');
class GuildDeleteAction extends Action {
constructor(client) {
super(client);
this.deleted = {};
this.timeouts = [];
}
handle(data) {
let client = this.client;
let guild = client.store.get('guilds', data.id);
if (guild) {
if (guild.available && data.unavailable) {
// guild is unavailable
guild.available = false;
client.emit(Constants.Events.GUILD_UNAVAILABLE, guild);
// stops the GuildDelete packet thinking a guild was actually deleted,
// handles emitting of event itself
return {
guild: null,
};
} else {
// delete guild
client.store.remove('guilds', guild);
this.deleted[guild.id] = guild;
this.scheduleForDeletion(guild.id);
}
} else if (this.deleted[data.id]) {
guild = this.deleted[data.id];
}
return {
guild,
};
}
scheduleForDeletion(id) {
this.timeouts.push(
setTimeout(() => delete this.deleted[id],
this.client.options.rest_ws_bridge_timeout)
);
}
};
module.exports = GuildDeleteAction;