diff options
| author | sofushn <[email protected]> | 2024-09-07 21:49:10 +0200 |
|---|---|---|
| committer | sofushn <[email protected]> | 2024-09-07 21:51:35 +0200 |
| commit | 107464e22244e5f488212269f780675bc1494190 (patch) | |
| tree | 3919b7bb6435b54b2bc90e6f3669977a4d05c891 /src/utils | |
| parent | af639159d1647ffb7b4c5c5f7ad035fe8766b6dc (diff) | |
| download | muse-107464e22244e5f488212269f780675bc1494190.tar.xz muse-107464e22244e5f488212269f780675bc1494190.zip | |
chore: make linter parse
Diffstat (limited to 'src/utils')
| -rw-r--r-- | src/utils/get-youtube-and-spotify-suggestions-for.ts | 23 |
1 files changed, 9 insertions, 14 deletions
diff --git a/src/utils/get-youtube-and-spotify-suggestions-for.ts b/src/utils/get-youtube-and-spotify-suggestions-for.ts index c33cbee..bd6f1c8 100644 --- a/src/utils/get-youtube-and-spotify-suggestions-for.ts +++ b/src/utils/get-youtube-and-spotify-suggestions-for.ts @@ -15,12 +15,11 @@ const filterDuplicates = <T extends {name: string}>(items: T[]) => { }; const getYouTubeAndSpotifySuggestionsFor = async (query: string, spotify?: SpotifyWebApi, limit = 10): Promise<APIApplicationCommandOptionChoice[]> => { - // Only search Spotify if enabled - let spotifySuggestionPromise = spotify !== undefined - ? spotify.search(query, ['album', 'track'], {limit}) - : undefined; - + const spotifySuggestionPromise = spotify === undefined + ? undefined + : spotify.search(query, ['album', 'track'], {limit}); + const youtubeSuggestions = await getYouTubeSuggestionsFor(query); const totalYouTubeResults = youtubeSuggestions.length; @@ -36,11 +35,9 @@ const getYouTubeAndSpotifySuggestionsFor = async (query: string, spotify?: Spoti value: suggestion, }), )); - - + if (spotify !== undefined && spotifySuggestionPromise !== undefined) { - - const spotifyResponse = (await spotifySuggestionPromise).body + const spotifyResponse = (await spotifySuggestionPromise).body; const spotifyAlbums = filterDuplicates(spotifyResponse.albums?.items ?? []); const spotifyTracks = filterDuplicates(spotifyResponse.tracks?.items ?? []); @@ -51,14 +48,13 @@ const getYouTubeAndSpotifySuggestionsFor = async (query: string, spotify?: Spoti const maxSpotifySuggestions = Math.floor(limit / 2); const numOfSpotifySuggestions = Math.min(maxSpotifySuggestions, totalSpotifyResults); - const maxSpotifyAlbums = Math.floor(numOfSpotifySuggestions / 2); const numOfSpotifyAlbums = Math.min(maxSpotifyAlbums, spotifyResponse.albums?.items.length ?? 0); const maxSpotifyTracks = numOfSpotifySuggestions - numOfSpotifyAlbums; - // make room for spotify results + // Make room for spotify results const maxYouTubeSuggestions = limit - numOfSpotifySuggestions; - suggestions = suggestions.slice(0, maxYouTubeSuggestions) + suggestions = suggestions.slice(0, maxYouTubeSuggestions); suggestions.push( ...spotifyAlbums.slice(0, maxSpotifyAlbums).map(album => ({ @@ -66,14 +62,13 @@ const getYouTubeAndSpotifySuggestionsFor = async (query: string, spotify?: Spoti value: `spotify:album:${album.id}`, })), ); - + suggestions.push( ...spotifyTracks.slice(0, maxSpotifyTracks).map(track => ({ name: `Spotify: 🎵 ${track.name}${track.artists.length > 0 ? ` - ${track.artists[0].name}` : ''}`, value: `spotify:track:${track.id}`, })), ); - } return suggestions; |
