mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-11 00:53:31 +01:00
Add MessageUpdate handling
This commit is contained in:
@@ -39,6 +39,7 @@ class WebSocketPacketManager {
|
||||
this.register(Constants.WSEvents.TYPING_START, 'TypingStart');
|
||||
this.register(Constants.WSEvents.MESSAGE_CREATE, 'MessageCreate');
|
||||
this.register(Constants.WSEvents.MESSAGE_DELETE, 'MessageDelete');
|
||||
this.register(Constants.WSEvents.MESSAGE_UPDATE, 'MessageUpdate');
|
||||
}
|
||||
|
||||
get client() {
|
||||
|
||||
35
src/client/websocket/packets/handlers/MessageUpdate.js
Normal file
35
src/client/websocket/packets/handlers/MessageUpdate.js
Normal file
@@ -0,0 +1,35 @@
|
||||
'use strict';
|
||||
|
||||
const AbstractHandler = require('./AbstractHandler');
|
||||
const Structure = name => require(`../../../../structures/${name}`);
|
||||
const Constants = require('../../../../util/Constants');
|
||||
const CloneObject = require('../../../../util/CloneObject');
|
||||
|
||||
const Message = Structure('Message');
|
||||
const Guild = Structure('Guild');
|
||||
|
||||
class MessageUpdateHandler extends AbstractHandler {
|
||||
|
||||
constructor(packetManager) {
|
||||
super(packetManager);
|
||||
}
|
||||
|
||||
handle(packet) {
|
||||
let data = packet.d;
|
||||
let client = this.packetManager.client;
|
||||
let channel = client.store.get('channels', data.channel_id);
|
||||
|
||||
if (channel) {
|
||||
let message = channel.store.get('messages', data.id);
|
||||
if (message) {
|
||||
let oldMessage = CloneObject(message);
|
||||
message.patch(data);
|
||||
client.emit(Constants.Events.MESSAGE_UPDATE, oldMessage, message);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
module.exports = MessageUpdateHandler;
|
||||
Reference in New Issue
Block a user