Haha-Yes/event/listeners/messageReactionAdd.js

87 lines
3 KiB
JavaScript
Raw Normal View History

2019-01-01 03:49:46 +01:00
const { Listener } = require('discord-akairo');
2019-06-28 03:50:16 +02:00
const fs = require('fs');
2019-01-10 09:00:30 +01:00
let messageID = require('../../json/starboard.json');
2019-01-01 03:49:46 +01:00
2019-06-28 03:50:16 +02:00
2019-01-01 03:49:46 +01:00
class MessageReactionAddListener extends Listener {
2019-01-02 08:09:45 +01:00
constructor() {
super('messagereactionadd', {
emitter: 'client',
2019-01-02 21:46:12 +01:00
event: 'messageReactionAdd'
2019-01-02 08:09:45 +01:00
});
}
async exec(reaction, user) {
2019-03-19 21:05:47 +01:00
if (reaction.message.author == user) return;
2019-06-28 03:50:16 +02:00
let starboardChannel, shameboardChannel, staremote, starcount, shameemote, shamecount;
2019-06-30 22:47:25 +02:00
let messageContent = reaction.message.content;
let messageAttachments = reaction.message.attachments.map(u=> u.url);
2019-07-11 17:30:26 +02:00
// Starboard
2019-06-28 03:50:16 +02:00
if (fs.existsSync(`./board/star${reaction.message.guild.id}.json`)) {
starboardChannel = require(`../../board/star${reaction.message.guild.id}.json`);
2019-02-15 01:09:08 +01:00
staremote = starboardChannel['emote'];
starcount = starboardChannel['count'];
2019-06-30 22:47:25 +02:00
if (reaction.emoji.name == staremote && reaction.count == starcount) {
2019-07-11 17:30:26 +02:00
if (messageID.includes(reaction.message.id)) {
console.log('Message already in starboard!');
} else {
messageID.push(reaction.message.id);
sendEmbed('starboard', staremote, this.client);
}
2019-06-30 22:47:25 +02:00
}
2019-02-15 01:09:08 +01:00
}
2019-06-30 22:47:25 +02:00
2019-07-11 17:30:26 +02:00
//Shameboard
2019-06-28 03:50:16 +02:00
if (fs.existsSync(`./board/shame${reaction.message.guild.id}.json`)) {
shameboardChannel = require(`../../board/shame${reaction.message.guild.id}.json`);
2019-02-15 01:09:08 +01:00
shameemote = shameboardChannel['emote'];
shamecount = shameboardChannel['count'];
2019-02-14 18:44:21 +01:00
2019-06-30 22:47:25 +02:00
if (reaction.emoji.name == shameemote && reaction.count == shamecount) {
2019-07-11 17:30:26 +02:00
if (messageID.includes(reaction.message.id)) {
console.log('Message already in shameboard!');
} else {
messageID.push(reaction.message.id);
sendEmbed('shameboard', shameemote, this.client);
}
2019-06-30 22:47:25 +02:00
}
2019-03-30 03:50:35 +01:00
}
2019-03-30 03:50:35 +01:00
function sendEmbed(name, emote, client) {
let channel;
if (name == 'starboard') {
channel = client.channels.get(starboardChannel['starboard']);
} else {
channel = client.channels.get(shameboardChannel['shameboard']);
}
2019-01-15 19:22:23 +01:00
2019-11-22 12:30:20 +01:00
let Embed = this.client.util.embed()
2019-01-04 19:43:10 +01:00
.setColor(reaction.message.member.displayHexColor)
.setAuthor(reaction.message.author.username, reaction.message.author.displayAvatarURL())
2019-06-22 17:48:17 +02:00
.addField('Jump to', `[message](https://discordapp.com/channels/${reaction.message.guild.id}/${reaction.message.channel.id}/${reaction.message.id})`, true)
.addField('Channel', reaction.message.channel, true)
2019-03-30 03:50:35 +01:00
.setFooter(reaction.count + ' ' + emote)
.setTimestamp();
2019-01-02 08:09:45 +01:00
// if message come from nsfw channel and the star/shameboard channel isn't nsfw put it in spoiler
if (reaction.message.channel.nsfw && !channel.nsfw) {
Embed.setDescription(`||${messageContent}||`);
if (messageAttachments != '') {
return channel.send(`||${messageAttachments}||`, {embed: Embed});
}
else {
return channel.send({embed: Embed});
}
} else {
Embed.setDescription(messageContent);
return channel.send({files: messageAttachments, embed: Embed})
.catch(() => channel.send(messageAttachments, { embed: Embed}));
}
2019-01-02 08:09:45 +01:00
}
}
2019-01-01 03:49:46 +01:00
}
module.exports = MessageReactionAddListener;