All commands and some events finished
diff --git a/src/actions/createModActionTicket.ts b/src/actions/createModActionTicket.ts
index 481666b..d6e9cd9 100644
--- a/src/actions/createModActionTicket.ts
+++ b/src/actions/createModActionTicket.ts
@@ -6,7 +6,7 @@
export async function create(
guild: Discord.Guild,
- member: Discord.User,
+ user: Discord.User,
createdBy: Discord.User,
reason: string | null,
customReason?: string
@@ -14,7 +14,7 @@
const config = await client.database.guilds.read(guild.id);
const { log, NucleusColors, entry, renderUser, renderChannel, renderDelta } = client.logger;
const overwrites = [{
- id: member,
+ id: user,
allow: ["ViewChannel", "SendMessages", "AttachFiles", "AddReactions", "ReadMessageHistory"],
type: OverwriteType.Member
}] as unknown as Discord.OverwriteResolvable[];
@@ -30,78 +30,146 @@
type: OverwriteType.Role
});
}
+ const targetChannel: Discord.CategoryChannel | Discord.TextChannel = (await guild.channels.fetch(config.tickets.category!))! as Discord.CategoryChannel | Discord.TextChannel;
- let c;
- try {
- c = await guild.channels.create({
- name: member.username,
- type: ChannelType.GuildText,
- 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] : []
+ let c: Discord.TextChannel | Discord.PrivateThreadChannel;
+ if (targetChannel.type === Discord.ChannelType.GuildCategory) {
+ const overwrites = [
+ {
+ id: user,
+ allow: ["ViewChannel", "SendMessages", "AttachFiles", "AddReactions", "ReadMessageHistory"],
+ type: Discord.OverwriteType.Member
}
+ ] as Discord.OverwriteResolvable[];
+ overwrites.push({
+ id: guild.roles.everyone,
+ deny: ["ViewChannel"],
+ type: Discord.OverwriteType.Role
});
- await c.send({
- embeds: [
- new EmojiEmbed()
- .setTitle("New Ticket")
- .setDescription(
- "Ticket created by a Moderator\n" +
+ if (config.tickets.supportRole !== null) {
+ overwrites.push({
+ id: guild.roles.cache.get(config.tickets.supportRole)!,
+ allow: ["ViewChannel", "SendMessages", "AttachFiles", "AddReactions", "ReadMessageHistory"],
+ type: Discord.OverwriteType.Role
+ });
+ }
+
+ try {
+ c = await guild.channels.create({
+ name: `${user.username.toLowerCase()}`,
+ type: ChannelType.GuildText,
+ topic: `${user.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:
+ `<@${user.id}>` +
+ (config.tickets.supportRole !== null ? ` • <@&${config.tickets.supportRole}>` : ""),
+ allowedMentions: {
+ users: [user.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 ${await getCommandMentionByName("ticket/close")} to close this ticket.`
- )
- .setStatus("Success")
- .setEmoji("GUILD.TICKET.OPEN")
- ],
- components: [
- new ActionRowBuilder<Discord.ButtonBuilder>().addComponents([
- new ButtonBuilder()
- .setLabel("Close")
- .setStyle(ButtonStyle.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()).toString(), renderDelta(new Date().getTime())),
- ticketChannel: entry(c.id, renderChannel(c))
- },
- hidden: {
- guild: guild.id
- }
- };
- log(data);
- } catch (e) {
- console.log(e);
- return null;
+ )
+ .setStatus("Success")
+ .setEmoji("GUILD.TICKET.OPEN")
+ ],
+ components: [
+ new ActionRowBuilder<ButtonBuilder>().addComponents([
+ new ButtonBuilder()
+ .setLabel("Close")
+ .setStyle(ButtonStyle.Danger)
+ .setCustomId("closeticket")
+ .setEmoji(getEmojiByName("CONTROL.CROSS", "id"))
+ ])
+ ]
+ });
+ } catch (e) {
+ return null;
+ }
+ } else {
+ c = await targetChannel.threads.create({name: `${user.username} - ${user.id} - Active`,
+ autoArchiveDuration: 60 * 24 * 7,
+ type: Discord.ChannelType.PrivateThread,
+ reason: "Creating ticket"
+ }) as Discord.PrivateThreadChannel;
+ c.members.add(user.id);
+ c.members.add(createdBy.id);
+ try {
+ await c.send({
+ content:
+ `<@${user.id}>` +
+ (config.tickets.supportRole !== null ? ` • <@&${config.tickets.supportRole}>` : ""),
+ allowedMentions: {
+ users: [user.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 ${await getCommandMentionByName("ticket/close")} to close this ticket.`
+ )
+ .setStatus("Success")
+ .setEmoji("GUILD.TICKET.OPEN")
+ ],
+ components: [
+ new ActionRowBuilder<ButtonBuilder>().addComponents([
+ new ButtonBuilder()
+ .setLabel("Close")
+ .setStyle(ButtonStyle.Danger)
+ .setCustomId("closeticket")
+ .setEmoji(getEmojiByName("CONTROL.CROSS", "id"))
+ ])
+ ]
+ });
+ } catch (e) {
+ return null;
+ }
}
+ const data = {
+ meta: {
+ type: "ticketCreate",
+ displayName: "Ticket Created",
+ calculateType: "ticketUpdate",
+ color: NucleusColors.green,
+ emoji: "GUILD.TICKET.OPEN",
+ timestamp: new Date().getTime()
+ },
+ list: {
+ ticketFor: entry(user.id, renderUser(user)),
+ createdBy: entry(createdBy.id, renderUser(createdBy)),
+ created: entry((new Date().getTime()).toString(), renderDelta(new Date().getTime())),
+ ticketChannel: entry(c.id, renderChannel(c))
+ },
+ hidden: {
+ guild: guild.id
+ }
+ };
+ log(data);
return c.id;
}