Added channel.delete()

This commit is contained in:
hydrabolt
2016-04-27 16:25:57 +01:00
parent b436fac5c4
commit 2341c83638
7 changed files with 51 additions and 8 deletions

View File

@@ -10,6 +10,7 @@ class ActionsManager {
this.register('MessageDelete');
this.register('MessageUpdate');
this.register('ChannelCreate');
this.register('ChannelDelete');
}
register(name) {

View File

@@ -0,0 +1,27 @@
'use strict';
const Action = require('./Action');
const Constants = require('../../util/Constants');
const Message = require('../../structures/Message');
class ChannelDeleteAction extends Action {
constructor(client) {
super(client);
}
handle(data) {
let client = this.client;
let channel = client.store.get('channels', data.id);
if (channel) {
client.store.KillChannel(channel);
}
return {
channel,
};
}
};
module.exports = ChannelDeleteAction;

View File

@@ -85,6 +85,17 @@ class RESTMethods{
.catch(reject);
});
}
DeleteChannel(channel) {
return new Promise((resolve, reject) => {
this.rest.makeRequest('del', Constants.Endpoints.CHANNEL(channel.id), true)
.then(data => {
data.id = channel.id;
resolve(this.rest.client.actions.ChannelDelete.handle(data).channel);
})
.catch(reject);
});
}
}
module.exports = RESTMethods;

View File

@@ -19,10 +19,10 @@ class ChannelDeleteHandler extends AbstractHandler {
let data = packet.d;
let client = this.packetManager.client;
let channel = client.store.get('channels', data.id);
let response = client.actions.ChannelCreate.handle(data);
if (channel) {
client.store.KillChannel(channel);
if (response.channel) {
client.emit(Constants.Events.CHANNEL_DELETE, response.channel);
}
}

View File

@@ -17,6 +17,10 @@ class Channel {
setup(data) {
this.id = data.id;
}
delete() {
return this.client.rest.methods.DeleteChannel(this);
}
}
module.exports = Channel;

View File

@@ -87,10 +87,6 @@ class ClientDataStore extends AbstractDataStore{
if (channel instanceof ServerChannel) {
channel.guild.store.remove('channels', channel);
}
if (already && this.pastReady) {
this.client.emit(Constants.Events.CHANNEL_DELETE, channel);
}
}
UpdateGuild(currentGuild, newData) {

View File

@@ -23,7 +23,7 @@ client.on('channelCreate', channel => {
// console.log(channel);
});
client.on('channelDelete', channel => {
console.log(channel);
console.log('channDel', channel);
});
client.on('channelUpdate', (old, chan) => {
@@ -75,6 +75,10 @@ client.on('message', message => {
message.channel.guild.createChannel('hi', 'text').then(console.log);
}
}
if (message.content === 'delchann') {
message.channel.delete();
}
}
});