From 43a98805357167726305d618cd251961253d4640 Mon Sep 17 00:00:00 2001 From: zhiyan114 Date: Tue, 25 Jul 2023 11:35:08 -0400 Subject: [PATCH 1/6] fix: iconUrl should not throw error if empty --- src/utils/close.ts | 2 +- src/utils/createTicket.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/utils/close.ts b/src/utils/close.ts index 95f05359..9e755f18 100644 --- a/src/utils/close.ts +++ b/src/utils/close.ts @@ -178,7 +178,7 @@ export async function close(interaction: ButtonInteraction | CommandInteraction // Please respect the project by keeping the credits, (if it is too disturbing you can credit me in the "about me" of the bot discord) text: `ticket.pm ${footer.trim() !== "" ? `- ${footer}` : ""}`, // Please respect the LICENSE :D // Please respect the project by keeping the credits, (if it is too disturbing you can credit me in the "about me" of the bot discord) - iconURL: locale.getSubValue("embeds", "ticketClosedDM", "footer", "iconUrl") + iconURL: locale.getNoErrorSubValue("embeds", "ticketClosedDM", "footer", "iconUrl") }); client.users.fetch(creator).then((user) => { diff --git a/src/utils/createTicket.ts b/src/utils/createTicket.ts index 348188b1..abd51659 100644 --- a/src/utils/createTicket.ts +++ b/src/utils/createTicket.ts @@ -149,7 +149,7 @@ export const createTicket = async (interaction: StringSelectMenuInteraction | Mo // Please respect the project by keeping the credits, (if it is too disturbing you can credit me in the "about me" of the bot discord) text: `ticket.pm ${footer.trim() !== "" ? `- ${footer}` : ""}`, // Please respect the LICENSE :D // Please respect the project by keeping the credits, (if it is too disturbing you can credit me in the "about me" of the bot discord) - iconURL: locale.getSubValue("embeds", "ticketOpened", "footer", "iconUrl") + iconURL: locale.getNoErrorSubValue("embeds", "ticketOpened", "footer", "iconUrl") }); const row = new ActionRowBuilder(); From 761d75b83457f5a260210806196a1f45c073947c Mon Sep 17 00:00:00 2001 From: zhiyan114 Date: Tue, 25 Jul 2023 11:37:05 -0400 Subject: [PATCH 2/6] style: fixed lint warnings --- src/utils/translation.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/utils/translation.ts b/src/utils/translation.ts index 3847e451..31538d33 100644 --- a/src/utils/translation.ts +++ b/src/utils/translation.ts @@ -52,7 +52,9 @@ export class Translation { * @param key All the keys leading to the value (or the classic dot access `"first.second"`) * @returns the translation data or throw error if the translation data cannot be found at all */ + // eslint-disable-next-line no-unused-vars getSubValue(keys: string): string; + // eslint-disable-next-line no-unused-vars getSubValue(...keys: string[]): string; getSubValue(...keys: string[]): string { // Convert the dot to array From 62cea22a258537e08fe11264729b903db45c55d4 Mon Sep 17 00:00:00 2001 From: zhiyan114 Date: Tue, 25 Jul 2023 11:53:12 -0400 Subject: [PATCH 3/6] feat(translation): Support raw value returns --- src/utils/translation.ts | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/src/utils/translation.ts b/src/utils/translation.ts index 31538d33..112c3ee3 100644 --- a/src/utils/translation.ts +++ b/src/utils/translation.ts @@ -78,6 +78,7 @@ export class Translation { console.warn(`TRANSLATION: Key '${keys.join(".")}' is missing translation. If you can, please help fill in the translation and make PR for it.`); return bkup; } + /** * Used for translation keys that can be empty * @param keys All the keys leading to the value @@ -90,6 +91,38 @@ export class Translation { return; } } + + /** + * Get the raw translation value (getSubValue but without string/number checks) + * @param key All the keys leading to the value (or the classic dot access `"first.second"`) + * @returns the translation data or throw error if the translation data cannot be found at all + */ + // eslint-disable-next-line no-unused-vars + getSubRawValue(keys: string): string | number | null | object; + // eslint-disable-next-line no-unused-vars + getSubRawValue(...keys: string[]): string | number | null | object; + getSubRawValue(...keys: string[]): string | number | null | object { + // Convert the dot to array + if(keys.length === 1) + keys = keys[0].split("."); + + // Check the primary value first + let main: {[k: string]: string | undefined} | string | undefined = this.primaryData; + let bkup: {[k: string]: string | undefined} | string | undefined = this.backupData; + + for(const key of keys) { + if(typeof(main) === "object") + main = main[key]; + if(this.backupData && typeof(bkup) === "object") + bkup = bkup[key]; + } + + if(main !== undefined) return main; + if(bkup === undefined) + throw new TranslationError(`TRANSLATION: Key '${keys.join(".")}' failed to pull backup translation. This indicates this key data does not exist at all.`); + console.warn(`TRANSLATION: Key '${keys.join(".")}' is missing translation. If you can, please help fill in the translation and make PR for it.`); + return bkup; + } } export class TranslationError { From 49871cc463af9dcf99f495def6d260ce059e233b Mon Sep 17 00:00:00 2001 From: zhiyan114 Date: Tue, 25 Jul 2023 11:55:51 -0400 Subject: [PATCH 4/6] fix: Several translation errors with close.ts --- src/utils/close.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/utils/close.ts b/src/utils/close.ts index 9e755f18..a67b956f 100644 --- a/src/utils/close.ts +++ b/src/utils/close.ts @@ -150,7 +150,7 @@ export async function close(interaction: ButtonInteraction | CommandInteraction interaction.channel?.send({ embeds: [ JSON.parse( - JSON.stringify(locale.getSubValue("embeds", "ticketClosed")) + JSON.stringify(locale.getSubRawValue("embeds", "ticketClosed")) .replace("TICKETCOUNT", ticket.id.toString()) .replace("REASON", (ticket.closereason ?? client.locales.getSubValue("other", "noReasonGiven")).replace(/[\n\r]/g, "\\n")) .replace("CLOSERNAME", interaction.user.tag) @@ -166,7 +166,7 @@ export async function close(interaction: ButtonInteraction | CommandInteraction const ticketClosedDMEmbed = new EmbedBuilder({ color: 0, }) - .setColor(locale.getSubValue("embeds", "ticketClosedDM", "color") as ColorResolvable ?? client.config.mainColor) + .setColor(locale.getNoErrorSubValue("embeds", "ticketClosedDM", "color") as ColorResolvable ?? client.config.mainColor) .setDescription( client.locales.getSubValue("embeds", "ticketClosedDM", "description") .replace("TICKETCOUNT", ticket.id.toString()) From 5986f8f785ea44706a1e41e5277523ed26337979 Mon Sep 17 00:00:00 2001 From: zhiyan114 Date: Tue, 25 Jul 2023 11:59:32 -0400 Subject: [PATCH 5/6] changed some translation text --- src/utils/translation.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/utils/translation.ts b/src/utils/translation.ts index 112c3ee3..9d9147dc 100644 --- a/src/utils/translation.ts +++ b/src/utils/translation.ts @@ -120,7 +120,7 @@ export class Translation { if(main !== undefined) return main; if(bkup === undefined) throw new TranslationError(`TRANSLATION: Key '${keys.join(".")}' failed to pull backup translation. This indicates this key data does not exist at all.`); - console.warn(`TRANSLATION: Key '${keys.join(".")}' is missing translation. If you can, please help fill in the translation and make PR for it.`); + console.warn(`TRANSLATION: Key '${keys.join(".")}' is missing translation. This is a raw value operation so please contact the dev before translating it.`); return bkup; } } From 26cf3272de203a9b2c41757ab03ad1d20e6e136d Mon Sep 17 00:00:00 2001 From: zhiyan114 Date: Tue, 25 Jul 2023 18:07:37 -0400 Subject: [PATCH 6/6] feat: Prisma showing minmal error to prevent confusion caused by stacktrace --- src/structure/ExtendedClient.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/structure/ExtendedClient.ts b/src/structure/ExtendedClient.ts index e8b6cbfe..2e205c86 100644 --- a/src/structure/ExtendedClient.ts +++ b/src/structure/ExtendedClient.ts @@ -18,7 +18,9 @@ export default class ExtendedClient extends Client { super(options); this.config = config; - this.prisma = new PrismaClient(); + this.prisma = new PrismaClient({ + errorFormat: "minimal" + }); this.locales = new Translation(this.config.lang, path.join(__dirname, "../../locales/")); this.commands = new Collection([ [AddCommand.data.name, new AddCommand(this)],