mirror of
https://github.com/reality/dbot.git
synced 2025-02-17 14:01:04 +01:00
link for ~youtube (lol) [#534]
This commit is contained in:
parent
26eebdab98
commit
bad2662081
@ -11,6 +11,7 @@ var youtube = function(dbot) {
|
|||||||
'alt': 'json',
|
'alt': 'json',
|
||||||
'v': 2
|
'v': 2
|
||||||
};
|
};
|
||||||
|
this.LinkRegex = /^.*(youtu.be\/|v\/|u\/\w\/|embed\/|watch\?v=|\&v=)([^#\&\?]*).*/;
|
||||||
|
|
||||||
this.commands = {
|
this.commands = {
|
||||||
'~youtube': function(event) {
|
'~youtube': function(event) {
|
||||||
@ -32,24 +33,25 @@ var youtube = function(dbot) {
|
|||||||
if(!_.has(v, 'yt$statistics')) {
|
if(!_.has(v, 'yt$statistics')) {
|
||||||
v['yt$statistics'] = { 'viewCount': 0 };
|
v['yt$statistics'] = { 'viewCount': 0 };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var link = v.link[0].href.match(this.LinkRegex)[2];
|
||||||
event.reply(dbot.t('yt_video', {
|
event.reply(dbot.t('yt_video', {
|
||||||
'title': v.title['$t'],
|
'title': v.title['$t'],
|
||||||
'plays': v['yt$statistics'].viewCount,
|
'plays': v['yt$statistics'].viewCount,
|
||||||
'author': v.author[0].name['$t'],
|
'author': v.author[0].name['$t'],
|
||||||
'likes': v['yt$rating'].numLikes,
|
'likes': v['yt$rating'].numLikes,
|
||||||
'dislikes': v['yt$rating'].numDislikes
|
'dislikes': v['yt$rating'].numDislikes
|
||||||
}));
|
}) + ' - ' + 'http://youtu.be/' + link);
|
||||||
} else {
|
} else {
|
||||||
event.reply(dbot.t('yt_noresults'));
|
event.reply(dbot.t('yt_noresults'));
|
||||||
}
|
}
|
||||||
});
|
}.bind(this));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
this.commands['~youtube'].regex = [/^~youtube (.+)$/, 2];
|
this.commands['~youtube'].regex = [/^~youtube (.+)$/, 2];
|
||||||
|
|
||||||
this.onLoad = function() {
|
this.onLoad = function() {
|
||||||
dbot.api.link.addHandler(this.name,
|
dbot.api.link.addHandler(this.name, this.LinkRegex,
|
||||||
/^.*(youtu.be\/|v\/|u\/\w\/|embed\/|watch\?v=|\&v=)([^#\&\?]*).*/,
|
|
||||||
function(event, match, name) {
|
function(event, match, name) {
|
||||||
request.get(this.ApiRoot + '/videos/' + match[2], {
|
request.get(this.ApiRoot + '/videos/' + match[2], {
|
||||||
'qs': this.params,
|
'qs': this.params,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user