You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Haha-Yes/event/listeners/messageReactionAdd.js

87 lines
3.0 KiB
JavaScript

6 years ago
const { Listener } = require('discord-akairo');
5 years ago
const fs = require('fs');
let messageID = require('../../json/starboard.json');
6 years ago
5 years ago
6 years ago
class MessageReactionAddListener extends Listener {
6 years ago
constructor() {
super('messagereactionadd', {
emitter: 'client',
event: 'messageReactionAdd'
6 years ago
});
}
async exec(reaction, user) {
if (reaction.message.author == user) return;
5 years ago
let starboardChannel, shameboardChannel, staremote, starcount, shameemote, shamecount;
let messageContent = reaction.message.content;
let messageAttachments = reaction.message.attachments.map(u=> u.url);
// Starboard
5 years ago
if (fs.existsSync(`./board/star${reaction.message.guild.id}.json`)) {
starboardChannel = require(`../../board/star${reaction.message.guild.id}.json`);
staremote = starboardChannel['emote'];
starcount = starboardChannel['count'];
if (reaction.emoji.name == staremote && reaction.count == starcount) {
if (messageID.includes(reaction.message.id)) {
console.log('Message already in starboard!');
} else {
messageID.push(reaction.message.id);
sendEmbed('starboard', staremote, this.client);
}
}
}
//Shameboard
5 years ago
if (fs.existsSync(`./board/shame${reaction.message.guild.id}.json`)) {
shameboardChannel = require(`../../board/shame${reaction.message.guild.id}.json`);
shameemote = shameboardChannel['emote'];
shamecount = shameboardChannel['count'];
if (reaction.emoji.name == shameemote && reaction.count == shamecount) {
if (messageID.includes(reaction.message.id)) {
console.log('Message already in shameboard!');
} else {
messageID.push(reaction.message.id);
sendEmbed('shameboard', shameemote, this.client);
}
}
}
5 years ago
async function sendEmbed(name, emote, client) {
let channel;
if (name == 'starboard') {
channel = client.channels.get(starboardChannel['starboard']);
} else {
channel = client.channels.get(shameboardChannel['shameboard']);
}
5 years ago
let Embed = client.util.embed()
.setColor(reaction.message.member.displayHexColor)
.setAuthor(reaction.message.author.username, reaction.message.author.displayAvatarURL())
.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)
.setFooter(reaction.count + ' ' + emote)
.setTimestamp();
6 years ago
// 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})
5 years ago
.catch(async () => channel.send(messageAttachments, { embed: Embed}));
}
6 years ago
}
}
6 years ago
}
module.exports = MessageReactionAddListener;