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

119 lines
4.3 KiB
JavaScript

6 years ago
const { Listener } = require('discord-akairo');
const { MessageEmbed } = require('discord.js');
const reload = require('auto-reload');
let messageID = require('../../json/starboard.json');
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;
6 years ago
let messageContent = reaction.message.content;
let messageAttachments = reaction.message.attachments.map(u=> u.url);
let starboardChannel;
let staremote;
let starcount;
try {
starboardChannel = reload(`../../board/star${reaction.message.guild.id}.json`);
staremote = starboardChannel['emote'];
starcount = starboardChannel['count'];
} catch (err) {
return null;
}
6 years ago
// Starboard
if (reaction.emoji.name == staremote && reaction.count == starcount) {
if (messageID.includes(reaction.message.id))
return console.log('Message already in starboard!');
messageID.push(reaction.message.id);
6 years ago
const channel = this.client.channels.get(starboardChannel['starboard']);
if (!messageContent) {
const starEmbed = new MessageEmbed()
.setColor(reaction.message.member.displayHexColor)
.setAuthor(reaction.message.author.username, reaction.message.author.displayAvatarURL())
.setDescription(`[Jump to message](https://discordapp.com/channels/${reaction.message.guild.id}/${reaction.message.channel.id}/${reaction.message.id})`)
.addField('Channel', reaction.message.channel)
.setFooter(reaction.count + ' ' + staremote)
.setTimestamp();
return channel.send({files: messageAttachments, embed: starEmbed})
.catch(() => channel.send(messageAttachments, { embed: starEmbed }));
}
const starEmbed = new MessageEmbed()
.setColor(reaction.message.member.displayHexColor)
.setAuthor(reaction.message.author.username, reaction.message.author.displayAvatarURL())
.setDescription(messageContent)
5 years ago
.addField('Jump to', `[message](https://discordapp.com/channels/${reaction.message.guild.id}/${reaction.message.channel.id}/${reaction.message.id})`)
.addField('Channel', reaction.message.channel)
.setFooter(reaction.count + ' ' + staremote)
.setTimestamp();
6 years ago
return channel.send({files: messageAttachments, embed: starEmbed})
.catch(() => channel.send(messageAttachments, { embed: starEmbed}));
6 years ago
}
let shameboardChannel;
let shameemote;
let shamecount;
try {
shameboardChannel = reload(`../../board/shame${reaction.message.guild.id}.json`);
shameemote = shameboardChannel['emote'];
shamecount = shameboardChannel['count'];
} catch (err) {
return null;
}
//Shameboard
if (reaction.emoji.name == shameemote && reaction.count == shamecount) {
if (messageID.includes(reaction.message.id))
return console.log('Message already in starboard!');
6 years ago
messageID.push(reaction.message.id);
6 years ago
const channel = this.client.channels.get(shameboardChannel['shameboard']);
6 years ago
if (!messageContent) {
const shameEmbed = new MessageEmbed()
.setColor(reaction.message.member.displayHexColor)
.setAuthor(reaction.message.author.username, reaction.message.author.displayAvatarURL())
.setDescription(`[Jump to message](https://discordapp.com/channels/${reaction.message.guild.id}/${reaction.message.channel.id}/${reaction.message.id})`)
.addField('Channel', reaction.message.channel)
.setFooter(reaction.count + ' ' + shameemote)
.setTimestamp();
return channel.send({files: messageAttachments, embed: shameEmbed })
.catch(() => channel.send(messageAttachments, { embed: shameEmbed}));
}
6 years ago
const shameEmbed = new MessageEmbed()
.setColor(reaction.message.member.displayHexColor)
.setAuthor(reaction.message.author.username, reaction.message.author.displayAvatarURL())
.setDescription(messageContent)
5 years ago
.addField('Jump to', `[message](https://discordapp.com/channels/${reaction.message.guild.id}/${reaction.message.channel.id}/${reaction.message.id})`)
.addField('Channel', reaction.message.channel)
.setFooter(reaction.count + ' ' + shameemote)
.setTimestamp();
6 years ago
return channel.send({files: messageAttachments, embed: shameEmbed})
.catch(() => channel.send(messageAttachments, { embed: shameEmbed}));
6 years ago
}
}
6 years ago
}
module.exports = MessageReactionAddListener;