Better formatting and LFM reaction support
This commit is contained in:
@@ -1,4 +1,6 @@
|
||||
const { Events, Partials } = require('discord.js');
|
||||
const axios = require('axios').default;
|
||||
const { lfmKey } = require('../config.json');
|
||||
|
||||
module.exports = {
|
||||
name: Events.MessageReactionAdd,
|
||||
@@ -31,12 +33,28 @@ module.exports = {
|
||||
title = reaction.message.content.split("\n")[0];
|
||||
}
|
||||
|
||||
let reply = `${user.displayName} rated **${title}** with ${reaction._emoji.toString()}`;
|
||||
if(title.startsWith('https://')) {
|
||||
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({
|
||||
content: `${user.displayName} rated **${title}** with ${reaction._emoji.toString()}`,
|
||||
content: reply,
|
||||
reply: { messageReference: reaction.message.id }
|
||||
});
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user