Improve title formatting a little

This commit is contained in:
Corwin Brust 2026-05-22 10:40:18 +05:30
parent 3ef54d8169
commit 3e40fc510c

16
bot.js
View file

@ -131,10 +131,10 @@ function formatArtist(artist,album,year) {
rv = rv ? rv + ' ' + album : album; rv = rv ? rv + ' ' + album : album;
} }
if(year && album != year) { if(year && album != year) {
rv = rv ? `${rv}, /${year}/` : year rv = rv ? `${rv}, *${year}*` : year
} }
if(artist) { if(artist) {
rv = rv ? (rv.includes('(')?`${artist}, ${rv}` : `${artist} (${rv})`) : artist; rv = rv ? (rv.includes('(')?`__${artist}__, ${rv}` : `__${artist}__ (${rv})`) : artist;
} }
return rv; return rv;
} }
@ -149,12 +149,8 @@ function formatTrackTitle(meta) {
filename.replace('/spokes/gw11/storage/ftp/music/','') filename.replace('/spokes/gw11/storage/ftp/music/','')
); );
//console.log({title:title,who:who,fileUri:fileUri,artist:artist,album:album,date:date,year:year,filename:filename}); //console.log({title:title,who:who,fileUri:fileUri,artist:artist,album:album,date:date,year:year,filename:filename});
const rv // //'[🔗]('+ fileUri +') '+ '**' +
= //'[🔗]('+ fileUri +') ' const rv = title +' '+ formatArtist(artist,album,year||date);
//+ ' ' +
title
+ ' '
+ formatArtist(artist,album,year||date)
return [rv,fileUri]; return [rv,fileUri];
} }
const setStatus = async function() { const setStatus = async function() {
@ -176,7 +172,7 @@ const setStatus = async function() {
if(json) { if(json) {
let [newTitle,newLink] = formatTrackTitle(Object.fromEntries( json )); let [newTitle,newLink] = formatTrackTitle(Object.fromEntries( json ));
if(newTitle && newTitle != title) { if(newTitle && newTitle != title) {
console.log("New track title: " + newTitle + ' at ' + newLink); console.log("Playing[discord]: " + newTitle + ' at ' + newLink);
title = newTitle; title = newTitle;
trackUri = newLink; trackUri = newLink;
bot.editStatus("online", [ { name: title, type: 0, url: newLink}]); bot.editStatus("online", [ { name: title, type: 0, url: newLink}]);
@ -224,7 +220,7 @@ bot.on('messageCreate', async (msg) => {
// throw new Error(`Title response status: ${response.status}`); // throw new Error(`Title response status: ${response.status}`);
// } // }
// const json = await response.json(); // const json = await response.json();
await msg.channel.createMessage( "Playing: " + title + "\n\nDownload: " + trackUri + "\n" ); await msg.channel.createMessage(title +"\n\n[Download/Permalink]("+ trackUri +")\n");
//setStatus(); //setStatus();
} }
} catch (err) { } catch (err) {