feat(UsrBG & UserPFP): UrlForDB Setting

This commit is contained in:
thororen 2024-04-20 13:54:06 -04:00
parent b955a1c2ba
commit 854769cd22
2 changed files with 15 additions and 8 deletions

View file

@ -10,22 +10,25 @@ import { EquicordDevs } from "@utils/constants";
import definePlugin, { OptionType } from "@utils/types"; import definePlugin, { OptionType } from "@utils/types";
import { User } from "discord-types/general"; import { User } from "discord-types/general";
const BASE_URL = "https://userpfp.github.io/UserPFP/source/data.json";
let data = { let data = {
avatars: {} as Record<string, string>, avatars: {} as Record<string, string>,
}; };
const settings = definePluginSettings({ const settings = definePluginSettings({
preferNitro: { preferNitro: {
description: description: "Which avatar to use if both default animated (Nitro) pfp and UserPFP avatars are present",
"Which avatar to use if both default animated (Nitro) pfp and UserPFP avatars are present",
type: OptionType.SELECT, type: OptionType.SELECT,
options: [ options: [
{ label: "UserPFP", value: false }, { label: "UserPFP", value: false },
{ label: "Nitro", value: true, default: true }, { label: "Nitro", value: true, default: true },
], ],
}, },
urlForDB: {
type: OptionType.STRING,
description: "Which Database url to use to load avatars, KNOW WHAT YOUR DOING",
default: "https://userpfp.github.io/UserPFP/source/data.json",
placeholder: "Default value: https://userpfp.github.io/UserPFP/source/data.json"
}
}); });
export default definePlugin({ export default definePlugin({
@ -67,7 +70,7 @@ export default definePlugin({
return data.avatars[user.id] ?? original(user, animated, size); return data.avatars[user.id] ?? original(user, animated, size);
}, },
async start() { async start() {
const res = await fetch(BASE_URL); const res = await fetch(settings.store.urlForDB);
if (res.ok) this.data = data = await res.json(); if (res.ok) this.data = data = await res.json();
} }
}); });

View file

@ -24,8 +24,6 @@ import definePlugin, { OptionType } from "@utils/types";
import style from "./index.css?managed"; import style from "./index.css?managed";
const BASE_URL = "https://raw.githubusercontent.com/AutumnVN/usrbg/main/usrbg.json";
let data = {} as Record<string, string>; let data = {} as Record<string, string>;
const settings = definePluginSettings({ const settings = definePluginSettings({
@ -42,6 +40,12 @@ const settings = definePluginSettings({
type: OptionType.BOOLEAN, type: OptionType.BOOLEAN,
default: true, default: true,
restartNeeded: true restartNeeded: true
},
urlForDB: {
type: OptionType.STRING,
description: "Which Database url to use to load banners, KNOW WHAT YOUR DOING",
default: "https://raw.githubusercontent.com/AutumnVN/usrbg/main/usrbg.json",
placeholder: "Default value: https://raw.githubusercontent.com/AutumnVN/usrbg/main/usrbg.json"
} }
}); });
@ -118,7 +122,7 @@ export default definePlugin({
async start() { async start() {
enableStyle(style); enableStyle(style);
const res = await fetch(BASE_URL); const res = await fetch(settings.store.urlForDB);
if (res.ok) { if (res.ok) {
data = await res.json(); data = await res.json();
this.data = data; this.data = data;