Skip to content

Commit

Permalink
handle ticket modal with the rest
Browse files Browse the repository at this point in the history
  • Loading branch information
jvnipers committed Jan 6, 2025
1 parent 9a125ce commit c63033f
Show file tree
Hide file tree
Showing 2 changed files with 103 additions and 102 deletions.
103 changes: 103 additions & 0 deletions src/modals.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ const { client } = require("./index.js");

client.on(Events.InteractionCreate, async (interaction) => {
if (!interaction.isModalSubmit()) return;
if (!interaction.customId) return;

if (interaction.customId === "modalMc") {
const uuid = interaction.fields.getTextInputValue("uuidMc");
Expand Down Expand Up @@ -268,5 +269,107 @@ client.on(Events.InteractionCreate, async (interaction) => {
ephemeral: true,
});
}

if (interaction.customId === "modalTicket") {
const data = await system.findOne({
Guild: interaction.guild.id,
Type: "tickets",
});
if (!data) return;

const topicInput = interaction.fields.getTextInputValue("topicTicket");
const infoInput = interaction.fields.getTextInputValue("infoTicket");
const additionalInput =
interaction.fields.getTextInputValue("additionalTicket");

if (infoInput.length > 500 || additionalInput.length > 500) {
return await interaction.reply({
content: `You have entered too much text, please shorten it and try again.`,
ephemeral: true,
});
}

const posChannel = await interaction.guild.channels.cache.find(
(c) => c.name === `ticket-${interaction.user.id}`
);
if (posChannel)
return await interaction.reply({
content: `You already have an open ticket - ${posChannel}`,
ephemeral: true,
});

const category = data.Channel;

if (!category) {
return await interaction.reply({
content: `Tickets are currently disabled, please try again later.`,
ephemeral: true,
});
}

const embed = new EmbedBuilder()
.setColor("#ff00b3")
.setTitle(`${interaction.user.username}'s Ticket`)
.setDescription(
`Thank you for opening a ticket. Please wait while the staff reviews your information. We will respond to you shortly.`
)
.addFields([
{
name: `Topic`,
value: `${topicInput}`,
inline: false,
},
{
name: `Info`,
value: `${infoInput}`,
inline: false,
},
{
name: `Additional Info`,
value: `${additionalInput}`,
inline: false,
},
{
name: `Type`,
value: `${data.Ticket}`,
inline: false,
},
])
.setFooter({ text: `${interaction.guild.name} Tickets` })
.setTimestamp()
.setImage("https://femboy.kz/images/wide.png");

const buttonClose = new ActionRowBuilder().addComponents(
new ButtonBuilder()
.setCustomId("ticket-close")
.setLabel("Close ticket")
.setStyle(ButtonStyle.Danger)
);

let channel = await interaction.guild.channels.create({
name: `ticket-${interaction.user.id}`,
type: ChannelType.GuildText,
parent: `${category}`,
});

try {
await channel.send({
embeds: [embed],
components: [buttonClose],
});
await interaction.reply({
content: `You have opened a ticket: ${channel}`,
ephemeral: true,
});

const member = interaction.user.id;
await channel.permissionOverwrites.edit(member, {
SendMessages: true,
ViewChannel: true,
});
} catch (error) {
console.error("Error submitting modal:", error);
}
}
}
});
102 changes: 0 additions & 102 deletions src/tickets.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,108 +57,6 @@ client.on(Events.InteractionCreate, async (interaction) => {
}
});

client.on(Events.InteractionCreate, async (interaction) => {
if (interaction.isModalSubmit()) {
if (interaction.customId === "modalTicket") {
const data = await system.findOne({
Guild: interaction.guild.id,
Type: "tickets",
});
if (!data) return;

const topicInput = interaction.fields.getTextInputValue("topicTicket");
const infoInput = interaction.fields.getTextInputValue("infoTicket");
const additionalInput =
interaction.fields.getTextInputValue("additionalTicket");

if (infoInput.length > 500 || additionalInput.length > 500) {
return await interaction.reply({
content: `You have entered too much text, please shorten it and try again.`,
ephemeral: true,
});
}

const posChannel = await interaction.guild.channels.cache.find(
(c) => c.name === `ticket-${interaction.user.id}`
);
if (posChannel)
return await interaction.reply({
content: `You already have an open ticket - ${posChannel}`,
ephemeral: true,
});

const category = data.Channel;

if (!category) {
return await interaction.reply({
content: `Tickets are currently disabled, please try again later.`,
ephemeral: true,
});
}

const embed = new EmbedBuilder()
.setColor("#ff00b3")
.setTitle(`${interaction.user.username}'s Ticket`)
.setDescription(
`Thank you for opening a ticket. Please wait while the staff reviews your information. We will respond to you shortly.`
)
.addFields([
{
name: `Topic`,
value: `${topicInput}`,
inline: false,
},
{
name: `Info`,
value: `${infoInput}`,
inline: false,
},
{
name: `Additional Info`,
value: `${additionalInput}`,
inline: false,
},
{
name: `Type`,
value: `${data.Ticket}`,
inline: false,
},
])
.setFooter({ text: `${interaction.guild.name} Tickets` })
.setTimestamp()
.setImage("https://femboy.kz/images/wide.png");

const buttonClose = new ActionRowBuilder().addComponents(
new ButtonBuilder()
.setCustomId("ticket-close")
.setLabel("Close ticket")
.setStyle(ButtonStyle.Danger)
);

let channel = await interaction.guild.channels.create({
name: `ticket-${interaction.user.id}`,
type: ChannelType.GuildText,
parent: `${category}`,
});

await channel.send({
embeds: [embed],
components: [buttonClose],
});
await interaction.reply({
content: `You have opened a ticket: ${channel}`,
ephemeral: true,
});

const member = interaction.user.id;
await channel.permissionOverwrites.edit(member, {
SendMessages: true,
ViewChannel: true,
});
}
}
});

client.on(Events.InteractionCreate, async (interaction) => {
if (interaction.isButton()) {
if (
Expand Down

0 comments on commit c63033f

Please sign in to comment.