mirror of
https://gitlab.com/bignutty/labscore.git
synced 2025-06-07 21:53:07 -04:00
new lyrics service
This commit is contained in:
parent
ecc954a1be
commit
b3bb678193
3 changed files with 51 additions and 57 deletions
|
@ -6,21 +6,36 @@ const { lyrics } = require('../../../labscore/api');
|
||||||
const { paginator } = require('../../../labscore/client');
|
const { paginator } = require('../../../labscore/client');
|
||||||
|
|
||||||
const { Permissions } = require("detritus-client/lib/constants");
|
const { Permissions } = require("detritus-client/lib/constants");
|
||||||
|
const { smallIconPill } = require('../../../labscore/utils/markdown');
|
||||||
|
|
||||||
|
const META_FIELDS = {
|
||||||
|
"Album": "stat_videos",
|
||||||
|
"Released": "note"
|
||||||
|
}
|
||||||
|
|
||||||
|
function renderMetadata(metadata){
|
||||||
|
const pills = []
|
||||||
|
for(const m of metadata){
|
||||||
|
if(!META_FIELDS[m.id]) continue;
|
||||||
|
pills.push(smallIconPill(META_FIELDS[m.id], `${m.id}: ${m.value}`))
|
||||||
|
}
|
||||||
|
return pills.join(' ')
|
||||||
|
}
|
||||||
|
|
||||||
function createLyricsPage(context, search, fields){
|
function createLyricsPage(context, search, fields){
|
||||||
let em = createEmbed("default", context, {
|
let em = createEmbed("default", context, {
|
||||||
author: {
|
author: {
|
||||||
iconUrl: search.body.artist.image,
|
iconUrl: search.body.track.artist_cover,
|
||||||
name: search.body.song.title,
|
name: `${search.body.track.title} by ${search.body.track.artist}`
|
||||||
url: search.body.song.url
|
|
||||||
},
|
},
|
||||||
fields: fields,
|
fields: fields,
|
||||||
footer: {
|
footer: {
|
||||||
iconUrl: STATICS.genius,
|
iconUrl: STATICS.musixmatch,
|
||||||
text: `Genius • ${context.application.name}`
|
text: `Musixmatch • ${context.application.name}`
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
if(search.body.song.image) em.thumbnail = { url: search.body.song.image }
|
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)
|
||||||
return em;
|
return em;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -44,60 +59,33 @@ module.exports = {
|
||||||
|
|
||||||
if(search.body.status == 2) return editOrReply(context, {embeds:[createEmbed("error", context, search.body.message)]})
|
if(search.body.status == 2) return editOrReply(context, {embeds:[createEmbed("error", context, search.body.message)]})
|
||||||
let fields = [];
|
let fields = [];
|
||||||
let lyricsText = search.body.lyrics.replace(/\[Footnote .*?\]/g,'').replace(/\[choir\]/g,'');
|
|
||||||
if(lyricsText.includes('[')){
|
|
||||||
// Split lyrics into field-sizes chunks if multiple verses are present
|
|
||||||
let chunks = lyricsText.split(/\[(.*?)\]/)
|
|
||||||
let cur = {
|
|
||||||
inline: false
|
|
||||||
};
|
|
||||||
let i = 0;
|
|
||||||
for(const c of chunks){
|
|
||||||
if(c.length == 0) continue;
|
|
||||||
if(i == 0){
|
|
||||||
cur.name = `[${c.substr(0,250)}]`
|
|
||||||
i += 1
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
cur.value = c.substr(0,1000)
|
|
||||||
if(cur.value.endsWith('\n\n')) cur.value = cur.value.substr(0,cur.value.length-1)
|
|
||||||
cur.value += ``
|
|
||||||
i = 0
|
|
||||||
fields.push(cur)
|
|
||||||
cur = {
|
|
||||||
inline: false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
let message = createLyricsPage(context, search, [])
|
|
||||||
message.description = lyricsText.substr(0, 1024)
|
|
||||||
return editOrReply(context, message)
|
|
||||||
}
|
|
||||||
|
|
||||||
if(fields.length > 2){
|
for(const f of search.body.lyrics.split('\n\n')){
|
||||||
let pages = []
|
fields.push({
|
||||||
while(fields.length) {
|
name: '',
|
||||||
let pageFields = fields.splice(0,2)
|
value: f,
|
||||||
|
inline: false
|
||||||
// Display less fields if they take up too much vertical space
|
})
|
||||||
while(pageFields.map((f)=>f.value).join('\n').split('\n').length >= 36 && pageFields[1]){
|
|
||||||
fields.unshift(pageFields[pageFields.length - 1])
|
|
||||||
pageFields = pageFields.splice(0, pageFields.length - 1)
|
|
||||||
}
|
|
||||||
|
|
||||||
pages.push({embeds:[createLyricsPage(context, search, pageFields)]})
|
|
||||||
}
|
|
||||||
|
|
||||||
pages = formatPaginationEmbeds(pages)
|
|
||||||
const paging = await paginator.createPaginator({
|
|
||||||
context,
|
|
||||||
pages
|
|
||||||
});
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return editOrReply(context, {embeds: [createLyricsPage(context, search, fields)]})
|
let pages = []
|
||||||
|
while(fields.length) {
|
||||||
|
let pageFields = fields.splice(0,3)
|
||||||
|
|
||||||
|
// Display less fields if they take up too much vertical space
|
||||||
|
while(pageFields.map((f)=>f.value).join('\n').split('\n').length >= 30 && pageFields[1]){
|
||||||
|
fields.unshift(pageFields[pageFields.length - 1])
|
||||||
|
pageFields = pageFields.splice(0, pageFields.length - 1)
|
||||||
|
}
|
||||||
|
|
||||||
|
pages.push({embeds:[createLyricsPage(context, search, pageFields)]})
|
||||||
|
}
|
||||||
|
|
||||||
|
pages = formatPaginationEmbeds(pages)
|
||||||
|
const paging = await paginator.createPaginator({
|
||||||
|
context,
|
||||||
|
pages
|
||||||
|
});
|
||||||
}catch(e){
|
}catch(e){
|
||||||
if(e.response?.body?.status){
|
if(e.response?.body?.status){
|
||||||
if(e.response.body.status == 2){
|
if(e.response.body.status == 2){
|
||||||
|
|
|
@ -30,7 +30,7 @@ const Api = Object.freeze({
|
||||||
SEARCH_BING_IMAGES: '/search/bing-images',
|
SEARCH_BING_IMAGES: '/search/bing-images',
|
||||||
SEARCH_GOOGLE: '/search/google',
|
SEARCH_GOOGLE: '/search/google',
|
||||||
SEARCH_GOOGLE_IMAGES: '/search/google-images',
|
SEARCH_GOOGLE_IMAGES: '/search/google-images',
|
||||||
SEARCH_LYRICS: '/search/lyrics',
|
SEARCH_LYRICS: '/search/lyrics-v2',
|
||||||
SEARCH_QUORA: '/search/quora',
|
SEARCH_QUORA: '/search/quora',
|
||||||
SEARCH_QUORA_RESULT: '/search/quora-result',
|
SEARCH_QUORA_RESULT: '/search/quora-result',
|
||||||
SEARCH_REDDIT: '/search/reddit',
|
SEARCH_REDDIT: '/search/reddit',
|
||||||
|
@ -57,6 +57,7 @@ const Api = Object.freeze({
|
||||||
UTILS_PERSPECTIVE: '/utils/perspective',
|
UTILS_PERSPECTIVE: '/utils/perspective',
|
||||||
UTILS_SCREENSHOT: '/utils/screenshot',
|
UTILS_SCREENSHOT: '/utils/screenshot',
|
||||||
UTILS_TEXTGENERATOR: '/utils/text-generator',
|
UTILS_TEXTGENERATOR: '/utils/text-generator',
|
||||||
|
UTILS_WEATHER: '/utils/weather',
|
||||||
})
|
})
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
|
|
|
@ -40,6 +40,10 @@ const Statics = Object.freeze({
|
||||||
file: "brands/makesweet.png",
|
file: "brands/makesweet.png",
|
||||||
revision: 0
|
revision: 0
|
||||||
},
|
},
|
||||||
|
musixmatch: {
|
||||||
|
file: "brands/musixmatch.png",
|
||||||
|
revision: 0
|
||||||
|
},
|
||||||
openai: {
|
openai: {
|
||||||
file: "brands/openai.png",
|
file: "brands/openai.png",
|
||||||
revision: 0
|
revision: 0
|
||||||
|
@ -127,6 +131,7 @@ module.exports.STATICS = Object.freeze({
|
||||||
inspirobot: staticAsset(Statics.brands.inspirobot),
|
inspirobot: staticAsset(Statics.brands.inspirobot),
|
||||||
labscore: staticAsset(Statics.brands.labscore),
|
labscore: staticAsset(Statics.brands.labscore),
|
||||||
makesweet: staticAsset(Statics.brands.makesweet),
|
makesweet: staticAsset(Statics.brands.makesweet),
|
||||||
|
musixmatch: staticAsset(Statics.brands.musixmatch),
|
||||||
openai: staticAsset(Statics.brands.openai),
|
openai: staticAsset(Statics.brands.openai),
|
||||||
openweathermap: staticAsset(Statics.brands.openweathermap),
|
openweathermap: staticAsset(Statics.brands.openweathermap),
|
||||||
perspectiveapi: staticAsset(Statics.brands.perspectiveapi),
|
perspectiveapi: staticAsset(Statics.brands.perspectiveapi),
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue