twitch_bot/commands/fm.js

37 lines
1 KiB
JavaScript
Raw Normal View History

import fetch from "node-fetch";
2023-02-01 12:04:14 +01:00
const command = {
name: "fm",
desc: "get last played track from last.fm with your username",
2023-02-01 12:04:14 +01:00
run: async (client, msg, splitted) => {
if (splitted[2] === undefined) {
client.say(
msg.channelName,
`${msg.displayName}, supply your Last.FM username PoroSad`
);
return;
2023-02-01 12:04:14 +01:00
}
const data = await fetch(
`https://ws.audioscrobbler.com/2.0/?method=user.getrecenttracks&user=${splitted[2]}&api_key=${process.env.LASTFM_KEY}&format=json&limit=1`
)
.then((res) => res.json())
.then((data) => {
return data.recenttracks.track[0];
})
.catch((err) => console.log(err));
if (data === undefined) {
client.say(msg.channelName, `${msg.displayName}, Invalid user PoroSad`);
return;
2023-02-01 12:04:14 +01:00
}
await client.say(
msg.channelName,
`${msg.displayName}, (Now Playing) Album: ${data.album["#text"]} Track: ${data.name} Artist: ${data.artist["#text"]} | ${data.url}`
);
2023-02-01 12:04:14 +01:00
},
};
export default { command };