| import Discord, { MessageActionRow, MessageButton } from "discord.js"; |
| import EmojiEmbed from "../utils/generateEmojiEmbed.js"; |
| import getEmojiByName from "../utils/getEmojiByName.js"; |
| import client from "../utils/client.js"; |
| |
| export async function create(guild: Discord.Guild, member: Discord.User, createdBy: Discord.User, reason: string, customReason?: string) { |
| const config = await client.database.guilds.read(guild.id); |
| const { log, NucleusColors, entry, renderUser, renderChannel, renderDelta } = client.logger; |
| const overwrites = [{ |
| id: member, |
| allow: ["VIEW_CHANNEL", "SEND_MESSAGES", "ATTACH_FILES", "ADD_REACTIONS", "READ_MESSAGE_HISTORY"], |
| type: "member" |
| }] as Discord.OverwriteResolvable[]; |
| overwrites.push({ |
| id: guild.roles.everyone, |
| deny: ["VIEW_CHANNEL"], |
| type: "role" |
| }); |
| if (config.tickets.supportRole !== null) { |
| overwrites.push({ |
| id: guild.roles.cache.get(config.tickets.supportRole), |
| allow: ["VIEW_CHANNEL", "SEND_MESSAGES", "ATTACH_FILES", "ADD_REACTIONS", "READ_MESSAGE_HISTORY"], |
| type: "role" |
| }); |
| } |
| |
| let c; |
| try { |
| c = await guild.channels.create(member.username, { |
| type: "GUILD_TEXT", |
| topic: `${member.id} Active`, |
| parent: config.tickets.category, |
| nsfw: false, |
| permissionOverwrites: (overwrites as Discord.OverwriteResolvable[]), |
| reason: "Creating ticket" |
| }); |
| } catch (e) { |
| return null; |
| } |
| try { |
| await c.send( |
| { |
| content: (`<@${member.id}>` + (config.tickets.supportRole !== null ? ` • <@&${config.tickets.supportRole}>` : "")), |
| allowedMentions: { |
| users: [member.id], |
| roles: (config.tickets.supportRole !== null ? [config.tickets.supportRole] : []) |
| } |
| } |
| ); |
| await c.send({ embeds: [new EmojiEmbed() |
| .setTitle("New Ticket") |
| .setDescription( |
| "Ticket created by a Moderator\n" + |
| `**Support type:** ${customReason ? customReason : "Appeal submission"}\n` + (reason !== null ? `**Reason:**\n> ${reason}\n` : "") + |
| `**Ticket ID:** \`${c.id}\`\n` + |
| "Type `/ticket close` to close this ticket." |
| ) |
| .setStatus("Success") |
| .setEmoji("GUILD.TICKET.OPEN") |
| ], components: [new MessageActionRow().addComponents([new MessageButton() |
| .setLabel("Close") |
| .setStyle("DANGER") |
| .setCustomId("closeticket") |
| .setEmoji(getEmojiByName("CONTROL.CROSS", "id")) |
| ])]}); |
| const data = { |
| meta:{ |
| type: "ticketCreate", |
| displayName: "Ticket Created", |
| calculateType: "ticketUpdate", |
| color: NucleusColors.green, |
| emoji: "GUILD.TICKET.OPEN", |
| timestamp: new Date().getTime() |
| }, |
| list: { |
| ticketFor: entry(member.id, renderUser(member)), |
| createdBy: entry(createdBy.id, renderUser(createdBy)), |
| created: entry(new Date().getTime(), renderDelta(new Date().getTime())), |
| ticketChannel: entry(c.id, renderChannel(c)) |
| }, |
| hidden: { |
| guild: guild.id |
| } |
| }; |
| log(data); |
| } catch (e) { console.log(e); return null; } |
| return c.id; |
| } |
| |
| export async function areTicketsEnabled(guild: string) { |
| const config = await client.database.guilds.read(guild); |
| return config.tickets.enabled; |
| } |