aboutsummaryrefslogtreecommitdiff
path: root/src/plugins/apiBadges.tsx
diff options
context:
space:
mode:
authorV <vendicated@riseup.net>2023-05-02 02:55:38 +0200
committerGitHub <noreply@github.com>2023-05-02 02:55:38 +0200
commitbc1d8694d4fcaaf9b4b0b744d8e81afc52b0d6f9 (patch)
tree9f56df7433fde877b1f6c70deb77b06e6ba28676 /src/plugins/apiBadges.tsx
parent7bc1362cbd3323c982dcc8bf10d399e581082d18 (diff)
downloadVencord-bc1d8694d4fcaaf9b4b0b744d8e81afc52b0d6f9.tar.gz
Vencord-bc1d8694d4fcaaf9b4b0b744d8e81afc52b0d6f9.tar.bz2
Vencord-bc1d8694d4fcaaf9b4b0b744d8e81afc52b0d6f9.zip
new plugin: VencordToolbox (#998)
Diffstat (limited to 'src/plugins/apiBadges.tsx')
-rw-r--r--src/plugins/apiBadges.tsx51
1 files changed, 37 insertions, 14 deletions
diff --git a/src/plugins/apiBadges.tsx b/src/plugins/apiBadges.tsx
index bf1906f..48e9eb9 100644
--- a/src/plugins/apiBadges.tsx
+++ b/src/plugins/apiBadges.tsx
@@ -26,7 +26,7 @@ import Logger from "@utils/Logger";
import { Margins } from "@utils/margins";
import { closeModal, Modals, openModal } from "@utils/modal";
import definePlugin from "@utils/types";
-import { Forms } from "@webpack/common";
+import { Forms, Toasts } from "@webpack/common";
const CONTRIBUTOR_BADGE = "https://cdn.discordapp.com/attachments/1033680203433660458/1092089947126780035/favicon.png";
@@ -49,6 +49,26 @@ const ContributorBadge: ProfileBadge = {
const DonorBadges = {} as Record<string, Pick<ProfileBadge, "image" | "description">[]>;
+async function loadBadges(noCache = false) {
+ const init = {} as RequestInit;
+ if (noCache)
+ init.cache = "no-cache";
+
+ const badges = await fetch("https://gist.githubusercontent.com/Vendicated/51a3dd775f6920429ec6e9b735ca7f01/raw/badges.csv", init)
+ .then(r => r.text());
+
+ const lines = badges.trim().split("\n");
+ if (lines.shift() !== "id,tooltip,image") {
+ new Logger("BadgeAPI").error("Invalid badges.csv file!");
+ return;
+ }
+
+ for (const line of lines) {
+ const [id, description, image] = line.split(",");
+ (DonorBadges[id] ??= []).push({ image, description });
+ }
+}
+
export default definePlugin({
name: "BadgeAPI",
description: "API to add badges to users.",
@@ -81,24 +101,27 @@ export default definePlugin({
}
],
+ toolboxActions: {
+ async "Refetch Badges"() {
+ await loadBadges(true);
+ Toasts.show({
+ id: Toasts.genId(),
+ message: "Successfully refetched badges!",
+ type: Toasts.Type.SUCCESS
+ });
+ }
+ },
+
+ async start() {
+ Vencord.Api.Badges.addBadge(ContributorBadge);
+ await loadBadges();
+ },
+
renderBadgeComponent: ErrorBoundary.wrap((badge: ProfileBadge & BadgeUserArgs) => {
const Component = badge.component!;
return <Component {...badge} />;
}, { noop: true }),
- async start() {
- Vencord.Api.Badges.addBadge(ContributorBadge);
- const badges = await fetch("https://gist.githubusercontent.com/Vendicated/51a3dd775f6920429ec6e9b735ca7f01/raw/badges.csv").then(r => r.text());
- const lines = badges.trim().split("\n");
- if (lines.shift() !== "id,tooltip,image") {
- new Logger("BadgeAPI").error("Invalid badges.csv file!");
- return;
- }
- for (const line of lines) {
- const [id, description, image] = line.split(",");
- (DonorBadges[id] ??= []).push({ image, description });
- }
- },
getDonorBadges(userId: string) {
return DonorBadges[userId]?.map(badge => ({