diff --git a/commands/interaction/slash/search/lyrics.js b/commands/interaction/slash/search/lyrics.js index 92194f6..82d8d77 100644 --- a/commands/interaction/slash/search/lyrics.js +++ b/commands/interaction/slash/search/lyrics.js @@ -23,6 +23,35 @@ function renderMetadata(metadata){ return pills.join(' ') } +// These have to be synced with the backend (search_service/endpoints/lyrics). +const LYRIC_PROVIDERS = { + UNKNOWN_PROVIDER: 0, + MUSIXMATCH: 1, + GENIUS: 2 +} + +function renderLyricsFooter(context, provider){ + switch(provider){ + case LYRIC_PROVIDERS.MUSIXMATCH: + return { + text: `Musixmatch • ${context.application.name}`, + iconUrl: STATICS.musixmatch + } + break; + case LYRIC_PROVIDERS.GENIUS: + return { + text: `Genius • ${context.application.name}`, + iconUrl: STATICS.genius + } + break; + default: // Fallback, this should never happen + return { + text: context.application.name, + iconUrl: STATICS.labscore + } + } +} + function createLyricsPage(context, search, fields){ let em = createEmbed("default", context, { author: { @@ -30,10 +59,7 @@ function createLyricsPage(context, search, fields){ name: `${search.body.track.title} by ${search.body.track.artist}` }, fields: fields, - footer: { - iconUrl: STATICS.musixmatch, - text: `Musixmatch • ${context.application.name}` - } + footer: renderLyricsFooter(context, search.body.lyrics_provider) }) if(search.body.track.cover) em.thumbnail = { url: search.body.track.cover } if(search.body.track.metadata.length) em.description = renderMetadata(search.body.track.metadata) @@ -79,7 +105,7 @@ module.exports = { for(const f of search.body.lyrics.split('\n\n')){ fields.push({ name: '​', - value: f.substr(0,1024), + value: f.substr(0,1024).replace(/\[(.*?)\]/g,"-# [$1]"), inline: false }) } diff --git a/commands/message/search/lyrics.js b/commands/message/search/lyrics.js index dffa2eb..f2255bb 100644 --- a/commands/message/search/lyrics.js +++ b/commands/message/search/lyrics.js @@ -23,6 +23,35 @@ function renderMetadata(metadata){ return pills.join(' ') } +// These have to be synced with the backend (search_service/endpoints/lyrics). +const LYRIC_PROVIDERS = { + UNKNOWN_PROVIDER: 0, + MUSIXMATCH: 1, + GENIUS: 2 +} + +function renderLyricsFooter(context, provider){ + switch(provider){ + case LYRIC_PROVIDERS.MUSIXMATCH: + return { + text: `Musixmatch • ${context.application.name}`, + iconUrl: STATICS.musixmatch + } + break; + case LYRIC_PROVIDERS.GENIUS: + return { + text: `Genius • ${context.application.name}`, + iconUrl: STATICS.genius + } + break; + default: // Fallback, this should never happen + return { + text: context.application.name, + iconUrl: STATICS.labscore + } + } +} + function createLyricsPage(context, search, fields){ let em = createEmbed("default", context, { author: { @@ -30,10 +59,7 @@ function createLyricsPage(context, search, fields){ name: `${search.body.track.title} by ${search.body.track.artist}` }, fields: fields, - footer: { - iconUrl: STATICS.musixmatch, - text: `Musixmatch • ${context.application.name}` - } + footer: renderLyricsFooter(context, search.body.lyrics_provider) }) if(search.body.track.cover) em.thumbnail = { url: search.body.track.cover } if(search.body.track.metadata.length) em.description = renderMetadata(search.body.track.metadata) @@ -65,7 +91,7 @@ module.exports = { for(const f of search.body.lyrics.split('\n\n')){ fields.push({ name: '​', - value: f, + value: f.substr(0,1024).replace(/\[(.*?)\]/g,"-# [$1]"), inline: false }) } @@ -89,7 +115,7 @@ module.exports = { }); }catch(e){ if(e.response?.body?.status && e.response.body.status == 2 && e.response.body.message) return editOrReply(context, createEmbed("error", context, e.response.body.message)) - console.log(JSON.stringify(e.raw)) + console.log(JSON.stringify(e.raw) || e) return editOrReply(context, createEmbed("error", context, `Something went wrong.`)) } }, diff --git a/labscore/api/endpoints.js b/labscore/api/endpoints.js index 911db01..938ae25 100644 --- a/labscore/api/endpoints.js +++ b/labscore/api/endpoints.js @@ -33,7 +33,7 @@ const Api = Object.freeze({ SEARCH_BING_IMAGES: '/search/bing-images', SEARCH_GOOGLE: '/search/google', SEARCH_GOOGLE_IMAGES: '/search/google-images', - SEARCH_LYRICS: '/search/lyrics-v2', + SEARCH_LYRICS: '/search/lyrics', SEARCH_QUORA: '/search/quora', SEARCH_QUORA_RESULT: '/search/quora-result', SEARCH_REDDIT: '/search/reddit',