generated from vendetta-mod/plugin-template
-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
92 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
{ | ||
"name": "UserBG", | ||
"description": "https://github.com/Discord-Custom-Covers/usrbg#request-your-own-usrbg", | ||
"authors": [ | ||
{ | ||
"name": "sapphire", | ||
"id": "757982547861962752" | ||
}, | ||
{ | ||
"name": "Rico040", | ||
"id": "619474349845643275" | ||
} | ||
], | ||
"main": "src/index.tsx", | ||
"vendetta": { | ||
"icon": "ic_profile_24px" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import { React, url } from "@vendetta/metro/common" | ||
import { getAssetIDByName } from "@vendetta/ui/assets" | ||
import { Forms, General } from "@vendetta/ui/components" | ||
import { showToast } from "@vendetta/ui/toasts" | ||
|
||
import { fetchData } from "./index" | ||
|
||
const { ScrollView } = General | ||
const { FormSection, FormRow } = Forms | ||
|
||
export default () => (<ScrollView> | ||
<FormSection> | ||
<FormRow | ||
label="Discord Server" | ||
leading={<FormRow.Icon source={getAssetIDByName("Discord")} />} | ||
trailing={FormRow.Arrow} | ||
onPress={() => url.openDeeplink("https://discord.gg/TeRQEPb")} | ||
/> | ||
<FormRow | ||
label="Reload DB" | ||
leading={<FormRow.Icon source={getAssetIDByName("ic_message_retry")} />} | ||
onPress={async () => { | ||
const fetch = await fetchData() | ||
if (!fetch) return showToast("Failed to reload DB", getAssetIDByName("small")) | ||
return showToast("Reloaded DB", getAssetIDByName("check")) | ||
}} | ||
/> | ||
</FormSection> | ||
</ScrollView>) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import { logger } from "@vendetta" | ||
import { findByProps } from "@vendetta/metro" | ||
import { after } from "@vendetta/patcher" | ||
import { safeFetch } from "@vendetta/utils" | ||
import { showToast } from "@vendetta/ui/toasts" | ||
|
||
import Settings from "./Settings" | ||
|
||
interface userBGData { | ||
endpoint: string; | ||
bucket: string; | ||
prefix: string; | ||
users: Record<string, string>; | ||
} | ||
|
||
const getUserBannerURL = findByProps("default", "getUserBannerURL") | ||
|
||
let data: userBGData | ||
let unpatch: () => void | ||
|
||
export const fetchData = async () => { | ||
try { | ||
data = await (await safeFetch("https://usrbg.is-hardly.online/users", { cache: "no-store" })).json() | ||
return data | ||
} catch (e) { | ||
logger.error("Failed to fetch userBG data", e) | ||
} | ||
} | ||
|
||
export const onLoad = async () => { | ||
await fetchData() | ||
if (!data) return showToast("Failed to load DB") | ||
const { endpoint, bucket, prefix, users } = data; | ||
unpatch = after("getUserBannerURL", getUserBannerURL, ([user]) => { | ||
const customBanner = Object.entries(users).find(([userId, etag]) => userId === user?.id) | ||
if (user?.banner === undefined && customBanner) { | ||
const [userId, etag] = customBanner; | ||
return `${endpoint}/${bucket}/${prefix}${userId}?${etag}` | ||
} | ||
}) | ||
} | ||
|
||
export const onUnload = () => unpatch?.() | ||
|
||
export const settings = Settings |