From 0faa44e462649c61af56af82dc412722afa7b541 Mon Sep 17 00:00:00 2001 From: loicbersier Date: Fri, 13 Sep 2019 18:51:02 +0200 Subject: [PATCH] Made tag overwritable only by owner of the tag and admin/owner also make the command able to delete from here --- commands/admin/tag.js | 28 +++++++++++++++++++++++++--- 1 file changed, 25 insertions(+), 3 deletions(-) diff --git a/commands/admin/tag.js b/commands/admin/tag.js index 073eee9..25e0bfc 100644 --- a/commands/admin/tag.js +++ b/commands/admin/tag.js @@ -1,5 +1,6 @@ const { Command } = require('discord-akairo'); const Tag = require('../../models').Tag; +const { prefix, ownerID } = require('../../config.json'); class TagCommand extends Command { constructor() { @@ -21,14 +22,20 @@ class TagCommand extends Command { match: 'rest', prompt: { start: 'What word or sentence should the response be?', + optional: true } + }, + { + id: 'remove', + match: 'flag', + flag: '--remove' } ], channelRestriction: 'guild', description: { - content: 'Create custom autoresponse [Click here to see the complete list of "tag"](https://cdn.discordapp.com/attachments/502198809355354133/561043193949585418/unknown.png) (Need "" if the trigger contains spaces)', + content: 'Create custom autoresponse (--remove to delete a tag) [Click here to see the complete list of "tag"](https://cdn.discordapp.com/attachments/502198809355354133/561043193949585418/unknown.png) (Need "" if the trigger contains spaces)', usage: '[trigger] [response]', - examples: ['"do you know da wea" Fuck off dead meme', 'hello Hello [author], how are you today?'] + examples: ['"do you know da wea" Fuck off dead meme', 'hello Hello [author], how are you today?', 'hello --remove'] } }); } @@ -36,11 +43,24 @@ class TagCommand extends Command { async exec(message, args) { const tag = await Tag.findOne({where: {trigger: args.trigger, serverID: message.guild.id}}); + if (args.remove) { + if (tag) { + if (tag.get('ownerID') == message.author.id || message.member.hasPermission('ADMINISTRATOR') || message.author.id == ownerID) { + Tag.destroy({where: {trigger: args.trigger, serverID: message.guild.id}}); + return message.channel.send('successfully deleted the following tag: ' + args.trigger); + } else { + return message.channel.send(`You are not the owner of this tag, if you think it is problematic ask an admin to remove it by doing ${prefix[0]}tag ${args.trigger} --remove`); + } + } else { + return message.channel.send('Did not find the specified tag, are you sure it exist?'); + } + } + if (!tag) { const body = {trigger: args.trigger, response: args.response, ownerID: message.author.id, serverID: message.guild.id}; await Tag.create(body); return message.channel.send(`tag have been set to ${args.trigger} : ${args.response}`); - } else { + } else if (tag.get('ownerID') == message.author.id || message.member.hasPermission('ADMINISTRATOR') || message.author.id == ownerID) { message.channel.send('This tag already exist, do you want to update it? y/n'); const filter = m => m.content && m.author.id == message.author.id; message.channel.awaitMessages(filter, {time: 5000, max: 1, errors: ['time'] }) @@ -58,6 +78,8 @@ class TagCommand extends Command { console.error(err); return message.channel.send('Took too long to answer. didin\'t update anything.'); }); + } else { + return message.channel.send(`You are not the owner of this tag, if you think it is problematic ask an admin to remove it by doing ${prefix[0]}tag ${args.trigger} --remove`); } } }