From 3e066d08ce7a806e6ae32b3e5e0074ea7aa83100 Mon Sep 17 00:00:00 2001 From: Noah Date: Fri, 11 Feb 2022 23:34:38 -0600 Subject: [PATCH] New Departments --- Commands/ticket.js | 120 ++++++++++++++++++++--------------------- Configs/supportbot.yml | 42 +++++++-------- Events/ready.js | 41 ++++++++------ 3 files changed, 104 insertions(+), 99 deletions(-) diff --git a/Commands/ticket.js b/Commands/ticket.js index 8813bab..897650e 100644 --- a/Commands/ticket.js +++ b/Commands/ticket.js @@ -31,6 +31,13 @@ module.exports = new Command({ permissions: ["SEND_MESSAGES"], async run(interaction) { + let disableCommand = true; + if (interaction.isCommand() && disableCommand) + return interaction.reply({ + content: "This command is disabled", + ephemeral: true, + }); + let department = interaction.customId?.split("-")[1] || null; let TicketData = await JSON.parse( fs.readFileSync("./Data/TicketData.json", "utf8") ); @@ -73,8 +80,7 @@ module.exports = new Command({ const TicketExists = new MessageEmbed() .setTitle("Ticket Exists!") - .setDescription(`${supportbot.TicketExists}`) - .setColor(supportbot.WarningColour); + .setDescription(`${supportbot.TicketExists}`); if ( await interaction.guild.channels.cache.find( @@ -89,19 +95,7 @@ module.exports = new Command({ } const Staff = await getRole(supportbot.Staff, interaction.guild); const Admin = await getRole(supportbot.Admin, interaction.guild); - const DeptRole1 = await getRole( - supportbot.DepartmentRole_1, - interaction.guild - ); - const DeptRole2 = await getRole( - supportbot.DepartmentRole_2, - interaction.guild - ); - const DeptRole3 = await getRole( - supportbot.DepartmentRole_3, - interaction.guild - ); - if (!Staff || !Admin || !DeptRole1 || !DeptRole2 || !DeptRole3) + if (!Staff || !Admin) return interaction.reply({ content: "Some roles seem to be missing!\nPlease check for errors when starting the bot.", @@ -109,7 +103,7 @@ module.exports = new Command({ }); const Author = interaction.user; let TicketCategory = await getCategory( - supportbot.TicketCategory, + supportbot.Departments[department].category || supportbot.TicketCategory, interaction.guild ); const ticketChannel = await interaction.guild.channels.create( @@ -133,13 +127,13 @@ module.exports = new Command({ ], } ); - if (supportbot.AllowStaff) { - ticketChannel.permissionOverwrites.edit(Staff.id, { + if (supportbot.AllowAllStaff) { + await ticketChannel.permissionOverwrites.edit(Staff.id, { VIEW_CHANNEL: true, }); } - if (supportbot.TicketDepartments) { - ticketChannel.permissionOverwrites.edit(interaction.user.id, { + if (supportbot.TicketDepartments && !department) { + await ticketChannel.permissionOverwrites.edit(interaction.user.id, { SEND_MESSAGES: false, }); } @@ -203,10 +197,10 @@ module.exports = new Command({ } } - if (supportbot.TicketDepartments) { + if (supportbot.TicketDepartments && !department) { TicketMessage.addFields({ name: "Departments", - value: ` **${supportbot.DepartmentTitle_1}**\n **${supportbot.DepartmentTitle_2}**\n **${supportbot.DepartmentTitle_3}**`, + value: ` **${supportbot.Departments.map((X) => X.title).join("\n")}**`, }); } const CloseButton = new MessageButton() @@ -222,33 +216,16 @@ module.exports = new Command({ .setEmoji(supportbot.TicketLockEmoji); const row2 = new MessageActionRow().addComponents(CloseButton, LockButton); - - if (supportbot.TicketDepartments) { + if (supportbot.TicketDepartments && !department) { try { - const Department1Button = new MessageButton() - .setCustomId("Department1") - .setLabel(supportbot.DepartmentTitle_1) - .setStyle(supportbot.TicketDept1Colour) - .setEmoji(supportbot.TicketDept1Emoji); - - const Department2Button = new MessageButton() - .setCustomId("Department2") - .setLabel(supportbot.DepartmentTitle_2) - .setStyle(supportbot.TicketDept2Colour) - .setEmoji(supportbot.TicketDept2Emoji); - - const Department3Button = new MessageButton() - .setCustomId("Department3") - .setLabel(supportbot.DepartmentTitle_3) - .setStyle(supportbot.TicketDept3Colour) - .setEmoji(supportbot.TicketDept3Emoji); - - const row = new MessageActionRow().addComponents( - Department1Button, - Department2Button, - Department3Button + let buttons = await supportbot.Departments.map((x) => + new MessageButton() + .setCustomId("Department" + supportbot.Departments.indexOf(x)) + .setLabel(x.title) + .setStyle(x.color) + .setEmoji(x.emoji) ); - + const row = new MessageActionRow().addComponents(buttons); const m = await ticketChannel.send({ embeds: [TicketMessage], components: [row], @@ -287,20 +264,9 @@ module.exports = new Command({ return await ticketChannel.delete(); } } - let role; - let title; - if (collector.customId === "Department1") { - role = DeptRole1; - title = supportbot.DepartmentTitle_1; - } - if (collector.customId === "Department2") { - role = DeptRole2; - title = supportbot.DepartmentTitle_2; - } - if (collector.customId === "Department3") { - role = DeptRole3; - title = supportbot.DepartmentTitle_3; - } + let num = collector.customId.split("Department")[1]; + let role = getRole(supportbot.Departments[num].role, interaction.guild); + let title = supportbot.Departments[num].title; await ticketChannel.permissionOverwrites.edit(role.id, { VIEW_CHANNEL: true, @@ -327,7 +293,37 @@ module.exports = new Command({ }); } catch (error) {} } else { - await ticketChannel.send({ embeds: [TicketMessage], components: [row2] }); + await ticketChannel.send({ + embeds: [TicketMessage], + components: [row2], + }); + if (department) { + let role = await getRole( + supportbot.Departments[department].role, + interaction.guild + ); + let title = supportbot.Departments[department].title; + await ticketChannel.permissionOverwrites.edit(role.id, { + VIEW_CHANNEL: true, + }); + let TicketCat = await getCategory( + supportbot.Departments[department].category || + supportbot.TicketCategory, + interaction.guild + ); + await ticketChannel.setParent(TicketCat.id); + await ticketChannel.send({ + embeds: [ + { + description: `> Thank for reaching out to the **${title} Department**. Please provide us information regarding your query.`, + color: supportbot.EmbedColour, + }, + ], + }); + } + if (supportbot.AllowTicketMentions) { + await ticketChannel.send("@here"); + } } }, }); diff --git a/Configs/supportbot.yml b/Configs/supportbot.yml index 20ea2f9..93ca137 100644 --- a/Configs/supportbot.yml +++ b/Configs/supportbot.yml @@ -84,7 +84,7 @@ SuggestionDownvote: "❌" # Tickets Configuration # ------------------------- -TicketCategory: "Tickets" +TicketCategory: "Tickets" # Only for tickets without a category TicketPrefix: "ticket-" # The prefix for ticket channel names TicketLog: "logs" @@ -143,14 +143,6 @@ TicketCloseColour: "DANGER" TicketDeleteColour: "DANGER" TicketLockColour: "PRIMARY" -TicketDept1Colour: "PRIMARY" -TicketDept2Colour: "PRIMARY" -TicketDept3Colour: "PRIMARY" - -TicketDept1Emoji: "1️⃣" -TicketDept2Emoji: "2️⃣" -TicketDept3Emoji: "3️⃣" - TranscriptSavedMessage: "📝 **Transcript Saved!**" TicketLockMessage: "❌ **Ticket Locked!**" TicketDeleteMessage: "⚠ **Ticket Deleting!**" # Tickets deleting after 5 seconds by default. @@ -161,22 +153,28 @@ TicketDeleteMessage: "⚠ **Ticket Deleting!**" # Tickets deleting after 5 secon TicketDepartments: true # Delete the ticket if no department selected. TIME IN MINUTES Timeout: 5 -AllowStaff: true -# If set to false users with the "Staff" role will not be able to view tickets -# without a valid department role set below. +# Set to true to allow all staff to access the ticket +AllowAllStaff: false -# Set to false to allow "Staff" to see tickets whether its a department for them or not. - -DepartmentTitle_1: "General Support" -DepartmentTitle_2: "Billing Support" -DepartmentTitle_3: "Admin Team" -# Ticket department title, This is the title for a ticket department to help users know what is available. - -DepartmentRole_1: "Support" -DepartmentRole_2: "Support" -DepartmentRole_3: "Admin" # Ticket roles are the roles that will be able to gain access to tickets depending on what department has been chosen. +Departments: + - title: "General Support" + role: "Support" + color: "PRIMARY" + emoji: "1️⃣" + category: "Tickets" + - title: "Billing Support" + role: "Support" + color: "PRIMARY" + emoji: "2️⃣" + category: "Billing" + - title: "Admin Team" + role: "Admin" + color: "PRIMARY" + emoji: "3️⃣" + category: "Tickets" + # --- Closing Config --- # --- Start --- diff --git a/Events/ready.js b/Events/ready.js index 396360a..12beb16 100644 --- a/Events/ready.js +++ b/Events/ready.js @@ -39,10 +39,12 @@ module.exports = new Event("ready", async (client) => { `Connected to Discord` ); console.log( - `\u001b[33m`, - `Invite to your server:`, - `\u001b[36m`, - `https://discord.com/api/oauth2/authorize?client_id=` + client.user.id + `&permissions=8&scope=bot%20applications.commands` + `\u001b[33m`, + `Invite to your server:`, + `\u001b[36m`, + `https://discord.com/api/oauth2/authorize?client_id=` + + client.user.id + + `&permissions=8&scope=bot%20applications.commands` ); console.log( `\u001b[33m`, @@ -88,10 +90,10 @@ module.exports = new Event("ready", async (client) => { supportbot.Admin, supportbot.Staff, supportbot.TicketBlackListRole, - supportbot.DepartmentRole_1, - supportbot.DepartmentRole_2, - supportbot.DepartmentRole_3, ]; + if (supportbot.TicketDepartments) { + supportbot.Departments.forEach((department) => roles.push(department.role)); + } if (supportbot.AutoRole) roles.push(supportbot.AutoRole_Role); const channels = [ supportbot.SuggestionChannel, @@ -160,7 +162,7 @@ module.exports = new Event("ready", async (client) => { fs.readFileSync("./Data/ticket-panel-id.json", "utf8") ); - chan1.messages.fetch(panelid.TicketPanelID).catch(async (r) => { + chan1.messages.fetch(panelid.TicketPanelID).catch(async () => { let embed = new Discord.MessageEmbed() .setTitle(`${panelconfig.PanelTitle}`) .setColor(supportbot.SuccessColour) @@ -177,13 +179,22 @@ module.exports = new Event("ready", async (client) => { if (panelconfig.TicketPanel_Image) { embed.setImage(panelconfig.PanelImage); } - - let button = new Discord.MessageButton() - .setLabel(panelconfig.ButtonLabel) - .setCustomId("openticket") - .setStyle(panelconfig.ButtonColour) - .setEmoji(panelconfig.ButtonEmoji); - + let button; + if (supportbot.TicketDepartments) { + button = supportbot.Departments.map((x) => + new Discord.MessageButton() + .setCustomId("department-" + supportbot.Departments.indexOf(x)) + .setLabel(x.title) + .setStyle(x.color) + .setEmoji(x.emoji) + ); + } else { + button = new Discord.MessageButton() + .setLabel(panelconfig.ButtonLabel) + .setCustomId("openticket") + .setStyle(panelconfig.ButtonColour) + .setEmoji(panelconfig.ButtonEmoji); + } let row = new Discord.MessageActionRow().addComponents(button); await chan1