Haha-Yes/commands/admin/shameboard.js

48 lines
1.3 KiB
JavaScript
Raw Normal View History

const { Command } = require('discord-akairo');
const fs = require('fs');
2019-01-01 09:42:54 +01:00
class shameboardCommand extends Command {
2019-01-02 08:09:45 +01:00
constructor() {
super('shameboard', {
aliases: ['shameboard'],
category: 'admin',
channelRestriction: 'guild',
userPermissions: ['ADMINISTRATOR'],
description: {
content: 'Set shameboard',
usage: '[]',
examples: ['']
}
});
}
2019-01-02 08:09:45 +01:00
async exec(message) {
let shameboardChannel = message.channel.id;
2019-01-02 08:09:45 +01:00
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);
}
2019-01-02 18:45:53 +01:00
2019-01-02 08:09:45 +01:00
return message.channel.send('This channel have been set as the shameboard');
});
} 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) {
2019-01-02 18:45:53 +01:00
2019-01-02 08:09:45 +01:00
return console.log(err);
}
});
}
});
2019-01-02 18:45:53 +01:00
2019-01-02 08:09:45 +01:00
return message.channel.send('This channel have been set as the shameboard');
}
}
2019-01-01 09:42:54 +01:00
module.exports = shameboardCommand;