Temp commit
This commit is contained in:
parent
22d688ee80
commit
357f93623a
2 changed files with 64 additions and 60 deletions
|
@ -4,20 +4,20 @@ const getFmUsername = require("./getFmUsername");
|
|||
const Discord = require('discord.js');
|
||||
|
||||
require("dotenv").config();
|
||||
module.exports = async function(userID, guild) {
|
||||
module.exports = async function (userID, guild) {
|
||||
let parse = parseMention(userID, guild)
|
||||
let user = guild.members.cache.get(parse);
|
||||
let nickname = getNickname(user, guild)
|
||||
if(nickname == null){
|
||||
if (nickname == null) {
|
||||
nickname = user.user.username;
|
||||
}
|
||||
let isCurrentScrobble = "Current";
|
||||
let sendText = {text: "", embed: null}
|
||||
let sendText = { text: "", embed: null }
|
||||
let scrobble = {};
|
||||
const apiKey = process.env.LAST_FM_API_KEY;
|
||||
let lastfmUsername = await getFmUsername(userID);
|
||||
if(lastfmUsername != undefined){
|
||||
scrobble = await new Promise ((resolve, reject) => {
|
||||
if (lastfmUsername != undefined) {
|
||||
scrobble = await new Promise((resolve, reject) => {
|
||||
fetch(`https://ws.audioscrobbler.com/2.0/?method=user.getrecenttracks&user=${lastfmUsername}&api_key=${apiKey}&format=json`)
|
||||
.then(response => response.json())
|
||||
.then(data => {
|
||||
|
@ -25,15 +25,14 @@ module.exports = async function(userID, guild) {
|
|||
let tracks = [];
|
||||
let track;
|
||||
try {
|
||||
for(let i = 0; i < 2; i++){
|
||||
for (let i = 0; i < 2; i++) {
|
||||
track = data.recenttracks.track[i];
|
||||
scrobble.artist = track.artist["#text"];
|
||||
scrobble.song = track.name;
|
||||
console.log(`Track ${i}: ${scrobble.song}`);
|
||||
scrobble.album = track.album["#text"];
|
||||
scrobble.cover = track.image[3]["#text"];
|
||||
if(i === 0){
|
||||
if(track['@attr'] != undefined || track['@attr'].nowplaying !== "true"){
|
||||
if (i === 0) {
|
||||
if (!track["@attr"]) {
|
||||
isCurrentScrobble = "Last";
|
||||
}
|
||||
}
|
||||
|
@ -42,7 +41,7 @@ module.exports = async function(userID, guild) {
|
|||
resolve(tracks);
|
||||
} catch (error) {
|
||||
scrobble.error = true;
|
||||
if(data.error === 6){
|
||||
if (data.error === 6) {
|
||||
scrobble.errorMsg = "User not found. Use `<prefix>fm set <lastfm_username>` to set your last.fm username.";
|
||||
resolve(scrobble);
|
||||
}
|
||||
|
@ -55,7 +54,7 @@ module.exports = async function(userID, guild) {
|
|||
reject(error);
|
||||
});
|
||||
});
|
||||
if(scrobble.error != null){
|
||||
if (scrobble.error != null) {
|
||||
sendText.text = scrobble.errorMsg;
|
||||
return sendText;
|
||||
}
|
||||
|
@ -66,7 +65,7 @@ module.exports = async function(userID, guild) {
|
|||
.addFields({
|
||||
name: `${isCurrentScrobble}:`, value: `${scrobble[0].song}\n **${scrobble[0].artist} • ** ${scrobble[0].album}`
|
||||
},)
|
||||
if(isCurrentScrobble === "Current"){
|
||||
if (isCurrentScrobble === "Current") {
|
||||
embed.addFields({
|
||||
name: "Previous:", value: `${scrobble[1].song}\n **${scrobble[1].artist} • ** ${scrobble[1].album}`
|
||||
},)
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
// http://ws.audioscrobbler.com/2.0/?method=user.gettoptracks&user=username&api_key=YOUR_API_KEY&format=json
|
||||
|
||||
const Discord = require('discord.js');
|
||||
const getFmUsername = require("./getFmUsername")
|
||||
|
||||
module.exports = async function (userID, option) {
|
||||
let lastfmUsername = await getFmUsername(userID);
|
||||
let sendText = "";
|
||||
let sendText = {text: "", embed: null};
|
||||
let tracks = [];
|
||||
const options = {
|
||||
"alltime": "overall",
|
||||
|
@ -65,12 +65,17 @@ module.exports = async function (userID, option) {
|
|||
reject(error);
|
||||
});
|
||||
});
|
||||
sendText = `Top ${duration} tracks for ${lastfmUsername}:\n`;
|
||||
let author = `Top ${duration} tracks for ${lastfmUsername}:\n`;
|
||||
let toptracks = "";
|
||||
for(let i = 0; i < tracks.length; i++){
|
||||
sendText += `${i}. ${tracks[i].artist} - ${tracks[i].song} (${tracks[i].playcount} plays)\n`;
|
||||
}
|
||||
const embed = new Discord.MessageEmbed()
|
||||
.setAuthor(`Now playing - ${nickname}`, user.user.avatarURL({ dynamic: true, size: 4096 }))
|
||||
.setColor(15780145)
|
||||
|
||||
} else {
|
||||
sendText = "You haven't set your last.fm username yet. Use `fm set <lastfm_username>` to set it.";
|
||||
sendText.text = "You haven't set your last.fm username yet. Use `fm set <lastfm_username>` to set it.";
|
||||
}
|
||||
return sendText;
|
||||
}
|
Loading…
Add table
Reference in a new issue