Haha-Yes/commands/admin/autoresponse.js

91 lines
2.4 KiB
JavaScript
Raw Normal View History

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',
2019-06-23 03:41:59 +02:00
type: 'string',
prompt: {
start: 'Do you want to **enable** or **disable** auto response?',
}
2019-01-02 08:09:45 +01:00
},
{
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) {
2019-03-05 20:56:30 +01:00
let text = args.text;
let all = args.all;
2018-11-20 19:33:04 +01:00
if (text.toLowerCase() == 'enable' || text.toLowerCase() == 'disable') {
let autoresponse = {};
let json = JSON.stringify(autoresponse);
if (all == 'all') {
const guild = this.client.guilds.get(message.guild.id);
fs.readFile('./json/autoresponse.json', 'utf8', function readFileCallback(err, data) {
if (err) {
console.log(err);
} else {
autoresponse = JSON.parse(data); //now it an object
guild.channels.forEach(channel => autoresponse[channel] = text.toLowerCase());
json = JSON.stringify(autoresponse); //convert it back to json
json = json.replace(/[<#>]/g, '');
fs.writeFile('./json/autoresponse.json', json, 'utf8', function (err) {
if (err) {
return console.log(err);
}
});
}
});
return message.channel.send('Auto response have been disable/enable on every channel');
2019-06-16 19:05:24 +02:00
} else if (text.toLowerCase() == 'disable' || text.toLowerCase() == '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.toLowerCase();
json = JSON.stringify(autoresponse); //convert it back to json
fs.writeFile('./json/autoresponse.json', json, 'utf8', function (err) {
if (err) {
return console.log(err);
}
});
}
});
}
2019-01-02 10:48:26 +01:00
return message.channel.send(`Autoresponse have been ${text.toLowerCase()}d`);
} else {
return message.channel.send('You didin\'t type a valid input');
2018-12-30 01:20:24 +01:00
2019-01-02 08:09:45 +01:00
}
}
2019-01-02 04:35:34 +01:00
}
2018-12-30 01:20:24 +01:00
module.exports = autoresponseCommand;