Haha-Yes/commands/admin/untag.js

58 lines
1.3 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 {
2019-01-02 08:09:45 +01:00
constructor() {
super('untag', {
2019-02-08 19:42:43 +01:00
aliases: ['untag', 'removetag', 'delete'],
2019-01-02 08:09:45 +01:00
category: 'admin',
split: 'none',
2019-06-16 15:11:52 +02:00
userPermissions: ['MANAGE_MESSAGES'],
2019-01-02 08:09:45 +01:00
args: [
{
id: 'trigger',
2019-06-20 02:48:01 +02:00
type: 'string',
match: 'rest'
2019-01-02 08:09:45 +01:00
}
],
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();
let customresponse = {};
let json = JSON.stringify(customresponse);
fs.readFile(`./tag/${message.guild.id}.json`, 'utf8', function readFileCallback(err, data) {
if (err) {
console.log(err);
} else {
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) {
2019-01-02 10:48:26 +01:00
2019-01-02 08:09:45 +01:00
return console.log(err);
}
});
}
});
2019-01-02 10:48:26 +01:00
2019-01-02 08:09:45 +01:00
return message.channel.send(`The following autoresponse have been deleted: ${trigger}`);
}
2018-12-30 01:44:10 +01:00
}
module.exports = UnTagCommand;