Start work on adding reaction support

This commit is contained in:
Amish Shah
2016-10-27 15:22:42 +01:00
parent dd31ee0c5f
commit 81059885a2
12 changed files with 252 additions and 3 deletions

View File

@@ -6,6 +6,8 @@ class ActionsManager {
this.register('MessageDelete');
this.register('MessageDeleteBulk');
this.register('MessageUpdate');
this.register('MessageReactionAdd');
this.register('MessageReactionRemove');
this.register('ChannelCreate');
this.register('ChannelDelete');
this.register('ChannelUpdate');

View File

@@ -0,0 +1,38 @@
const Action = require('./Action');
const Constants = require('../../util/Constants');
/*
{ user_id: 'id',
message_id: 'id',
emoji: { name: '<27>', id: null },
channel_id: 'id' } }
*/
class MessageReactionAdd extends Action {
handle(data) {
const user = this.client.users.get(data.user_id);
if (!user) return false;
const channel = this.client.channels.get(data.channel_id);
if (!channel || channel.type === 'voice') return false;
const message = channel.messages.get(data.message_id);
if (!message) return false;
if (!data.emoji) return false;
const reaction = message._addReaction(data.emoji, user);
if (reaction) {
this.client.emit(Constants.Events.MESSAGE_REACTION_ADD, reaction, user);
}
return {
message,
reaction,
user,
};
}
}
module.exports = MessageReactionAdd;

View File

@@ -0,0 +1,38 @@
const Action = require('./Action');
const Constants = require('../../util/Constants');
/*
{ user_id: 'id',
message_id: 'id',
emoji: { name: '<27>', id: null },
channel_id: 'id' } }
*/
class MessageReactionRemove extends Action {
handle(data) {
const user = this.client.users.get(data.user_id);
if (!user) return false;
const channel = this.client.channels.get(data.channel_id);
if (!channel || channel.type === 'voice') return false;
const message = channel.messages.get(data.message_id);
if (!message) return false;
if (!data.emoji) return false;
const reaction = message._removeReaction(data.emoji, user);
if (reaction) {
this.client.emit(Constants.Events.MESSAGE_REACTION_REMOVE, reaction, user);
}
return {
message,
reaction,
user,
};
}
}
module.exports = MessageReactionRemove;