add vencord and equicord contributor to fetching
All checks were successful
Code quality checks / biome (push) Successful in 17s
All checks were successful
Code quality checks / biome (push) Successful in 17s
This commit is contained in:
parent
d300f20b49
commit
269b858e88
3 changed files with 100 additions and 12 deletions
|
@ -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<string, string> = {
|
||||
Vencord: "Custom badges from Vencord Discord client",
|
||||
|
@ -137,6 +140,7 @@ export {
|
|||
badgeServices,
|
||||
discordBadges,
|
||||
discordBadgeDetails,
|
||||
vencordEquicordContributorUrl,
|
||||
getServiceDescription,
|
||||
gitUrl,
|
||||
};
|
||||
|
|
|
@ -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<string>();
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
|
|
32
types/badge.d.ts
vendored
32
types/badge.d.ts
vendored
|
@ -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;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue