Bug fixes and ~~performance~~ typing improvements
diff --git a/src/actions/tickets/create.ts b/src/actions/tickets/create.ts
index ca5147a..d6bf822 100644
--- a/src/actions/tickets/create.ts
+++ b/src/actions/tickets/create.ts
@@ -6,20 +6,11 @@
function capitalize(s: string) {
s = s.replace(/([A-Z])/g, " $1");
- return s.length < 3
- ? s.toUpperCase()
- : s[0].toUpperCase() + s.slice(1).toLowerCase();
+ return s.length < 3 ? s.toUpperCase() : s[0].toUpperCase() + s.slice(1).toLowerCase();
}
export default async function (interaction) {
- const {
- log,
- NucleusColors,
- entry,
- renderUser,
- renderChannel,
- renderDelta
- } = client.logger;
+ const { log, NucleusColors, entry, renderUser, renderChannel, renderDelta } = client.logger;
const config = await client.database.guilds.read(interaction.guild.id);
if (!config.tickets.enabled || !config.tickets.category) {
@@ -27,9 +18,7 @@
embeds: [
new EmojiEmbed()
.setTitle("Tickets are disabled")
- .setDescription(
- "Please enable tickets in the configuration to use this command."
- )
+ .setDescription("Please enable tickets in the configuration to use this command.")
.setFooter({
text: interaction.member.permissions.has("MANAGE_GUILD")
? "You can enable it by running /settings tickets"
@@ -41,17 +30,11 @@
ephemeral: true
});
}
- const category = interaction.guild.channels.cache.get(
- config.tickets.category
- ) as Discord.CategoryChannel;
+ const category = interaction.guild.channels.cache.get(config.tickets.category) as Discord.CategoryChannel;
let count = 0;
category.children.forEach((element) => {
if (!(element.type === "GUILD_TEXT")) return;
- if (
- (element as Discord.TextChannel).topic.includes(
- `${interaction.member.user.id}`
- )
- ) {
+ if ((element as Discord.TextChannel).topic.includes(`${interaction.member.user.id}`)) {
if ((element as Discord.TextChannel).topic.endsWith("Active")) {
count++;
}
@@ -76,8 +59,7 @@
if (config.tickets.customTypes && config.tickets.useCustom) {
ticketTypes = config.tickets.customTypes;
custom = true;
- } else if (config.tickets.types)
- ticketTypes = toHexArray(config.tickets.types, tickets);
+ } else if (config.tickets.types) ticketTypes = toHexArray(config.tickets.types, tickets);
else ticketTypes = [];
let chosenType;
let splitFormattedTicketTypes = [];
@@ -85,29 +67,17 @@
let formattedTicketTypes = [];
formattedTicketTypes = ticketTypes.map((type) => {
if (custom) {
- return new MessageButton()
- .setLabel(type)
- .setStyle("PRIMARY")
- .setCustomId(type);
+ return new MessageButton().setLabel(type).setStyle("PRIMARY").setCustomId(type);
} else {
return new MessageButton()
.setLabel(capitalize(type))
.setStyle("PRIMARY")
.setCustomId(type)
- .setEmoji(
- getEmojiByName(
- "TICKETS." + type.toString().toUpperCase(),
- "id"
- )
- );
+ .setEmoji(getEmojiByName("TICKETS." + type.toString().toUpperCase(), "id"));
}
});
for (let i = 0; i < formattedTicketTypes.length; i += 5) {
- splitFormattedTicketTypes.push(
- new MessageActionRow().addComponents(
- formattedTicketTypes.slice(i, i + 5)
- )
- );
+ splitFormattedTicketTypes.push(new MessageActionRow().addComponents(formattedTicketTypes.slice(i, i + 5)));
}
const m = await interaction.reply({
embeds: [
@@ -142,21 +112,12 @@
.setLabel(capitalize(type))
.setStyle(chosenType === type ? "SUCCESS" : "SECONDARY")
.setCustomId(type)
- .setEmoji(
- getEmojiByName(
- "TICKETS." + type.toString().toUpperCase(),
- "id"
- )
- )
+ .setEmoji(getEmojiByName("TICKETS." + type.toString().toUpperCase(), "id"))
.setDisabled(true);
}
});
for (let i = 0; i < formattedTicketTypes.length; i += 5) {
- splitFormattedTicketTypes.push(
- new MessageActionRow().addComponents(
- formattedTicketTypes.slice(i, i + 5)
- )
- );
+ splitFormattedTicketTypes.push(new MessageActionRow().addComponents(formattedTicketTypes.slice(i, i + 5)));
}
component.update({
embeds: [
@@ -171,11 +132,7 @@
} else {
chosenType = null;
await interaction.reply({
- embeds: [
- new EmojiEmbed()
- .setTitle("Create Ticket")
- .setEmoji("GUILD.TICKET.OPEN")
- ],
+ embeds: [new EmojiEmbed().setTitle("Create Ticket").setEmoji("GUILD.TICKET.OPEN")],
ephemeral: true,
components: splitFormattedTicketTypes
});
@@ -183,13 +140,7 @@
const overwrites = [
{
id: interaction.member,
- allow: [
- "VIEW_CHANNEL",
- "SEND_MESSAGES",
- "ATTACH_FILES",
- "ADD_REACTIONS",
- "READ_MESSAGE_HISTORY"
- ],
+ allow: ["VIEW_CHANNEL", "SEND_MESSAGES", "ATTACH_FILES", "ADD_REACTIONS", "READ_MESSAGE_HISTORY"],
type: "member"
}
] as Discord.OverwriteResolvable[];
@@ -201,31 +152,21 @@
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"
- ],
+ allow: ["VIEW_CHANNEL", "SEND_MESSAGES", "ATTACH_FILES", "ADD_REACTIONS", "READ_MESSAGE_HISTORY"],
type: "role"
});
}
let c;
try {
- c = await interaction.guild.channels.create(
- interaction.member.user.username,
- {
- type: "GUILD_TEXT",
- topic: `${interaction.member.user.id} Active`,
- parent: config.tickets.category,
- nsfw: false,
- permissionOverwrites:
- overwrites as Discord.OverwriteResolvable[],
- reason: "Creating ticket"
- }
- );
+ c = await interaction.guild.channels.create(interaction.member.user.username, {
+ type: "GUILD_TEXT",
+ topic: `${interaction.member.user.id} Active`,
+ parent: config.tickets.category,
+ nsfw: false,
+ permissionOverwrites: overwrites as Discord.OverwriteResolvable[],
+ reason: "Creating ticket"
+ });
} catch (e) {
return await interaction.editReply({
embeds: [
@@ -241,24 +182,15 @@
await c.send({
content:
`<@${interaction.member.user.id}>` +
- (config.tickets.supportRole !== null
- ? ` • <@&${config.tickets.supportRole}>`
- : ""),
+ (config.tickets.supportRole !== null ? ` • <@&${config.tickets.supportRole}>` : ""),
allowedMentions: {
users: [(interaction.member as Discord.GuildMember).id],
- roles:
- config.tickets.supportRole !== null
- ? [config.tickets.supportRole]
- : []
+ roles: config.tickets.supportRole !== null ? [config.tickets.supportRole] : []
}
});
- let content = interaction.options
- ? interaction.options.getString("message") || ""
- : "";
+ let content = interaction.options ? interaction.options.getString("message") || "" : "";
if (content) content = `**Message:**\n> ${content}\n`;
- const emoji = custom
- ? ""
- : getEmojiByName("TICKETS." + chosenType.toUpperCase());
+ const emoji = custom ? "" : getEmojiByName("TICKETS." + chosenType.toUpperCase());
await c.send({
embeds: [
new EmojiEmbed()
@@ -266,9 +198,7 @@
.setDescription(
`Ticket created by <@${interaction.member.user.id}>\n` +
`**Support type:** ${
- chosenType !== null
- ? emoji + " " + capitalize(chosenType)
- : "General"
+ chosenType !== null ? emoji + " " + capitalize(chosenType) : "General"
}\n` +
`**Ticket ID:** \`${c.id}\`\n${content}\n` +
"Type `/ticket close` to close this ticket."
@@ -296,14 +226,8 @@
timestamp: new Date().getTime()
},
list: {
- ticketFor: entry(
- interaction.member.user.id,
- renderUser(interaction.member.user)
- ),
- created: entry(
- new Date().getTime(),
- renderDelta(new Date().getTime())
- ),
+ ticketFor: entry(interaction.member.user.id, renderUser(interaction.member.user)),
+ created: entry(new Date().getTime(), renderDelta(new Date().getTime())),
ticketChannel: entry(c.id, renderChannel(c))
},
hidden: {
@@ -318,9 +242,7 @@
embeds: [
new EmojiEmbed()
.setTitle("Create Ticket")
- .setDescription(
- `Ticket created. You can view it here: <#${c.id}>`
- )
+ .setDescription(`Ticket created. You can view it here: <#${c.id}>`)
.setStatus("Success")
.setEmoji("GUILD.TICKET.OPEN")
],
diff --git a/src/actions/tickets/delete.ts b/src/actions/tickets/delete.ts
index 6509c03..d692a1e 100644
--- a/src/actions/tickets/delete.ts
+++ b/src/actions/tickets/delete.ts
@@ -4,14 +4,7 @@
import getEmojiByName from "../../utils/getEmojiByName.js";
export default async function (interaction) {
- const {
- log,
- NucleusColors,
- entry,
- renderUser,
- renderChannel,
- renderDelta
- } = client.logger;
+ const { log, NucleusColors, entry, renderUser, renderChannel, renderDelta } = client.logger;
const config = await client.database.guilds.read(interaction.guild.id);
let thread = false;
@@ -21,9 +14,7 @@
if (
!channel.parent ||
config.tickets.category !== channel.parent.id ||
- (thread
- ? threadChannel.parent.parent.id !== config.tickets.category
- : false)
+ (thread ? threadChannel.parent.parent.id !== config.tickets.category : false)
) {
return interaction.reply({
embeds: [
@@ -61,22 +52,10 @@
list: {
ticketFor: entry(
channel.topic.split(" ")[0],
- renderUser(
- (
- await interaction.guild.members.fetch(
- channel.topic.split(" ")[0]
- )
- ).user
- )
+ renderUser((await interaction.guild.members.fetch(channel.topic.split(" ")[0])).user)
),
- deletedBy: entry(
- interaction.member.user.id,
- renderUser(interaction.member.user)
- ),
- deleted: entry(
- new Date().getTime(),
- renderDelta(new Date().getTime())
- )
+ deletedBy: entry(interaction.member.user.id, renderUser(interaction.member.user)),
+ deleted: entry(new Date().getTime(), renderDelta(new Date().getTime()))
},
hidden: {
guild: interaction.guild.id
@@ -109,16 +88,8 @@
] 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"
- ],
+ id: interaction.guild.roles.cache.get(config.tickets.supportRole),
+ allow: ["VIEW_CHANNEL", "SEND_MESSAGES", "ATTACH_FILES", "ADD_REACTIONS", "READ_MESSAGE_HISTORY"],
type: "role"
});
}
@@ -136,22 +107,10 @@
list: {
ticketFor: entry(
channel.topic.split(" ")[0],
- renderUser(
- (
- await interaction.guild.members.fetch(
- channel.topic.split(" ")[0]
- )
- ).user
- )
+ 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())
- ),
+ 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: {
@@ -184,12 +143,7 @@
.setLabel("Create Transcript and Delete")
.setStyle("PRIMARY")
.setCustomId("createtranscript")
- .setEmoji(
- getEmojiByName(
- "CONTROL.DOWNLOAD",
- "id"
- )
- )
+ .setEmoji(getEmojiByName("CONTROL.DOWNLOAD", "id"))
]
: []
)
@@ -219,8 +173,7 @@
}
});
if (deleted) {
- const { log, NucleusColors, entry, renderUser, renderDelta } =
- member.client.logger;
+ const { log, NucleusColors, entry, renderUser, renderDelta } = member.client.logger;
const data = {
meta: {
type: "ticketPurge",
@@ -233,10 +186,7 @@
list: {
ticketFor: entry(member, renderUser(member)),
deletedBy: entry(null, "Member left server"),
- deleted: entry(
- new Date().getTime(),
- renderDelta(new Date().getTime())
- ),
+ deleted: entry(new Date().getTime(), renderDelta(new Date().getTime())),
ticketsDeleted: deleted
},
hidden: {