mirror of
https://github.com/reality/dbot.git
synced 2024-11-23 12:29:26 +01:00
Merge pull request #672 from Scritches/master
Some more music module fixes
This commit is contained in:
commit
fbc4ac5afe
@ -92,6 +92,7 @@ var lastfm = function(dbot) {
|
||||
});
|
||||
},
|
||||
|
||||
/*
|
||||
'tasteCompare': function(user, oUser, callback) {
|
||||
request.get(this.ApiRoot, {
|
||||
'qs': {
|
||||
@ -105,6 +106,7 @@ var lastfm = function(dbot) {
|
||||
},
|
||||
'json': true
|
||||
}, function(err, res, body) {
|
||||
console.log(body);
|
||||
if(_.has(body, 'error') && body.error == 6 || body.error == 7) {
|
||||
callback('no_user', user, null);
|
||||
} else if(_.has(body, 'comparison') && _.has(body.comparison, 'result')) {
|
||||
@ -114,6 +116,7 @@ var lastfm = function(dbot) {
|
||||
}
|
||||
});
|
||||
},
|
||||
*/
|
||||
|
||||
'getInfo': function(lfm, callback) {
|
||||
request.get(this.ApiRoot, {
|
||||
@ -220,29 +223,54 @@ var lastfm = function(dbot) {
|
||||
'artist': track.artist.name
|
||||
});
|
||||
var term = track.name + ' ' + track.artist.name;
|
||||
|
||||
dbot.api.youtube.search(term, function(body) {
|
||||
if(_.isObject(body) && _.has(body, 'items') && body.items.length > 0) {
|
||||
var link = body.items[0].id.videoId
|
||||
if(link) {
|
||||
output += ' - http://youtu.be/' + link;
|
||||
}
|
||||
|
||||
async.parallel({
|
||||
youtube: function(cb) {
|
||||
dbot.api.youtube.search(term, function(body) {
|
||||
if(_.isObject(body) && _.has(body, 'items') && body.items.length > 0) {
|
||||
var link = body.items[0].id.videoId
|
||||
if(link) {
|
||||
cb(null,"https://youtu.be/" + link);
|
||||
} else {
|
||||
cb(null, undefined);
|
||||
}
|
||||
}
|
||||
});
|
||||
},
|
||||
spotify: function(cb) {
|
||||
dbot.api.spotify.spotifySearch(term, function(body, url, uri) {
|
||||
if(body) {
|
||||
if (!dbot.modules.minify) {
|
||||
cb(null, { url: url, uri:uri });
|
||||
} else {
|
||||
dbot.modules.minify.api.minify(url, "bitly", function(mini) {
|
||||
cb(null, { url:mini || url, uri:uri });
|
||||
});
|
||||
}
|
||||
} else {
|
||||
cb(null, undefined);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
dbot.api.spotify.spotifySearch(term, function(body, t) {
|
||||
if(body) {
|
||||
output += ' - ' + t;
|
||||
}
|
||||
|
||||
event.reply(output);
|
||||
});
|
||||
});
|
||||
}, function(err, results) {
|
||||
if (results.youtube || results.spotify) output += " - "
|
||||
|
||||
if (results.youtube) output += results.youtube;
|
||||
if (results.spotify) {
|
||||
if (results.youtube) output += " | ";
|
||||
output += results.spotify.url + " - " + results.spotify.uri;
|
||||
}
|
||||
|
||||
event.reply(output);
|
||||
});
|
||||
} else {
|
||||
event.reply('something broke');
|
||||
event.reply('Couldn\'t get any suggested tracks.');
|
||||
console.log(err);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
event.reply('something broke');
|
||||
event.reply('Couldn\'t find any similar artists to what you\'re listening to.');
|
||||
console.log(err);
|
||||
}
|
||||
}.bind(this));
|
||||
} else {
|
||||
@ -262,7 +290,7 @@ var lastfm = function(dbot) {
|
||||
user = event.res[0].user;
|
||||
lfm = event.res[0].lfm;
|
||||
}
|
||||
|
||||
|
||||
this.api.getListening(lfm, function(err, track) {
|
||||
if(!err) {
|
||||
var term = track.name + ' ' + track.artist['#text'],
|
||||
@ -327,10 +355,12 @@ var lastfm = function(dbot) {
|
||||
} else if(err == 'no_listen') {
|
||||
event.reply(dbot.t('no_listen', { 'user': user.currentNick }));
|
||||
}
|
||||
console.log(err);
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
/*
|
||||
'~taste': function(event) {
|
||||
var u1 = event.rUser,
|
||||
lfm1 = event.rProfile.lastfm,
|
||||
@ -431,6 +461,7 @@ var lastfm = function(dbot) {
|
||||
}.bind(this));
|
||||
}
|
||||
},
|
||||
*/
|
||||
|
||||
'~artists': function(event) {
|
||||
var u1 = event.rUser,
|
||||
@ -456,7 +487,7 @@ var lastfm = function(dbot) {
|
||||
});
|
||||
}
|
||||
};
|
||||
this.commands['~taste'].regex = [/^taste ([\d\w[\]{}^|\\`_-]+?)/, 2];
|
||||
//this.commands['~taste'].regex = [/^taste ([\d\w[\]{}^|\\`_-]+?)/, 2];
|
||||
this.commands['~artists'].regex = [/^artists ([\d\w[\]{}^|\\`_-]+?)/, 2];
|
||||
|
||||
_.each(this.commands, function(command) {
|
||||
|
@ -6,16 +6,6 @@ var request = require('request'),
|
||||
_ = require('underscore')._;
|
||||
|
||||
var spotify = function(dbot) {
|
||||
/* Examples:
|
||||
* http://open.spotify.com/track/42SYMWISn7xUpTNPLw9V5E
|
||||
* spotify:track:42SYMWISn7xUpTNPLw9V5E
|
||||
* http://open.spotify.com/artist/3yY2gUcIsjMr8hjo51PoJ8
|
||||
* spotify:artist:3yY2gUcIsjMr8hjo51PoJ8
|
||||
* http://open.spotify.com/album/30g571JKoxs8AnsgAViV2J
|
||||
* spotify:album:30g571JKoxs8AnsgAViV2J
|
||||
*/
|
||||
this.spotifyRegex = /(\b(https?:\/\/open.spotify.com\/(artist|track|album)\/\w*|spotify:(artist|track|album):\w*)\b)/ig;
|
||||
this.spotifyLookup = 'http://ws.spotify.com/lookup/1/.json';
|
||||
this.spotifySearch = 'https://api.spotify.com/v1/search';
|
||||
this.youtubeRegex = /^.*(youtu.be\/|v\/|u\/\w\/|embed\/|watch\?v=|\&v=)([^#\&\?]*).*/;
|
||||
this.spotifyText = '\u00039spotify\u000f';
|
||||
@ -40,37 +30,6 @@ var spotify = function(dbot) {
|
||||
});
|
||||
};
|
||||
|
||||
this.lookup = function(link, callback) {
|
||||
this.authenticate(function(token) {
|
||||
request({
|
||||
'url': this.spotifyLookup,
|
||||
'qs': { 'uri': link },
|
||||
'json': true,
|
||||
'headers': { 'Authorization': "Bearer " + token }
|
||||
}, function(error, response, body) {
|
||||
if(!error && response.statusCode == 200) {
|
||||
if(_.has(body, 'track')) {
|
||||
callback(dbot.t('track', {
|
||||
'artist': _.map(body.track.artists,
|
||||
function(a) { return a.name }).join(', '),
|
||||
'album': body.track.album.name,
|
||||
'track': body.track.name
|
||||
}));
|
||||
} else if(_.has(body, 'album')) {
|
||||
callback(dbot.t('album', {
|
||||
'artist': body.album.artist,
|
||||
'album': body.album.name
|
||||
}));
|
||||
} else if(_.has(body, 'artist')) {
|
||||
callback(dbot.t('artist', {
|
||||
'artist': body.artist.name
|
||||
}));
|
||||
}
|
||||
}
|
||||
});
|
||||
}.bind(this));
|
||||
};
|
||||
|
||||
this.api = {
|
||||
'spotifySearch': function(query, callback) {
|
||||
this.authenticate(function(token) {
|
||||
@ -157,11 +116,6 @@ var spotify = function(dbot) {
|
||||
commands['~spotify'].regex = [/^spotify (.*)/, 2];
|
||||
this.commands = commands;
|
||||
|
||||
this.onLoad = function() {
|
||||
dbot.api.link.addHandler(this.name, this.spotifyRegex, function(matches, name, callback) {
|
||||
this.lookup(matches[0], callback);
|
||||
}.bind(this));
|
||||
}.bind(this);
|
||||
};
|
||||
|
||||
exports.fetch = function(dbot) {
|
||||
|
@ -5,7 +5,7 @@ var words = function(dbot) {
|
||||
this.commands = {
|
||||
'~define': function(event) {
|
||||
var query = event.params.slice(1).join(" ");
|
||||
this.wn.definitions(encodeURIComponent(query), function(err, defs) {
|
||||
this.wn.definitions(encodeURIComponent(query), { useCanonical: true }, function(err, defs) {
|
||||
if(!err && defs[0]) {
|
||||
event.reply(dbot.t('def', {
|
||||
'word': query,
|
||||
|
@ -93,6 +93,7 @@ var youtube = function(dbot) {
|
||||
}, function(error, response, body) {
|
||||
if(_.isObject(body) && _.has(body, 'items') && body.items.length > 0) {
|
||||
event.reply(this.internalAPI.formatLink(body.items[0]));
|
||||
dbot.modules.link.links[event.channel.name] = 'https://youtu.be/' + body.items[0].id;
|
||||
}
|
||||
}.bind(this));
|
||||
} else {
|
||||
|
Loading…
Reference in New Issue
Block a user