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
All checks were successful
Code quality checks / biome (push) Successful in 16s
This commit is contained in:
parent
269b858e88
commit
2f9b38ace8
7 changed files with 72 additions and 49 deletions
|
@ -85,16 +85,36 @@ const discordBadgeDetails = {
|
|||
tooltip: "Uses AutoMod",
|
||||
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[] = [
|
||||
{
|
||||
service: "Vencord",
|
||||
url: "https://badges.vencord.dev/badges.json",
|
||||
pluginsUrl:
|
||||
"https://raw.githubusercontent.com/Vencord/builds/main/plugins.json",
|
||||
},
|
||||
{
|
||||
service: "Equicord", // Ekwekord ! WOOP
|
||||
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",
|
||||
|
@ -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 {
|
||||
const descriptions: Record<string, string> = {
|
||||
Vencord: "Custom badges from Vencord Discord client",
|
||||
|
@ -140,7 +157,6 @@ export {
|
|||
badgeServices,
|
||||
discordBadges,
|
||||
discordBadgeDetails,
|
||||
vencordEquicordContributorUrl,
|
||||
getServiceDescription,
|
||||
gitUrl,
|
||||
};
|
||||
|
|
|
@ -18,7 +18,7 @@ const badgeFetchInterval: number = process.env.BADGE_FETCH_INTERVAL
|
|||
const botToken: string | undefined = process.env.DISCORD_TOKEN;
|
||||
|
||||
function verifyRequiredVariables(): void {
|
||||
const requiredVariables = ["HOST", "PORT", "DISCORD_TOKEN"];
|
||||
const requiredVariables = ["HOST", "PORT"];
|
||||
|
||||
let hasError = false;
|
||||
|
||||
|
|
5
public/badges/equicord.svg
Normal file
5
public/badges/equicord.svg
Normal file
File diff suppressed because one or more lines are too long
After Width: | Height: | Size: 16 KiB |
BIN
public/badges/vencord.png
Normal file
BIN
public/badges/vencord.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 900 B |
|
@ -2,9 +2,9 @@ import { echo } from "@atums/echo";
|
|||
import {
|
||||
badgeFetchInterval,
|
||||
badgeServices,
|
||||
discordBadgeDetails,
|
||||
gitUrl,
|
||||
redisTtl,
|
||||
vencordEquicordContributorUrl,
|
||||
} from "@config";
|
||||
import { redis } from "bun";
|
||||
|
||||
|
@ -117,8 +117,8 @@ class BadgeCacheManager {
|
|||
}
|
||||
}
|
||||
|
||||
if (typeof vencordEquicordContributorUrl === "string") {
|
||||
const contributorRes = await fetch(vencordEquicordContributorUrl, {
|
||||
if (typeof service.pluginsUrl === "string") {
|
||||
const contributorRes = await fetch(service.pluginsUrl, {
|
||||
headers: {
|
||||
"User-Agent": `BadgeAPI/1.0 ${gitUrl}`,
|
||||
},
|
||||
|
@ -136,20 +136,9 @@ class BadgeCacheManager {
|
|||
|
||||
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);
|
||||
}
|
||||
for (const author of plugin.authors) {
|
||||
if (author.id) {
|
||||
contributors.add(author.id);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -158,12 +147,14 @@ class BadgeCacheManager {
|
|||
const badgeDetails =
|
||||
serviceKey === "vencord"
|
||||
? {
|
||||
tooltip: "Vencord Contributor",
|
||||
badge: "https://vencord.dev/assets/favicon.png",
|
||||
tooltip:
|
||||
discordBadgeDetails.VENCORD_CONTRIBUTOR.tooltip,
|
||||
badge: discordBadgeDetails.VENCORD_CONTRIBUTOR.icon,
|
||||
}
|
||||
: {
|
||||
tooltip: "Equicord Contributor",
|
||||
badge: "https://i.imgur.com/57ATLZu.png",
|
||||
tooltip:
|
||||
discordBadgeDetails.EQUICORD_CONTRIBUTOR.tooltip,
|
||||
badge: discordBadgeDetails.EQUICORD_CONTRIBUTOR.icon,
|
||||
};
|
||||
|
||||
for (const authorId of contributors) {
|
||||
|
|
|
@ -11,6 +11,8 @@ function getRequestOrigin(request: Request): string {
|
|||
return `${forwardedProto}://${host}`;
|
||||
}
|
||||
|
||||
const USER_CACHE_SERVICES = ["discord", "enmity"];
|
||||
|
||||
export async function fetchBadges(
|
||||
userId: string | undefined,
|
||||
services: string[],
|
||||
|
@ -26,23 +28,26 @@ export async function fetchBadges(
|
|||
|
||||
const userCachePromises = services.map(async (service) => {
|
||||
const serviceKey = service.toLowerCase();
|
||||
|
||||
if (!USER_CACHE_SERVICES.includes(serviceKey) || nocache) {
|
||||
return false;
|
||||
}
|
||||
|
||||
const userCacheKey = `user_badges:${serviceKey}:${userId}`;
|
||||
|
||||
if (!nocache) {
|
||||
try {
|
||||
const cached = await redis.get(userCacheKey);
|
||||
if (cached) {
|
||||
const parsed: Badge[] = JSON.parse(cached);
|
||||
results[serviceKey] = parsed;
|
||||
return true;
|
||||
}
|
||||
} catch {}
|
||||
}
|
||||
try {
|
||||
const cached = await redis.get(userCacheKey);
|
||||
if (cached) {
|
||||
const parsed: Badge[] = JSON.parse(cached);
|
||||
results[serviceKey] = parsed;
|
||||
return true;
|
||||
}
|
||||
} catch {}
|
||||
|
||||
return false;
|
||||
});
|
||||
|
||||
const cacheHits = await Promise.all(userCachePromises);
|
||||
|
||||
const servicesToFetch = services.filter((_, index) => !cacheHits[index]);
|
||||
|
||||
await Promise.all(
|
||||
|
@ -68,10 +73,16 @@ export async function fetchBadges(
|
|||
|
||||
const userBadges = serviceData[userId];
|
||||
if (Array.isArray(userBadges)) {
|
||||
const origin = request ? getRequestOrigin(request) : "";
|
||||
|
||||
for (const badgeItem of userBadges) {
|
||||
const badgeUrl = badgeItem.badge.startsWith("/")
|
||||
? `${origin}${badgeItem.badge}`
|
||||
: badgeItem.badge;
|
||||
|
||||
result.push({
|
||||
tooltip: badgeItem.tooltip,
|
||||
badge: badgeItem.badge,
|
||||
badge: badgeUrl,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -199,8 +210,8 @@ export async function fetchBadges(
|
|||
|
||||
if (data.avatar?.startsWith("a_")) {
|
||||
result.push({
|
||||
tooltip: "Discord Nitro",
|
||||
badge: `${origin}/public/badges/discord/NITRO.svg`,
|
||||
tooltip: discordBadgeDetails.DISCORD_NITRO.tooltip,
|
||||
badge: `${origin}${discordBadgeDetails.DISCORD_NITRO.icon}`,
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -228,17 +239,16 @@ export async function fetchBadges(
|
|||
break;
|
||||
}
|
||||
|
||||
results[serviceKey] = result;
|
||||
|
||||
if (
|
||||
result.length > 0 ||
|
||||
serviceKey === "discord" ||
|
||||
serviceKey === "enmity"
|
||||
USER_CACHE_SERVICES.includes(serviceKey) &&
|
||||
!nocache &&
|
||||
result.length > 0
|
||||
) {
|
||||
results[serviceKey] = result;
|
||||
if (!nocache) {
|
||||
const userCacheKey = `user_badges:${serviceKey}:${userId}`;
|
||||
await redis.set(userCacheKey, JSON.stringify(result));
|
||||
await redis.expire(userCacheKey, Math.min(redisTtl, 900));
|
||||
}
|
||||
const userCacheKey = `user_badges:${serviceKey}:${userId}`;
|
||||
await redis.set(userCacheKey, JSON.stringify(result));
|
||||
await redis.expire(userCacheKey, Math.min(redisTtl, 900));
|
||||
}
|
||||
} catch (error) {
|
||||
echo.warn({
|
||||
|
|
1
types/badge.d.ts
vendored
1
types/badge.d.ts
vendored
|
@ -19,6 +19,7 @@ type BadgeService = {
|
|||
user: string;
|
||||
badge: (id: string) => string;
|
||||
});
|
||||
pluginsUrl?: string;
|
||||
};
|
||||
|
||||
interface VencordEquicordData {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue