diff --git a/commands/admin/shameboard.js b/commands/admin/shameboard.js new file mode 100644 index 0000000..a746a15 --- /dev/null +++ b/commands/admin/shameboard.js @@ -0,0 +1,61 @@ +const { Command } = require('discord-akairo'); +const fs = require('fs'); + +class shameboardCommand extends Command { + constructor() { + super('shameboard', { + aliases: ['shameboard'], + category: 'admin', + channelRestriction: 'guild', + args: [ + { + id: 'delete', + type: 'string' + } + ], + userPermissions: ['ADMINISTRATOR'], + description: { + content: 'Set shameboard', + usage: '[]', + examples: [''] + } + }); + } + + async exec(message, args) { + let shameboardChannel = message.channel.id; + + + + fs.readFile(`./starboard/${message.guild.id}.json`, 'utf8', function readFileCallback(err, data){ + if (err){ + fs.writeFile(`./starboard/${message.guild.id}.json`, `{"shameboard": "${shameboardChannel}"}`, function (err) { + if (err){ + console.log(err); + } + }) + } else { + if (args.delete == 'delete') { + let shameboard = JSON.parse(data); //now it an object + shameboard ['shameboard'] = ''; + var json = JSON.stringify(shameboard); //convert it back to json + var deleteBoard = true; + } 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(`./starboard/${message.guild.id}.json`, json, 'utf8', function(err) { + if(err) { + return console.log(err); + } + })}}); + if (deleteBoard) + return message.channel.send('The shameboard have been deleted'); + else + return message.channel.send(`This channel have been set as the shameboard`); + } +} + +module.exports = shameboardCommand; \ No newline at end of file diff --git a/commands/admin/starboard.js b/commands/admin/starboard.js new file mode 100644 index 0000000..74c56ce --- /dev/null +++ b/commands/admin/starboard.js @@ -0,0 +1,58 @@ +const { Command } = require('discord-akairo'); +const fs = require('fs'); + +class StarBoardCommand extends Command { + constructor() { + super('starboard', { + aliases: ['starboard'], + category: 'admin', + channelRestriction: 'guild', + args: [ + { + id: 'delete', + type: 'string' + } + ], + userPermissions: ['ADMINISTRATOR'], + description: { + content: 'Set starboard', + usage: '[]', + examples: [''] + } + }); + } + + async exec(message, args) { + let starboardChannel = message.channel.id; + + fs.readFile(`./starboard/${message.guild.id}.json`, 'utf8', function readFileCallback(err, data){ + if (err){ + fs.writeFile(`./starboard/${message.guild.id}.json`, `{"starboard": "${starboardChannel}"}`, function (err) { + if (err){ + console.log(err); + } + }) + } else { + if (args.delete == 'delete') { + let starboard = JSON.parse(data); //now it an object + starboard ['starboard'] = ''; + var json = JSON.stringify(starboard); //convert it back to json + var deleteBoard = true; + } 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(`./starboard/${message.guild.id}.json`, json, 'utf8', function(err) { + if(err) { + return console.log(err); + } + })}}); + if (deleteBoard) + return message.channel.send('The starboard have been deleted') + else + return message.channel.send(`This channel have been set as the starboard`); + } +} + +module.exports = StarBoardCommand; \ No newline at end of file