support custom emote

This commit is contained in:
loicbersier 2019-12-26 18:37:40 +01:00
parent ac2df5fb65
commit aef0caae25

View file

@ -1,6 +1,5 @@
const { Listener } = require('discord-akairo'); const { Listener } = require('discord-akairo');
const fs = require('fs'); const fs = require('fs');
let messageID = require('../../json/starboard.json');
class MessageReactionAddListener extends Listener { class MessageReactionAddListener extends Listener {
@ -13,49 +12,50 @@ class MessageReactionAddListener extends Listener {
async exec(reaction, user) { async exec(reaction, user) {
if (reaction.message.author == user) return; if (reaction.message.author == user) return;
let starboardChannel, shameboardChannel, staremote, starcount, shameemote, shamecount; let messageID = []; // Where reaction.message.id that entered a board will be stocked so it doesn't enter again
let starboardChannel, shameboardChannel;
let messageContent = reaction.message.content; if (messageID.includes(reaction.message.id)) return;
let messageAttachments = reaction.message.attachments.map(u=> u.url);
// Starboard // Starboard
if (fs.existsSync(`./board/star${reaction.message.guild.id}.json`)) { if (fs.existsSync(`./board/star${reaction.message.guild.id}.json`)) {
starboardChannel = require(`../../board/star${reaction.message.guild.id}.json`); starboardChannel = require(`../../board/star${reaction.message.guild.id}.json`);
staremote = starboardChannel['emote']; let staremote = starboardChannel.emote;
starcount = starboardChannel['count']; let starcount = starboardChannel.count;
delete require.cache[require.resolve(`../../board/star${reaction.message.guild.id}.json`)]; // Delete the boardChannel cache so it can reload it next time
if (this.client.util.resolveEmoji(staremote, reaction.message.guild.emojis)) {
staremote = this.client.util.resolveEmoji(staremote, reaction.message.guild.emojis).name;
}
if (reaction.emoji.name == staremote && reaction.count == starcount) { 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); messageID.push(reaction.message.id);
sendEmbed('starboard', staremote, this.client); return sendEmbed('starboard', staremote, this.client);
}
} }
} }
//Shameboard //Shameboard
if (fs.existsSync(`./board/shame${reaction.message.guild.id}.json`)) { if (fs.existsSync(`./board/shame${reaction.message.guild.id}.json`)) {
shameboardChannel = require(`../../board/shame${reaction.message.guild.id}.json`); shameboardChannel = require(`../../board/shame${reaction.message.guild.id}.json`);
shameemote = shameboardChannel['emote']; let shameemote = shameboardChannel.emote;
shamecount = shameboardChannel['count']; let shamecount = shameboardChannel.count;
delete require.cache[require.resolve(`../../board/shame${reaction.message.guild.id}.json`)]; // Delete the boardChannel cache so it can reload it next time
if (reaction.emoji.name == shameemote && reaction.count == shamecount) { 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); messageID.push(reaction.message.id);
sendEmbed('shameboard', shameemote, this.client); return sendEmbed('shameboard', shameemote, this.client);
}
} }
} }
async function sendEmbed(name, emote, client) { async function sendEmbed(name, emote, client) {
let messageAttachments = reaction.message.attachments.map(u=> u.url);
// Should change this so it automatically pic the channel ( I'm lazy right now )
let channel; let channel;
if (name == 'starboard') { if (name == 'starboard') {
channel = client.channels.get(starboardChannel['starboard']); channel = client.channels.get(starboardChannel.starboard);
} else { } else {
channel = client.channels.get(shameboardChannel['shameboard']); channel = client.channels.get(shameboardChannel.shameboard);
} }
let Embed = client.util.embed() let Embed = client.util.embed()
@ -66,9 +66,13 @@ class MessageReactionAddListener extends Listener {
.setFooter(reaction.count + ' ' + emote) .setFooter(reaction.count + ' ' + emote)
.setTimestamp(); .setTimestamp();
if (reaction.message.guild.emojis.find(emoji => emoji.name === emote)) {
Embed.setFooter(reaction.count, reaction.message.guild.emojis.find(emoji => emoji.name === emote).url);
}
// if message come from nsfw channel and the star/shameboard channel isn't nsfw put it in spoiler // 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) { if (reaction.message.channel.nsfw && !channel.nsfw) {
Embed.setDescription(`||${messageContent}||`); Embed.setDescription(`||${reaction.message.content}||`);
if (messageAttachments != '') { if (messageAttachments != '') {
return channel.send(`||${messageAttachments}||`, { embed: Embed }); return channel.send(`||${messageAttachments}||`, { embed: Embed });
} }
@ -76,7 +80,7 @@ class MessageReactionAddListener extends Listener {
return channel.send({embed: Embed}); return channel.send({embed: Embed});
} }
} else { } else {
Embed.setDescription(messageContent); Embed.setDescription(reaction.message.content);
return channel.send({ files: messageAttachments, embed: Embed }) return channel.send({ files: messageAttachments, embed: Embed })
.catch(async () => channel.send(messageAttachments, { embed: Embed })); .catch(async () => channel.send(messageAttachments, { embed: Embed }));
} }