Haha-Yes/commands/admin/tag.js

65 lines
2.1 KiB
JavaScript
Raw Normal View History

2018-12-30 01:20:24 +01:00
const { Command } = require('discord-akairo');
2018-12-18 17:02:05 +01:00
const fs = require('fs');
2018-12-25 19:17:07 +01:00
2018-12-30 01:20:24 +01:00
class TagCommand extends Command {
constructor() {
super('tag', {
aliases: ['tag'],
category: 'admin',
split: 'quoted',
2018-12-18 17:02:05 +01:00
args: [
{
2018-12-30 01:20:24 +01:00
id: "trigger",
type: "string"
2018-12-18 17:02:05 +01:00
},
{
2018-12-30 01:20:24 +01:00
id: "response",
type: "string"
2018-12-18 17:02:05 +01:00
}
2018-12-30 01:20:24 +01:00
],
channelRestriction: 'guild',
description: {
content: 'Create custom autoresponse',
usage: '[trigger] [response]',
examples: ['"do you know da wea" "Fuck off dead meme"']
}
2018-12-18 17:02:05 +01:00
});
}
2018-12-30 01:20:24 +01:00
async exec(message, args) {
let trigger = args.trigger;
let response = args.response;
2018-12-18 17:02:05 +01:00
2018-12-30 01:20:24 +01:00
trigger = trigger.toLowerCase();
2018-12-18 17:02:05 +01:00
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);
}
})}});
2018-12-30 01:20:24 +01:00
return message.channel.send(`autoresponse have been set to ${trigger} : ${response}`);
}
}
module.exports = TagCommand;