From 42426625fc2dfaf93063737f5c5cf93ea0f6962a Mon Sep 17 00:00:00 2001 From: Supositware Date: Tue, 1 Jan 2019 03:49:46 +0100 Subject: [PATCH] starboard --- listeners/messageReactionAdd.js | 51 +++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 listeners/messageReactionAdd.js diff --git a/listeners/messageReactionAdd.js b/listeners/messageReactionAdd.js new file mode 100644 index 00000000..394e18bb --- /dev/null +++ b/listeners/messageReactionAdd.js @@ -0,0 +1,51 @@ +const { Listener } = require('discord-akairo'); +const Discord = require('discord.js'); +const SelfReloadJSON = require('self-reload-json'); + +class MessageReactionAddListener extends Listener { + constructor() { + super('messagereactionadd', { + emitter: 'client', + eventName: 'messageReactionAdd' + }); + } + + async exec(reaction, message, client) { + let messageContent = reaction.message.content; + let messageAttachments = reaction.message.attachments.map(u=> `${u.url}`); + + if (reaction.emoji.name === '🌟' && reaction.count === 4) { + let starboardChannel = new SelfReloadJSON(`./starboard/${reaction.message.guild.id}.json`); + const channel = this.client.channels.get(starboardChannel['starboard']); + + const starEmbed = new Discord.RichEmbed() + .setColor() + .setDescription(messageContent) + .setAuthor(reaction.message.author.username, reaction.message.author.displayAvatarURL) + .setTimestamp() + + channel.send({ embed: starEmbed}); + return channel.send(`From: ${reaction.message.channel}\n${messageAttachments}`); + } + if (reaction.emoji.name === '✡' && reaction.count === 4) { + let shameboardChannel = new SelfReloadJSON(`./starboard/${message.guild.id}.json`); + const channel = client.channels.get(shameboardChannel['shameboard']); + + const starEmbed = new Discord.RichEmbed() + .setColor() + .setDescription(messageContent) + .setAuthor(reaction.message.author.username, reaction.message.author.displayAvatarURL) + .setTimestamp() + + try { + channel.send({ embed: starEmbed}); + await channel.send(messageAttachments); + } catch(err) { + console.error('There is no shameboard'); + } + } + + } +} + +module.exports = MessageReactionAddListener; \ No newline at end of file