changes to how deleting tickets works, and UI when creating mod tickets
diff --git a/src/automations/createModActionTicket.ts b/src/automations/createModActionTicket.ts
index 4de2924..ef317b7 100644
--- a/src/automations/createModActionTicket.ts
+++ b/src/automations/createModActionTicket.ts
@@ -3,7 +3,7 @@
import generateEmojiEmbed from '../utils/generateEmojiEmbed.js';
import getEmojiByName from "../utils/getEmojiByName.js";
-export async function create(guild: Discord.Guild, member: Discord.User, client) {
+export async function create(guild: Discord.Guild, member: Discord.User, createdBy: Discord.User, client) {
let config = await readConfig(guild.id);
// @ts-ignore
const { log, NucleusColors, entry, renderUser, renderChannel, renderDelta } = client.logger
@@ -70,6 +70,7 @@
},
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)),
},
diff --git a/src/automations/tickets/delete.ts b/src/automations/tickets/delete.ts
index 32315bc..17d889a 100644
--- a/src/automations/tickets/delete.ts
+++ b/src/automations/tickets/delete.ts
@@ -11,7 +11,7 @@
let channel = (interaction.channel as Discord.TextChannel)
if (!channel.parent || config.tickets.category != channel.parent.id) {
return interaction.reply({embeds: [new generateEmojiEmbed()
- .setTitle("Close Ticket")
+ .setTitle("Deleting Ticket...")
.setDescription("This ticket is not in your tickets category, so cannot be deleted. You cannot run close in a thread.") // TODO bridge to cross later!
.setStatus("Danger")
.setEmoji("CONTROL.BLOCKCROSS")
@@ -19,96 +19,92 @@
}
let status = channel.topic.split(" ")[1];
if (status == "Archived") {
- interaction.reply({embeds: [new generateEmojiEmbed()
- .setTitle("Close Ticket")
- .setDescription("This ticket will be deleted in 3 seconds.")
+ await interaction.reply({embeds: [new generateEmojiEmbed()
+ .setTitle("Delete Ticket")
+ .setDescription("Your ticket is being deleted...")
.setStatus("Danger")
.setEmoji("GUILD.TICKET.CLOSE")
]});
- setTimeout(async () => {
- let data = {
- meta:{
- type: 'ticketClosed',
- displayName: 'Ticket Closed',
- calculateType: true,
- color: NucleusColors.red,
- emoji: 'GUILD.TICKET.CLOSE',
- timestamp: new Date().getTime()
- },
- list: {
- ticketFor: entry(channel.topic.split(" ")[0], renderUser((await interaction.guild.members.fetch(channel.topic.split(" ")[0])).user)),
- closedBy: entry(interaction.member.user.id, renderUser(interaction.member.user)),
- closed: entry(new Date().getTime(), renderDelta(new Date().getTime()))
- },
- hidden: {
- guild: interaction.guild.id
- }
+ let data = {
+ meta:{
+ type: 'ticketDeleted',
+ displayName: 'Ticket Deleted',
+ calculateType: true,
+ color: NucleusColors.red,
+ emoji: 'GUILD.TICKET.CLOSE',
+ timestamp: new Date().getTime()
+ },
+ list: {
+ ticketFor: entry(channel.topic.split(" ")[0], renderUser((await interaction.guild.members.fetch(channel.topic.split(" ")[0])).user)),
+ deletedBy: entry(interaction.member.user.id, renderUser(interaction.member.user)),
+ closed: entry(new Date().getTime(), renderDelta(new Date().getTime()))
+ },
+ hidden: {
+ guild: interaction.guild.id
}
- log(data, interaction.client);
- interaction.channel.delete();
- }, 3000);
+ }
+ log(data, interaction.client);
+ interaction.channel.delete();
return;
} else if (status == "Active") {
- interaction.reply({embeds: [new generateEmojiEmbed()
+ await interaction.reply({embeds: [new generateEmojiEmbed()
.setTitle("Close Ticket")
- .setDescription("This ticket will be archived in 3 seconds.")
+ .setDescription("Your ticket is being closed...")
.setStatus("Warning")
.setEmoji("GUILD.TICKET.ARCHIVED")
]});
- setTimeout(async () =>{
- let overwrites = [
- {
- id: channel.topic.split(" ")[0],
- deny: ["VIEW_CHANNEL"],
- type: "member"
- },
- {
- id: interaction.guild.id,
- deny: ["VIEW_CHANNEL"],
- type: "role"
- }
- ] as Discord.OverwriteResolvable[];
- if (config.tickets.supportRole != null) {
- overwrites.push({
- id: interaction.guild.roles.cache.get(config.tickets.supportRole),
- allow: ["VIEW_CHANNEL", "SEND_MESSAGES", "ATTACH_FILES", "ADD_REACTIONS", "READ_MESSAGE_HISTORY"],
- type: "role"
- })
+ let overwrites = [
+ {
+ id: channel.topic.split(" ")[0],
+ deny: ["VIEW_CHANNEL"],
+ type: "member"
+ },
+ {
+ id: interaction.guild.id,
+ deny: ["VIEW_CHANNEL"],
+ type: "role"
}
- channel.edit({permissionOverwrites: overwrites})
- channel.setTopic(`${channel.topic.split(" ")[0]} Archived`);
- let data = {
- meta:{
- type: 'ticketArchive',
- displayName: 'Ticket Archived',
- calculateType: true,
- color: NucleusColors.yellow,
- emoji: 'GUILD.TICKET.ARCHIVED',
- timestamp: new Date().getTime()
- },
- list: {
- ticketFor: entry(channel.topic.split(" ")[0], renderUser((await interaction.guild.members.fetch(channel.topic.split(" ")[0])).user)),
- archivedBy: entry(interaction.member.user.id, renderUser(interaction.member.user)),
- archived: entry(new Date().getTime(), renderDelta(new Date().getTime())),
- ticketChannel: entry(channel.id, renderChannel(channel)),
- },
- hidden: {
- guild: interaction.guild.id
- }
+ ] as Discord.OverwriteResolvable[];
+ if (config.tickets.supportRole != null) {
+ overwrites.push({
+ id: interaction.guild.roles.cache.get(config.tickets.supportRole),
+ allow: ["VIEW_CHANNEL", "SEND_MESSAGES", "ATTACH_FILES", "ADD_REACTIONS", "READ_MESSAGE_HISTORY"],
+ type: "role"
+ })
+ }
+ channel.edit({permissionOverwrites: overwrites})
+ channel.setTopic(`${channel.topic.split(" ")[0]} Archived`);
+ let data = {
+ meta:{
+ type: 'ticketClosed',
+ displayName: 'Ticket Closed',
+ calculateType: true,
+ color: NucleusColors.yellow,
+ emoji: 'GUILD.TICKET.ARCHIVED',
+ timestamp: new Date().getTime()
+ },
+ list: {
+ ticketFor: entry(channel.topic.split(" ")[0], renderUser((await interaction.guild.members.fetch(channel.topic.split(" ")[0])).user)),
+ closedBy: entry(interaction.member.user.id, renderUser(interaction.member.user)),
+ closed: entry(new Date().getTime(), renderDelta(new Date().getTime())),
+ ticketChannel: entry(channel.id, renderChannel(channel)),
+ },
+ hidden: {
+ guild: interaction.guild.id
}
- log(data, interaction.client);
- await interaction.editReply({embeds: [new generateEmojiEmbed()
- .setTitle("Close Ticket")
- .setDescription("This ticket has been archived.\nType `/ticket close` to delete it.")
- .setStatus("Warning")
- .setEmoji("GUILD.TICKET.ARCHIVED") // TODO:[Premium] Add a transcript option ||\----/|| <- the bridge we will cross when we come to it
- ], components: [new MessageActionRow().addComponents([new MessageButton()
- .setLabel("Close")
- .setStyle("DANGER")
- .setCustomId("closeticket")
- .setEmoji(getEmojiByName("CONTROL.CROSS", "id"))
- ])]});
- }, 3000);
+ }
+ log(data, interaction.client);
+ await interaction.editReply({embeds: [new generateEmojiEmbed()
+ .setTitle("Close Ticket")
+ .setDescription("This ticket has been closed.\nType `/ticket close` again to delete it.")
+ .setStatus("Warning")
+ .setEmoji("GUILD.TICKET.ARCHIVED") // TODO:[Premium] Add a transcript option ||\----/|| <- the bridge we will cross when we come to it
+ ], components: [new MessageActionRow().addComponents([new MessageButton()
+ .setLabel("Delete")
+ .setStyle("DANGER")
+ .setCustomId("closeticket")
+ .setEmoji(getEmojiByName("CONTROL.CROSS", "id"))
+ ])]});
return;
}
}
diff --git a/src/commands/mod/mute.ts b/src/commands/mod/mute.ts
index d81a5cc..b2cc94e 100644
--- a/src/commands/mod/mute.ts
+++ b/src/commands/mod/mute.ts
@@ -6,7 +6,6 @@
import confirmationMessage from "../../utils/confirmationMessage.js";
import keyValueList from "../../utils/generateKeyValueList.js";
import humanizeDuration from "humanize-duration";
-import { create, areTicketsEnabled } from "../../automations/createModActionTicket.js";
import readConfig from "../../utils/readConfig.js";
const command = (builder: SlashCommandSubcommandBuilder) =>
diff --git a/src/commands/mod/nick.ts b/src/commands/mod/nick.ts
index cd3a7af..e8463f4 100644
--- a/src/commands/mod/nick.ts
+++ b/src/commands/mod/nick.ts
@@ -29,10 +29,10 @@
+ `The user **will${interaction.options.getString("notify") == "yes" ? '' : ' not'}** be notified\n\n`
+ `Are you sure you want to ${interaction.options.getString("name") ? "change" : "clear"} <@!${(interaction.options.getMember("user") as GuildMember).id}>'s nickname?`)
.setColor("Danger")
- .addCustomCallback(
+ .addCustomBoolean(
"Create appeal ticket", !(await areTicketsEnabled(interaction.guild.id)),
- () => { create(interaction.guild, interaction.options.getUser("user"), interaction.client)},
- "An appeal ticket was created")
+ async () => await create(interaction.guild, interaction.options.getUser("user"), interaction.user, interaction.client),
+ "An appeal ticket will be created when Confirm is clicked")
// pluralize("day", interaction.options.getInteger("delete"))
// const pluralize = (word: string, count: number) => { return count === 1 ? word : word + "s" }
.send()
@@ -96,7 +96,7 @@
await interaction.editReply({embeds: [new generateEmojiEmbed()
.setEmoji(`PUNISH.NICKNAME.${failed ? "YELLOW" : "GREEN"}`)
.setTitle(`Nickname`)
- .setDescription("The members nickname was changed" + (failed ? ", but was not notified" : ""))
+ .setDescription("The members nickname was changed" + (failed ? ", but was not notified" : "") + (confirmation.response ? ` and an appeal ticket was opened in <#${confirmation.response}>` : ``))
.setStatus(failed ? "Warning" : "Success")
], components: []})
} else {
diff --git a/src/commands/mod/purge.ts b/src/commands/mod/purge.ts
index e388ea0..924e507 100644
--- a/src/commands/mod/purge.ts
+++ b/src/commands/mod/purge.ts
@@ -5,7 +5,6 @@
import generateEmojiEmbed from "../../utils/generateEmojiEmbed.js";
import keyValueList from "../../utils/generateKeyValueList.js";
import getEmojiByName from "../../utils/getEmojiByName.js";
-import { create, areTicketsEnabled } from "../../automations/createModActionTicket.js";
const command = (builder: SlashCommandSubcommandBuilder) =>
builder
diff --git a/src/commands/mod/unnamed.ts b/src/commands/mod/unnamed.ts
index 20ebc30..ca0bcef 100644
--- a/src/commands/mod/unnamed.ts
+++ b/src/commands/mod/unnamed.ts
@@ -129,10 +129,10 @@
+ `The user **will${interaction.options.getString("notify") === "no" ? ' not' : ''}** be notified\n\n`
+ `Are you sure you want to mute <@!${(interaction.options.getMember("user") as GuildMember).id}>?`) // TODO
.setColor("Danger")
- .addCustomCallback(
+ .addCustomBoolean(
"Create appeal ticket", !(await areTicketsEnabled(interaction.guild.id)),
- () => { create(interaction.guild, interaction.options.getUser("user"), interaction.client)},
- "An appeal ticket was created")
+ async () => await create(interaction.guild, interaction.options.getUser("user"), interaction.user, interaction.client),
+ "An appeal ticket will be created when Confirm is clicked")
// pluralize("day", interaction.options.getInteger("delete"))
// const pluralize = (word: string, count: number) => { return count === 1 ? word : word + "s" }
.send()
diff --git a/src/commands/mod/warn.ts b/src/commands/mod/warn.ts
index 3f63cce..ce54cfb 100644
--- a/src/commands/mod/warn.ts
+++ b/src/commands/mod/warn.ts
@@ -30,10 +30,10 @@
+ `The user **will${interaction.options.getString("notify") === "no" ? ' not' : ''}** be notified\n\n`
+ `Are you sure you want to warn <@!${(interaction.options.getMember("user") as GuildMember).id}>?`)
.setColor("Danger")
- .addCustomCallback(
+ .addCustomBoolean(
"Create appeal ticket", !(await areTicketsEnabled(interaction.guild.id)),
- () => { create(interaction.guild, interaction.options.getUser("user"), interaction.client)},
- "An appeal ticket was created")
+ async () => await create(interaction.guild, interaction.options.getUser("user"), interaction.user, interaction.client),
+ "An appeal ticket will be created when Confirm is clicked")
// pluralize("day", interaction.options.getInteger("delete"))
// const pluralize = (word: string, count: number) => { return count === 1 ? word : word + "s" }
.send()
@@ -85,7 +85,7 @@
await interaction.editReply({embeds: [new generateEmojiEmbed()
.setEmoji(`PUNISH.WARN.GREEN`)
.setTitle(`Warn`)
- .setDescription("The user was warned")
+ .setDescription("The user was warned" + (confirmation.response ? ` and an appeal ticket was opened in <#${confirmation.response}>` : ``))
.setStatus("Success")
], components: []})
} else {
@@ -135,7 +135,7 @@
return await interaction.editReply({embeds: [new generateEmojiEmbed()
.setEmoji(`PUNISH.WARN.GREEN`)
.setTitle(`Warn`)
- .setDescription("The user was warned")
+ .setDescription("The user was warned" + (confirmation.response ? ` and an appeal ticket was opened in <#${confirmation.response}>` : ``))
.setStatus("Success")
], components: []})
} else {
diff --git a/src/utils/confirmationMessage.ts b/src/utils/confirmationMessage.ts
index dd97603..7a06d83 100644
--- a/src/utils/confirmationMessage.ts
+++ b/src/utils/confirmationMessage.ts
@@ -14,6 +14,8 @@
customCallbackString: string = "";
customCallbackClicked: boolean = false;
customCallbackResponse: any = null;
+ customBoolean: () => any;
+ customBooleanClicked: boolean = null;
inverted: boolean;
constructor(interaction: CommandInteraction) {
@@ -23,8 +25,9 @@
this.emoji = "";
this.description = "";
this.color = "";
- this.inverted = false
- this.customCallback = () => {}
+ this.inverted = false;
+ this.customCallback = () => {};
+ this.customBoolean = () => {};
}
setTitle(title: string) { this.title = title; return this }
@@ -33,12 +36,23 @@
setColor(color: string) { this.color = color; return this }
setInverted(inverted: boolean) { this.inverted = inverted; return this }
addCustomCallback(title: string, disabled: boolean, callback: () => any, callbackClicked: string) {
+ if (this.customButtonTitle) return this
this.customButtonTitle = title;
this.customButtonDisabled = disabled;
this.customCallback = callback;
this.customCallbackString = callbackClicked;
return this;
}
+ addCustomBoolean(title: string, disabled: boolean, callback: () => any, callbackClicked: string) {
+ if (this.customButtonTitle) return this
+ this.customButtonTitle = title;
+ this.customButtonDisabled = disabled;
+ this.customBoolean = callback;
+ this.customCallbackString = callbackClicked;
+ this.customBooleanClicked = false;
+ return this;
+ }
+
async send(editOnly?: boolean) {
while (true) {
@@ -49,7 +63,7 @@
.setTitle(this.title)
.setDescription(this.description)
.setStatus(this.color)
- .setFooter({text: this.customCallbackClicked ? this.customCallbackString : ""})
+ .setFooter({text: (this.customBooleanClicked ?? this.customCallbackClicked) ? this.customCallbackString : ""})
],
components: [
new MessageActionRow().addComponents([
@@ -66,7 +80,10 @@
].concat(this.customButtonTitle ? [new Discord.MessageButton()
.setCustomId("custom")
.setLabel(this.customButtonTitle)
- .setStyle("PRIMARY")
+ .setStyle(this.customBooleanClicked !== null ?
+ ( this.customBooleanClicked ? "SUCCESS" : "PRIMARY" ) :
+ "PRIMARY"
+ )
.setDisabled(this.customButtonDisabled)
.setEmoji(getEmojiByName("CONTROL.TICKET", "id"))
] : []))
@@ -84,19 +101,36 @@
try {
component = await (m as Message).awaitMessageComponent({filter: (m) => m.user.id === this.interaction.user.id, time: 2.5 * 60 * 1000});
} catch (e) {
- return { success: false, buttonClicked: this.customCallbackClicked, response: this.customCallbackResponse };
+ return {
+ success: false,
+ buttonClicked: this.customBooleanClicked ?? this.customCallbackClicked,
+ response: this.customCallbackResponse
+ };
}
if (component.customId === "yes") {
component.deferUpdate();
- return { success: true, buttonClicked: this.customCallbackClicked, response: this.customCallbackResponse };
+ if (this.customBooleanClicked === true) this.customCallbackResponse = await this.customBoolean();
+ return {
+ success: true,
+ buttonClicked: this.customBooleanClicked ?? this.customCallbackClicked,
+ response: this.customCallbackResponse
+ };
} else if (component.customId === "no") {
component.deferUpdate();
- return { success: false, buttonClicked: this.customCallbackClicked, response: this.customCallbackResponse };
+ return {
+ success: false,
+ buttonClicked: this.customBooleanClicked ?? this.customCallbackClicked,
+ response: this.customCallbackResponse
+ };
} else if (component.customId === "custom") {
component.deferUpdate();
- this.customCallbackResponse = this.customCallback();
- this.customCallbackClicked = true;
- this.customButtonDisabled = true;
+ if (this.customBooleanClicked !== null) {
+ this.customBooleanClicked = !this.customBooleanClicked;
+ } else {
+ this.customCallbackResponse = await this.customCallback();
+ this.customCallbackClicked = true;
+ this.customButtonDisabled = true;
+ }
editOnly = true;
}
}