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.
- Loading branch information
1 parent
6c7cff7
commit 738ca9d
Showing
3 changed files
with
98 additions
and
62 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
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,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.` }) | ||
} | ||
} | ||
} |
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,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.` }) | ||
} | ||
} | ||
} |