Skip to content
Closed
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
1 change: 1 addition & 0 deletions packages/bot/src/lastfm/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ export {
getSimilarTracks,
getTagTopTracks,
getLovedTracks,
getArtistTopTracks,
isLastFmInvalidSessionError,
normalizeLastFmArtist,
normalizeLastFmTitle,
Expand Down
28 changes: 28 additions & 0 deletions packages/bot/src/lastfm/lastFmApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -320,3 +320,31 @@ export async function getLovedTracks(
return []
}
}

export async function getArtistTopTracks(
artist: string,
limit = 10,
): Promise<{ artist: string; title: string }[]> {
const config = getApiConfig()
if (!config) return []
try {
const response = await fetch(
`${API_BASE}?method=artist.getTopTracks&artist=${encodeURIComponent(artist)}&limit=${limit}&format=json&api_key=${config.apiKey}`,
)
const data = (await response.json()) as {
toptracks?: {
track?: Array<{
name: string
artist: { name: string }
}>
}
}
return (data.toptracks?.track ?? []).map((t) => ({
artist: t.artist.name,
title: t.name,
}))
} catch (err) {
logAndSwallow(err, 'lastfm.getArtistTopTracks', { artist })
return []
}
}
25 changes: 24 additions & 1 deletion packages/bot/src/services/musicRecommendation/feedbackService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -470,8 +470,31 @@ export class RecommendationFeedbackService {
async getImplicitLikeKeys(userId: string): Promise<Set<string>> {
return this.getImplicitKeysByType(userId, 'implicit_like')
}
}

async getPreferredArtistNames(
guildId: string,
userId: string | undefined,
): Promise<Set<string>> {
if (!userId) return new Set<string>()

try {
const db = getPrismaClient()
const prefs = await db.userArtistPreference.findMany({
where: { discordUserId: userId, guildId, preference: 'prefer' },
select: { artistName: true },
})
return new Set(
prefs
.map((p) => p.artistName.trim())
.filter((name) => name.length > 0),
)
} catch {
return new Set<string>()
}
}

export const recommendationFeedbackService = new RecommendationFeedbackService(
parseInt(process.env.AUTOPLAY_FEEDBACK_TTL_DAYS ?? '30', 10),
)

}
Comment on lines +474 to +500

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🔴 Critical

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Description: Inspect the class/export boundary around the parse error.
sed -n '470,502p' packages/bot/src/services/musicRecommendation/feedbackService.ts

Repository: LucasSantana-Dev/Lucky

Length of output: 1042


🏁 Script executed:

#!/bin/bash
# Get the class definition and structure around the reported lines
cat -n packages/bot/src/services/musicRecommendation/feedbackService.ts | sed -n '450,510p'

Repository: LucasSantana-Dev/Lucky

Length of output: 1971


🏁 Script executed:

#!/bin/bash
# Find the class declaration to confirm the structure
rg -n "class RecommendationFeedbackService" packages/bot/src/services/musicRecommendation/feedbackService.ts

Repository: LucasSantana-Dev/Lucky

Length of output: 113


Move the service export outside the class body.

The class closing brace is placed on line 500, after the export statement on line 496. This causes a syntax error since the export declaration cannot exist at module scope while still nested inside the class body. The closing brace must move to line 495, immediately after the getPreferredArtistNames method ends.

Compile fix
     async getPreferredArtistNames(
         guildId: string,
         userId: string | undefined,
     ): Promise<Set<string>> {
         if (!userId) return new Set<string>()
 
         try {
             const db = getPrismaClient()
             const prefs = await db.userArtistPreference.findMany({
                 where: { discordUserId: userId, guildId, preference: 'prefer' },
                 select: { artistName: true },
             })
             return new Set(
                 prefs
                     .map((p) => p.artistName.trim())
                     .filter((name) => name.length > 0),
             )
         } catch {
             return new Set<string>()
         }
     }
+}
 
 export const recommendationFeedbackService = new RecommendationFeedbackService(
     parseInt(process.env.AUTOPLAY_FEEDBACK_TTL_DAYS ?? '30', 10),
 )
-
-}
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
async getPreferredArtistNames(
guildId: string,
userId: string | undefined,
): Promise<Set<string>> {
if (!userId) return new Set<string>()
try {
const db = getPrismaClient()
const prefs = await db.userArtistPreference.findMany({
where: { discordUserId: userId, guildId, preference: 'prefer' },
select: { artistName: true },
})
return new Set(
prefs
.map((p) => p.artistName.trim())
.filter((name) => name.length > 0),
)
} catch {
return new Set<string>()
}
}
export const recommendationFeedbackService = new RecommendationFeedbackService(
parseInt(process.env.AUTOPLAY_FEEDBACK_TTL_DAYS ?? '30', 10),
)
}
async getPreferredArtistNames(
guildId: string,
userId: string | undefined,
): Promise<Set<string>> {
if (!userId) return new Set<string>()
try {
const db = getPrismaClient()
const prefs = await db.userArtistPreference.findMany({
where: { discordUserId: userId, guildId, preference: 'prefer' },
select: { artistName: true },
})
return new Set(
prefs
.map((p) => p.artistName.trim())
.filter((name) => name.length > 0),
)
} catch {
return new Set<string>()
}
}
}
export const recommendationFeedbackService = new RecommendationFeedbackService(
parseInt(process.env.AUTOPLAY_FEEDBACK_TTL_DAYS ?? '30', 10),
)
🧰 Tools
🪛 Biome (2.4.11)

[error] 496-496: expected a semicolon to end the class property, but found none

(parse)


[error] 496-496: expected a semicolon to end the class property, but found none

(parse)

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@packages/bot/src/services/musicRecommendation/feedbackService.ts` around
lines 474 - 500, The export for recommendationFeedbackService is currently
placed inside the RecommendationFeedbackService class body causing a syntax
error; move the class closing brace so that the class ends immediately after the
getPreferredArtistNames method (i.e., close the RecommendationFeedbackService
class right after getPreferredArtistNames) and then keep the export const
recommendationFeedbackService = new RecommendationFeedbackService(...) at module
scope; verify the class name RecommendationFeedbackService and the exported
identifier recommendationFeedbackService match after the change.

Loading
Loading