Configurable starboard

This commit is contained in:
loicbersier 2019-02-14 18:44:21 +01:00
parent d807067acd
commit fcaa51a555
3 changed files with 47 additions and 41 deletions

View file

@ -8,6 +8,18 @@ class shameboardCommand extends Command {
category: 'admin', category: 'admin',
channelRestriction: 'guild', channelRestriction: 'guild',
userPermissions: ['MANAGE_CHANNELS'], userPermissions: ['MANAGE_CHANNELS'],
args: [
{
id: 'emote',
type: 'string',
default: '🌟'
},
{
id: 'count',
type: 'integer',
default: '4'
}
],
description: { description: {
content: 'Set shameboard', content: 'Set shameboard',
usage: '[]', usage: '[]',
@ -16,30 +28,16 @@ class shameboardCommand extends Command {
}); });
} }
async exec(message) { async exec(message, args) {
let shameboardChannel = message.channel.id; 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) { if (err) {
console.log(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); return message.channel.send(`This channel have been set as the shameboard with ${args.emote} with the minium of ${args.count}`);
}
});
}
});
return message.channel.send('This channel have been set as the shameboard');
} }
} }

View file

@ -8,6 +8,18 @@ class StarBoardCommand extends Command {
category: 'admin', category: 'admin',
channelRestriction: 'guild', channelRestriction: 'guild',
userPermissions: ['MANAGE_CHANNELS'], userPermissions: ['MANAGE_CHANNELS'],
args: [
{
id: 'emote',
type: 'string',
default: '🌟'
},
{
id: 'count',
type: 'integer',
default: '4'
}
],
description: { description: {
content: 'Set starboard', content: 'Set starboard',
usage: '[]', usage: '[]',
@ -16,31 +28,17 @@ class StarBoardCommand extends Command {
}); });
} }
async exec(message) { async exec(message, args) {
console.log(args);
let starboardChannel = message.channel.id; 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) { if (err) {
console.log(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); return message.channel.send(`This channel have been set as the starboard with ${args.emote} with the minium of ${args.count}`);
}
});
}
});
return message.channel.send('This channel have been set as the starboard');
} }
} }

View file

@ -14,15 +14,18 @@ class MessageReactionAddListener extends Listener {
async exec(reaction) { async exec(reaction) {
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 = reload(`../../board/star${reaction.message.guild.id}.json`);
let staremote = starboardChannel['emote'];
let starcount = starboardChannel['count'];
// Starboard // Starboard
if (reaction.emoji.name === '🌟' && reaction.count === 4) { if (reaction.emoji.name == staremote && reaction.count == starcount) {
if (messageID.includes(reaction.message.id)) if (messageID.includes(reaction.message.id))
return console.log('Message already in starboard!'); return console.log('Message already in starboard!');
messageID.push(reaction.message.id); messageID.push(reaction.message.id);
let starboardChannel = reload(`../../board/star${reaction.message.guild.id}.json`);
const channel = this.client.channels.get(starboardChannel['starboard']); const channel = this.client.channels.get(starboardChannel['starboard']);
if (!messageContent) if (!messageContent)
@ -37,14 +40,21 @@ class MessageReactionAddListener extends Listener {
channel.send({ embed: starEmbed}); channel.send({ embed: starEmbed});
return channel.send(`in: ${reaction.message.channel} ID: ${reaction.message.id} \n${messageAttachments}`); 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 //Shameboard
if (reaction.emoji.name === '✡' && reaction.count === 4) { if (reaction.emoji.name == shameemote && reaction.count == shamecount) {
if (messageID.includes(reaction.message.id)) if (messageID.includes(reaction.message.id))
return console.log('Message already in starboard!'); return console.log('Message already in starboard!');
messageID.push(reaction.message.id); messageID.push(reaction.message.id);
let shameboardChannel = reload(`../../board/shame${reaction.message.guild.id}.json`);
const channel = this.client.channels.get(shameboardChannel['shameboard']); const channel = this.client.channels.get(shameboardChannel['shameboard']);
if (!messageContent) if (!messageContent)