made it better

This commit is contained in:
Loïc Bersier 2019-06-28 03:50:16 +02:00
parent 021051e6a3
commit da53c24feb

View file

@ -1,8 +1,9 @@
const { Listener } = require('discord-akairo'); const { Listener } = require('discord-akairo');
const { MessageEmbed } = require('discord.js'); const { MessageEmbed } = require('discord.js');
const reload = require('auto-reload'); const fs = require('fs');
let messageID = require('../../json/starboard.json'); let messageID = require('../../json/starboard.json');
class MessageReactionAddListener extends Listener { class MessageReactionAddListener extends Listener {
constructor() { constructor() {
super('messagereactionadd', { super('messagereactionadd', {
@ -13,30 +14,21 @@ 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;
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 (fs.existsSync(`./board/shame${reaction.message.guild.id}.json`)) {
shameboardChannel = require(`../../board/shame${reaction.message.guild.id}.json`);
shameemote = shameboardChannel['emote'];
shamecount = shameboardChannel['count'];
}
let messageContent = reaction.message.content; let messageContent = reaction.message.content;
let messageAttachments = reaction.message.attachments.map(u=> u.url); let messageAttachments = reaction.message.attachments.map(u=> u.url);
let starboardChannel, staremote, starcount, shameboardChannel, shameemote, shamecount;
try {
starboardChannel = reload(`../../board/star${reaction.message.guild.id}.json`);
staremote = starboardChannel['emote'];
starcount = starboardChannel['count'];
} catch (err) {
console.log(`No shameboard for ${reaction.message.guild.name}, not an error`);
}
try {
shameboardChannel = reload(`../../board/shame${reaction.message.guild.id}.json`);
shameemote = shameboardChannel['emote'];
shamecount = shameboardChannel['count'];
} catch (err) {
console.log(`No shameboard for ${reaction.message.guild.name}, not an error`);
}
// Starboard // Starboard
if (reaction.emoji.name == staremote && reaction.count == starcount) { if (reaction.emoji.name == staremote && reaction.count == starcount) {
if (messageID.includes(reaction.message.id)) if (messageID.includes(reaction.message.id))