Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/structure/ExtendedClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)],
Expand Down
6 changes: 3 additions & 3 deletions src/utils/close.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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())
Expand All @@ -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) => {
Expand Down
2 changes: 1 addition & 1 deletion src/utils/createTicket.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<ButtonBuilder>();
Expand Down
35 changes: 35 additions & 0 deletions src/utils/translation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -76,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
Expand All @@ -88,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. This is a raw value operation so please contact the dev before translating it.`);
return bkup;
}
}

export class TranslationError {
Expand Down