BadgeAPI: Add support for multiple donor badges

This commit is contained in:
Vendicated 2023-04-29 02:06:52 +02:00
parent ec72b4c91d
commit a2e03084b0
No known key found for this signature in database
GPG key ID: A1DC0CFB5615D905
2 changed files with 70 additions and 73 deletions

View file

@ -79,8 +79,8 @@ export function _getBadges(args: BadgeUserArgs) {
: badges.push({ ...badge, ...args }); : badges.push({ ...badge, ...args });
} }
} }
const donorBadge = (Plugins.BadgeAPI as any).getDonorBadge(args.user.id); const donorBadges = (Plugins.BadgeAPI as unknown as typeof import("../plugins/apiBadges").default).getDonorBadges(args.user.id);
if (donorBadge) badges.unshift(donorBadge); if (donorBadges) badges.unshift(...donorBadges);
return badges; return badges;
} }

View file

@ -48,7 +48,7 @@ const ContributorBadge: ProfileBadge = {
link: "https://github.com/Vendicated/Vencord" link: "https://github.com/Vendicated/Vencord"
}; };
const DonorBadges = {} as Record<string, Pick<ProfileBadge, "image" | "description">>; const DonorBadges = {} as Record<string, Pick<ProfileBadge, "image" | "description">[]>;
export default definePlugin({ export default definePlugin({
name: "BadgeAPI", name: "BadgeAPI",
@ -97,14 +97,12 @@ export default definePlugin({
} }
for (const line of lines) { for (const line of lines) {
const [id, description, image] = line.split(","); const [id, description, image] = line.split(",");
DonorBadges[id] = { image, description }; (DonorBadges[id] ??= []).push({ image, description });
} }
}, },
getDonorBadge(userId: string) { getDonorBadges(userId: string) {
const badge = DonorBadges[userId]; return DonorBadges[userId]?.map(badge => ({
if (badge) {
return {
...badge, ...badge,
position: BadgePosition.START, position: BadgePosition.START,
props: { props: {
@ -168,7 +166,6 @@ export default definePlugin({
</ErrorBoundary> </ErrorBoundary>
)); ));
}, },
}; }));
}
} }
}); });