Skip to content
20 changes: 18 additions & 2 deletions packages/bot/src/utils/music/autoplay/spotifyRecommender.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
getSpotifyRecommendations,
type SpotifyAudioFeatures,
} from '../../../spotify/spotifyApi'
import { getUserSpotifySeeds } from '../../../spotify/spotifyUserSeeds'
import {
cleanTitle,
cleanAuthor,
Expand Down Expand Up @@ -63,6 +64,10 @@ export async function collectSpotifyRecommendationCandidates(
).catch(() => null)
if (!token) return

const userSpotifySeeds = await Promise.resolve(
getUserSpotifySeeds(requestedBy.id),
).catch(() => null)

const seedIds = seedTracks
.map(extractSpotifyTrackId)
.filter((id): id is string => id !== null)
Expand Down Expand Up @@ -140,9 +145,20 @@ export async function collectSpotifyRecommendationCandidates(
sessionMood,
)
if (rec.score === -Infinity) continue
let score = rec.score + 0.3
let reason = rec.reason ? `${rec.reason} • spotify rec` : 'spotify rec'

if (userSpotifySeeds !== null) {
const trackArtistLower = track.author.toLowerCase()
if (userSpotifySeeds.artistNames.has(trackArtistLower)) {
score += 0.08
reason += ' • spotify taste'
}
}

upsertScoredCandidate(candidates, track, {
score: rec.score + 0.3,
reason: rec.reason ? `${rec.reason} • spotify rec` : 'spotify rec',
score,
reason,
})
}
}
Expand Down
Loading