-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
index.js
85 lines (74 loc) · 2.78 KB
/
index.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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
const { get } = require('powercord/http');
const { Plugin } = require('powercord/entities');
const { spotifySocket } = require('powercord/webpack');
module.exports = class Lyrics extends Plugin {
startPlugin() {
powercord.api.commands.registerCommand({
command: 'lyrics',
aliases: ['l'],
description: 'Get lyrics to a specific song or the current song.',
usage: '{c} [song]',
executor: this.searchLyrics.bind(this)
});
}
pluginWillUnload() {
powercord.api.commands.unregisterCommand('lyrics');
}
async searchLyrics(args) {
const base = 'https://some-random-api.ml/lyrics?title=';
try {
const playingOnSpotify = spotifySocket.getTrack(); // thanks to Harley for this!
if (!args[0]) {
// Check if there is something playing on Spotify.
// If there is, assign that track's artist + name to ``args``
if (playingOnSpotify) {
args = `${playingOnSpotify.artists[0].name} ${playingOnSpotify.name}`;
} else {
return {
send: false,
result: 'Error: No Spotify status detected and no song to search for provided.'
};
}
}
let data;
await get(encodeURI(base + args)).then(res => data = res.body);
if (!data || data.error) {
return {
send: false,
result: 'Error: Song not found.'
};
}
let { links, author, title, lyrics } = data;
// If the lyrics are more than 2048 characters, the embed's description
// will simply be a hyperlink to the lyrics
if (lyrics.length > 2048) {
lyrics = `[Click Here](${links.genius})`;
links.genius = null;
}
const embed = {
type: 'rich',
author: {
name: author
},
url: links.genius,
title: title,
color: 0x209cee,
description: lyrics,
footer: {
icon_url: 'https://i.some-random-api.ml/logo.png',
text: `Lyrics provided by Some Random API | © ${author}`
}
};
return {
send: false,
result: embed
};
} catch (e) {
console.error('Error with lyrics plugin:', e);
return {
send: false,
result: 'Error: Something broke. Please check the Developer Console for information.'
};
}
}
};