import rp from "request-promise"; import { cfg } from "../../inc/cfg"; export default bot => { bot._trigger.set("lastfm", new bot.trigger({ call: /^(\.|\/)np/i, /*help: { text: "", usage: "[b].np[/b] [i][/i]" },*/ f: e => { const api = `http://ws.audioscrobbler.com/2.0/?method=user.getRecentTracks&limit=1&api_key=${cfg.main.lastfm.val.key}&format=json&user=`; const nick = e.args[0] || e.user.nick; rp(`${api}${nick}`, { json: true }) .then(res => { 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 }; if(info.playing) e.reply( `[b]${info.user}[/b] is listening to [b]${info.track}[/b]` ); else e.reply( `[b]${info.user}[/b] is not listening to anything. They last listened to [b]${info.track}[/b]` ); }) .catch(err => { console.log(err); }); } })); };