diff --git a/plugins/Last.fm/src/index.ts b/plugins/Last.fm/src/index.ts index e568ba5..3f1a4a9 100644 --- a/plugins/Last.fm/src/index.ts +++ b/plugins/Last.fm/src/index.ts @@ -17,7 +17,7 @@ export const currentSettings = { ...plugin.storage } as LFMSettings; // Discord modules that we need export const UserStore = findByStoreName("UserStore"); -export const SET_ACTIVITY = findByProps("SET_ACTIVITY").SET_ACTIVITY; +export const { SET_ACTIVITY } = findByProps("SET_ACTIVITY"); export const verboseLog = (...message: any) => currentSettings.verboseLogging && console.log(...message); diff --git a/plugins/Last.fm/src/utils.ts b/plugins/Last.fm/src/utils.ts index e16102f..cf801f1 100644 --- a/plugins/Last.fm/src/utils.ts +++ b/plugins/Last.fm/src/utils.ts @@ -5,7 +5,11 @@ import { showToast } from "@vendetta/ui/toasts"; import { UserStore, currentSettings, global, verboseLog } from "."; import Constants from "./constants"; -const AssetManager = findByProps("getAssetIds"); +const AssetManager = findByProps("getAssetIds") as { + getAssetIds: (appId: string, ids: string[]) => string[]; + fetchAssetIds: (appId: string, ids: string[]) => Promise; + [key: PropertyKey]: any; +}; const PresenceStore = findByStoreName("PresenceStore"); enum ActivityType { @@ -82,15 +86,13 @@ function sendRequest(activity: Activity) { } /** Fetches a Discord application's asset */ -async function fetchAsset(asset: T, appId: string = Constants.APPLICATION_ID): Promise { - if (!asset) return null; +async function fetchAsset(asset: string[], appId: string = Constants.APPLICATION_ID): Promise { + if (!asset) return []; - if (typeof asset === "string") { - const assetId = await AssetManager.getAssetIds(appId, [asset]); - return assetId[0] as T; - } + const assetIds = AssetManager.getAssetIds(appId, asset); + if (assetIds.length > 0) return assetIds; - return await AssetManager.getAssetIds(appId, asset); + return await AssetManager.fetchAssetIds(appId, asset); } /** @@ -161,7 +163,7 @@ async function update() { if (lastTrack.album) { activity.assets = { - large_image: await fetchAsset(lastTrack.albumArt), + large_image: (await fetchAsset([lastTrack.albumArt]))[0], large_text: `on ${lastTrack.album}` }; } diff --git a/plugins/defs.d.ts b/plugins/defs.d.ts index dc372e7..84285b3 100644 --- a/plugins/defs.d.ts +++ b/plugins/defs.d.ts @@ -6,7 +6,7 @@ type Activity = { details?: string; state?: string; timestamps?: { - _enabled: boolean; + _enabled?: boolean; start: number | string; end?: number | string; };