MessageDelete handling

This commit is contained in:
hydrabolt
2016-04-18 18:06:31 +01:00
parent c947e172d6
commit d437fd31cf
7 changed files with 44 additions and 2 deletions

View File

@@ -38,6 +38,7 @@ class WebSocketPacketManager {
this.register(Constants.WSEvents.VOICE_STATE_UPDATE, 'VoiceStateUpdate');
this.register(Constants.WSEvents.TYPING_START, 'TypingStart');
this.register(Constants.WSEvents.MESSAGE_CREATE, 'MessageCreate');
this.register(Constants.WSEvents.MESSAGE_DELETE, 'MessageDelete');
}
get client() {

View File

@@ -0,0 +1,32 @@
'use strict';
const AbstractHandler = require('./AbstractHandler');
const Structure = name => require(`../../../../structures/${name}`);
const Constants = require('../../../../util/Constants');
const Message = Structure('Message');
const Guild = Structure('Guild');
class MessageDeleteHandler 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) {
channel.store.remove('messages', message.id);
client.emit(Constants.Events.MESSAGE_DELETE, message);
}
}
}
};
module.exports = MessageDeleteHandler;

View File

@@ -20,8 +20,9 @@ class DMChannel extends Channel{
let storeKeys = Object.keys(this.store);
if (storeKeys.length >= maxSize) {
this.store.remove(storeKeys[0]);
this.store.add('messages', message);
}
this.store.add('messages', message);
}
setup(data) {

View File

@@ -20,6 +20,7 @@ class Message {
this.embeds = data.embeds;
this.attachments = data.attachments;
this.mentions = [];
this.id = data.id;
for (let mention of data.mentions) {
let user = this.guild.client.store.get('users', mention.id);
if (user) {

View File

@@ -20,8 +20,9 @@ class TextChannel extends ServerChannel {
let storeKeys = Object.keys(this.store);
if (storeKeys.length >= maxSize) {
this.store.remove(storeKeys[0]);
this.store.add('messages', message);
}
this.store.add('messages', message);
}
}

View File

@@ -100,6 +100,7 @@ const Events = exports.Events = {
WARN: 'warn',
GUILD_MEMBERS_CHUNK: 'guildMembersChunk',
MESSAGE_CREATE: 'message',
MESSAGE_DELETE: 'messageDelete',
};
const WSEvents = exports.WSEvents = {

View File

@@ -68,5 +68,10 @@ client.on('typingStop.', (channel, user, data) => {
});
client.on('message', message => {
if (message.author.username === 'hydrabolt')
console.log(message.author.username, 'said', message.content, 'in', message.channel.name);
});
client.on('messageDelete', message => {
console.log('Message deleted by', message.author.username);
});