From 2156fe51b82e7101ea2a94e7ff604bf1ada7af50 Mon Sep 17 00:00:00 2001 From: Waren Gonzaga Date: Fri, 5 May 2023 07:13:08 +0000 Subject: [PATCH] =?UTF-8?q?=F0=9F=93=A6=20NEW:=20close=20command?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/bot.js | 121 ++++++++++++++++++++++++++++++------------ src/config.json | 4 ++ src/utils/database.js | 5 ++ 3 files changed, 96 insertions(+), 34 deletions(-) diff --git a/src/bot.js b/src/bot.js index b3bd32e..2be5a2c 100644 --- a/src/bot.js +++ b/src/bot.js @@ -66,15 +66,12 @@ client.on('messageCreate', async (message) => { if (typeof post.availableTags !== 'undefined') { // filter the tags to get the resolution tag name ID const resolutionTag = post.availableTags.filter((item) => { return item.name == config.tag_name_resolve }); + const closeTag = post.availableTags.filter((item) => { return item.name == config.tag_name_close }); // get the existing tags of the post const postTags = message.channel.appliedTags; - - // collect tags - let initialTags = [resolutionTag[0].id,...postTags]; - let tags = [...new Set(initialTags)]; // check if the command has the prefix and includes "resolve" - if (message.content.startsWith(config.command_prefix) && message.content.includes(config.command_resolve)) { + if (message.content.startsWith(config.command_prefix)) { await message.delete(); // delete the commmand message // check if the message is in the forum post and from the support role @@ -83,39 +80,91 @@ client.on('messageCreate', async (message) => { // check if the post has fewer tags if (postTags.length < 5) { - // send embed message before resolving the post - await message.channel.send({ embeds: [ - sendEmbedMessage(`${config.reminder_resolve}`) - ], - content: `🔔 <@${message.channel.ownerId}>` - }) - - // then archive and lock it - message.channel.edit({ - appliedTags: tags, - archived: true - }); - // gather data const postId = message.channel.id; const resolutionTime = formatTime(message.createdTimestamp); const resolvedBy = member.user.username; - // check if there's a mentioned user - if (mention.users.first()) { - // send the data, use the mentioned user as resolvedBy - sendData({ - post_id: postId, - resolution_time: resolutionTime, - resolved_by: mention.users.first().username, - }, config.datasheet_resolve); - } else { - // send the data with the one who sends the command - sendData({ - post_id: postId, - resolution_time: resolutionTime, - resolved_by: resolvedBy - }, config.datasheet_resolve); + // functions for resolve command + if (message.content.includes(config.command_resolve)) { + + // data for resolve command + // collect tags + let initialTags = [resolutionTag[0].id,...postTags]; + let tags = [...new Set(initialTags)]; + + // send embed message upon executing the resolve command + await message.channel.send({ + embeds: [ + sendEmbedMessage(`${config.reminder_resolve}`) + ], + content: `🔔 <@${message.channel.ownerId}>` + }); + + // then archive and lock it + message.channel.edit({ + appliedTags: tags, + archived: true + }); + + // check if there's a mentioned user + if (mention.users.first()) { + // send the data, use the mentioned user as resolvedBy + sendData({ + post_id: postId, + resolution_time: resolutionTime, + resolved_by: mention.users.first().username, + }, config.datasheet_resolve); + } else { + // send the data with the one who sends the command + sendData({ + post_id: postId, + resolution_time: resolutionTime, + resolved_by: resolvedBy + }, config.datasheet_resolve); + } + + } + + // functions for close command + if (message.content.includes(config.command_close)) { + + // data for resolve command + // collect tags + let initialTags = [closeTag[0].id,...postTags]; + let tags = [...new Set(initialTags)]; + + // send embed message upon executing the close command + await message.channel.send({ + embeds: [ + sendEmbedMessage(`${config.reminder_close}`) + ], + content: `🔔 <@${message.channel.ownerId}>` + }); + + // then archive and lock it + message.channel.edit({ + appliedTags: tags, + archived: true + }); + + // check if there's a mentioned user + if (mention.users.first()) { + // send the data, use the mentioned user as resolvedBy + sendData({ + post_id: postId, + close_time: resolutionTime, + closed_by: mention.users.first().username, + }, config.datasheet_close); + } else { + // send the data with the one who sends the command + sendData({ + post_id: postId, + close_time: resolutionTime, + closed_by: resolvedBy + }, config.datasheet_close); + } + } } else { @@ -211,8 +260,10 @@ client.on('threadCreate', async post => { const tags = forumTags.join(', '); const firstResponse = `=IFERROR(VLOOKUP(A2:A,${config.datasheet_response}!A2:B,2,0))`; const resolutionTime = `=IFERROR(VLOOKUP(A2:A,${config.datasheet_resolve}!A2:B,2,0))`; + const closeTime = `=IFERROR(VLOOKUP(A2:A,${config.datasheet_close}!A2:B,2,0))`; const responder = `=IFERROR(VLOOKUP(A2:A,{${config.datasheet_response}!A2:A,${config.datasheet_response}!C2:C},2,0))`; const resolvedBy = `=IFERROR(VLOOKUP(A2:A,{${config.datasheet_resolve}!A2:A,${config.datasheet_resolve}!C2:C},2,0))`; + const closedBy = `=IFERROR(VLOOKUP(A2:A,{${config.datasheet_close}!A2:A,${config.datasheet_close}!C2:C},2,0))`; // send the data sendData({ @@ -225,7 +276,9 @@ client.on('threadCreate', async post => { responder: responder, first_response: firstResponse, resolution_time: resolutionTime, - resolved_by: resolvedBy + resolved_by: resolvedBy, + close_time: closeTime, + closed_by: closedBy }, config.datasheet_init); }); diff --git a/src/config.json b/src/config.json index 7c8cefd..1a19a16 100644 --- a/src/config.json +++ b/src/config.json @@ -3,12 +3,16 @@ "command_resolve": "resolve", "command_close": "close", "command_escalate": "escalate", + "command_reopen": "reopen", "tag_name_resolve": "Solved", "tag_name_close": "Closed", "tag_name_escalate": "Escalated", "datasheet_init": "init", "datasheet_response": "response", "datasheet_resolve": "resolve", + "datasheet_close": "close", + "datasheet_escalate": "escalate", + "datasheet_reopen": "reopen", "utc_offset": -8, "reminder_mention": "Hey! If you need help, please read the information in <#1074862134284005396> and post your questions or issues in the <#1029543258822553680> channel. Our team and community members are always ready to help you out. Thank you for building with us!", "reminder_max_tags": "Max tags (5) exceeded. Please update the original post with fewer tags and try again.", diff --git a/src/utils/database.js b/src/utils/database.js index a8326f0..06b1d2a 100644 --- a/src/utils/database.js +++ b/src/utils/database.js @@ -34,6 +34,11 @@ const sendData = async (data, datasheet) => { if (datasheet === config.datasheet_resolve) { await sheet.addRow(data); }; + + // check if the data will be send to close sheet + if (datasheet === config.datasheet_close) { + await sheet.addRow(data); + }; } module.exports = {