2018-10-19 23:39:42 +02:00
|
|
|
const fs = require('fs');
|
2018-12-30 01:20:24 +01:00
|
|
|
const { Command } = require('discord-akairo');
|
|
|
|
|
|
|
|
class autoresponseCommand extends Command {
|
2019-01-02 08:09:45 +01:00
|
|
|
constructor() {
|
|
|
|
super('autoresponse', {
|
|
|
|
aliases: ['autoresponse'],
|
|
|
|
category: 'admin',
|
|
|
|
args: [
|
|
|
|
{
|
|
|
|
id: 'text',
|
|
|
|
type: 'string'
|
|
|
|
},
|
|
|
|
{
|
|
|
|
id: 'all',
|
|
|
|
type: 'string'
|
|
|
|
}
|
|
|
|
],
|
2019-01-12 17:00:36 +01:00
|
|
|
userPermissions: ['MANAGE_MESSAGES'],
|
2019-01-02 08:09:45 +01:00
|
|
|
channelRestriction: 'guild',
|
|
|
|
description: {
|
|
|
|
content: 'enable/disable autoresponse',
|
|
|
|
usage: '[enable/disable] (optional) [all]',
|
|
|
|
examples: ['enable all']
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2018-10-19 23:39:42 +02:00
|
|
|
|
2019-01-02 08:09:45 +01:00
|
|
|
async exec(message, args) {
|
|
|
|
let text = args.text;
|
|
|
|
let all = args.all;
|
2018-10-19 23:39:42 +02:00
|
|
|
|
2019-01-02 08:09:45 +01:00
|
|
|
let autoresponse = {};
|
|
|
|
let json = JSON.stringify(autoresponse);
|
2018-10-19 23:39:42 +02:00
|
|
|
|
2019-01-02 08:09:45 +01:00
|
|
|
if (all == 'all') {
|
|
|
|
const guild = this.client.guilds.get(message.guild.id);
|
2018-12-30 01:20:24 +01:00
|
|
|
|
2019-01-02 08:09:45 +01:00
|
|
|
fs.readFile('./json/autoresponse.json', 'utf8', function readFileCallback(err, data) {
|
|
|
|
if (err) {
|
2019-01-02 10:48:26 +01:00
|
|
|
|
2019-01-02 08:09:45 +01:00
|
|
|
console.log(err);
|
|
|
|
} else {
|
2018-12-30 01:20:24 +01:00
|
|
|
|
2019-01-02 08:09:45 +01:00
|
|
|
autoresponse = JSON.parse(data); //now it an object
|
|
|
|
guild.channels.forEach(channel => autoresponse[channel] = text);
|
|
|
|
json = JSON.stringify(autoresponse); //convert it back to json
|
|
|
|
json = json.replace(/[<#>]/g, '');
|
|
|
|
fs.writeFile('./json/autoresponse.json', json, 'utf8', function (err) {
|
|
|
|
if (err) {
|
2019-01-02 10:48:26 +01:00
|
|
|
|
2019-01-02 08:09:45 +01:00
|
|
|
return console.log(err);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
2018-11-20 19:33:04 +01:00
|
|
|
|
2019-01-02 10:48:26 +01:00
|
|
|
|
2019-01-02 08:09:45 +01:00
|
|
|
return message.channel.send('Auto response have been disable/enable on every channel');
|
2018-12-30 01:20:24 +01:00
|
|
|
|
2019-01-02 08:09:45 +01:00
|
|
|
} else if (text == 'disable' || 'enable') {
|
|
|
|
fs.readFile('./json/autoresponse.json', 'utf8', function readFileCallback(err, data) {
|
|
|
|
if (err) {
|
|
|
|
console.log(err);
|
|
|
|
} else {
|
|
|
|
autoresponse = JSON.parse(data); //now it an object
|
|
|
|
autoresponse[message.channel.id] = text;
|
|
|
|
json = JSON.stringify(autoresponse); //convert it back to json
|
|
|
|
fs.writeFile('./json/autoresponse.json', json, 'utf8', function (err) {
|
|
|
|
if (err) {
|
2019-01-02 10:48:26 +01:00
|
|
|
|
2019-01-02 08:09:45 +01:00
|
|
|
return console.log(err);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2019-01-02 04:35:34 +01:00
|
|
|
|
2019-01-02 10:48:26 +01:00
|
|
|
|
2019-01-02 08:09:45 +01:00
|
|
|
return message.channel.send(`Autoresponse have been ${text}d`);
|
|
|
|
}
|
2019-01-02 04:35:34 +01:00
|
|
|
}
|
2018-12-30 01:20:24 +01:00
|
|
|
module.exports = autoresponseCommand;
|