parent
68ec778817
commit
897d064699
@ -0,0 +1,50 @@ |
|||||||
|
const Discord = require('discord.js'); |
||||||
|
|
||||||
|
const Saves = require("../../models/saves"); |
||||||
|
|
||||||
|
module.exports = { |
||||||
|
name: "nowplaying", |
||||||
|
aliases: ['np'], |
||||||
|
meta: { |
||||||
|
category: 'Fun', |
||||||
|
description: "Show off the music you're currently listening to through last.fm!", |
||||||
|
syntax: '`nowplaying [@mention]`', |
||||||
|
extra: null |
||||||
|
}, |
||||||
|
help: new Discord.MessageEmbed() |
||||||
|
.setTitle("Help -> Now Playing") |
||||||
|
.setDescription("Accesses last.fm's API to show off what music you're currently listening to. Use the `lfm` command for more information.") |
||||||
|
.addField("Syntax", "`nowplaying [@mention]`"), |
||||||
|
async execute(message, msg, args, cmd, prefix, mention, client) { |
||||||
|
let savess = await Saves.findOne({name: 'lfm'}) ? await Saves.findOne({name: 'lfm'}) : new Saves({name: 'lfm'}); |
||||||
|
let saves = savess.saves; |
||||||
|
let user = mention || message.author; |
||||||
|
if (!saves.get(user.id)) {return message.channel.send(`${mention ? "That person's" : "Your"} last.fm username isn't set! ${mention ? "They" : "You"} can set it with \`${prefix}lfm set <username>\``);} |
||||||
|
|
||||||
|
let found = false; |
||||||
|
try { |
||||||
|
const glfm = function() {return new Promise(resolve => { |
||||||
|
let timeout = setTimeout(() => {return resolve(undefined);}, 3000); |
||||||
|
let stream = client.lfm.stream(saves.get(user.id)); |
||||||
|
stream.on('nowPlaying', t => { |
||||||
|
clearTimeout(timeout); |
||||||
|
message.channel.send(new Discord.MessageEmbed() |
||||||
|
.setAuthor(message.guild ? message.guild.members.cache.get(user.id) ? message.guild.members.cache.get(user.id).displayName : user.username : user.username, user.avatarURL()) |
||||||
|
.setTitle(`${saves.get(user.id)} | Now Playing`) |
||||||
|
.setDescription(`<@${user.id}> is currently listening to **${t.name}** by **${t.artist['#text']}**.\nView the song [here](${t.url}).`) |
||||||
|
.setColor("c375f0") |
||||||
|
.setThumbnail(t.image[3]['#text']) |
||||||
|
.setTimestamp() |
||||||
|
) |
||||||
|
found = true; |
||||||
|
stream.stop(); |
||||||
|
return resolve(undefined); |
||||||
|
}); |
||||||
|
stream.start(); |
||||||
|
});} |
||||||
|
await glfm().catch((e) => {console.error(e);}); |
||||||
|
} catch (e) {console.error(e);} |
||||||
|
|
||||||
|
if (!found) {return message.channel.send(`I couldn't find what \"${saves.get(user.id)}\" is listening to. Perhaps ${!mention ? "you" : "they"}'re not listening to anything, or you got ${!mention ? "your" : "their"} name wrong?`);} |
||||||
|
} |
||||||
|
}; |
@ -0,0 +1,40 @@ |
|||||||
|
const Discord = require('discord.js'); |
||||||
|
|
||||||
|
const Saves = require('../../models/saves'); |
||||||
|
|
||||||
|
const ask = require("../../util/ask"); |
||||||
|
|
||||||
|
module.exports = { |
||||||
|
name: "lfm", |
||||||
|
aliases: ['lastfm'], |
||||||
|
meta: { |
||||||
|
category: 'Misc', |
||||||
|
description: "Interact with the last.fm service", |
||||||
|
syntax: '` <>`', |
||||||
|
extra: null |
||||||
|
}, |
||||||
|
help: new Discord.MessageEmbed() |
||||||
|
.setTitle("Help -> Last.fm") |
||||||
|
.setDescription("Interact with last.fm, a service that stores and analyzes your Spotify listening activity.") |
||||||
|
.addField("Notice", "Most of the features of this command require you to have an account. You can make one at [last.fm](https://last.fm)") |
||||||
|
.addField("Syntax", "``"), |
||||||
|
async execute(message, msg, args, cmd, prefix, mention, client) { |
||||||
|
if (!args.length) {return message.channel.send(`Syntax: \`${prefix}\``);} |
||||||
|
|
||||||
|
let savess = await Saves.findOne({name: 'lfm'}) || new Saves({name: 'lfm'}); |
||||||
|
let saves = savess.saves; |
||||||
|
|
||||||
|
if (['s', 'set', 'setname', 'setusername', 'setn'].includes(args[0].toLowerCase())) { |
||||||
|
args.shift(); |
||||||
|
let name; |
||||||
|
if (!args.length) { |
||||||
|
name = await ask(message, "What is your last.fm username?", 60000); |
||||||
|
if (!name) {return;} |
||||||
|
} |
||||||
|
saves.set(message.author.id, name || args.join(" ").trim()); |
||||||
|
savess.saves = saves; |
||||||
|
savess.save(); |
||||||
|
return message.channel.send(`Last.fm username set! Try \`${prefix}nowplaying\` if you're listening to music to show off what you're currently listening to!`); |
||||||
|
} |
||||||
|
} |
||||||
|
}; |
File diff suppressed because it is too large
Load Diff
Loading…
Reference in new issue