fixed an issue where we could put anything in the autoresponse

This commit is contained in:
Supositware 2019-03-03 23:12:02 +01:00
parent 9dee4389c4
commit 829f73d2c7

View file

@ -27,57 +27,62 @@ class autoresponseCommand extends Command {
} }
async exec(message, args) { async exec(message, args) {
let text = args.text; let text = args.text.toLowerCase();
let all = args.all; let all = args.all.toLowerCase();
let autoresponse = {}; if (text.toLowerCase() == 'enable' || text.toLowerCase() == 'disable') {
let json = JSON.stringify(autoresponse); let autoresponse = {};
let json = JSON.stringify(autoresponse);
if (all == 'all') { if (all == 'all') {
const guild = this.client.guilds.get(message.guild.id); const guild = this.client.guilds.get(message.guild.id);
fs.readFile('./json/autoresponse.json', 'utf8', function readFileCallback(err, data) { fs.readFile('./json/autoresponse.json', 'utf8', function readFileCallback(err, data) {
if (err) { if (err) {
console.log(err); console.log(err);
} else { } else {
autoresponse = JSON.parse(data); //now it an object autoresponse = JSON.parse(data); //now it an object
guild.channels.forEach(channel => autoresponse[channel] = text); guild.channels.forEach(channel => autoresponse[channel] = text.toLowerCase());
json = JSON.stringify(autoresponse); //convert it back to json json = JSON.stringify(autoresponse); //convert it back to json
json = json.replace(/[<#>]/g, ''); json = json.replace(/[<#>]/g, '');
fs.writeFile('./json/autoresponse.json', json, 'utf8', function (err) { fs.writeFile('./json/autoresponse.json', json, 'utf8', function (err) {
if (err) { if (err) {
return console.log(err); return console.log(err);
} }
}); });
} }
}); });
return message.channel.send('Auto response have been disable/enable on every channel'); return message.channel.send('Auto response have been disable/enable on every channel');
} else if (text == 'disable' || 'enable') { } else if (text.toLowerCase() == 'disable' || 'enable') {
fs.readFile('./json/autoresponse.json', 'utf8', function readFileCallback(err, data) { fs.readFile('./json/autoresponse.json', 'utf8', function readFileCallback(err, data) {
if (err) { if (err) {
console.log(err); console.log(err);
} else { } else {
autoresponse = JSON.parse(data); //now it an object autoresponse = JSON.parse(data); //now it an object
autoresponse[message.channel.id] = text; autoresponse[message.channel.id] = text.toLowerCase();
json = JSON.stringify(autoresponse); //convert it back to json json = JSON.stringify(autoresponse); //convert it back to json
fs.writeFile('./json/autoresponse.json', json, 'utf8', function (err) { fs.writeFile('./json/autoresponse.json', json, 'utf8', function (err) {
if (err) { if (err) {
return console.log(err);
}
});
}
});
}
return message.channel.send(`Autoresponse have been ${text.toLowerCase()}d`);
} else {
return message.channel.send('You didin\'t type a valid input');
return console.log(err);
}
});
}
});
} }
return message.channel.send(`Autoresponse have been ${text}d`);
} }
} }
module.exports = autoresponseCommand; module.exports = autoresponseCommand;