2018-12-05 21:34:43 +01:00
|
|
|
const { Command } = require('discord.js-commando');
|
|
|
|
const blacklist = require('../../json/blacklist.json');
|
|
|
|
const fs = require('fs');
|
|
|
|
module.exports = class CustomResponseCommand extends Command {
|
|
|
|
constructor(client) {
|
|
|
|
super(client, {
|
2018-12-06 01:30:35 +01:00
|
|
|
name: 'tag',
|
2018-12-06 04:18:21 +01:00
|
|
|
aliases: ['customresponse'],
|
|
|
|
group: 'utility',
|
2018-12-06 01:30:35 +01:00
|
|
|
memberName: 'tag',
|
|
|
|
description: `Custom auto response`,
|
2018-12-07 19:58:26 +01:00
|
|
|
userPermissions: ['MANAGE_MESSAGES'],
|
2018-12-05 21:34:43 +01:00
|
|
|
args: [
|
|
|
|
{
|
|
|
|
key: 'trigger',
|
2018-12-06 04:18:21 +01:00
|
|
|
prompt: 'The word that will trigger the autoresponse (use "--" instead of spaces)',
|
2018-12-05 21:34:43 +01:00
|
|
|
type: 'string',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
key: 'response',
|
2018-12-06 04:18:21 +01:00
|
|
|
prompt: 'The response to the word ( you can use spaces here )',
|
2018-12-05 21:34:43 +01:00
|
|
|
type: 'string',
|
|
|
|
}
|
|
|
|
]
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
async run(message, { trigger, response }) {
|
|
|
|
if(blacklist[message.author.id])
|
|
|
|
return message.channel.send("You are blacklisted")
|
|
|
|
|
|
|
|
trigger = trigger.toLowerCase();
|
2018-12-06 01:30:35 +01:00
|
|
|
do {
|
|
|
|
trigger = trigger.replace('--', ' ')
|
|
|
|
} while (trigger.includes('--'))
|
|
|
|
|
2018-12-05 21:34:43 +01:00
|
|
|
let customresponse = {}
|
|
|
|
let json = JSON.stringify(customresponse)
|
|
|
|
|
2018-12-06 01:30:35 +01:00
|
|
|
|
2018-12-06 19:05:40 +01:00
|
|
|
|
2018-12-06 18:50:18 +01:00
|
|
|
|
2018-12-06 23:01:40 +01:00
|
|
|
fs.readFile(`./tag/${message.guild.id}.json`, 'utf8', function readFileCallback(err, data){
|
2018-12-05 21:34:43 +01:00
|
|
|
if (err){
|
2018-12-06 23:01:40 +01:00
|
|
|
fs.writeFile(`./tag/${message.guild.id}.json`, `{"${trigger}":"${response}"}`, function (err) {
|
2018-12-06 19:05:40 +01:00
|
|
|
if (err){
|
|
|
|
console.log(err);
|
|
|
|
}
|
|
|
|
})
|
2018-12-06 19:42:05 +01:00
|
|
|
} else {
|
|
|
|
customresponse = JSON.parse(data); //now it an object
|
2018-12-06 18:50:18 +01:00
|
|
|
customresponse [trigger] = response
|
2018-12-05 21:34:43 +01:00
|
|
|
json = JSON.stringify(customresponse); //convert it back to json
|
2018-12-06 23:01:40 +01:00
|
|
|
fs.writeFile(`./tag/${message.guild.id}.json`, json, 'utf8', function(err) {
|
2018-12-05 21:34:43 +01:00
|
|
|
if(err) {
|
|
|
|
return console.log(err);
|
|
|
|
}
|
|
|
|
})}});
|
|
|
|
|
2018-12-06 04:36:37 +01:00
|
|
|
return message.say(`autoresponse have been set to ${trigger} : ${response}`);
|
2018-12-05 21:34:43 +01:00
|
|
|
}
|
|
|
|
};
|