I think I got ChannelUpdate working??

This commit is contained in:
hydrabolt
2016-04-30 18:22:09 +01:00
parent 2341c83638
commit 90cf787759
9 changed files with 130 additions and 12 deletions

View File

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

View File

@@ -0,0 +1,39 @@
'use strict';
const Action = require('./Action');
const Constants = require('../../util/Constants');
const CloneObject = require('../../util/CloneObject');
const Message = require('../../structures/Message');
class ChannelUpdateAction extends Action {
constructor(client) {
super(client);
}
handle(data) {
let client = this.client;
let channel = client.store.get('channels', data.id);
if (channel) {
let oldChannel = CloneObject(channel);
channel.setup(data);
if (!oldChannel.equals(data)) {
client.emit(Constants.Events.CHANNEL_UPDATE, oldChannel, channel);
}
return {
old: oldChannel,
updated: channel,
};
}
return {
old: null,
updated: null,
};
}
};
module.exports = ChannelUpdateAction;

View File

@@ -25,7 +25,13 @@ class MessageUpdateAction extends Action {
old: oldMessage,
updated: message,
};
client.emit(Constants.Events.MESSAGE_UPDATE, oldMessage, message);
}
return {
old: message,
updated: message,
};
}
return {

View File

@@ -96,6 +96,21 @@ class RESTMethods{
.catch(reject);
});
}
UpdateChannel(channel, data) {
return new Promise((resolve, reject) => {
data.name = (data.name || channel.name).trim();
data.topic = data.topic || channel.topic;
data.position = data.position || channel.position;
data.bitrate = data.bitrate || channel.bitrate;
this.rest.makeRequest('patch', Constants.Endpoints.CHANNEL(channel.id), true, data)
.then(data => {
resolve(this.rest.client.actions.ChannelUpdate.handle(data).updated);
})
.catch(reject);
});
}
}
module.exports = RESTMethods;

View File

@@ -20,12 +20,7 @@ class ChannelUpdateHandler extends AbstractHandler {
let data = packet.d;
let client = this.packetManager.client;
let channel = client.store.get('channels', data.id);
if (channel) {
client.store.UpdateChannel(channel, data);
}
client.actions.ChannelUpdate.handle(data);
}
};

View File

@@ -20,10 +20,6 @@ class MessageUpdateHandler extends AbstractHandler {
let response = client.actions.MessageUpdate.handle(data);
if (response.old) {
client.emit(Constants.Events.MESSAGE_UPDATE, response.old, response.updated);
}
}
};