forked from StormPacer/yatb
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add close button and fix stale ticket bug
- Loading branch information
1 parent
f925e84
commit ffb53a0
Showing
5 changed files
with
78 additions
and
52 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
const { ButtonBuilder, ButtonStyle, EmbedBuilder, ActionRowBuilder } = require("discord.js"); | ||
const db = require("../../../connectDb"); | ||
|
||
export async function closeRequest(interaction) { | ||
const channel = interaction.channel; | ||
|
||
if (!channel.name.startsWith("ticket-")) { | ||
return interaction.reply({ content: "This is not a ticket channel.", ephemeral: true }) | ||
} | ||
|
||
let embed = new EmbedBuilder() | ||
.setDescription(`${interaction.user} wants to close the ticket.`) | ||
.setColor("Random") | ||
|
||
const ticket = await db("tickets") | ||
.select("*") | ||
.where("channel_id", channel.id) | ||
.first(); | ||
|
||
if (interaction.user.id === ticket.user_id) { | ||
embed.setFooter({ text: "Wait for a staff member to close the ticket." }) | ||
} | ||
|
||
else { | ||
embed.setFooter({ text: `${ticket.user_id} | ${interaction.user.id}` }) | ||
} | ||
|
||
const row = new ActionRowBuilder() | ||
.addComponents( | ||
new ButtonBuilder() | ||
.setCustomId("confirm_close") | ||
.setLabel("Confirm") | ||
.setStyle(ButtonStyle.Success) | ||
.setEmoji("✅") | ||
) | ||
.addComponents( | ||
new ButtonBuilder() | ||
.setCustomId("cancel_close") | ||
.setLabel("Cancel") | ||
.setStyle(ButtonStyle.Danger) | ||
.setEmoji("✖️") | ||
) | ||
|
||
await db("tickets") | ||
.where("channel_id", channel.id) | ||
.update({ close_requested_at: new Date() }) | ||
|
||
await interaction.reply({ embeds: [embed], components: [row] }); | ||
if (interaction.user.id !== ticket.user_id) { | ||
await interaction.channel.send({ content: `<@${ticket.user_id}>, Please confirm the closing of this ticket.` }) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import { closeRequest } from "../../../helpers/closeRequestEmbed"; | ||
|
||
module.exports = { | ||
id: "close_request", | ||
async execute(interaction) { | ||
closeRequest(interaction); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,57 +1,12 @@ | ||
const { SlashCommandBuilder, ButtonBuilder, ButtonStyle, EmbedBuilder, ActionRowBuilder } = require("discord.js"); | ||
const db = require("../../../connectDb"); | ||
const { SlashCommandBuilder } = require("discord.js"); | ||
|
||
import { closeRequest } from "../../../helpers/closeRequestEmbed"; | ||
|
||
module.exports = { | ||
data: new SlashCommandBuilder() | ||
.setName('close') | ||
.setDescription('Close a ticket.'), | ||
async execute(interaction) { | ||
const channel = interaction.channel; | ||
|
||
if (!channel.name.startsWith("ticket-")) { | ||
return interaction.reply({ content: "This is not a ticket channel.", ephemeral: true }) | ||
} | ||
|
||
let embed = new EmbedBuilder() | ||
.setDescription(`${interaction.user} wants to close the ticket.`) | ||
.setColor("Random") | ||
|
||
const ticket = await db("tickets") | ||
.select("*") | ||
.where("channel_id", channel.id) | ||
.first(); | ||
|
||
if (interaction.user.id === ticket.user_id) { | ||
embed.setFooter({ text: "Wait for a staff member to close the ticket." }) | ||
} | ||
|
||
else { | ||
embed.setFooter({ text: `${ticket.user_id} | ${interaction.user.id}` }) | ||
} | ||
|
||
const row = new ActionRowBuilder() | ||
.addComponents( | ||
new ButtonBuilder() | ||
.setCustomId("confirm_close") | ||
.setLabel("Confirm") | ||
.setStyle(ButtonStyle.Success) | ||
.setEmoji("✅") | ||
) | ||
.addComponents( | ||
new ButtonBuilder() | ||
.setCustomId("cancel_close") | ||
.setLabel("Cancel") | ||
.setStyle(ButtonStyle.Danger) | ||
.setEmoji("✖️") | ||
) | ||
|
||
await db("tickets") | ||
.where("channel_id", channel.id) | ||
.update({ close_requested_at: new Date() }) | ||
|
||
await interaction.reply({ embeds: [embed], components: [row] }); | ||
if (interaction.user.id !== ticket.user_id) { | ||
await interaction.channel.send({ content: `<@${ticket.user_id}>, Please confirm the closing of this ticket.` }) | ||
} | ||
closeRequest(interaction); | ||
} | ||
} |