diff --git a/src/plugins/betterFolders/index.tsx b/src/plugins/betterFolders/index.tsx index 3d04419d..50dee4f5 100644 --- a/src/plugins/betterFolders/index.tsx +++ b/src/plugins/betterFolders/index.tsx @@ -275,12 +275,16 @@ export default definePlugin({ }, makeGuildsBarGuildListFilter(isBetterFolders: boolean) { - return child => { - if (isBetterFolders) { - return child?.props?.["aria-label"] === getIntlMessage("SERVERS"); - } + try { + return child => { + if (isBetterFolders) { + return child?.props?.["aria-label"] === getIntlMessage("SERVERS"); + } + return true; + }; + } catch { return true; - }; + } }, makeGuildsBarTreeFilter(isBetterFolders: boolean) { diff --git a/src/plugins/moreUserTags/index.tsx b/src/plugins/moreUserTags/index.tsx index 043c6063..db071e72 100644 --- a/src/plugins/moreUserTags/index.tsx +++ b/src/plugins/moreUserTags/index.tsx @@ -192,9 +192,9 @@ export default definePlugin({ replacement: [ // make the tag show the right text { - match: /(switch\((\i)\){.+?)case (\i(?:\.\i)?)\.BOT:default:(\i)=.{0,40}#{intl::APP_TAG}"\]\)/, - replace: (_, origSwitch, variant, tags, displayedText) => - `${origSwitch}default:{${displayedText} = $self.getTagText(${tags}[${variant}])}` + match: /(switch\((\i)\){.+?)case (\i(?:\.\i)?)\.BOT:default:(\i)=(.{0,40}#{intl::APP_TAG}"\]\))/, + replace: (_, origSwitch, variant, tags, displayedText, originalText) => + `${origSwitch}default:{${displayedText} = $self.getTagText(${tags}[${variant}],${originalText})}` }, // show OP tags correctly { @@ -296,21 +296,25 @@ export default definePlugin({ isOPTag: (tag: number) => tag === Tag.Types.ORIGINAL_POSTER || tags.some(t => tag === Tag.Types[`${t.name}-OP`]), - getTagText(passedTagName: string) { - if (!passedTagName) return getIntlMessage("APP_TAG"); - const [tagName, variant] = passedTagName.split("-"); - const tag = tags.find(({ name }) => tagName === name); - if (!tag) return getIntlMessage("APP_TAG"); - if (variant === "BOT" && tagName !== "WEBHOOK" && this.settings.store.dontShowForBots) return getIntlMessage("APP_TAG"); + getTagText(passedTagName: string, originalText: string) { + try { + const [tagName, variant] = passedTagName.split("-"); + if (!passedTagName) return getIntlMessage("APP_TAG"); + const tag = tags.find(({ name }) => tagName === name); + if (!tag) return getIntlMessage("APP_TAG"); + if (variant === "BOT" && tagName !== "WEBHOOK" && this.settings.store.dontShowForBots) return getIntlMessage("APP_TAG"); - const tagText = settings.store.tagSettings?.[tag.name]?.text || tag.displayName; - switch (variant) { - case "OP": - return `${getIntlMessage("BOT_TAG_FORUM_ORIGINAL_POSTER")} • ${tagText}`; - case "BOT": - return `${getIntlMessage("APP_TAG")} • ${tagText}`; - default: - return tagText; + const tagText = settings.store.tagSettings?.[tag.name]?.text || tag.displayName; + switch (variant) { + case "OP": + return `${getIntlMessage("BOT_TAG_FORUM_ORIGINAL_POSTER")} • ${tagText}`; + case "BOT": + return `${getIntlMessage("APP_TAG")} • ${tagText}`; + default: + return tagText; + } + } catch { + return originalText; } }, diff --git a/src/plugins/typingIndicator/index.tsx b/src/plugins/typingIndicator/index.tsx index b58d1db7..e23cf49d 100644 --- a/src/plugins/typingIndicator/index.tsx +++ b/src/plugins/typingIndicator/index.tsx @@ -73,8 +73,6 @@ function TypingIndicator({ channelId }: { channelId: string; }) { const typingUsersArray = Object.keys(typingUsers).filter(id => id !== myId && !(RelationshipStore.isBlocked(id) && !settings.store.includeBlockedUsers)); let tooltipText: string; - // the new syntax is getIntlMessage("ONE_USER_TYPING", { a: getDisplayName(guildId, typingUsersArray[0]) }); - switch (typingUsersArray.length) { case 0: break; case 1: { diff --git a/src/utils/discord.tsx b/src/utils/discord.tsx index ccdb2fb9..91fd791b 100644 --- a/src/utils/discord.tsx +++ b/src/utils/discord.tsx @@ -24,24 +24,32 @@ import { Channel, Guild, Message, User } from "discord-types/general"; import { Except } from "type-fest"; import { runtimeHashMessageKey } from "./intlHash"; +import { Logger } from "./Logger"; import { MediaModalItem, MediaModalProps, openMediaModal } from "./modal"; +const IntlManagerLogger = new Logger("IntlManager"); + /** * Get an internationalized message from a non hashed key * @param key The plain message key * @param values The values to interpolate, if it's a rich message */ export function getIntlMessage(key: string, values?: Record): any { - return getIntlMessageFromHash(runtimeHashMessageKey(key), values); + return getIntlMessageFromHash(runtimeHashMessageKey(key), values, key); } /** * Get an internationalized message from a hashed key - * @param key The hashed message key + * @param hashedKey The hashed message key * @param values The values to interpolate, if it's a rich message */ -export function getIntlMessageFromHash(key: string, values?: Record): any { - return values == null ? i18n.intl.string(i18n.t[key]) : i18n.intl.format(i18n.t[key], values); +export function getIntlMessageFromHash(hashedKey: string, values?: Record, originalKey?: string): any { + try { + return values == null ? i18n.intl.string(i18n.t[hashedKey]) : i18n.intl.format(i18n.t[hashedKey], values); + } catch (e) { + IntlManagerLogger.error(`Failed to get intl message for key: ${originalKey ?? hashedKey}`, e); + return originalKey ?? ""; + } } /**