Haha-Yes/commands/admin/tag.js

62 lines
2.2 KiB
JavaScript
Raw Normal View History

2018-12-18 17:02:05 +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, {
name: 'tag',
aliases: ['customresponse'],
2018-12-18 23:33:42 +01:00
group: 'admin',
2018-12-18 17:02:05 +01:00
memberName: 'tag',
description: `Custom auto response`,
userPermissions: ['MANAGE_MESSAGES'],
args: [
{
key: 'trigger',
prompt: 'The word that will trigger the autoresponse (use "--" instead of spaces)',
type: 'string',
},
{
key: 'response',
prompt: 'The response to the word ( you can use spaces here )',
type: 'string',
}
]
});
}
async run(message, { trigger, response }) {
if(blacklist[message.author.id])
return message.channel.send("You are blacklisted")
trigger = trigger.toLowerCase();
do {
trigger = trigger.replace('--', ' ')
} while (trigger.includes('--'))
let customresponse = {}
let json = JSON.stringify(customresponse)
fs.readFile(`./tag/${message.guild.id}.json`, 'utf8', function readFileCallback(err, data){
if (err){
2018-12-18 23:33:42 +01:00
fs.writeFile(`./tag/${message.guild.id}.json`, `{"${trigger}":"${response}"}`, function (err) {
2018-12-18 17:02:05 +01:00
if (err){
console.log(err);
}
})
} else {
customresponse = JSON.parse(data); //now it an object
2018-12-18 23:33:42 +01:00
customresponse [trigger] = response
2018-12-18 17:02:05 +01:00
json = JSON.stringify(customresponse); //convert it back to json
fs.writeFile(`./tag/${message.guild.id}.json`, json, 'utf8', function(err) {
if(err) {
return console.log(err);
}
})}});
return message.say(`autoresponse have been set to ${trigger} : ${response}`);
}
};