Skip to content

Commit

Permalink
refactor(createTicket): show date in non-custom title (#395)
Browse files Browse the repository at this point in the history
  • Loading branch information
CarelessInternet authored Sep 3, 2024
1 parent 6381a3d commit 5ee3071
Show file tree
Hide file tree
Showing 4 changed files with 109 additions and 104 deletions.
2 changes: 1 addition & 1 deletion apps/bot/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"@ticketer/djs-framework": "workspace:*",
"@ticketer/env": "workspace:*",
"chalk": "^5.3.0",
"discord.js": "^14.15.3",
"discord.js": "^14.16.1",
"tsx": "^4.19.0",
"typesafe-i18n": "^5.26.2",
"zod": "^3.23.8"
Expand Down
23 changes: 11 additions & 12 deletions apps/bot/src/utils/thread-ticketing/createTicket.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import {
ticketThreadsConfigurations,
ticketsThreads,
} from '@ticketer/database';
import { ticketButtons, ticketThreadsOpeningMessageEmbed, zodErrorToString } from '..';
import { formatDateShort, ticketButtons, ticketThreadsOpeningMessageEmbed, zodErrorToString } from '..';
import { translate } from '@/i18n';
import { z } from 'zod';

Expand Down Expand Up @@ -56,7 +56,7 @@ export async function createTicket(
await interaction.deferReply({ ephemeral: true });
}

const { client, guild, guildId, guildLocale, locale, user: interactionUser } = interaction;
const { createdAt, client, guild, guildId, guildLocale, locale, user: interactionUser } = interaction;
const customId = 'customId' in interaction ? interaction.customId : undefined;
const fields = 'fields' in interaction ? interaction.fields : undefined;

Expand All @@ -65,9 +65,8 @@ export async function createTicket(
const { data: categoryId, success } = ticketThreadsCategoriesSelectSchema.shape.id.safeParse(
Number(incomingCategoryId ?? dynamicValues?.at(0) ?? dynamicValue),
);
const isProxied = !!(proxiedUserId ?? dynamicValues?.at(1));
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion, @typescript-eslint/no-non-null-asserted-optional-chain
const user = isProxied ? await this.client.users.fetch(proxiedUserId ?? dynamicValues?.at(1)!) : interactionUser;
const proxiedUser = proxiedUserId ?? dynamicValues?.at(1);
const { nickname, user } = await guild.members.fetch(proxiedUser ?? interactionUser);

const translations = translate(locale).tickets.threads.categories;
const guildTranslations = translate(guildLocale).tickets.threads.categories;
Expand Down Expand Up @@ -186,7 +185,7 @@ export async function createTicket(
components: [],
embeds: [
this.userEmbedError(user, translations.createTicket.errors.tooManyTickets.title()).setDescription(
isProxied
proxiedUser
? translations.createTicket.errors.tooManyTickets.proxy.description({
amount: configuration.ticketThreadsConfigurations.activeTickets,
member: user.toString(),
Expand Down Expand Up @@ -228,7 +227,7 @@ export async function createTicket(
const thread = await channel.threads.create({
autoArchiveDuration: ThreadAutoArchiveDuration.OneWeek,
invitable: false,
name: title || user.displayName,
name: title || `[${formatDateShort(createdAt)}] ${nickname ?? user.displayName}`,
type: isPrivate ? ChannelType.PrivateThread : ChannelType.PublicThread,
});

Expand All @@ -242,7 +241,7 @@ export async function createTicket(
title: configuration.ticketThreadsCategories.openingMessageTitle,
user,
});
const ticketEmbed = (isProxied ? this.embed : this.userEmbed(user)).setColor(Colors.Green);
const ticketEmbed = (proxiedUser ? this.embed : this.userEmbed(user)).setColor(Colors.Green);

if (title) {
ticketEmbed.setTitle(title);
Expand Down Expand Up @@ -300,11 +299,11 @@ export async function createTicket(

await thread.members.add(user);

const ticketCreatedEmbed = this.userEmbed(isProxied ? interactionUser : user)
const ticketCreatedEmbed = this.userEmbed(proxiedUser ? interactionUser : user)
.setColor(Colors.Green)
.setTitle(translations.createTicket.ticketCreated.title())
.setDescription(
isProxied
proxiedUser
? translations.createTicket.ticketCreated.proxy.user.description({
channel: thread.toString(),
member: user.toString(),
Expand All @@ -324,7 +323,7 @@ export async function createTicket(
await logsChannel.send({
embeds: [
ticketCreatedEmbed.setTitle(guildTranslations.createTicket.ticketCreated.title()).setDescription(
isProxied
proxiedUser
? guildTranslations.createTicket.ticketCreated.proxy.logs.description({
channel: thread.toString(),
creator: interactionUser.toString(),
Expand All @@ -339,7 +338,7 @@ export async function createTicket(
});
}

if (isProxied) {
if (proxiedUser) {
user
.send({
embeds: [
Expand Down
2 changes: 1 addition & 1 deletion packages/eslint-config/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"eslint-config-turbo": "^2.1.1",
"eslint-plugin-drizzle": "^0.2.3",
"eslint-plugin-prettier": "^5.2.1",
"eslint-plugin-react": "^7.35.0",
"eslint-plugin-react": "^7.35.1",
"eslint-plugin-unicorn": "^55.0.0",
"typescript-eslint": "^8.4.0"
}
Expand Down
Loading

0 comments on commit 5ee3071

Please sign in to comment.