This repository has been archived by the owner on Dec 17, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcommands.js
84 lines (78 loc) · 2.64 KB
/
commands.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
const config = require('./config.json');
module.exports = function(bot, spotify){
// fallback, adds songs
bot.addCommand("@"+config.followUsername, "fuck", function(message, args, channel, username, extra){
if(message.indexOf("sandstorm") !== -1 || message.indexOf("darude") !== -1){
bot.sendMessage("@" + username + " DUDUDUDU DUDUDU DUDUDUDUDU DUDUDUDU", extra.tweet.id_str);
}else{
spotify.searchTracks(message).then(function(data){
var track = data.body.tracks.items[0];
if(data.body.tracks.total <= 0){
bot.sendMessage("Sorry, @" + username + "... I don't know that one.", extra.tweet.id_str);
}else{
trackInPlaylist(track, function(inPlaylist){
if(inPlaylist){
bot.sendMessage("Sorry, @" + username + "... that song is already queued up!", extra.tweet.id_str);
}else if(track.explicit || artistBlacklisted(track.artists)){
bot.sendMessage("Sorry, @" + username + "... I don't like that one.", extra.tweet.id_str);
}else{
spotify.addTracksToPlaylist(config.playlistUsername, config.playlistId, [track.uri])
.then(function() {
bot.sendMessage(randomGreeting("addSong") + ", @" + username + "! I've added " + track.name + " to the queue.", extra.tweet.id_str);
});
}
});
}
});
}
});
var greetings = {
generic: [
"Hi",
"Yo",
"Sup",
"Ayy lmao"
],
addSong: [
"Nice track",
"I love that song",
"Awesome choice",
"This is my jam",
"Couldn't have picked better",
"ayy lmao"
]
};
var artistBlacklist = [
// Rick Astley
"0gxyHStUsqpMadRV0Di1Qt",
// Childish Gambino
"73sIBHcqh3Z3NyqHKZ7FOL",
// Justin Bieber
// "1uNFoZAHBGtllmzznpCI3s",
// Toby Fox (Meglovania)
"57DlMWmbVIf2ssJ8QBpBau"
];
function trackInPlaylist(track, callback){
spotify.getPlaylist(config.playlistUsername, config.playlistId)
.then(function(data) {
var tracks = data.body.tracks.items;
var inPlaylist = false;
for(var i=0; i<tracks.length; i++){
if(tracks[i].track.id === track.id)
inPlaylist = true;
}
callback(inPlaylist);
});
}
function randomGreeting(category){
return greetings[category][Math.floor(Math.random() * greetings[category].length)];
}
function artistBlacklisted(artists){
var blacklisted = false;
for(var i=0; i<artists.length; i++){
if(artistBlacklist.indexOf(artists[i].id) !== -1)
blacklisted = true;
}
return blacklisted;
}
};