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

@ -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;
} }

@ -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,78 +97,75 @@ 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) { ...badge,
return { position: BadgePosition.START,
...badge, props: {
position: BadgePosition.START, style: {
props: { borderRadius: "50%",
style: { transform: "scale(0.9)" // The image is a bit too big compared to default badges
borderRadius: "50%", }
transform: "scale(0.9)" // The image is a bit too big compared to default badges },
} onClick() {
}, const modalKey = openModal(props => (
onClick() { <ErrorBoundary noop onError={() => {
const modalKey = openModal(props => ( closeModal(modalKey);
<ErrorBoundary noop onError={() => { VencordNative.ipc.invoke(IpcEvents.OPEN_EXTERNAL, "https://github.com/sponsors/Vendicated");
closeModal(modalKey); }}>
VencordNative.ipc.invoke(IpcEvents.OPEN_EXTERNAL, "https://github.com/sponsors/Vendicated"); <Modals.ModalRoot {...props}>
}}> <Modals.ModalHeader>
<Modals.ModalRoot {...props}> <Flex style={{ width: "100%", justifyContent: "center" }}>
<Modals.ModalHeader> <Forms.FormTitle
<Flex style={{ width: "100%", justifyContent: "center" }}> tag="h2"
<Forms.FormTitle style={{
tag="h2" width: "100%",
style={{ textAlign: "center",
width: "100%", margin: 0
textAlign: "center", }}
margin: 0 >
}} <Heart />
> Vencord Donor
<Heart /> </Forms.FormTitle>
Vencord Donor </Flex>
</Forms.FormTitle> </Modals.ModalHeader>
</Flex> <Modals.ModalContent>
</Modals.ModalHeader> <Flex>
<Modals.ModalContent> <img
<Flex> role="presentation"
<img src="https://cdn.discordapp.com/emojis/1026533070955872337.png"
role="presentation" alt=""
src="https://cdn.discordapp.com/emojis/1026533070955872337.png" style={{ margin: "auto" }}
alt="" />
style={{ margin: "auto" }} <img
/> role="presentation"
<img src="https://cdn.discordapp.com/emojis/1026533090627174460.png"
role="presentation" alt=""
src="https://cdn.discordapp.com/emojis/1026533090627174460.png" style={{ margin: "auto" }}
alt="" />
style={{ margin: "auto" }} </Flex>
/> <div style={{ padding: "1em" }}>
</Flex> <Forms.FormText>
<div style={{ padding: "1em" }}> This Badge is a special perk for Vencord Donors
<Forms.FormText> </Forms.FormText>
This Badge is a special perk for Vencord Donors <Forms.FormText className={Margins.top20}>
</Forms.FormText> Please consider supporting the development of Vencord by becoming a donor. It would mean a lot!!
<Forms.FormText className={Margins.top20}> </Forms.FormText>
Please consider supporting the development of Vencord by becoming a donor. It would mean a lot!! </div>
</Forms.FormText> </Modals.ModalContent>
</div> <Modals.ModalFooter>
</Modals.ModalContent> <Flex style={{ width: "100%", justifyContent: "center" }}>
<Modals.ModalFooter> <DonateButton />
<Flex style={{ width: "100%", justifyContent: "center" }}> </Flex>
<DonateButton /> </Modals.ModalFooter>
</Flex> </Modals.ModalRoot>
</Modals.ModalFooter> </ErrorBoundary>
</Modals.ModalRoot> ));
</ErrorBoundary> },
)); }));
},
};
}
} }
}); });