Haha-Yes/commands/admin/untag.js

56 lines
1.6 KiB
JavaScript
Raw Normal View History

2018-12-30 01:44:10 +01:00
const { Command } = require('discord-akairo');
const fs = require('fs');
class UnTagCommand extends Command {
constructor() {
super('untag', {
aliases: ['untag'],
category: 'admin',
split: 'none',
args: [
{
id: "trigger",
type: "string"
}
],
channelRestriction: 'guild',
description: {
content: 'Remove created custom autoresponse',
usage: '[trigger]',
examples: ['"do you know da wea"']
}
});
}
async exec(message, args) {
let trigger = args.trigger;
trigger = trigger.toLowerCase();
2019-01-02 04:35:34 +01:00
2018-12-30 01:44:10 +01:00
let customresponse = {}
let json = JSON.stringify(customresponse)
2019-01-02 04:35:34 +01:00
fs.readFile(`./tag/${message.guild.id}.json`, 'utf8', function readFileCallback(err, data) {
if (err) {
2018-12-30 01:44:10 +01:00
console.log(err);
} else {
2019-01-02 04:35:34 +01:00
customresponse = JSON.parse(data); //now it an object
delete customresponse[trigger]
json = JSON.stringify(customresponse); //convert it back to json
fs.writeFile(`./tag/${message.guild.id}.json`, json, 'utf8', function (err) {
if (err) {
fs.close();
return console.log(err);
}
})
}
});
fs.close();
2018-12-30 02:14:43 +01:00
return message.channel.send(`The following autoresponse have been deleted: ${trigger}`);
2018-12-30 01:44:10 +01:00
}
}
module.exports = UnTagCommand;