mirror of
https://github.com/Equicord/Equicord.git
synced 2025-02-21 23:58:52 -05:00
UsrBG Update kaboom
This commit is contained in:
parent
a634f41886
commit
8fa585fbb6
1 changed files with 32 additions and 18 deletions
|
@ -24,7 +24,15 @@ import definePlugin, { OptionType } from "@utils/types";
|
||||||
|
|
||||||
import style from "./index.css?managed";
|
import style from "./index.css?managed";
|
||||||
|
|
||||||
let data = {} as Record<string, string>;
|
const API_URL = "https://usrbg.is-hardly.online/users";
|
||||||
|
const cachebust = Date.now();
|
||||||
|
|
||||||
|
interface UsrbgApiReturn {
|
||||||
|
endpoint: string;
|
||||||
|
bucket: string;
|
||||||
|
prefix: string;
|
||||||
|
users: string[];
|
||||||
|
}
|
||||||
|
|
||||||
const settings = definePluginSettings({
|
const settings = definePluginSettings({
|
||||||
nitroFirst: {
|
nitroFirst: {
|
||||||
|
@ -40,19 +48,13 @@ 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"
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
export default definePlugin({
|
export default definePlugin({
|
||||||
name: "USRBG",
|
name: "USRBG",
|
||||||
description: "Displays user banners from USRBG, allowing anyone to get a banner without Nitro",
|
description: "Displays user banners from USRBG, allowing anyone to get a banner without Nitro",
|
||||||
authors: [Devs.AutumnVN, Devs.pylix, Devs.TheKodeToad],
|
authors: [Devs.AutumnVN, Devs.pylix, Devs.TheKodeToad, Devs.katlyn],
|
||||||
settings,
|
settings,
|
||||||
patches: [
|
patches: [
|
||||||
{
|
{
|
||||||
|
@ -84,8 +86,7 @@ export default definePlugin({
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
|
|
||||||
|
data: null as UsrbgApiReturn | null,
|
||||||
data,
|
|
||||||
|
|
||||||
settingsAboutComponent: () => {
|
settingsAboutComponent: () => {
|
||||||
return (
|
return (
|
||||||
|
@ -95,9 +96,9 @@ export default definePlugin({
|
||||||
|
|
||||||
voiceBackgroundHook({ className, participantUserId }: any) {
|
voiceBackgroundHook({ className, participantUserId }: any) {
|
||||||
if (className.includes("tile_")) {
|
if (className.includes("tile_")) {
|
||||||
if (data[participantUserId]) {
|
if (this.userHasBackground(participantUserId)) {
|
||||||
return {
|
return {
|
||||||
backgroundImage: `url(${data[participantUserId]})`,
|
backgroundImage: `url(${this.getImageUrl(participantUserId)})`,
|
||||||
backgroundSize: "cover",
|
backgroundSize: "cover",
|
||||||
backgroundPosition: "center",
|
backgroundPosition: "center",
|
||||||
backgroundRepeat: "no-repeat"
|
backgroundRepeat: "no-repeat"
|
||||||
|
@ -108,24 +109,37 @@ export default definePlugin({
|
||||||
|
|
||||||
useBannerHook({ displayProfile, user }: any) {
|
useBannerHook({ displayProfile, user }: any) {
|
||||||
if (displayProfile?.banner && settings.store.nitroFirst) return;
|
if (displayProfile?.banner && settings.store.nitroFirst) return;
|
||||||
if (data[user.id]) return data[user.id];
|
if (this.userHasBackground(user.id)) return this.getImageUrl(user.id);
|
||||||
},
|
},
|
||||||
|
|
||||||
premiumHook({ userId }: any) {
|
premiumHook({ userId }: any) {
|
||||||
if (data[userId]) return 2;
|
if (this.userHasBackground(userId)) return 2;
|
||||||
},
|
},
|
||||||
|
|
||||||
shouldShowBadge({ displayProfile, user }: any) {
|
shouldShowBadge({ displayProfile, user }: any) {
|
||||||
return displayProfile?.banner && (!data[user.id] || settings.store.nitroFirst);
|
return displayProfile?.banner && (!this.userHasBackground(user.id) || settings.store.nitroFirst);
|
||||||
|
},
|
||||||
|
|
||||||
|
userHasBackground(userId: string) {
|
||||||
|
if (this.data === null) return false;
|
||||||
|
return this.data.users.includes(userId);
|
||||||
|
},
|
||||||
|
|
||||||
|
getImageUrl(userId: string): string | null {
|
||||||
|
if (this.data == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
const { endpoint, bucket, prefix } = this.data;
|
||||||
|
return `${endpoint}/${bucket}/${prefix}${userId}?${cachebust}`;
|
||||||
},
|
},
|
||||||
|
|
||||||
async start() {
|
async start() {
|
||||||
enableStyle(style);
|
enableStyle(style);
|
||||||
|
|
||||||
const res = await fetch(settings.store.urlForDB);
|
const res = await fetch(API_URL);
|
||||||
if (res.ok) {
|
if (res.ok) {
|
||||||
data = await res.json();
|
this.data = await res.json();
|
||||||
this.data = data;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
Loading…
Add table
Reference in a new issue