3 static data_constants:any;
4 static irc = require("irc");
5 static details_fetcher = new DetailsFetcher();
6 static linkifier_bot:any;
8 static getConnectionProperties(){
9 console.log("Reading Constants");
10 var fs = require('fs');
11 this.data_constants = JSON.parse(fs.readFileSync('bot-properties.json','utf8'));
15 console.log("Initializing Bot");
17 Main.linkifier_bot = new Main.irc.Client(this.data_constants["SERVER"], this.data_constants["NICK"], {
18 channels: this.data_constants["CHANNELS"],
19 port: this.data_constants["SERVER-PORT"],
23 console.log(this.data_constants["CHANNELS"]);
25 Main.linkifier_bot.addListener('message', (sender:string, channel:string, text:string, message_obj:any) => {
26 console.log("M " + text);
29 Main.linkifier_bot.say(channel, "IRC-YouTube-Bot " + this.data_constants["VERSION"] +" - @Verniy\nhttps://github.com/ECHibiki/IRC-YouTube-Bot");
32 Main.linkifier_bot.say(channel, "Enter a YouTube link in the form of 'www.youtube.com/watch?*' or 'youtu.be/*' and this bot will output the details.");
35 Main.linkifier_bot.say(channel, "!YTBot -v : Output version info\n!YTBot -h : Output help info");
38 var reg_pag = /\b(www\.youtube\.com\/watch\?[\w?=\-&_]+|youtu\.be\/[\w?=\-&_]+)\b/gu;
39 if(reg_pag.test(text)){
40 // Main.linkifier_bot.say(channel, "!YTBot: Recieved");
41 this.details_fetcher.fetchYoutubeDetails(text.match(reg_pag), Main.displayYouTubeDetails, channel);
47 Main.linkifier_bot.addListener('kick', (channel:string, nick:string, by:string, reason:string, message_obj:any) =>{
48 console.log("Bot was kicked from " + channel);
52 static displayYouTubeDetails(details_obj:any, channel:string){
53 if(details_obj == undefined || details_obj == "" || details_obj.items.length == 0){
54 console.log("Failed");
55 Main.linkifier_bot.say(channel, "!YTBot: link error");
58 details_obj.items.forEach((details:any, ind:number)=>{
59 console.log(ind,channel,details.snippet.title + " [" + details.snippet.channelTitle + "]");
60 Main.linkifier_bot.say(channel,details.snippet.title + " [" + details.snippet.channelTitle + "]");
65 this.getConnectionProperties();
67 console.log("Bot Listening");