From 269b858e8848b5f8d14cc355096ef0313e4d0911 Mon Sep 17 00:00:00 2001 From: creations Date: Thu, 5 Jun 2025 19:49:23 -0400 Subject: [PATCH] add vencord and equicord contributor to fetching --- config/constants.ts | 6 +++- src/lib/badgeCache.ts | 74 ++++++++++++++++++++++++++++++++++++++++++- types/badge.d.ts | 32 +++++++++++++------ 3 files changed, 100 insertions(+), 12 deletions(-) diff --git a/config/constants.ts b/config/constants.ts index 37a8a5a..ac3a5c6 100644 --- a/config/constants.ts +++ b/config/constants.ts @@ -87,7 +87,7 @@ const discordBadgeDetails = { }, }; -const badgeServices: badgeURLMap[] = [ +const badgeServices: BadgeService[] = [ { service: "Vencord", url: "https://badges.vencord.dev/badges.json", @@ -118,6 +118,9 @@ const badgeServices: badgeURLMap[] = [ }, ]; +const vencordEquicordContributorUrl = + "https://raw.githubusercontent.com/Equicord/Equibored/refs/heads/main/plugins.json"; + function getServiceDescription(service: string): string { const descriptions: Record = { Vencord: "Custom badges from Vencord Discord client", @@ -137,6 +140,7 @@ export { badgeServices, discordBadges, discordBadgeDetails, + vencordEquicordContributorUrl, getServiceDescription, gitUrl, }; diff --git a/src/lib/badgeCache.ts b/src/lib/badgeCache.ts index 682f6c9..8711187 100644 --- a/src/lib/badgeCache.ts +++ b/src/lib/badgeCache.ts @@ -1,5 +1,11 @@ import { echo } from "@atums/echo"; -import { badgeFetchInterval, badgeServices, gitUrl, redisTtl } from "@config"; +import { + badgeFetchInterval, + badgeServices, + gitUrl, + redisTtl, + vencordEquicordContributorUrl, +} from "@config"; import { redis } from "bun"; class BadgeCacheManager { @@ -110,6 +116,72 @@ class BadgeCacheManager { data = (await res.json()) as VencordEquicordData; } } + + if (typeof vencordEquicordContributorUrl === "string") { + const contributorRes = await fetch(vencordEquicordContributorUrl, { + headers: { + "User-Agent": `BadgeAPI/1.0 ${gitUrl}`, + }, + }); + + if (contributorRes.ok) { + const pluginData = await contributorRes.json(); + + if (Array.isArray(pluginData)) { + if (!data) { + data = {} as VencordEquicordData; + } + + const contributors = new Set(); + + for (const plugin of pluginData) { + if (plugin.authors && Array.isArray(plugin.authors)) { + const isEquicordPlugin = + plugin.filePath && + typeof plugin.filePath === "string" && + plugin.filePath.includes("equicordplugins/"); + + const shouldInclude = + (serviceKey === "equicord" && isEquicordPlugin) || + (serviceKey === "vencord" && !isEquicordPlugin); + + if (shouldInclude) { + for (const author of plugin.authors) { + if (author.id) { + contributors.add(author.id); + } + } + } + } + } + + const badgeDetails = + serviceKey === "vencord" + ? { + tooltip: "Vencord Contributor", + badge: "https://vencord.dev/assets/favicon.png", + } + : { + tooltip: "Equicord Contributor", + badge: "https://i.imgur.com/57ATLZu.png", + }; + + for (const authorId of contributors) { + if (!data[authorId]) { + data[authorId] = []; + } + + const hasContributorBadge = data[authorId].some( + (badge) => badge.tooltip === badgeDetails.tooltip, + ); + + if (!hasContributorBadge) { + data[authorId].push(badgeDetails); + } + } + } + } + } break; } diff --git a/types/badge.d.ts b/types/badge.d.ts index 7d17c08..08043b9 100644 --- a/types/badge.d.ts +++ b/types/badge.d.ts @@ -10,7 +10,7 @@ interface FetchBadgesOptions { separated?: boolean; } -type badgeURLMap = { +type BadgeService = { service: string; url: | string @@ -51,15 +51,6 @@ interface ReviewDbData type BadgeServiceData = VencordEquicordData | NekocordData | ReviewDbData; -interface BadgeService { - service: string; - url: - | string - | (( - userId: string, - ) => string | { user: string; badge: (id: string) => string }); -} - interface VencordBadgeItem { tooltip: string; badge: string; @@ -87,3 +78,24 @@ interface DiscordUserData { avatar: string; flags: number; } + +interface PluginData { + hasPatches: boolean; + hasCommands: boolean; + enabledByDefault: boolean; + required: boolean; + tags: string[]; + name: string; + description: string; + authors: Array<{ + name: string; + id: string; + }>; + filePath: string; + commands?: Array<{ + name: string; + description: string; + }>; + dependencies?: string[]; + target?: string; +}