diff options
author | Vendicated <vendicated@riseup.net> | 2022-11-17 00:21:13 +0100 |
---|---|---|
committer | Vendicated <vendicated@riseup.net> | 2022-11-17 00:21:20 +0100 |
commit | 410613726b7f2da85d653bbf0e9cb662f1abd32e (patch) | |
tree | f424d91dc7d93e65431caf28b873c1a0a4a548cf /src/plugins | |
parent | 8b3f290e3ce1b166a3a15019b1f3504e015464c5 (diff) | |
download | Vencord-410613726b7f2da85d653bbf0e9cb662f1abd32e.tar.gz Vencord-410613726b7f2da85d653bbf0e9cb662f1abd32e.tar.bz2 Vencord-410613726b7f2da85d653bbf0e9cb662f1abd32e.zip |
Donor Badges && Add donate info to settings
Diffstat (limited to 'src/plugins')
-rw-r--r-- | src/plugins/apiBadges.tsx | 93 |
1 files changed, 92 insertions, 1 deletions
diff --git a/src/plugins/apiBadges.tsx b/src/plugins/apiBadges.tsx index e26a7a1..831bf86 100644 --- a/src/plugins/apiBadges.tsx +++ b/src/plugins/apiBadges.tsx @@ -17,9 +17,16 @@ */ import { BadgePosition, ProfileBadge } from "../api/Badges"; +import DonateButton from "../components/DonateButton"; +import ErrorBoundary from "../components/ErrorBoundary"; +import { Flex } from "../components/Flex"; +import { Heart } from "../components/Heart"; import { Devs } from "../utils/constants"; import IpcEvents from "../utils/IpcEvents"; +import Logger from "../utils/Logger"; +import { closeModal, Modals, openModal } from "../utils/modal"; import definePlugin from "../utils/types"; +import { Forms, Margins } from "../webpack/common"; const CONTRIBUTOR_BADGE = "https://media.discordapp.net/stickers/1026517526106087454.webp"; @@ -40,6 +47,8 @@ const ContributorBadge: ProfileBadge = { onClick: () => VencordNative.ipc.invoke(IpcEvents.OPEN_EXTERNAL, "https://github.com/Vendicated/Vencord") }; +const DonorBadges = {} as Record<string, Pick<ProfileBadge, "image" | "tooltip">>; + export default definePlugin({ name: "BadgeAPI", description: "API to add badges to users.", @@ -64,7 +73,89 @@ export default definePlugin({ } } ], - start() { + + async start() { Vencord.Api.Badges.addBadge(ContributorBadge); + const badges = await fetch("https://gist.githubusercontent.com/Vendicated/51a3dd775f6920429ec6e9b735ca7f01/raw/badges.csv").then(r => r.text()); + const lines = badges.trim().split("\n"); + if (lines.shift() !== "id,tooltip,image") { + new Logger("BadgeAPI").error("Invalid badges.csv file!"); + return; + } + for (const line of lines) { + const [id, tooltip, image] = line.split(","); + DonorBadges[id] = { image, tooltip }; + } }, + + addDonorBadge(badges: ProfileBadge[], userId: string) { + const badge = DonorBadges[userId]; + if (badge) { + badges.unshift({ + ...badge, + position: BadgePosition.START, + props: { + style: { + borderRadius: "50%", + transform: "scale(0.9)" // The image is a bit too big compared to default badges + } + }, + onClick() { + const modalKey = openModal(props => ( + <ErrorBoundary noop onError={() => { + closeModal(modalKey); + VencordNative.ipc.invoke(IpcEvents.OPEN_EXTERNAL, "https://github.com/sponsors/Vendicated"); + }}> + <Modals.ModalRoot {...props}> + <Modals.ModalHeader> + <Flex style={{ width: "100%", justifyContent: "center" }}> + <Forms.FormTitle + tag="h2" + style={{ + width: "100%", + textAlign: "center", + margin: 0 + }} + > + <Heart /> + Vencord Donor + </Forms.FormTitle> + </Flex> + </Modals.ModalHeader> + <Modals.ModalContent> + <Flex> + <img + role="presentation" + src="https://cdn.discordapp.com/emojis/1026533070955872337.png" + alt="" + style={{ margin: "auto" }} + /> + <img + role="presentation" + src="https://cdn.discordapp.com/emojis/1026533090627174460.png" + alt="" + style={{ margin: "auto" }} + /> + </Flex> + <div style={{ padding: "1em" }}> + <Forms.FormText> + This Badge is a special perk for Vencord Donors + </Forms.FormText> + <Forms.FormText className={Margins.marginTop20}> + Please consider supporting the development of Vencord by becoming a donor. It would mean a lot!! + </Forms.FormText> + </div> + </Modals.ModalContent> + <Modals.ModalFooter> + <Flex style={{ width: "100%", justifyContent: "center" }}> + <DonateButton /> + </Flex> + </Modals.ModalFooter> + </Modals.ModalRoot> + </ErrorBoundary> + )); + }, + }); + } + } }); |