Skip to content

Commit

Permalink
undo helper function
Browse files Browse the repository at this point in the history
  • Loading branch information
bloodcloak committed Jun 8, 2024
1 parent 6c7cff7 commit 738ca9d
Show file tree
Hide file tree
Showing 3 changed files with 98 additions and 62 deletions.
56 changes: 0 additions & 56 deletions helpers/closeRequestEmbed.js

This file was deleted.

51 changes: 49 additions & 2 deletions interactions/buttons/operation/closeRequest.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,55 @@
const closeRequestEmbed = require("../../../helpers/closeRequestEmbed");
const { ButtonBuilder, ButtonStyle, EmbedBuilder, ActionRowBuilder } = require("discord.js");
const db = require("../../../connectDb");

module.exports = {
id: "close_request",
async execute(interaction) {
closeRequestEmbed(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.` })
}
}
}
53 changes: 49 additions & 4 deletions interactions/slash/operation/close.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,57 @@
const { SlashCommandBuilder } = require("discord.js");

const closeRequestEmbed = require("../../../helpers/closeRequestEmbed");
const { SlashCommandBuilder, ButtonBuilder, ButtonStyle, EmbedBuilder, ActionRowBuilder } = require("discord.js");
const db = require("../../../connectDb");

module.exports = {
data: new SlashCommandBuilder()
.setName('close')
.setDescription('Close a ticket.'),
async execute(interaction) {
closeRequestEmbed(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.` })
}
}
}

0 comments on commit 738ca9d

Please sign in to comment.