From c154965d7072179cca3933bb5f387f8ae1d6711b Mon Sep 17 00:00:00 2001 From: Vendicated Date: Sun, 12 Feb 2023 21:06:49 +0100 Subject: [PATCH] TypingTweaks: Fix crash after changing language --- src/plugins/typingTweaks.tsx | 35 ++++++++++++++--------------------- 1 file changed, 14 insertions(+), 21 deletions(-) diff --git a/src/plugins/typingTweaks.tsx b/src/plugins/typingTweaks.tsx index f03779c..4548179 100644 --- a/src/plugins/typingTweaks.tsx +++ b/src/plugins/typingTweaks.tsx @@ -22,6 +22,7 @@ import { Devs } from "@utils/constants"; import definePlugin, { OptionType } from "@utils/types"; import { findByCodeLazy } from "@webpack"; import { GuildMemberStore, React, RelationshipStore } from "@webpack/common"; +import { User } from "discord-types/general"; const Avatar = findByCodeLazy(".Positions.TOP,spacing:"); @@ -64,36 +65,28 @@ export default definePlugin({ replace: "return $1" } }, - // Changes indicator to format message with the typing users - { - find: '"SEVERAL_USERS_TYPING":"', - replacement: { - match: /("SEVERAL_USERS_TYPING"):".+?"/, - replace: "$1:\"**!!{a}!!**, **!!{b}!!**, and {c} others are typing...\"" - }, - predicate: () => settings.store.alternativeFormatting - }, - { - find: ",\"SEVERAL_USERS_TYPING\",\"", - replacement: { - match: /(?<="SEVERAL_USERS_TYPING",)".+?"/, - replace: '"**!!{a}!!**, **!!{b}!!**, and {c} others are typing..."' - }, - predicate: () => settings.store.alternativeFormatting - }, // Adds the alternative formatting for several users typing { find: "getCooldownTextStyle", replacement: { - match: /(\i)\.length\?.\..\.Messages\.THREE_USERS_TYPING.format\(\{a:(\i),b:(\i),c:.}\).+?SEVERAL_USERS_TYPING/, - replace: "$&.format({a:$2,b:$3,c:$1.length-2})" + match: /((\i)\.length\?.\..\.Messages\.THREE_USERS_TYPING.format\(\{a:(\i),b:(\i),c:.}\)):.+?SEVERAL_USERS_TYPING/, + replace: "$1:$self.buildSeveralUsers({a:$3,b:$4,c:$2.length-2})" }, predicate: () => settings.store.alternativeFormatting } ], settings, - mutateChildren(props, users, children) { + buildSeveralUsers({ a, b, c }: { a: string, b: string, c: number; }) { + return [ + {a}, + ", ", + {b}, + `, and ${c} others are typing...` + ]; + }, + + mutateChildren(props: any, users: User[], children: any) { if (!Array.isArray(children)) return children; let element = 0; @@ -101,7 +94,7 @@ export default definePlugin({ return children.map(c => c.type === "strong" ? : c); }, - TypingUser: ErrorBoundary.wrap(({ user, guildId }) => { + TypingUser: ErrorBoundary.wrap(({ user, guildId }: { user: User, guildId: string; }) => { return