pineafan | ad54d75 | 2022-04-18 19:01:43 +0100 | [diff] [blame^] | 1 | import Discord from 'discord.js'; |
| 2 | import readConfig from '../utils/readConfig.js' |
| 3 | import generateEmojiEmbed from '../utils/generateEmojiEmbed.js' |
| 4 | |
| 5 | export async function create(guild: Discord.Guild, member: Discord.User, client) { |
| 6 | let config = await readConfig(guild.id); |
| 7 | // @ts-ignore |
| 8 | const { log, NucleusColors, entry, renderUser, renderChannel, renderDelta } = client.logger |
| 9 | let overwrites = [{ |
| 10 | id: member, |
| 11 | allow: ["VIEW_CHANNEL", "SEND_MESSAGES", "ATTACH_FILES", "ADD_REACTIONS", "READ_MESSAGE_HISTORY"], |
| 12 | type: "member" |
| 13 | }] as Discord.OverwriteResolvable[]; |
| 14 | if (config.tickets.supportRole != null) { |
| 15 | overwrites.push({ |
| 16 | id: guild.roles.cache.get(config.tickets.supportRole), |
| 17 | allow: ["VIEW_CHANNEL", "SEND_MESSAGES", "ATTACH_FILES", "ADD_REACTIONS", "READ_MESSAGE_HISTORY"], |
| 18 | type: "role" |
| 19 | }) |
| 20 | } |
| 21 | |
| 22 | let c; |
| 23 | try { |
| 24 | c = await guild.channels.create(member.username, { |
| 25 | type: "GUILD_TEXT", |
| 26 | topic: `${member.id} Active`, |
| 27 | parent: config.tickets.category, |
| 28 | nsfw: false, |
| 29 | permissionOverwrites: (overwrites as Discord.OverwriteResolvable[]), |
| 30 | reason: "Creating ticket" |
| 31 | }) |
| 32 | } catch (e) { |
| 33 | return null |
| 34 | } |
| 35 | try { |
| 36 | await c.send( |
| 37 | { |
| 38 | content: (`<@${member.id}>` + (config.tickets.supportRole != null ? ` • <@&${config.tickets.supportRole}>` : "")), |
| 39 | allowedMentions: { |
| 40 | users: [member.id], |
| 41 | roles: (config.tickets.supportRole != null ? [config.tickets.supportRole] : []) |
| 42 | } |
| 43 | } |
| 44 | ) |
| 45 | await c.send({ embeds: [new generateEmojiEmbed() |
| 46 | .setTitle("New Ticket") |
| 47 | .setDescription( |
| 48 | `Ticket created by a Moderator\n` + |
| 49 | `**Support type:** Appeal submission\n` + |
| 50 | `**Ticket ID:** \`${c.id}\`\n` + |
| 51 | `Type \`/ticket close\` to archive this ticket.`, |
| 52 | ) |
| 53 | .setStatus("Success") |
| 54 | .setEmoji("GUILD.TICKET.OPEN") |
| 55 | ]}) |
| 56 | let data = { |
| 57 | meta:{ |
| 58 | type: 'ticketCreate', |
| 59 | displayName: 'Ticket Created', |
| 60 | calculateType: true, |
| 61 | color: NucleusColors.green, |
| 62 | emoji: 'GUILD.TICKET.OPEN', |
| 63 | timestamp: new Date().getTime() |
| 64 | }, |
| 65 | list: { |
| 66 | ticketFor: entry(member.id, renderUser(member)), |
| 67 | created: entry(new Date().getTime(), renderDelta(new Date().getTime())), |
| 68 | ticketChannel: entry(c.id, renderChannel(c)), |
| 69 | }, |
| 70 | hidden: { |
| 71 | guild: guild.id |
| 72 | } |
| 73 | } |
| 74 | log(data, client); |
| 75 | } catch (e) { console.log(e); return null } |
| 76 | return c.id |
| 77 | } |
| 78 | |
| 79 | export async function areTicketsEnabled(guild: string) { |
| 80 | let config = await readConfig(guild); |
| 81 | return config.tickets.enabled; |
| 82 | } |