Skip to content

Commit

Permalink
📦 NEW: close command
Browse files Browse the repository at this point in the history
  • Loading branch information
warengonzaga authored May 5, 2023
1 parent da0e59e commit 2156fe5
Show file tree
Hide file tree
Showing 3 changed files with 96 additions and 34 deletions.
121 changes: 87 additions & 34 deletions src/bot.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 {
Expand Down Expand Up @@ -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({
Expand All @@ -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);
});

Expand Down
4 changes: 4 additions & 0 deletions src/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -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.",
Expand Down
5 changes: 5 additions & 0 deletions src/utils/database.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down

0 comments on commit 2156fe5

Please sign in to comment.