/* * 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 . */ import { BadgePosition, BadgeUserArgs, 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 Logger from "@utils/Logger"; import { Margins } from "@utils/margins"; import { closeModal, Modals, openModal } from "@utils/modal"; import definePlugin from "@utils/types"; import { Forms } from "@webpack/common"; const CONTRIBUTOR_BADGE = "https://cdn.discordapp.com/attachments/1033680203433660458/1092089947126780035/favicon.png"; /** List of vencord contributor IDs */ const contributorIds: string[] = Object.values(Devs).map(d => d.id.toString()); const ContributorBadge: ProfileBadge = { description: "Vencord Contributor", image: CONTRIBUTOR_BADGE, position: BadgePosition.START, props: { style: { borderRadius: "50%", transform: "scale(0.9)" // The image is a bit too big compared to default badges } }, shouldShow: ({ user }) => contributorIds.includes(user.id), link: "https://github.com/Vendicated/Vencord" }; const DonorBadges = {} as Record[]>; export default definePlugin({ name: "BadgeAPI", description: "API to add badges to users.", authors: [Devs.Megu, Devs.Ven, Devs.TheSun], required: true, patches: [ /* Patch the badge list component on user profiles */ { find: "Messages.PROFILE_USER_BADGES,role:", replacement: [ { match: /null==\i\?void 0:(\i)\.getBadges\(\)/, replace: (_, badgesMod) => `Vencord.Api.Badges._getBadges(arguments[0]).concat(${badgesMod}?.getBadges()??[])`, }, { // alt: "", aria-hidden: false, src: originalSrc match: /alt:" ","aria-hidden":!0,src:(?=(\i)\.src)/g, // ...badge.props, ..., src: badge.image ?? ... replace: "...$1.props,$& $1.image??" }, { match: /children:function(?<=(\i)\.(?:tooltip|description),spacing:\d.+?)/g, replace: "children:$1.component ? () => $self.renderBadgeComponent($1) : function" }, { match: /onClick:function(?=.{0,200}href:(\i)\.link)/, replace: "onClick:$1.onClick??function" } ] } ], renderBadgeComponent: ErrorBoundary.wrap((badge: ProfileBadge & BadgeUserArgs) => { const Component = badge.component!; return ; }, { noop: true }), 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, description, image] = line.split(","); (DonorBadges[id] ??= []).push({ image, description }); } }, getDonorBadges(userId: string) { return DonorBadges[userId]?.map(badge => ({ ...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 => ( { closeModal(modalKey); VencordNative.native.openExternal("https://github.com/sponsors/Vendicated"); }}> Vencord Donor
This Badge is a special perk for Vencord Donors Please consider supporting the development of Vencord by becoming a donor. It would mean a lot!!
)); }, })); } });