Better formatting and LFM reaction support
This commit is contained in:
@@ -74,33 +74,32 @@ module.exports = {
|
|||||||
.setDescription(`asdasdasda`)
|
.setDescription(`asdasdasda`)
|
||||||
.setTimestamp();
|
.setTimestamp();
|
||||||
|
|
||||||
|
let links = [];
|
||||||
for (let index = 0; index < urls.length; index++) {
|
for (let index = 0; index < urls.length; index++) {
|
||||||
let url = urls[index];
|
let url = urls[index];
|
||||||
|
|
||||||
if (url.startsWith('https://listen.minzkraut.com/')) {
|
if (url.startsWith('https://listen.minzkraut.com/')) {
|
||||||
description += `[<:drmoe:1220702607836839956> Navidrome](${url}) `
|
links.push(`[<:drmoe:1220702607836839956> Navidrome ](${url})`);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (url.startsWith('https://open.spotify.com/')) {
|
if (url.startsWith('https://open.spotify.com/')) {
|
||||||
url = url.split('?')[0];
|
url = url.split('?')[0];
|
||||||
description += `[<:sptfy:1224677302109995078> Spotify](${url}) `;
|
links.push(`[<:sptfy:1224677302109995078> Spotify ](${url})`);
|
||||||
//https://open.spotify.com/track/4FuOHRPC3ZIQ7VQd7KMbds?si=cadd634ea5a14689
|
//https://open.spotify.com/track/4FuOHRPC3ZIQ7VQd7KMbds?si=cadd634ea5a14689
|
||||||
spotifyID = url.split('/').pop();
|
spotifyID = url.split('/').pop();
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (url.startsWith('https://listen.tidal.com/')) {
|
if (url.startsWith('https://listen.tidal.com/')) {
|
||||||
description += `[<:tidal:1221732946525032498> Tidal](${url}) `
|
links.push(`[<:tidal:1221732946525032498> Tidal ](${url})`);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (url.startsWith('https://www.youtube.com/')) {
|
if (url.startsWith('https://www.youtube.com/')) {
|
||||||
description += `[<:ytbm:1224704771248750622> Youtube](${url}) `
|
links.push(`[<:ytbm:1224704771248750622> Youtube ](${url})`);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if(spotifyID) {
|
if(spotifyID) {
|
||||||
let spotifyTrack = await this.spotifyAPI.getTrack(spotifyID);
|
let spotifyTrack = await this.spotifyAPI.getTrack(spotifyID);
|
||||||
trackEmbed.setImage(spotifyTrack['body'].album.images[0].url);
|
trackEmbed.setImage(spotifyTrack['body'].album.images[0].url);
|
||||||
@@ -134,7 +133,7 @@ module.exports = {
|
|||||||
|
|
||||||
let db = await interaction.client.localDB;
|
let db = await interaction.client.localDB;
|
||||||
let dbResult = await db.get(`SELECT * FROM lastfm WHERE discord_id = ?`,[interaction.member.id]);
|
let dbResult = await db.get(`SELECT * FROM lastfm WHERE discord_id = ?`,[interaction.member.id]);
|
||||||
let lfmUsername = dbResult['lastfm_name'];
|
let lfmUsername = dbResult?.['lastfm_name'];
|
||||||
let lfmData = await axios.get(`https://ws.audioscrobbler.com/2.0/?method=track.getInfo&api_key=${lfmKey}&artist=${mainArtist}&track=${songName}&format=json&user=${lfmUsername}`);
|
let lfmData = await axios.get(`https://ws.audioscrobbler.com/2.0/?method=track.getInfo&api_key=${lfmKey}&artist=${mainArtist}&track=${songName}&format=json&user=${lfmUsername}`);
|
||||||
|
|
||||||
if(interaction.options.getInteger('scrobbles', false) || lfmData.data['track']?.['userplaycount'] > 0) {
|
if(interaction.options.getInteger('scrobbles', false) || lfmData.data['track']?.['userplaycount'] > 0) {
|
||||||
@@ -144,14 +143,14 @@ module.exports = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if(lfmData.data['track']) {
|
if(lfmData.data['track']) {
|
||||||
description += `<:lfm:1225099203039203338> [View on LFM](${lfmData.data['track']['url']})`;
|
links.push(`<:lfm:1225099203039203338> [View on LFM](${lfmData.data['track']['url']})`);
|
||||||
let tags = lfmData.data['track']['toptags']['tag'].map(a => a.name);
|
let tags = lfmData.data['track']['toptags']['tag'].map(a => a.name);
|
||||||
console.log(lfmData.data['track']);
|
console.log(lfmData.data['track']);
|
||||||
let listeners = this.numToHumanReadable(lfmData.data['track']['listeners']);
|
let listeners = this.numToHumanReadable(lfmData.data['track']['listeners']);
|
||||||
let globalScrobbles = this.numToHumanReadable(lfmData.data['track']['playcount']);
|
let globalScrobbles = this.numToHumanReadable(lfmData.data['track']['playcount']);
|
||||||
|
|
||||||
trackEmbed.addFields(
|
trackEmbed.addFields(
|
||||||
{ name: `LFM Global`, value: `Listeners: ${listeners}\nScrobbles: ${globalScrobbles}\n`, inline: false },
|
{ name: `LFM Global`, value: `Listeners: ${listeners} • Scrobbles: ${globalScrobbles}\n`, inline: false },
|
||||||
)
|
)
|
||||||
|
|
||||||
let tagHeader = 'Tags';
|
let tagHeader = 'Tags';
|
||||||
@@ -163,13 +162,15 @@ module.exports = {
|
|||||||
tagHeader = `Artist ${tagHeader}`;
|
tagHeader = `Artist ${tagHeader}`;
|
||||||
}
|
}
|
||||||
if(tags) {
|
if(tags) {
|
||||||
tags = this.joinLineBreak(tags, ', ', 3);
|
tags = this.joinLineBreak(tags, ', ', 4);
|
||||||
trackEmbed.addFields(
|
trackEmbed.addFields(
|
||||||
{ name: `${tagHeader}`, value: `${tags.substr(0,60)}${tags.length > 60 ? '...' : ''}`, inline: true },
|
{ name: `${tagHeader}`, value: `${tags.substr(0,60)}${tags.length > 60 ? '...' : ''}`, inline: true },
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
description = `${description}\n${this.joinLineBreak(links, ' ∘ ', 3)}`
|
||||||
|
|
||||||
if(!description) {
|
if(!description) {
|
||||||
await interaction.reply({content: 'Sorry, no valid link has bee supplied.', ephemeral: true });
|
await interaction.reply({content: 'Sorry, no valid link has bee supplied.', ephemeral: true });
|
||||||
return;
|
return;
|
||||||
|
|||||||
@@ -1,4 +1,6 @@
|
|||||||
const { Events, Partials } = require('discord.js');
|
const { Events, Partials } = require('discord.js');
|
||||||
|
const axios = require('axios').default;
|
||||||
|
const { lfmKey } = require('../config.json');
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
name: Events.MessageReactionAdd,
|
name: Events.MessageReactionAdd,
|
||||||
@@ -31,12 +33,28 @@ module.exports = {
|
|||||||
title = reaction.message.content.split("\n")[0];
|
title = reaction.message.content.split("\n")[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let reply = `${user.displayName} rated **${title}** with ${reaction._emoji.toString()}`;
|
||||||
if(title.startsWith('https://')) {
|
if(title.startsWith('https://')) {
|
||||||
title = `<${title}>`;
|
title = `<${title}>`;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let db = await reaction.client.localDB;
|
||||||
|
let dbResult = await db.get(`SELECT * FROM lastfm WHERE discord_id = ?`,[user.id]);
|
||||||
|
let lfmUsername = dbResult?.['lastfm_name'];
|
||||||
|
if (lfmUsername) {
|
||||||
|
let songName = title.split(' - ')[0];
|
||||||
|
let artistName = title.split(' - ').slice(1);
|
||||||
|
let lfmData = await axios.get(`https://ws.audioscrobbler.com/2.0/?method=track.getInfo&api_key=${lfmKey}&artist=${artistName}&track=${songName}&format=json&user=${lfmUsername}`);
|
||||||
|
if (lfmData.data['track']?.['userplaycount'] > 0) {
|
||||||
|
reply = `${reply}\nAfter listening ${lfmData.data['track']?.['userplaycount']} times`;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
await reaction.message.channel.send({
|
await reaction.message.channel.send({
|
||||||
content: `${user.displayName} rated **${title}** with ${reaction._emoji.toString()}`,
|
content: reply,
|
||||||
reply: { messageReference: reaction.message.id }
|
reply: { messageReference: reaction.message.id }
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|||||||
Reference in New Issue
Block a user