Haha-Yes/commands/admin/autoresponse.js

45 lines
1.6 KiB
JavaScript
Raw Normal View History

2018-10-19 23:39:42 +02:00
const { Command } = require('discord.js-commando');
const blacklist = require('../../json/blacklist.json');
const fs = require('fs');
2018-10-21 20:48:38 +02:00
module.exports = class AutoresponseCommand extends Command {
2018-10-19 23:39:42 +02:00
constructor(client) {
super(client, {
name: 'autoresponse',
group: 'admin',
memberName: 'autoresponse',
userPermissions: ['MANAGE_MESSAGES'],
2018-10-21 20:46:57 +02:00
description: `Can disable autoresponse in the channel`,
2018-10-19 23:39:42 +02:00
args: [
{
key: 'text',
2018-10-21 20:46:57 +02:00
prompt: 'Disable or enable?',
2018-10-19 23:39:42 +02:00
type: 'string',
oneOf: ['disable', 'enable'],
}
]
});
}
async run(message, { text }) {
if(blacklist[message.author.id])
return message.channel.send("You are blacklisted")
2018-10-20 16:00:39 +02:00
let autoresponse = {}
let json = JSON.stringify(autoresponse)
2018-10-19 23:39:42 +02:00
fs.readFile('json/autoresponse.json', 'utf8', function readFileCallback(err, data){
if (err){
console.log(err);
} else {
2018-10-20 16:00:39 +02:00
autoresponse = JSON.parse(data); //now it an object
autoresponse [message.channel.id] = text
json = JSON.stringify(autoresponse); //convert it back to json
2018-10-19 23:39:42 +02:00
fs.writeFile('json/autoresponse.json', json, 'utf8', function(err) {
if(err) {
return console.log(err);
}
})}});
2018-10-21 20:46:57 +02:00
message.say(`Autoresponse have been ${text}d`);
2018-10-19 23:39:42 +02:00
}
};