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
16 changes: 11 additions & 5 deletions packages/bot/src/functions/music/commands/album.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
requireDJRole,
} from '../../../utils/command/commandValidations'
import { resolveGuildQueue } from '../../../utils/music/queueResolver'
import { moveUserTrackToPriority } from '../../../utils/music/queueManipulation'
import { moveUserTrackToPriority } from '../../../services/musicManagement/queueManipulation'
import {
createErrorEmbed,
createSuccessEmbed,
Expand Down Expand Up @@ -70,9 +70,12 @@ export default new Command({
return
}

const isEnabled = await featureToggleService.isEnabled('ALBUM_COMMAND', {
guildId: interaction.guildId,
})
const isEnabled = await featureToggleService.isEnabled(
'ALBUM_COMMAND',
{
guildId: interaction.guildId,
},
)
if (!isEnabled) {
await interactionReply({
interaction,
Expand All @@ -93,7 +96,10 @@ export default new Command({
if (!(await requireVoiceChannel(interaction))) return
if (!(await requireDJRole(interaction, interaction.guildId))) return

const voiceChannel = assertDefined(member.voice.channel, 'voice channel present after requireVoiceChannel guard')
const voiceChannel = assertDefined(
member.voice.channel,
'voice channel present after requireVoiceChannel guard',
)
const query = interaction.options.getString('query', true)
const artistFilter = interaction.options.getString('artist')

Expand Down
16 changes: 11 additions & 5 deletions packages/bot/src/functions/music/commands/artist.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
requireDJRole,
} from '../../../utils/command/commandValidations'
import { resolveGuildQueue } from '../../../utils/music/queueResolver'
import { moveUserTrackToPriority } from '../../../utils/music/queueManipulation'
import { moveUserTrackToPriority } from '../../../services/musicManagement/queueManipulation'
import {
createErrorEmbed,
createSuccessEmbed,
Expand Down Expand Up @@ -66,9 +66,12 @@ export default new Command({
return
}

const isEnabled = await featureToggleService.isEnabled('ARTIST_COMMAND', {
guildId: interaction.guildId,
})
const isEnabled = await featureToggleService.isEnabled(
'ARTIST_COMMAND',
{
guildId: interaction.guildId,
},
)
if (!isEnabled) {
await interactionReply({
interaction,
Expand All @@ -89,7 +92,10 @@ export default new Command({
if (!(await requireVoiceChannel(interaction))) return
if (!(await requireDJRole(interaction, interaction.guildId))) return

const voiceChannel = assertDefined(member.voice.channel, 'voice channel present after requireVoiceChannel guard')
const voiceChannel = assertDefined(
member.voice.channel,
'voice channel present after requireVoiceChannel guard',
)
const artistName = interaction.options.getString('name', true)
const limit = interaction.options.getInteger('limit') ?? DEFAULT_LIMIT

Expand Down
12 changes: 1 addition & 11 deletions packages/bot/src/functions/music/commands/autoplay.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ jest.mock('../../../utils/general/embeds', () => ({
},
}))

jest.mock('../../../utils/music/queueOperations', () => ({
jest.mock('../../../services/musicManagement/queueOperations', () => ({
replenishQueue: (...args: unknown[]) => replenishQueueMock(...args),
}))

Expand Down Expand Up @@ -154,8 +154,6 @@ describe('autoplay command', () => {
})
})



describe('status subcommand', () => {
it('should show autoplay status', async () => {
const interaction = createInteraction('status')
Expand All @@ -172,7 +170,6 @@ describe('autoplay command', () => {
expect(interactionReplyMock).toHaveBeenCalled()
})


it('should not show blend when only one member has last.fm', async () => {
getLastFmLinkMock
.mockResolvedValueOnce({ lastFmUsername: 'user1' })
Expand All @@ -195,7 +192,6 @@ describe('autoplay command', () => {
})
})


describe('analytics subcommand', () => {
it('should show autoplay analytics with data', async () => {
const interaction = createInteraction('analytics')
Expand Down Expand Up @@ -242,11 +238,5 @@ describe('autoplay command', () => {
expect(embed.description).toContain('No play history yet')
expect(interactionReplyMock).toHaveBeenCalled()
})

})





})
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jest.mock('../../../../utils/general/interactionReply', () => ({
interactionReply: (...args: unknown[]) => mockInteractionReply(...args),
}))

jest.mock('../../../../utils/music/queueOperations', () => ({
jest.mock('../../../../services/musicManagement/queueOperations', () => ({
replenishQueue: (...args: unknown[]) => mockReplenishQueue(...args),
}))

Expand Down Expand Up @@ -104,8 +104,14 @@ describe('handleAutoplayStatus', () => {
expect.objectContaining({
title: '📻 Autoplay Status',
fields: expect.arrayContaining([
expect.objectContaining({ name: '📊 Queue', value: '2 / 3 tracks' }),
expect.objectContaining({ name: '🎵 Status', value: expect.stringContaining('Enabled') }),
expect.objectContaining({
name: '📊 Queue',
value: '2 / 3 tracks',
}),
expect.objectContaining({
name: '🎵 Status',
value: expect.stringContaining('Enabled'),
}),
]),
}),
)
Expand All @@ -119,7 +125,10 @@ describe('handleAutoplayStatus', () => {
expect(mockCreateEmbed).toHaveBeenCalledWith(
expect.objectContaining({
fields: expect.arrayContaining([
expect.objectContaining({ name: '🎵 Status', value: 'Disabled' }),
expect.objectContaining({
name: '🎵 Status',
value: 'Disabled',
}),
]),
}),
)
Expand All @@ -133,7 +142,10 @@ describe('handleAutoplayStatus', () => {
expect(mockCreateEmbed).toHaveBeenCalledWith(
expect.objectContaining({
fields: expect.arrayContaining([
expect.objectContaining({ name: '📊 Queue', value: '0 / 0 tracks' }),
expect.objectContaining({
name: '📊 Queue',
value: '0 / 0 tracks',
}),
]),
}),
)
Expand All @@ -148,7 +160,9 @@ describe('handleAutoplayStatus', () => {

await handleAutoplayStatus(interaction, queue)

const call = mockCreateEmbed.mock.calls[0][0] as { fields: Array<{ name: string }> }
const call = mockCreateEmbed.mock.calls[0][0] as {
fields: Array<{ name: string }>
}
const blendField = call.fields.find((f) => f.name === '🎭 Blend')
expect(blendField).toBeUndefined()
})
Expand Down Expand Up @@ -189,15 +203,19 @@ describe('handleAutoplayStatus', () => {

await handleAutoplayStatus(interaction, queue)

const call = mockCreateEmbed.mock.calls[0][0] as { fields: Array<{ name: string }> }
const call = mockCreateEmbed.mock.calls[0][0] as {
fields: Array<{ name: string }>
}
const blendField = call.fields.find((f) => f.name === '🎭 Blend')
expect(blendField).toBeUndefined()
})

it('handles null metadata without throwing', async () => {
const queue = makeQueue([makeTrack(true)], null, 2)

await expect(handleAutoplayStatus(interaction, queue)).resolves.not.toThrow()
await expect(
handleAutoplayStatus(interaction, queue),
).resolves.not.toThrow()
})
})

Expand All @@ -210,7 +228,10 @@ describe('handleSkipAutoplayTrack', () => {

await handleSkipAutoplayTrack(interaction, queue)

expect(mockCreateErrorEmbed).toHaveBeenCalledWith('Queue Empty', expect.any(String))
expect(mockCreateErrorEmbed).toHaveBeenCalledWith(
'Queue Empty',
expect.any(String),
)
expect(mockReplenishQueue).not.toHaveBeenCalled()
})

Expand All @@ -220,7 +241,10 @@ describe('handleSkipAutoplayTrack', () => {

await handleSkipAutoplayTrack(interaction, queue)

expect(mockCreateErrorEmbed).toHaveBeenCalledWith('No Autoplay Tracks', expect.any(String))
expect(mockCreateErrorEmbed).toHaveBeenCalledWith(
'No Autoplay Tracks',
expect.any(String),
)
expect(mockReplenishQueue).not.toHaveBeenCalled()
})

Expand All @@ -245,7 +269,10 @@ describe('handleClearAutoplayTracks', () => {

await handleClearAutoplayTracks(interaction, queue)

expect(mockCreateErrorEmbed).toHaveBeenCalledWith('No Autoplay Tracks', expect.any(String))
expect(mockCreateErrorEmbed).toHaveBeenCalledWith(
'No Autoplay Tracks',
expect.any(String),
)
expect(mockReplenishQueue).not.toHaveBeenCalled()
})

Expand All @@ -261,7 +288,9 @@ describe('handleClearAutoplayTracks', () => {
expect((queue as any).removeTrack).toHaveBeenNthCalledWith(2, 0)
expect(mockReplenishQueue).toHaveBeenCalledWith(queue)
expect(mockCreateEmbed).toHaveBeenCalledWith(
expect.objectContaining({ description: expect.stringContaining('2 autoplay tracks') }),
expect.objectContaining({
description: expect.stringContaining('2 autoplay tracks'),
}),
)
})
})
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { interactionReply } from '../../../../utils/general/interactionReply'
import { replenishQueue } from '../../../../utils/music/queueOperations'
import { replenishQueue } from '../../../../services/musicManagement/queueOperations'
import {
createEmbed,
createErrorEmbed,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { createErrorEmbed } from '../../../../../utils/general/embeds'
import { interactionReply } from '../../../../../utils/general/interactionReply'
import { createUserFriendlyError } from '@lucky/shared/utils/general/errorSanitizer'
import { collaborativePlaylistService } from '../../../../../services/musicRecommendation/collaborativePlaylist'
import { moveUserTrackToPriority } from '../../../../../utils/music/queueManipulation'
import { moveUserTrackToPriority } from '../../../../../services/musicManagement/queueManipulation'
import { buildPlayResponseEmbed } from '../../../../../utils/music/nowPlayingEmbed'
import { registerNowPlayingMessage } from '../../../../../handlers/player/trackNowPlaying'
import { resolveGuildQueue } from '../../../../../utils/music/queueResolver'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jest.mock('./autoplayPreference', () => ({
applyStoredAutoplayPreference: (q: unknown, id: string) =>
applyStoredAutoplayPreference(q, id),
}))
jest.mock('../../../../../utils/music/queueManipulation', () => ({
jest.mock('../../../../../services/musicManagement/queueManipulation', () => ({
blendAutoplayTracks: (q: unknown, t: unknown) => blendAutoplayTracks(q, t),
}))
jest.mock(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import type { GuildQueue, Track } from 'discord-player'
import { QueueRepeatMode } from 'discord-player'
import { errorLog } from '@lucky/shared/utils'
import { addBreadcrumb } from '@lucky/shared/utils/monitoring'
import { blendAutoplayTracks } from '../../../../../utils/music/queueManipulation'
import { blendAutoplayTracks } from '../../../../../services/musicManagement/queueManipulation'
import { applyStoredAutoplayPreference } from './autoplayPreference'
import { clearAutoplayPause } from '../../../../../services/musicRecommendation/autoplay/skipCircuitBreaker'
import { clearSessionMoodCache } from '../../../../../services/musicRecommendation/autoplay/replenisher'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ jest.mock('discord-player', () => ({
},
}))

jest.mock('../../../../utils/music/queueManipulation', () => ({
jest.mock('../../../../services/musicManagement/queueManipulation', () => ({
moveUserTrackToPriority: (queue: unknown, track: unknown) =>
moveUserTrackToPriorityMock(queue, track),
blendAutoplayTracks: (queue: unknown, track: unknown) =>
Expand Down
6 changes: 4 additions & 2 deletions packages/bot/src/functions/music/commands/queue/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import { interactionReply } from '../../../../utils/general/interactionReply'
import {
smartShuffleQueue,
rescueQueue,
} from '../../../../utils/music/queueManipulation'
} from '../../../../services/musicManagement/queueManipulation'
import { resolveGuildQueue } from '../../../../utils/music/queueResolver'
import { createUserFriendlyError } from '@lucky/shared/utils/general/errorSanitizer'

Expand Down Expand Up @@ -63,7 +63,9 @@ export default new Command({
if (!queue) {
await interactionReply({
interaction,
content: { embeds: [createErrorEmbed('Error', 'No queue found')] },
content: {
embeds: [createErrorEmbed('Error', 'No queue found')],
},
})
return
}
Expand Down
2 changes: 1 addition & 1 deletion packages/bot/src/handlers/musicButtonHandler.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ jest.mock('../functions/music/commands/queue/queueEmbed', () => ({
createQueueEmbed: jest.fn(),
}))

jest.mock('../utils/music/queueManipulation', () => ({
jest.mock('../services/musicManagement/queueManipulation', () => ({
shuffleQueue: jest.fn(),
}))

Expand Down
2 changes: 1 addition & 1 deletion packages/bot/src/handlers/musicButtonHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import {
createLeaderboardPaginationButtons,
} from '../utils/music/buttonComponents'
import { createQueueEmbed } from '../functions/music/commands/queue/queueEmbed'
import { shuffleQueue } from '../utils/music/queueManipulation'
import { shuffleQueue } from '../services/musicManagement/queueManipulation'
import type { GuildQueue } from 'discord-player'
import { resolveGuildQueue } from '../utils/music/queueResolver'
import type { CustomClient } from '../types'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ jest.mock('../../services/musicManagement/watchdog', () => ({
},
}))

jest.mock('../../utils/music/queueOperations', () => ({
jest.mock('../../services/musicManagement/queueOperations', () => ({
replenishQueue: (...args: unknown[]) => replenishQueueMock(...args),
}))

Expand Down
2 changes: 1 addition & 1 deletion packages/bot/src/handlers/player/lifecycleHandlers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import * as voiceStatus from '../../services/VoiceChannelStatusService'
import { ENVIRONMENT_CONFIG } from '@lucky/shared/config'
import { musicWatchdogService } from '../../services/musicManagement/watchdog'
import { musicSessionSnapshotService } from '../../services/musicRecommendation/sessionSnapshots'
import { replenishQueue } from '../../utils/music/queueOperations'
import { replenishQueue } from '../../services/musicManagement/queueOperations'
import type { QueueMetadata } from '../../types/QueueMetadata'

export const setupVoiceKickDetection = (client: Client): void => {
Expand Down
2 changes: 1 addition & 1 deletion packages/bot/src/handlers/player/trackHandlers.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ jest.mock('@lucky/shared/services', () => ({
},
}))

jest.mock('../../utils/music/queueOperations', () => ({
jest.mock('../../services/musicManagement/queueOperations', () => ({
replenishQueue: (...args: unknown[]) => replenishQueueMock(...args),
}))

Expand Down
2 changes: 1 addition & 1 deletion packages/bot/src/handlers/player/trackHandlers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { QueueRepeatMode } from 'discord-player'
import { LRUCache } from 'lru-cache'
import { infoLog, debugLog, errorLog, warnLog } from '@lucky/shared/utils'
import { addTrackToHistory } from '../../utils/music/duplicateDetection'
import { replenishQueue } from '../../utils/music/queueOperations'
import { replenishQueue } from '../../services/musicManagement/queueOperations'
import { resetAutoplayCount } from '../../utils/music/autoplayManager'
import { featureToggleService } from '@lucky/shared/services'
import { constants } from '@lucky/shared/config'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export {
export { calculateRecommendationScore }
export { getTrackAudioFeatures }

export * from './trackNormalization'
export * from '../../utils/music/trackNormalization'
export * from './queueEditOps'
export * from '../../services/musicRecommendation/candidateFallback'
export * from './queueRescue'
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import type {
QueueOperationResult,
TrackManagementOptions,
QueueManagementOptions,
} from './types'
import { validateTracks } from './trackValidator'
} from '../../utils/music/types'
import { validateTracks } from '../../utils/music/trackValidator'
import { AsyncQueueManager } from './queue/asyncQueueManager'
import { debugLog, errorLog } from '@lucky/shared/utils'
export {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { Track, GuildQueue } from 'discord-player'
import type { QueueState } from './types'
import type { QueueState } from '../../utils/music/types'
import { debugLog } from '@lucky/shared/utils'

/**
Expand Down
Loading
Loading