From 72487019b3f255cece40a8073bbad8bc9968a3b7 Mon Sep 17 00:00:00 2001 From: "Alex Pooley (@zuedev)" Date: Wed, 22 Jul 2026 15:32:57 +0100 Subject: major code refactor, add uex lookup --- 174bg/discord-bot/source/utilities/createTicket.js | 55 ++++++++++++++++++++++ .../source/utilities/notifyRoleByName.js | 19 ++++++++ 2 files changed, 74 insertions(+) create mode 100644 174bg/discord-bot/source/utilities/createTicket.js create mode 100644 174bg/discord-bot/source/utilities/notifyRoleByName.js (limited to '174bg/discord-bot/source/utilities') diff --git a/174bg/discord-bot/source/utilities/createTicket.js b/174bg/discord-bot/source/utilities/createTicket.js new file mode 100644 index 0000000..6289715 --- /dev/null +++ b/174bg/discord-bot/source/utilities/createTicket.js @@ -0,0 +1,55 @@ +import { ChannelType, PermissionFlagsBits } from "discord.js"; + +export default async ( + interaction, + options = { roleNamesWithAccess: [], ticketNamePrefix: "ticket-" }, +) => { + const ticketsCategory = interaction.guild.channels.cache.find( + (channel) => + channel.name.toLowerCase() === "tickets" && + channel.type === ChannelType.GuildCategory, + ); + + if (!ticketsCategory) + return await interaction.reply("Tickets category not found."); + + // get the roles that should have access to this ticket + const rolesWithAccess = options.roleNamesWithAccess.map((roleName) => { + return interaction.guild.roles.cache.find( + (role) => role.name.toLowerCase() === roleName.toLowerCase(), + ); + }); + + // create a new text channel under the "tickets" category with the following format: ticket- + const timestamp = new Date() + .toISOString() + .replace(/[-:.T]/g, "") + .slice(2, 16); + + const channelName = `${options.ticketNamePrefix}${timestamp}`; + + const newChannel = await interaction.guild.channels.create({ + name: channelName, + type: ChannelType.GuildText, + parent: ticketsCategory.id, + // set permissions so that only the user who created the ticket and the roles with access can view it + permissionOverwrites: [ + { + id: interaction.user.id, + allow: [ + PermissionFlagsBits.ViewChannel, + PermissionFlagsBits.SendMessages, + ], + }, + ...rolesWithAccess.map((role) => ({ + id: role.id, + allow: [ + PermissionFlagsBits.ViewChannel, + PermissionFlagsBits.SendMessages, + ], + })), + ], + }); + + return newChannel; +}; diff --git a/174bg/discord-bot/source/utilities/notifyRoleByName.js b/174bg/discord-bot/source/utilities/notifyRoleByName.js new file mode 100644 index 0000000..1b2b82a --- /dev/null +++ b/174bg/discord-bot/source/utilities/notifyRoleByName.js @@ -0,0 +1,19 @@ +export default async (guild, roleName, message) => { + // get the role by name + const role = guild.roles.cache.find( + (role) => role.name.toLowerCase() === roleName.toLowerCase(), + ); + + if (!role) { + console.error(`Role "${roleName}" not found.`); + return; + } + + // get all members with the role + const membersWithRole = role.members; + + // send a DM to each member with the role + for (const member of membersWithRole.values()) { + await member.send(message); + } +}; -- cgit v1.2.3