From fcaa51a555a764b479eb80f5075ba5650ab315bb Mon Sep 17 00:00:00 2001 From: loicbersier Date: Thu, 14 Feb 2019 18:44:21 +0100 Subject: [PATCH] Configurable starboard --- commands/admin/shameboard.js | 34 ++++++++++++------------- commands/admin/starboard.js | 36 +++++++++++++-------------- event/listeners/messageReactionAdd.js | 18 +++++++++++--- 3 files changed, 47 insertions(+), 41 deletions(-) diff --git a/commands/admin/shameboard.js b/commands/admin/shameboard.js index 440d49f..1af1ba8 100644 --- a/commands/admin/shameboard.js +++ b/commands/admin/shameboard.js @@ -8,6 +8,18 @@ class shameboardCommand extends Command { category: 'admin', channelRestriction: 'guild', userPermissions: ['MANAGE_CHANNELS'], + args: [ + { + id: 'emote', + type: 'string', + default: '🌟' + }, + { + id: 'count', + type: 'integer', + default: '4' + } + ], description: { content: 'Set shameboard', usage: '[]', @@ -16,30 +28,16 @@ class shameboardCommand extends Command { }); } - async exec(message) { + async exec(message, args) { let shameboardChannel = message.channel.id; - fs.readFile(`./board/shame${message.guild.id}.json`, 'utf8', function readFileCallback(err, data) { + fs.writeFile(`./board/shame${message.guild.id}.json`, `{"shameboard": "${shameboardChannel}" , "emote": "${args.emote}", "count": "${args.count}"}`, function (err) { if (err) { - fs.writeFile(`./board/shame${message.guild.id}.json`, `{"shameboard": "${shameboardChannel}"}`, function (err) { - if (err) { - console.log(err); - } - }); - } else { - let shameboard = JSON.parse(data); //now it an object - shameboard['shameboard'] = shameboardChannel; - var json = JSON.stringify(shameboard); //convert it back to json - fs.writeFile(`./board/shame${message.guild.id}.json`, json, 'utf8', function (err) { - if (err) { - - return console.log(err); - } - }); + console.log(err); } }); - return message.channel.send('This channel have been set as the shameboard'); + return message.channel.send(`This channel have been set as the shameboard with ${args.emote} with the minium of ${args.count}`); } } diff --git a/commands/admin/starboard.js b/commands/admin/starboard.js index 5247479..0accf75 100644 --- a/commands/admin/starboard.js +++ b/commands/admin/starboard.js @@ -8,6 +8,18 @@ class StarBoardCommand extends Command { category: 'admin', channelRestriction: 'guild', userPermissions: ['MANAGE_CHANNELS'], + args: [ + { + id: 'emote', + type: 'string', + default: '🌟' + }, + { + id: 'count', + type: 'integer', + default: '4' + } + ], description: { content: 'Set starboard', usage: '[]', @@ -16,31 +28,17 @@ class StarBoardCommand extends Command { }); } - async exec(message) { + async exec(message, args) { + console.log(args); let starboardChannel = message.channel.id; - fs.readFile(`./board/star${message.guild.id}.json`, 'utf8', function readFileCallback(err, data) { + fs.writeFile(`./board/star${message.guild.id}.json`, `{"starboard": "${starboardChannel}", "emote": "${args.emote}", "count": "${args.count}"}`, function (err) { if (err) { - console.log('yes'); - fs.writeFile(`./board/star${message.guild.id}.json`, `{"starboard": "${starboardChannel}"}`, function (err) { - if (err) { - console.log(err); - } - }); - } else { - let starboard = JSON.parse(data); //now it an object - starboard['starboard'] = starboardChannel; - var json = JSON.stringify(starboard); //convert it back to json - fs.writeFile(`./board/star${message.guild.id}.json`, json, 'utf8', function (err) { - if (err) { - - return console.log(err); - } - }); + console.log(err); } }); - return message.channel.send('This channel have been set as the starboard'); + return message.channel.send(`This channel have been set as the starboard with ${args.emote} with the minium of ${args.count}`); } } diff --git a/event/listeners/messageReactionAdd.js b/event/listeners/messageReactionAdd.js index 542a10f..c5d52ce 100644 --- a/event/listeners/messageReactionAdd.js +++ b/event/listeners/messageReactionAdd.js @@ -14,15 +14,18 @@ class MessageReactionAddListener extends Listener { async exec(reaction) { let messageContent = reaction.message.content; let messageAttachments = reaction.message.attachments.map(u=> `${u.url}`); + let starboardChannel = reload(`../../board/star${reaction.message.guild.id}.json`); + + let staremote = starboardChannel['emote']; + let starcount = starboardChannel['count']; // Starboard - if (reaction.emoji.name === '🌟' && reaction.count === 4) { + 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); - let starboardChannel = reload(`../../board/star${reaction.message.guild.id}.json`); const channel = this.client.channels.get(starboardChannel['starboard']); if (!messageContent) @@ -37,14 +40,21 @@ class MessageReactionAddListener extends Listener { channel.send({ embed: starEmbed}); return channel.send(`in: ${reaction.message.channel} ID: ${reaction.message.id} \n${messageAttachments}`); } + + + let shameboardChannel = reload(`../../board/shame${reaction.message.guild.id}.json`); + + let shameemote = shameboardChannel['emote']; + let shamecount = shameboardChannel['count']; + + //Shameboard - if (reaction.emoji.name === '✡' && reaction.count === 4) { + if (reaction.emoji.name == shameemote && reaction.count == shamecount) { if (messageID.includes(reaction.message.id)) return console.log('Message already in starboard!'); messageID.push(reaction.message.id); - let shameboardChannel = reload(`../../board/shame${reaction.message.guild.id}.json`); const channel = this.client.channels.get(shameboardChannel['shameboard']); if (!messageContent)