forked from GitHub/dbot
Merge github.com:reality/depressionbot into database
This commit is contained in:
commit
90d34f3aa4
@ -1,7 +1,19 @@
|
|||||||
var ctcp = function(dbot) {
|
var ctcp = function(dbot) {
|
||||||
var commands = {
|
var commands = {
|
||||||
"\x01VERSION\x01": function(event) {
|
"\x01VERSION\x01": function(event) {
|
||||||
|
// the current client version
|
||||||
event.replyNotice("\x01VERSION " + dbot.config.version + "\x01");
|
event.replyNotice("\x01VERSION " + dbot.config.version + "\x01");
|
||||||
|
},
|
||||||
|
"\x01CLIENTINFO\x01": function(event){
|
||||||
|
// a list of all supported CTCP commands
|
||||||
|
event.replyNotice("\x01CLIENTINFO SOURCE VERSION USERINFO\x01");
|
||||||
|
},
|
||||||
|
"\x01SOURCE\x01": function(event){
|
||||||
|
event.replyNotice("\x01SOURCE https://github.com/reality/depressionbot\x01");
|
||||||
|
},
|
||||||
|
"\x01USERINFO\x01": function(event){
|
||||||
|
// a "witty" saying set by the user
|
||||||
|
event.replyNotice("\z01USERINFO " + dbot.config.name + "\x01");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
this.commands = commands;
|
this.commands = commands;
|
||||||
|
@ -1,8 +1,12 @@
|
|||||||
|
/**
|
||||||
|
* Name: Spotify
|
||||||
|
* Description: Various Spotify functionality
|
||||||
|
*/
|
||||||
var request = require('request'),
|
var request = require('request'),
|
||||||
_ = require('underscore')._;
|
_ = require('underscore')._;
|
||||||
|
|
||||||
var spotify = function(dbot) {
|
var spotify = function(dbot) {
|
||||||
/* examples:
|
/* Examples:
|
||||||
* http://open.spotify.com/track/42SYMWISn7xUpTNPLw9V5E
|
* http://open.spotify.com/track/42SYMWISn7xUpTNPLw9V5E
|
||||||
* spotify:track:42SYMWISn7xUpTNPLw9V5E
|
* spotify:track:42SYMWISn7xUpTNPLw9V5E
|
||||||
* http://open.spotify.com/artist/3yY2gUcIsjMr8hjo51PoJ8
|
* http://open.spotify.com/artist/3yY2gUcIsjMr8hjo51PoJ8
|
||||||
@ -14,24 +18,34 @@ var spotify = function(dbot) {
|
|||||||
this.spotifyLookup = 'http://ws.spotify.com/lookup/1/.json';
|
this.spotifyLookup = 'http://ws.spotify.com/lookup/1/.json';
|
||||||
this.spotifySearch = 'http://ws.spotify.com/search/1/track.json';
|
this.spotifySearch = 'http://ws.spotify.com/search/1/track.json';
|
||||||
this.youtubeRegex = /^http:\/\/(?:www\.)?youtube.com\/watch\?v=\w+(&\S*)?$/
|
this.youtubeRegex = /^http:\/\/(?:www\.)?youtube.com\/watch\?v=\w+(&\S*)?$/
|
||||||
this.spotifyText = "\u00039spotify\u000f";
|
this.spotifyText = '\u00039spotify\u000f';
|
||||||
|
|
||||||
this.lookup = function(event, link) {
|
this.lookup = function(event, link) {
|
||||||
request({
|
request({
|
||||||
url: this.spotifyLookup,
|
'url': this.spotifyLookup,
|
||||||
qs: {uri: link},
|
'qs': { 'uri': link },
|
||||||
json: true
|
'json': true
|
||||||
}, function(error, response, body) {
|
}, function(error, response, body) {
|
||||||
if(!error && response.statusCode == 200) {
|
if(!error && response.statusCode == 200) {
|
||||||
var spotify = "\u00039spotify\u000f";
|
|
||||||
if(_.has(body, 'track')) {
|
if(_.has(body, 'track')) {
|
||||||
event.reply(dbot.t("track", {s: spotify, artist: _.map(body.track.artists, function(a) { return a.name }).join(', '), album: body.track.album.name, track: body.track.name}));
|
event.reply(dbot.t('track', {
|
||||||
}
|
's': this.spotifyText,
|
||||||
else if (_.has(body, 'album')) {
|
'artist': _.map(body.track.artists,
|
||||||
event.reply(dbot.t("album", {s: spotify, artist: body.album.artist, album: body.album.name}));
|
function(a) { return a.name }).join(', '),
|
||||||
}
|
'album': body.track.album.name,
|
||||||
else if (_.has(body, 'artist')) {
|
'track': body.track.name
|
||||||
event.reply(dbot.t("artist", {s: spotify, artist: body.artist.name}));
|
}));
|
||||||
|
} else if(_.has(body, 'album')) {
|
||||||
|
event.reply(dbot.t('album', {
|
||||||
|
's': this.spotifyText,
|
||||||
|
'artist': body.album.artist,
|
||||||
|
'album': body.album.name
|
||||||
|
}));
|
||||||
|
} else if(_.has(body, 'artist')) {
|
||||||
|
event.reply(dbot.t('artist', {
|
||||||
|
's': this.spotifyText,
|
||||||
|
'artist': body.artist.name
|
||||||
|
}));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@ -40,9 +54,9 @@ var spotify = function(dbot) {
|
|||||||
this.api = {
|
this.api = {
|
||||||
'spotifySearch': function(query, callback) {
|
'spotifySearch': function(query, callback) {
|
||||||
request({
|
request({
|
||||||
url: this.spotifySearch,
|
'url': this.spotifySearch,
|
||||||
qs: {q: query},
|
'qs': { 'q': query },
|
||||||
json: true
|
'json': true
|
||||||
}, function(error, response, body) {
|
}, function(error, response, body) {
|
||||||
if(!error && response.statusCode == 200) {
|
if(!error && response.statusCode == 200) {
|
||||||
if(_.has(body, 'tracks') && body.tracks[0] && _.has(body.tracks[0], 'href')) {
|
if(_.has(body, 'tracks') && body.tracks[0] && _.has(body.tracks[0], 'href')) {
|
||||||
@ -63,16 +77,16 @@ var spotify = function(dbot) {
|
|||||||
var query = event.input[1];
|
var query = event.input[1];
|
||||||
this.api.spotifySearch(query, function(body, t) {
|
this.api.spotifySearch(query, function(body, t) {
|
||||||
if(body) {
|
if(body) {
|
||||||
event.reply(dbot.t("found", {
|
event.reply(dbot.t('found', {
|
||||||
s: this.spotifyText,
|
's': this.spotifyText,
|
||||||
artist: _.map(body.tracks[0].artists, function(a) {
|
'artist': _.map(body.tracks[0].artists, function(a) {
|
||||||
return a.name }).join(', '),
|
return a.name }).join(', '),
|
||||||
album: body.tracks[0].album.name,
|
'album': body.tracks[0].album.name,
|
||||||
track: body.tracks[0].name,
|
'track': body.tracks[0].name,
|
||||||
url: t
|
'url': t
|
||||||
}));
|
}));
|
||||||
} else {
|
} else {
|
||||||
event.reply(dbot.t("not-found", {s: spotify}));
|
event.reply(dbot.t('not-found', { 's': this.spotifyText }));
|
||||||
}
|
}
|
||||||
}.bind(this));
|
}.bind(this));
|
||||||
},
|
},
|
||||||
@ -88,13 +102,13 @@ var spotify = function(dbot) {
|
|||||||
name = title.replace(' - YouTube', '');
|
name = title.replace(' - YouTube', '');
|
||||||
this.api.spotifySearch(name, function(body, t) {
|
this.api.spotifySearch(name, function(body, t) {
|
||||||
if(body) {
|
if(body) {
|
||||||
event.reply(dbot.t("found", {
|
event.reply(dbot.t('found', {
|
||||||
s: this.spotifyText,
|
's': this.spotifyText,
|
||||||
artist: _.map(body.tracks[0].artists, function(a) {
|
'artist': _.map(body.tracks[0].artists,
|
||||||
return a.name }).join(', '),
|
function(a) { return a.name }).join(', '),
|
||||||
album: body.tracks[0].album.name,
|
'album': body.tracks[0].album.name,
|
||||||
track: body.tracks[0].name,
|
'track': body.tracks[0].name,
|
||||||
url: t
|
'url': t
|
||||||
}));
|
}));
|
||||||
} else {
|
} else {
|
||||||
event.reply('No results');
|
event.reply('No results');
|
||||||
@ -102,7 +116,7 @@ var spotify = function(dbot) {
|
|||||||
}.bind(this));
|
}.bind(this));
|
||||||
}.bind(this));
|
}.bind(this));
|
||||||
} else {
|
} else {
|
||||||
event.reply("That's not a YouTube link");
|
event.reply('That\'s not a YouTube link');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user