forked from chalda/DiscordBot
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathyoutube_plugin.js
More file actions
31 lines (24 loc) · 807 Bytes
/
youtube_plugin.js
File metadata and controls
31 lines (24 loc) · 807 Bytes
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
var util = require('util');
var youtube_node = require('youtube-node');
var AuthDetails = require("./auth.json");
function YoutubePlugin () {
this.RickrollUrl = 'http://www.youtube.com/watch?v=oHg5SJYRHA0';
this.youtube = new youtube_node();
this.youtube.setKey(AuthDetails.youtube_api_key);
this.youtube.addParam('type', 'video');
};
YoutubePlugin.prototype.respond = function (query, channel, bot) {
this.youtube.search(query, 1, function(error, result) {
if (error) {
channel.sendMessage("¯\\_(ツ)_/¯");
}
else {
if (!result || !result.items || result.items.length < 1) {
channel.sendMessage("¯\\_(ツ)_/¯");
} else {
channel.sendMessage("http://www.youtube.com/watch?v=" + result.items[0].id.videoId );
}
}
});
};
module.exports = YoutubePlugin;