diff --git a/scripts/build.mjs b/scripts/build.mjs index ff00c84..95da306 100644 --- a/scripts/build.mjs +++ b/scripts/build.mjs @@ -74,7 +74,7 @@ const config = { constModules: { globals: { "bunny-build-info": { - version: `"1.2.1"` + version: `"1.2.2"` } } }, diff --git a/src/core/plugins/badges/index.tsx b/src/core/plugins/badges/index.tsx index 96914a3..08c9828 100644 --- a/src/core/plugins/badges/index.tsx +++ b/src/core/plugins/badges/index.tsx @@ -2,7 +2,6 @@ import { after } from "@lib/api/patcher"; import { onJsxCreate } from "@lib/api/react/jsx"; import { findByName } from "@metro"; import { useEffect, useState } from "react"; - import { defineCorePlugin } from ".."; interface BunnyBadge { @@ -15,52 +14,79 @@ const useBadgesModule = findByName("useBadges", false); export default defineCorePlugin({ manifest: { id: "bunny.badges", - version: "1.0.0", + version: "1.1.0", type: "plugin", spec: 3, main: "", display: { name: "Badges", description: "Adds badges to user's profile", - authors: [{ name: "pylixonly" }] + authors: [{ name: "cocobo1"}, { name: "pylixonly" }] } }, + start() { - const propHolder = {} as Record; const badgeCache = {} as Record; - - onJsxCreate("RenderedBadge", (_, ret) => { - if (ret.props.id.match(/bunny-\d+-\d+/)) { - Object.assign(ret.props, propHolder[ret.props.id]); + const badgeProps = {} as Record; + + onJsxCreate("ProfileBadge", (component, ret) => { + if (ret.props.id?.startsWith("bunny-")) { + const cachedProps = badgeProps[ret.props.id]; + if (cachedProps) { + ret.props.source = cachedProps.source; + ret.props.label = cachedProps.label; + ret.props.id = cachedProps.id; + } } }); - - after("default", useBadgesModule, ([user], r) => { - const [badges, setBadges] = useState(user ? badgeCache[user.userId] ??= [] : []); - - useEffect(() => { - if (user) { - fetch(`https://raw.githubusercontent.com/pyoncord/badges/refs/heads/main/${user.userId}.json`) - .then(r => r.json()) - .then(badges => setBadges(badgeCache[user.userId] = badges)); + + onJsxCreate("RenderedBadge", (component, ret) => { + if (ret.props.id?.startsWith("bunny-")) { + const cachedProps = badgeProps[ret.props.id]; + if (cachedProps) { + Object.assign(ret.props, cachedProps); } - }, [user]); - - if (user) { - badges.forEach((badges, i) => { - propHolder[`bunny-${user.userId}-${i}`] = { - source: { uri: badges.url }, - id: `bunny-${i}`, - label: badges.label + } + }); + + after("default", useBadgesModule, ([user], result) => { + const [badges, setBadges] = useState( + user ? badgeCache[user.userId] || [] : [] + ); + + useEffect(() => { + if (user && !badgeCache[user.userId]) { + fetch(`https://raw.githubusercontent.com/ra1ncord/badges/refs/heads/main/${user.userId}.json`) + .then(r => r.json()) + .then(fetchedBadges => { + badgeCache[user.userId] = fetchedBadges; + setBadges(fetchedBadges); + }) + //user has no badges, but maybe they should get some by contributing + .catch(() => { + badgeCache[user.userId] = []; + }); + } + }, [user?.userId]); + + if (user && badges.length > 0) { + badges.forEach((badge, i) => { + const badgeId = `bunny-${user.userId}-${i}`; + + badgeProps[badgeId] = { + id: badgeId, + source: { uri: badge.url }, + label: badge.label, + userId: user.userId, }; - r.push({ - id: `bunny-${user.userId}-${i}`, - description: badges.label, - icon: "_", + result.push({ + id: badgeId, + description: badge.label, + icon: "dummy", }); }); } }); } -}); +}); \ No newline at end of file diff --git a/src/core/ui/settings/index.ts b/src/core/ui/settings/index.ts index 1b76226..d5f96d8 100644 --- a/src/core/ui/settings/index.ts +++ b/src/core/ui/settings/index.ts @@ -51,12 +51,6 @@ export default function initSettings() { ] }); - // Compat with Vendetta Plugins that use configs in settings - registerSection({ - name: "Vendetta", - items: [] - }); - // Compat with Bunny Plugins that use configs in settings registerSection({ name: "Bunny", @@ -68,4 +62,10 @@ export default function initSettings() { name: "Revenge", items: [] }); + + // Compat with Vendetta Plugins that use configs in settings + registerSection({ + name: "Vendetta", + items: [] + }); } \ No newline at end of file