diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/api/Badges.ts | 4 | ||||
-rw-r--r-- | src/components/DonateButton.tsx | 37 | ||||
-rw-r--r-- | src/components/Heart.tsx | 35 | ||||
-rw-r--r-- | src/components/Settings.tsx | 28 | ||||
-rw-r--r-- | src/plugins/apiBadges.tsx | 93 |
5 files changed, 193 insertions, 4 deletions
diff --git a/src/api/Badges.ts b/src/api/Badges.ts index 542f78d..55e9b3a 100644 --- a/src/api/Badges.ts +++ b/src/api/Badges.ts @@ -19,6 +19,8 @@ import { User } from "discord-types/general"; import { HTMLProps } from "react"; +import Plugins from "~plugins"; + export enum BadgePosition { START, END @@ -72,6 +74,8 @@ export function inject(badgeArray: ProfileBadge[], args: BadgeUserArgs) { : badgeArray.push(badge); } } + (Plugins.BadgeAPI as any).addDonorBadge(badgeArray, args.user.id); + return badgeArray; } diff --git a/src/components/DonateButton.tsx b/src/components/DonateButton.tsx new file mode 100644 index 0000000..6aae8ad --- /dev/null +++ b/src/components/DonateButton.tsx @@ -0,0 +1,37 @@ +/* + * Vencord, a modification for Discord's desktop app + * Copyright (c) 2022 Vendicated and contributors + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <https://www.gnu.org/licenses/>. +*/ + +import IpcEvents from "../utils/IpcEvents"; +import { Button } from "../webpack/common"; +import { Heart } from "./Heart"; + +export default function DonateButton(props: any) { + return ( + <Button + {...props} + look={Button.Looks.LINK} + color={Button.Colors.TRANSPARENT} + onClick={() => + VencordNative.ipc.invoke(IpcEvents.OPEN_EXTERNAL, "https://github.com/sponsors/Vendicated") + } + > + <Heart /> + Donate + </Button> + ); +} diff --git a/src/components/Heart.tsx b/src/components/Heart.tsx new file mode 100644 index 0000000..b33b836 --- /dev/null +++ b/src/components/Heart.tsx @@ -0,0 +1,35 @@ +/* + * Vencord, a modification for Discord's desktop app + * Copyright (c) 2022 Vendicated and contributors + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <https://www.gnu.org/licenses/>. +*/ + +export function Heart() { + return ( + <svg + aria-hidden="true" + height="16" + viewBox="0 0 16 16" + width="16" + style={{ marginRight: "0.5em", transform: "translateY(2px)" }} + > + <path + fill="#db61a2" + fill-rule="evenodd" + d="M4.25 2.5c-1.336 0-2.75 1.164-2.75 3 0 2.15 1.58 4.144 3.365 5.682A20.565 20.565 0 008 13.393a20.561 20.561 0 003.135-2.211C12.92 9.644 14.5 7.65 14.5 5.5c0-1.836-1.414-3-2.75-3-1.373 0-2.609.986-3.029 2.456a.75.75 0 01-1.442 0C6.859 3.486 5.623 2.5 4.25 2.5zM8 14.25l-.345.666-.002-.001-.006-.003-.018-.01a7.643 7.643 0 01-.31-.17 22.075 22.075 0 01-3.434-2.414C2.045 10.731 0 8.35 0 5.5 0 2.836 2.086 1 4.25 1 5.797 1 7.153 1.802 8 3.02 8.847 1.802 10.203 1 11.75 1 13.914 1 16 2.836 16 5.5c0 2.85-2.045 5.231-3.885 6.818a22.08 22.08 0 01-3.744 2.584l-.018.01-.006.003h-.002L8 14.25zm0 0l.345.666a.752.752 0 01-.69 0L8 14.25z" + /> + </svg> + ); +} diff --git a/src/components/Settings.tsx b/src/components/Settings.tsx index 363b1df..fc25901 100644 --- a/src/components/Settings.tsx +++ b/src/components/Settings.tsx @@ -20,7 +20,8 @@ import { useSettings } from "../api/settings"; import { ChangeList } from "../utils/ChangeList"; import IpcEvents from "../utils/IpcEvents"; import { useAwaiter } from "../utils/misc"; -import { Alerts, Button, Forms, Margins, Parser, React, Switch } from "../webpack/common"; +import { Alerts, Button, Card, Forms, Margins, Parser, React, Switch } from "../webpack/common"; +import DonateButton from "./DonateButton"; import ErrorBoundary from "./ErrorBoundary"; import { Flex } from "./Flex"; import { handleComponentFailed } from "./handleComponentFailed"; @@ -52,15 +53,36 @@ export default ErrorBoundary.wrap(function Settings() { return ( <Forms.FormSection tag="h1" title="Vencord"> + <Card style={{ + padding: "1em", + display: "flex", + flexDirection: "row", + marginBottom: "1em" + }}> + <div> + <Forms.FormTitle tag="h5">Support the Project</Forms.FormTitle> + <Forms.FormText> + Please consider supporting the Development of Vencord by donating! + </Forms.FormText> + <DonateButton style={{ transform: "translateX(-1em)" }} /> + </div> + <img + role="presentation" + src="https://cdn.discordapp.com/emojis/1026533090627174460.png" + alt="" + style={{ marginLeft: "auto", transform: "rotate(10deg)" }} + /> + </Card> + <Forms.FormTitle tag="h5"> Settings </Forms.FormTitle> - <Forms.FormText> + <Forms.FormText className={Margins.marginBottom8}> Settings Directory: <code style={{ userSelect: "text", cursor: "text" }}>{settingsDir}</code> </Forms.FormText> - {!IS_WEB && <Flex className={Margins.marginBottom20} style={{ marginTop: 8 }}> + {!IS_WEB && <Flex className={Margins.marginBottom20}> <Button onClick={() => window.DiscordNative.app.relaunch()} size={Button.Sizes.SMALL} 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> + )); + }, + }); + } + } }); |