fix required bot token, fix equicord and vencord contrib badges, move equicord to svg
All checks were successful
Code quality checks / biome (push) Successful in 16s

This commit is contained in:
creations 2025-06-07 21:08:10 -04:00
parent 269b858e88
commit 2f9b38ace8
Signed by: creations
GPG key ID: 8F553AA4320FC711
7 changed files with 72 additions and 49 deletions

View file

@ -85,16 +85,36 @@ const discordBadgeDetails = {
tooltip: "Uses AutoMod", tooltip: "Uses AutoMod",
icon: "/public/badges/discord/USES_AUTOMOD.svg", icon: "/public/badges/discord/USES_AUTOMOD.svg",
}, },
// Custom
VENCORD_CONTRIBUTOR: {
tooltip: "Vencord Contributor",
icon: "/public/badges/vencord.png",
},
EQUICORD_CONTRIBUTOR: {
tooltip: "Equicord Contributor",
icon: "/public/badges/equicord.svg",
},
DISCORD_NITRO: {
tooltip: "Discord Nitro",
icon: "/public/badges/discord/NITRO.svg",
},
}; };
const badgeServices: BadgeService[] = [ const badgeServices: BadgeService[] = [
{ {
service: "Vencord", service: "Vencord",
url: "https://badges.vencord.dev/badges.json", url: "https://badges.vencord.dev/badges.json",
pluginsUrl:
"https://raw.githubusercontent.com/Vencord/builds/main/plugins.json",
}, },
{ {
service: "Equicord", // Ekwekord ! WOOP service: "Equicord", // Ekwekord ! WOOP
url: "https://raw.githubusercontent.com/Equicord/Equibored/refs/heads/main/badges.json", url: "https://raw.githubusercontent.com/Equicord/Equibored/refs/heads/main/badges.json",
pluginsUrl:
"https://raw.githubusercontent.com/Equicord/Equibored/refs/heads/main/plugins.json",
}, },
{ {
service: "Nekocord", service: "Nekocord",
@ -118,9 +138,6 @@ const badgeServices: BadgeService[] = [
}, },
]; ];
const vencordEquicordContributorUrl =
"https://raw.githubusercontent.com/Equicord/Equibored/refs/heads/main/plugins.json";
function getServiceDescription(service: string): string { function getServiceDescription(service: string): string {
const descriptions: Record<string, string> = { const descriptions: Record<string, string> = {
Vencord: "Custom badges from Vencord Discord client", Vencord: "Custom badges from Vencord Discord client",
@ -140,7 +157,6 @@ export {
badgeServices, badgeServices,
discordBadges, discordBadges,
discordBadgeDetails, discordBadgeDetails,
vencordEquicordContributorUrl,
getServiceDescription, getServiceDescription,
gitUrl, gitUrl,
}; };

View file

@ -18,7 +18,7 @@ const badgeFetchInterval: number = process.env.BADGE_FETCH_INTERVAL
const botToken: string | undefined = process.env.DISCORD_TOKEN; const botToken: string | undefined = process.env.DISCORD_TOKEN;
function verifyRequiredVariables(): void { function verifyRequiredVariables(): void {
const requiredVariables = ["HOST", "PORT", "DISCORD_TOKEN"]; const requiredVariables = ["HOST", "PORT"];
let hasError = false; let hasError = false;

File diff suppressed because one or more lines are too long

After

Width:  |  Height:  |  Size: 16 KiB

BIN
public/badges/vencord.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 900 B

View file

@ -2,9 +2,9 @@ import { echo } from "@atums/echo";
import { import {
badgeFetchInterval, badgeFetchInterval,
badgeServices, badgeServices,
discordBadgeDetails,
gitUrl, gitUrl,
redisTtl, redisTtl,
vencordEquicordContributorUrl,
} from "@config"; } from "@config";
import { redis } from "bun"; import { redis } from "bun";
@ -117,8 +117,8 @@ class BadgeCacheManager {
} }
} }
if (typeof vencordEquicordContributorUrl === "string") { if (typeof service.pluginsUrl === "string") {
const contributorRes = await fetch(vencordEquicordContributorUrl, { const contributorRes = await fetch(service.pluginsUrl, {
headers: { headers: {
"User-Agent": `BadgeAPI/1.0 ${gitUrl}`, "User-Agent": `BadgeAPI/1.0 ${gitUrl}`,
}, },
@ -136,16 +136,6 @@ class BadgeCacheManager {
for (const plugin of pluginData) { for (const plugin of pluginData) {
if (plugin.authors && Array.isArray(plugin.authors)) { 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) { for (const author of plugin.authors) {
if (author.id) { if (author.id) {
contributors.add(author.id); contributors.add(author.id);
@ -153,17 +143,18 @@ class BadgeCacheManager {
} }
} }
} }
}
const badgeDetails = const badgeDetails =
serviceKey === "vencord" serviceKey === "vencord"
? { ? {
tooltip: "Vencord Contributor", tooltip:
badge: "https://vencord.dev/assets/favicon.png", discordBadgeDetails.VENCORD_CONTRIBUTOR.tooltip,
badge: discordBadgeDetails.VENCORD_CONTRIBUTOR.icon,
} }
: { : {
tooltip: "Equicord Contributor", tooltip:
badge: "https://i.imgur.com/57ATLZu.png", discordBadgeDetails.EQUICORD_CONTRIBUTOR.tooltip,
badge: discordBadgeDetails.EQUICORD_CONTRIBUTOR.icon,
}; };
for (const authorId of contributors) { for (const authorId of contributors) {

View file

@ -11,6 +11,8 @@ function getRequestOrigin(request: Request): string {
return `${forwardedProto}://${host}`; return `${forwardedProto}://${host}`;
} }
const USER_CACHE_SERVICES = ["discord", "enmity"];
export async function fetchBadges( export async function fetchBadges(
userId: string | undefined, userId: string | undefined,
services: string[], services: string[],
@ -26,9 +28,13 @@ export async function fetchBadges(
const userCachePromises = services.map(async (service) => { const userCachePromises = services.map(async (service) => {
const serviceKey = service.toLowerCase(); const serviceKey = service.toLowerCase();
if (!USER_CACHE_SERVICES.includes(serviceKey) || nocache) {
return false;
}
const userCacheKey = `user_badges:${serviceKey}:${userId}`; const userCacheKey = `user_badges:${serviceKey}:${userId}`;
if (!nocache) {
try { try {
const cached = await redis.get(userCacheKey); const cached = await redis.get(userCacheKey);
if (cached) { if (cached) {
@ -37,12 +43,11 @@ export async function fetchBadges(
return true; return true;
} }
} catch {} } catch {}
}
return false; return false;
}); });
const cacheHits = await Promise.all(userCachePromises); const cacheHits = await Promise.all(userCachePromises);
const servicesToFetch = services.filter((_, index) => !cacheHits[index]); const servicesToFetch = services.filter((_, index) => !cacheHits[index]);
await Promise.all( await Promise.all(
@ -68,10 +73,16 @@ export async function fetchBadges(
const userBadges = serviceData[userId]; const userBadges = serviceData[userId];
if (Array.isArray(userBadges)) { if (Array.isArray(userBadges)) {
const origin = request ? getRequestOrigin(request) : "";
for (const badgeItem of userBadges) { for (const badgeItem of userBadges) {
const badgeUrl = badgeItem.badge.startsWith("/")
? `${origin}${badgeItem.badge}`
: badgeItem.badge;
result.push({ result.push({
tooltip: badgeItem.tooltip, tooltip: badgeItem.tooltip,
badge: badgeItem.badge, badge: badgeUrl,
}); });
} }
} }
@ -199,8 +210,8 @@ export async function fetchBadges(
if (data.avatar?.startsWith("a_")) { if (data.avatar?.startsWith("a_")) {
result.push({ result.push({
tooltip: "Discord Nitro", tooltip: discordBadgeDetails.DISCORD_NITRO.tooltip,
badge: `${origin}/public/badges/discord/NITRO.svg`, badge: `${origin}${discordBadgeDetails.DISCORD_NITRO.icon}`,
}); });
} }
@ -228,18 +239,17 @@ export async function fetchBadges(
break; break;
} }
if (
result.length > 0 ||
serviceKey === "discord" ||
serviceKey === "enmity"
) {
results[serviceKey] = result; results[serviceKey] = result;
if (!nocache) {
if (
USER_CACHE_SERVICES.includes(serviceKey) &&
!nocache &&
result.length > 0
) {
const userCacheKey = `user_badges:${serviceKey}:${userId}`; const userCacheKey = `user_badges:${serviceKey}:${userId}`;
await redis.set(userCacheKey, JSON.stringify(result)); await redis.set(userCacheKey, JSON.stringify(result));
await redis.expire(userCacheKey, Math.min(redisTtl, 900)); await redis.expire(userCacheKey, Math.min(redisTtl, 900));
} }
}
} catch (error) { } catch (error) {
echo.warn({ echo.warn({
message: `Failed to fetch badges for service ${serviceKey}`, message: `Failed to fetch badges for service ${serviceKey}`,

1
types/badge.d.ts vendored
View file

@ -19,6 +19,7 @@ type BadgeService = {
user: string; user: string;
badge: (id: string) => string; badge: (id: string) => string;
}); });
pluginsUrl?: string;
}; };
interface VencordEquicordData { interface VencordEquicordData {