-
Notifications
You must be signed in to change notification settings - Fork 0
/
spotify.js
57 lines (49 loc) · 2.13 KB
/
spotify.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
const Discord = require("discord.js");
const convert = require("parse-ms");
exports.run = async (client, message, args) => {
let user;
if (message.mentions.users.first()) {
user = message.mentions.users.first();
} else {
user = message.author;
}
let status;
if (user.presence.activities.length === 1) status = user.presence.activities[0];
else if (user.presence.activities.length > 1) status = user.presence.activities[1];
if (user.presence.activities.length === 0 || status.name !== "Spotify" && status.type !== "LISTENING") {
return message.channel.send("This user isn't listening to Spotify.");
}
if (status !== null && status.type === "LISTENING" && status.name === "Spotify" && status.assets !== null) {
let image = `https://i.scdn.co/image/${status.assets.largeImage.slice(8)}`,
url = `https://open.spotify.com/track/${status.syncID}`,
name = status.details,
artist = status.state,
album = status.assets.largeText,
timeStart = status.timestamps.start,
timeEnd = status.timestamps.end,
timeConvert = convert(timeEnd - timeStart);
let minutes = timeConvert.minutes < 10 ? `0${timeConvert.minutes}` : timeConvert.minutes;
let seconds = timeConvert.seconds < 10 ? `0${timeConvert.seconds}` : timeConvert.seconds;
let time = `${minutes}:${seconds}`;
const embed = new Discord.MessageEmbed()
.setAuthor("Spotify Track Information", "https://image.flaticon.com/icons/svg/2111/2111624.svg")
.setColor(0x1ED768)
.setThumbnail(image)
.addField("Name:", name, true)
.addField("Album:", album, true)
.addField("Artist:", artist, true)
.addField("Duration:", time, false)
.addField("Listen now on Spotify!", `[\`${artist} - ${name}\`](${url})`, false)
return message.channel.send(embed)
}
}
exports.help = {
name: "spotify",
description: "Show a Listening Spotify user status.",
usage: "/spotify [@user]",
example: "/spotify @ray#1337"
};
exports.conf = {
aliases: [],
cooldown: 5
}