From 7f18a707b12cc892420adb79002c3208b261fadd Mon Sep 17 00:00:00 2001 From: zrodevkaan <90235641+zrodevkaan@users.noreply.github.com> Date: Tue, 2 Apr 2024 21:46:56 -0500 Subject: [PATCH] Fixed CoreMods badges --- src/renderer/coremods/badges/index.tsx | 30 ++++++++++++++++++-------- 1 file changed, 21 insertions(+), 9 deletions(-) diff --git a/src/renderer/coremods/badges/index.tsx b/src/renderer/coremods/badges/index.tsx index d7e935b26..5e43407c1 100644 --- a/src/renderer/coremods/badges/index.tsx +++ b/src/renderer/coremods/badges/index.tsx @@ -3,8 +3,10 @@ import { Logger } from "@replugged"; import type { User } from "discord-types/general"; import { Injector } from "../../modules/injector"; import { getByProps, waitForProps } from "../../modules/webpack"; +import {util} from "@replugged"; import { generalSettings } from "../settings/pages/General"; import { APIBadges, BadgeSizes, Custom, badgeElements, getBadgeSizeClass } from "./badge"; +import {Tree} from "../../util"; const injector = new Injector(); @@ -22,9 +24,9 @@ interface BadgeModArgs { type BadgeMod = (args: BadgeModArgs) => | React.ReactElement<{ - children?: React.ReactElement[]; - className: string; - }> + children?: React.ReactElement[]; + className: string; +}> | undefined; interface BadgeCache { @@ -32,9 +34,15 @@ interface BadgeCache { lastFetch: number; } +interface BadgeHighs +{ + props:{children:{props:{children:{}}}} +} + // todo: guilds const cache = new Map(); const REFRESH_INTERVAL = 1000 * 60 * 30; +type TreeWithCombine = Tree & { className: string }; export async function start(): Promise { const mod = await waitForProps<{ BadgeSizes: BadgeSizes; default: BadgeMod }>("BadgeSizes"); @@ -43,7 +51,7 @@ export async function start(): Promise { "containerWithContent", )!; - injector.after(mod, "default", ([props], res) => { + injector.after(mod, "default", ([props], res: BadgeHighs) => { let { user: { id }, shrinkAtCount, @@ -93,7 +101,7 @@ export async function start(): Promise { if (!badges) { return res; } - const children = res?.props.children; + const children = res?.props.children.props.children; if (!children || !Array.isArray(children)) { logger.error("Error injecting badges: res.props.children is not an array", { children }); return res; @@ -134,15 +142,19 @@ export async function start(): Promise { } }); + const badgesClassName: TreeWithCombine | any = util.findInTree(res as unknown as Tree, x => Boolean(x?.className)); + if (!badgesClassName) return; + if (children.length > 0) { - if (!res.props.className.includes(containerWithContent)) { - res.props.className += ` ${containerWithContent}`; + if (!badgesClassName.className.includes(containerWithContent)) { + badgesClassName.className += ` ${containerWithContent}`; } - if (!res.props.className.includes("replugged-badges-container")) { - res.props.className += " replugged-badges-container"; + if (!badgesClassName.className.includes("replugged-badges-container")) { + badgesClassName.className += " replugged-badges-container"; } } + return res; } catch (err) { logger.error(err);