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",
|
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,
|
||||||
};
|
};
|
||||||
|
|
|
@ -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;
|
||||||
|
|
||||||
|
|
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 {
|
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,20 +136,9 @@ 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 =
|
for (const author of plugin.authors) {
|
||||||
plugin.filePath &&
|
if (author.id) {
|
||||||
typeof plugin.filePath === "string" &&
|
contributors.add(author.id);
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -158,12 +147,14 @@ 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) {
|
||||||
|
|
|
@ -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,23 +28,26 @@ 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) {
|
const parsed: Badge[] = JSON.parse(cached);
|
||||||
const parsed: Badge[] = JSON.parse(cached);
|
results[serviceKey] = parsed;
|
||||||
results[serviceKey] = parsed;
|
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,17 +239,16 @@ export async function fetchBadges(
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
results[serviceKey] = result;
|
||||||
|
|
||||||
if (
|
if (
|
||||||
result.length > 0 ||
|
USER_CACHE_SERVICES.includes(serviceKey) &&
|
||||||
serviceKey === "discord" ||
|
!nocache &&
|
||||||
serviceKey === "enmity"
|
result.length > 0
|
||||||
) {
|
) {
|
||||||
results[serviceKey] = result;
|
const userCacheKey = `user_badges:${serviceKey}:${userId}`;
|
||||||
if (!nocache) {
|
await redis.set(userCacheKey, JSON.stringify(result));
|
||||||
const userCacheKey = `user_badges:${serviceKey}:${userId}`;
|
await redis.expire(userCacheKey, Math.min(redisTtl, 900));
|
||||||
await redis.set(userCacheKey, JSON.stringify(result));
|
|
||||||
await redis.expire(userCacheKey, Math.min(redisTtl, 900));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
echo.warn({
|
echo.warn({
|
||||||
|
|
1
types/badge.d.ts
vendored
1
types/badge.d.ts
vendored
|
@ -19,6 +19,7 @@ type BadgeService = {
|
||||||
user: string;
|
user: string;
|
||||||
badge: (id: string) => string;
|
badge: (id: string) => string;
|
||||||
});
|
});
|
||||||
|
pluginsUrl?: string;
|
||||||
};
|
};
|
||||||
|
|
||||||
interface VencordEquicordData {
|
interface VencordEquicordData {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue