mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-10 16:43:31 +01:00
I think I got ChannelUpdate working??
This commit is contained in:
@@ -11,6 +11,7 @@ class ActionsManager {
|
||||
this.register('MessageUpdate');
|
||||
this.register('ChannelCreate');
|
||||
this.register('ChannelDelete');
|
||||
this.register('ChannelUpdate');
|
||||
}
|
||||
|
||||
register(name) {
|
||||
|
||||
39
src/client/actions/ChannelUpdate.js
Normal file
39
src/client/actions/ChannelUpdate.js
Normal 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;
|
||||
@@ -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 {
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user