diff --git a/prisma/aikouticket.db b/prisma/aikouticket.db index 152e96f..5e86302 100644 Binary files a/prisma/aikouticket.db and b/prisma/aikouticket.db differ diff --git a/prisma/example.mongodb.schema.prisma b/prisma/example.mongodb.schema.prisma index 0f3b92d..bad004c 100644 --- a/prisma/example.mongodb.schema.prisma +++ b/prisma/example.mongodb.schema.prisma @@ -17,9 +17,4 @@ datasource db { model tickets { guildId String @id @map("_id") selectMenuOptions String -} - -model users { - userId String @id @map("_id") - activeTickets Int } \ No newline at end of file diff --git a/prisma/example.postgresql.schema.prisma b/prisma/example.postgresql.schema.prisma index 51c9af7..e2f603d 100644 --- a/prisma/example.postgresql.schema.prisma +++ b/prisma/example.postgresql.schema.prisma @@ -17,9 +17,4 @@ datasource db { model tickets { guildId String @id selectMenuOptions String -} - -model users { - userId String @id - activeTickets Int } \ No newline at end of file diff --git a/prisma/schema.prisma b/prisma/schema.prisma index 6a5c2f8..7991bf3 100644 --- a/prisma/schema.prisma +++ b/prisma/schema.prisma @@ -11,8 +11,4 @@ datasource db { model tickets { guildId String @id selectMenuOptions String -} - -model users { - userId String @id } \ No newline at end of file diff --git a/src/commands/tickets/panel.ts b/src/commands/tickets/panel.ts index 923de31..4d68503 100644 --- a/src/commands/tickets/panel.ts +++ b/src/commands/tickets/panel.ts @@ -1,6 +1,7 @@ import { ActionRowBuilder, CommandInteraction, + EmbedBuilder, StringSelectMenuBuilder, StringSelectMenuOptionBuilder, } from 'discord.js'; @@ -38,10 +39,42 @@ export default class PanelCommand extends Command { async run(client: Bot, interaction: CommandInteraction): Promise { await interaction.deferReply({ ephemeral: true }); - const configFile = fs.readFileSync('./config.yml', 'utf8'); - const config = YAML.parse(configFile); + let config; + try { + const configFile = fs.readFileSync('./config.yml', 'utf8'); + config = YAML.parse(configFile); + } catch (error) { + console.error('Error reading or parsing config file:', error); + await interaction.editReply({ + content: + 'There was an error loading the configuration. Please contact the administrator.', + }); + return; + } + + const panelEmbed = this.createPanelEmbed(client); + const selectMenu = this.createSelectMenu(config.ticketCategories, config.menuPlaceholder); + + const actionRowsMenus = new ActionRowBuilder().addComponents( + selectMenu + ); + + try { + await interaction.editReply({ content: 'Sending the panel in this channel...' }); + + await interaction.channel.send({ embeds: [panelEmbed], components: [actionRowsMenus] }); + + await this.saveTicketData(interaction.guild.id, selectMenu.options); + } catch (error) { + console.error('Error sending the panel or saving ticket data:', error); + await interaction.editReply({ + content: 'There was an error sending the panel. Please contact the administrator.', + }); + } + } - const panelEmbed = client + createPanelEmbed(client: Bot): EmbedBuilder { + return client .embed() .setColor(this.client.color) .setTitle('AikouTicket') @@ -52,9 +85,9 @@ export default class PanelCommand extends Command { 'https://cdn.discordapp.com/attachments/1109764526552915988/1136666715078533303/image.png?ex=6647695f&is=664617df&hm=ec6a3e7de621daf0813e7a70c6ec7b2c9741bad8450172d356f85f28273610b2&' ) .setTimestamp(); + } - const ticketCategories = config.ticketCategories; - + createSelectMenu(ticketCategories: any, placeholder: string): StringSelectMenuBuilder { const options = Object.keys(ticketCategories).map(customId => { const category = ticketCategories[customId]; const option = new StringSelectMenuOptionBuilder() @@ -69,28 +102,20 @@ export default class PanelCommand extends Command { return option; }); - const selectMenu = new StringSelectMenuBuilder() + return new StringSelectMenuBuilder() .setCustomId('categoryMenu') - .setPlaceholder(config.menuPlaceholder) + .setPlaceholder(placeholder) .setMinValues(1) .setMaxValues(1) .addOptions(options); + } - const actionRowsMenus = new ActionRowBuilder().addComponents( - selectMenu - ); - - await interaction.editReply({ content: 'Sending the panel in this channel...' }); - - await interaction.channel - .send({ embeds: [panelEmbed], components: [actionRowsMenus] }) - .then(async () => { - await this.client.prisma.tickets.create({ - data: { - guildId: interaction.guild.id, - selectMenuOptions: JSON.stringify(options), - }, - }); - }); + async saveTicketData(guildId: string, options: any): Promise { + await this.client.prisma.tickets.create({ + data: { + guildId, + selectMenuOptions: JSON.stringify(options), + }, + }); } }