Uwev2/src/inc/trigger/lastfm.mjs
2019-08-19 19:17:51 +00:00

37 lines
1.0 KiB
JavaScript

import fetch from "flumm-fetch-cookies";
import config from "../../../cfg/config.json";
const api = `http://ws.audioscrobbler.com/2.0/?method=user.getRecentTracks&limit=1&api_key=${config.apis.lastfm.key}&format=json&user=`;
export default async bot => {
return [{
name: "lastfm",
call: /^(\.|\/)np/i,
set: "uwe",
/*help: {
text: "",
usage: "[b].np[/b] [i]<user>[/i]"
},*/
f: async e => {
const nick = e.args[0] || e.user.nick;
let res = await (await fetch(`${api}${nick}`)).json();
if(res.error)
return e.reply("User not found");
res = res.recenttracks;
const track = res.track[0];
const info = {
user: res["@attr"].user,
track: `${track.artist["#text"]} - ${track.name}`,
playing: track["@attr"] ? true : false
};
return e.reply(info.playing ?
`[b]${info.user}[/b] is listening to [b]${info.track}[/b]` :
`[b]${info.user}[/b] is not listening to anything. They last listened to [b]${info.track}[/b]`);
}
}];
};