From d39620e15baf1421bbc8e8b90723e5c21767e73a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Bersier?= Date: Fri, 12 Jul 2019 06:06:17 +0200 Subject: [PATCH] Ask to update if tag already exist --- commands/admin/tag.js | 17 +++++++++++++++-- commands/owner/addResponse.js | 15 ++++++++++++++- 2 files changed, 29 insertions(+), 3 deletions(-) diff --git a/commands/admin/tag.js b/commands/admin/tag.js index cb8e389..83569a5 100644 --- a/commands/admin/tag.js +++ b/commands/admin/tag.js @@ -39,9 +39,22 @@ class TagCommand extends Command { if (!tag) { const body = {trigger: args.trigger, response: args.response, ownerID: message.author.id, serverID: message.guild.id}; Tag.create(body); - return message.channel.send(`autoresponse have been set to ${args.trigger} : ${args.response}`); + return message.channel.send(`tag have been set to ${args.trigger} : ${args.response}`); } else { - return message.channel.send('The tag already exist!'); + 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'] }) + .then(messages => { + let messageContent = messages.map(messages => messages.content); + if (messageContent == 'y' || messageContent == 'yes') { + const body = {trigger: args.trigger, response: args.response, ownerID: message.author.id, serverID: message.guild.id}; + Tag.update(body, {where: {serverID: message.guild.id}}); + return message.channel.send(`tag have been set to ${args.trigger} : ${args.response}`); + } + }) + .catch(() => { + return message.channel.send('Took too long to answer. didin\'t update anything.'); + }); } } } diff --git a/commands/owner/addResponse.js b/commands/owner/addResponse.js index 8f0a237..f08d901 100644 --- a/commands/owner/addResponse.js +++ b/commands/owner/addResponse.js @@ -48,7 +48,20 @@ class addResponseCommand extends Command { autoResponse.create(body); return message.channel.send(`autoresponse have been set to ${args.trigger} : ${args.response} with type: ${args.type}`); } else { - return message.channel.send('The autoresponse already exist!'); + message.channel.send('This autoresponse 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 * 1000, max: 1, errors: ['time'] }) + .then(messages => { + let messageContent = messages.map(messages => messages.content); + if (messageContent == 'y' || messageContent == 'yes') { + const body = {trigger: args.trigger, response: args.response, type: args.type}; + autoResponse.update(body, {where: {serverID: message.guild.id}}); + return message.channel.send(`autoresponse have been set to ${args.trigger} : ${args.response} with type: ${args.type}`); + } + }) + .catch(() => { + return message.channel.send('Took too long to answer. didin\'t update anything.'); + }); } } }