Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 68 additions & 0 deletions packages/bot/src/utils/music/queueManipulation.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -573,6 +573,74 @@ describe('queueManipulation.replenishQueue', () => {
}),
)
})

it('tags session novelty when candidate artist is not in recent history', async () => {
const queue = createQueueMock({
tracks: { size: 0, toArray: jest.fn().mockReturnValue([]) },
currentTrack: {
title: 'Current Song',
author: 'Current Artist',
url: 'https://example.com/current',
source: 'youtube',
} as unknown as Track,
player: {
search: jest.fn().mockResolvedValue({
tracks: [
{
title: 'Brand New Song',
author: 'Never Heard Before Artist',
url: 'https://example.com/new1',
source: 'spotify',
},
],
}),
},
})

await replenishQueue(queue as unknown as GuildQueue)

const addedTrack = queue.addTrack.mock.calls[0]?.[0] as Track
expect(addedTrack).toBeDefined()
expect(
(addedTrack?.metadata as Record<string, unknown>)
?.recommendationReason,
).toContain('session novelty')
})

it('tags similar energy when candidate duration is within 30% of current track', async () => {
const queue = createQueueMock({
tracks: { size: 0, toArray: jest.fn().mockReturnValue([]) },
currentTrack: {
title: 'Current Song',
author: 'Current Artist',
url: 'https://example.com/current',
source: 'youtube',
durationMS: 200000,
} as unknown as Track,
player: {
search: jest.fn().mockResolvedValue({
tracks: [
{
title: 'Similar Energy Song',
author: 'New Artist',
url: 'https://example.com/similar',
source: 'spotify',
durationMS: 210000,
},
],
}),
},
})

await replenishQueue(queue as unknown as GuildQueue)

const addedTrack = queue.addTrack.mock.calls[0]?.[0] as Track
expect(addedTrack).toBeDefined()
expect(
(addedTrack?.metadata as Record<string, unknown>)
?.recommendationReason,
).toContain('similar energy')
})
})

describe('queueManipulation.queueOperations', () => {
Expand Down
14 changes: 14 additions & 0 deletions packages/bot/src/utils/music/queueManipulation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -615,6 +615,9 @@

if (candidateArtist === currentArtist) {
score -= 0.35
} else if (!recentArtists.has(candidateArtist)) {

Check warning on line 618 in packages/bot/src/utils/music/queueManipulation.ts

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Unexpected negated condition.

See more on https://sonarcloud.io/project/issues?id=LucasSantana-Dev_NexusBot&issues=AZ0_5H8MNUDU8YZz4wqx&open=AZ0_5H8MNUDU8YZz4wqx&pullRequest=380
score += 0.15
reasons.push('session novelty')
} else {
reasons.push('fresh artist rotation')
}
Expand All @@ -634,6 +637,17 @@
if (tokenScore > 0) {
reasons.push('similar title mood')
}
if (
currentTrack.durationMS &&
candidate.durationMS &&
currentTrack.durationMS > 0
) {
const ratio = candidate.durationMS / currentTrack.durationMS
if (ratio >= 0.7 && ratio <= 1.3) {
score += 0.1
reasons.push('similar energy')
}
}

return {
score,
Expand Down
Loading