GlobalBadges: Update Filters & Toolbox Action
This commit is contained in:
parent
b48ce27250
commit
86a2704cad
2 changed files with 77 additions and 38 deletions
|
|
@ -13,51 +13,15 @@ import { BadgeContextMenu } from "@plugins/_api/badges";
|
|||
import { Devs, EquicordDevs } from "@utils/constants";
|
||||
import { openInviteModal } from "@utils/discord";
|
||||
import definePlugin from "@utils/types";
|
||||
import { ContextMenuApi, React } from "@webpack/common";
|
||||
import { ContextMenuApi, React, Toasts } from "@webpack/common";
|
||||
|
||||
import { settings } from "./settings";
|
||||
import { GlobalBadges, loadBadges } from "./utils";
|
||||
|
||||
let GlobalBadges = {};
|
||||
let intervalId: any;
|
||||
const INVITE_LINK = "kwHCJPxp8t";
|
||||
const cl = classNameFactory("vc-global-badges-");
|
||||
|
||||
async function loadBadges() {
|
||||
const globalBadges = await fetch("https://badges.equicord.org/users", { cache: "no-cache" })
|
||||
.then(r => r.json());
|
||||
|
||||
const filteredUsers: Record<string, typeof globalBadges.users[string]> = {};
|
||||
|
||||
for (const key in globalBadges.users) {
|
||||
filteredUsers[key] = globalBadges.users[key].map(b => {
|
||||
if (b.url) {
|
||||
return { tooltip: b.label, badge: b.url };
|
||||
}
|
||||
return b;
|
||||
}).filter(b => {
|
||||
const url = b.badge;
|
||||
// fix this when creations updates it
|
||||
return url &&
|
||||
url.startsWith("https://") &&
|
||||
!url.startsWith("https://cdn.discordapp.com") &&
|
||||
!url.startsWith("https://images.equicord.org") &&
|
||||
!(url.startsWith("https://badges.vencord.dev/badges") && !url.startsWith("https://badges.vencord.dev/badges/reviewdb")) &&
|
||||
// !(!settings.store.showAero && url.startsWith(":aero_icon:")) &&
|
||||
// !(!settings.store.showVelocity && url.startsWith("Velocity")) &&
|
||||
// !(!settings.store.showVelocity && url.startsWith("Official Velocity")) &&
|
||||
!(!settings.store.showCustom && url.startsWith("https://gb.obamabot.me")) &&
|
||||
!(!settings.store.showNekocord && url.startsWith("https://nekocord.dev")) &&
|
||||
!(!settings.store.showReviewDB && url.startsWith("https://badges.vencord.dev/badges/reviewdb")) &&
|
||||
!(!settings.store.showAliucord && url.startsWith("https://aliucord.com")) &&
|
||||
!(!settings.store.showRa1ncord && url.startsWith("https://codeberg.org/raincord/badges")) &&
|
||||
!(!settings.store.showEnmity && url.startsWith("https://raw.githubusercontent.com/enmity-mod/badges"));
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
GlobalBadges = filteredUsers;
|
||||
}
|
||||
|
||||
export default definePlugin({
|
||||
name: "GlobalBadges",
|
||||
description: "Adds global badges from other client mods",
|
||||
|
|
@ -82,6 +46,16 @@ export default definePlugin({
|
|||
async stop() {
|
||||
clearInterval(intervalId);
|
||||
},
|
||||
toolboxActions: {
|
||||
async "Refetch Global Badges"() {
|
||||
await loadBadges();
|
||||
Toasts.show({
|
||||
id: Toasts.genId(),
|
||||
message: "Successfully refetched global badges!",
|
||||
type: Toasts.Type.SUCCESS
|
||||
});
|
||||
}
|
||||
},
|
||||
get GlobalBadges() {
|
||||
return GlobalBadges;
|
||||
},
|
||||
|
|
|
|||
65
src/equicordplugins/globalBadges/utils.ts
Normal file
65
src/equicordplugins/globalBadges/utils.ts
Normal file
|
|
@ -0,0 +1,65 @@
|
|||
/*
|
||||
* Vencord, a Discord client mod
|
||||
* Copyright (c) 2025 Vendicated and contributors
|
||||
* SPDX-License-Identifier: GPL-3.0-or-later
|
||||
*/
|
||||
|
||||
import "./styles.css";
|
||||
|
||||
import { settings } from "./settings";
|
||||
|
||||
export let GlobalBadges = {};
|
||||
const serviceMap: Record<string, string> = {
|
||||
nekocord: "Nekocord",
|
||||
reviewdb: "ReviewDB",
|
||||
aero: "Aero",
|
||||
aliucord: "Aliucord",
|
||||
ra1ncord: "Ra1ncord",
|
||||
velocity: "Velocity",
|
||||
enmity: "Enmity",
|
||||
badgevault: "BadgeVault",
|
||||
vencord: "Vencord",
|
||||
equicord: "Equicord",
|
||||
};
|
||||
|
||||
export async function loadBadges() {
|
||||
const url = settings.store.apiUrl.endsWith("/") ? settings.store.apiUrl + "users" : settings.store.apiUrl + "/users";
|
||||
const globalBadges = await fetch(url, { cache: "no-cache" }).then(r => r.json());
|
||||
const filteredUsers: Record<string, typeof globalBadges.users[string]> = {};
|
||||
|
||||
for (const key in globalBadges.users) {
|
||||
filteredUsers[key] = globalBadges.users[key].filter(b => {
|
||||
const { mod } = b;
|
||||
if (!mod) return false;
|
||||
|
||||
const blockedMods = ["vencord", "equicord"];
|
||||
if (blockedMods.includes(mod)) return false;
|
||||
|
||||
const conditionalMods = {
|
||||
aero: settings.store.showAero,
|
||||
velocity: settings.store.showVelocity,
|
||||
badgevault: settings.store.showCustom,
|
||||
nekocord: settings.store.showNekocord,
|
||||
reviewdb: settings.store.showReviewDB,
|
||||
aliucord: settings.store.showAliucord,
|
||||
ra1ncord: settings.store.showRa1ncord,
|
||||
enmity: settings.store.showEnmity
|
||||
};
|
||||
|
||||
if (mod in conditionalMods && !conditionalMods[mod]) return false;
|
||||
|
||||
return true;
|
||||
}).map(b => {
|
||||
const modFormatted = serviceMap[b.mod];
|
||||
const prefix = settings.store.showPrefix ? `${modFormatted} - ` : "";
|
||||
const suffix = settings.store.showSuffix ? ` - ${modFormatted}` : "";
|
||||
const tooltip = prefix + b.tooltip + suffix;
|
||||
return {
|
||||
...b,
|
||||
tooltip
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
GlobalBadges = filteredUsers;
|
||||
}
|
||||
Loading…
Add table
Reference in a new issue