diff --git a/modules/kill_namespam/kill_namespam.js b/modules/kill_namespam/kill_namespam.js index 7bede0a..9e81f5a 100644 --- a/modules/kill_namespam/kill_namespam.js +++ b/modules/kill_namespam/kill_namespam.js @@ -19,18 +19,29 @@ var kill_namespam = function(dbot) { var matchedPattern = _.find(this.config.cliconn_patterns, function(p) { try { return event.message.match(p); } catch(e) {}; }); // ok.jpg if(matchedPattern) { - var ip = event.message.split(' ')[1] + var nick = event.message.split(' ')[2]; + dbot.api.nickserv.getUserHost(event.server, nick, function(host) { + var userIsAuthenticated = host && host.startsWith('tripsit/'); + if (userIsAuthenticated) { + event.reply(dbot.t('clikill_spared', { + 'user': nick, + 'pattern': matchedPattern + })); + } else { + var ip = event.message.split(' ')[1] - // Alternatively you can just do dbot.api.kick.kill(event.server, event.user, message); - dbot.say(event.server, 'operserv', 'akill add *@'+ ip +' !P Naughty Nelly Auto-kill v6.2. Matched pattern: /'+ matchedPattern +'/'); + // Alternatively you can just do dbot.api.kick.kill(event.server, event.user, message); + dbot.say(event.server, 'operserv', 'akill add *@'+ ip +' !P Naughty Nelly Auto-kill v6.2. Matched pattern: /'+ matchedPattern +'/'); - var msg = dbot.t('clikill_act', { - 'ip': ip, - 'pattern': matchedPattern - }); - event.reply(msg); - dbot.api.report.notify('autokill', event.server, event.rUser, - dbot.config.servers[event.server].admin_channel, msg, ip, ip); + var msg = dbot.t('clikill_act', { + 'ip': ip, + 'pattern': matchedPattern + }); + event.reply(msg); + dbot.api.report.notify('autokill', event.server, event.rUser, + dbot.config.servers[event.server].admin_channel, msg, ip, ip); + } + }, true); } } } diff --git a/modules/kill_namespam/strings.json b/modules/kill_namespam/strings.json index 8717fbf..c432f25 100644 --- a/modules/kill_namespam/strings.json +++ b/modules/kill_namespam/strings.json @@ -7,5 +7,8 @@ }, "clikill_act": { "en": "Added K-Line for {ip}, due to matching pattern: /{pattern}/" + }, + "clikill_spared": { + "en": "{user} spared from clikill matched pattern: /{pattern}/" } } diff --git a/modules/link/link.js b/modules/link/link.js index 2d077ab..62a7790 100644 --- a/modules/link/link.js +++ b/modules/link/link.js @@ -9,15 +9,15 @@ var request = require('request'), var link = function(dbot) { this.urlRegex = /(\b(https?|ftp|file):\/\/[-A-Z0-9+&@#\/%?=~_|!:,.;]*[-A-Z0-9+&@#\/%=~_|])/ig; - this.links = {}; + this.links = {}; this.handlers = []; - + this.api = { 'addHandler': function(name, regex, handler) { - this.handlers.push({ - 'name': name, - 'regex': regex, - 'callback': handler + this.handlers.push({ + 'name': name, + 'regex': regex, + 'callback': handler }); }, @@ -43,8 +43,8 @@ var link = function(dbot) { }, 'udLookup': function(query, callback) { - var reqUrl = 'http://api.urbandictionary.com/v0/define?term=' + - encodeURI(query); + var reqUrl = 'http://api.urbandictionary.com/v0/define?term=' + + encodeURI(query); request(reqUrl, function(error, response, body) { try { @@ -62,14 +62,14 @@ var link = function(dbot) { 'parseLink': function(link, callback) { var handler = false; for(var i=0;i p.title.indexOf(':') > 0); + + if (pages.length > 0) { + // See if any of these matches are exact title matches + var match = false; + _.each(pages, function(p) { + var title = p.title.slice(p.title.indexOf(':')+2).trim(); + if(title.toLowerCase() == comicId.toLowerCase()) { + match = p; + } + }); + + if (match) { + // We got a match! Get the ID and let's get tf out of here. + comicId = match.title.slice(0, match.title.indexOf(':')); + } else { + comicId = pages[0].title.slice(0, pages[0].title.indexOf(':')); + } + + var link = "http://xkcd.com/"+comicId+"/info.0.json"; + request(link, function(error, response, body) { + try { + if (response.statusCode == "200") { + data = JSON.parse(body); + event.reply(dbot.t("xkcd", data)); + } else { + event.reply(dbot.t("no-hits")); + } + } catch(err) { }; + }); + + + } else { + event.reply(dbot.t("no-hits")); + } + }); + } else { + if(comicId !== "") { + comicId = comicId + "/"; + } + + var link = "http://xkcd.com/"+comicId+"info.0.json"; + request(link, function(error, response, body) { + try { + if (response.statusCode == "200") { + data = JSON.parse(body); + event.reply(dbot.t("xkcd", data)); + } else { + event.reply(dbot.t("no-hits")); + } + } catch(err) { }; + }); + } } - }, - + '~ud': function(event) { var query = event.input[1]; @@ -151,7 +211,7 @@ var link = function(dbot) { console.log('DEBUG: got a link'); if(this.config.autoTitle == true) { this.api.parseLink(urlMatches[0], function(result) { - event.reply(result); + event.reply(result); }); } } diff --git a/modules/nickserv/nickserv.js b/modules/nickserv/nickserv.js index 88b50b5..e4903bf 100644 --- a/modules/nickserv/nickserv.js +++ b/modules/nickserv/nickserv.js @@ -26,18 +26,22 @@ var nickserv = function(dbot) { }.bind(this), 6000); }, - 'getUserHost': function(server, nick, callback) { + 'getUserHost': function(server, nick, callback, skipFallback) { if(!_.has(this.userStack, server)) this.userStack[server] = {}; this.userStack[server][nick] = callback; dbot.instance.connections[server].send('USERHOST ' + nick); setTimeout(function() { if(_.has(this.userStack[server], nick)) { - dbot.instance.connections[server].send('WHOWAS ' + nick + ' 1'); - setTimeout(function() { - if(_.has(this.userStack[server], nick)) { - callback(false); - } - }.bind(this), 2000); + if (skipFallback) { + callback(false); + } else { + dbot.instance.connections[server].send('WHOWAS ' + nick + ' 1'); + setTimeout(function() { + if(_.has(this.userStack[server], nick)) { + callback(false); + } + }.bind(this), 2000); + } } }.bind(this), 4000); } diff --git a/modules/omdb/config.json b/modules/omdb/config.json new file mode 100644 index 0000000..981489a --- /dev/null +++ b/modules/omdb/config.json @@ -0,0 +1,6 @@ +{ + "dependencies": [ ], + "ignorable": true, + "outputPrefix": "omdb", + "api_key": "insert api key here - get from http://www.omdbapi.com/apikey.aspx" +} diff --git a/modules/omdb/omdb.js b/modules/omdb/omdb.js new file mode 100644 index 0000000..028efa4 --- /dev/null +++ b/modules/omdb/omdb.js @@ -0,0 +1,83 @@ +/** + * Module Name: omdb + * Description: Interacts with the Open Movie Database to provide movie summary + * and review information. + */ + +var rp = require('request-promise-native'), + _ = require('underscore')._; + +var OMDB = function(dbot) { + this.apiRoot = 'http://www.omdbapi.com'; + this.imdbLinkPrefix = 'https://www.imdb.com/title/'; + + this.internalAPI = { + formatLink: r => { + var aRating = parseFloat(r.imdbRating) * 10; + var cRating = parseFloat(r.Metascore); + + if (isNaN(aRating)) { + aRating = " N/A"; + } else { + var aColour = (aRating <= 5) ? '\u00033 ' : '\u00034 '; + aRating = aColour + String(aRating) + '%\u000f'; + } + + if (isNaN(cRating)) { + cRating = " N/A"; + } else { + var cColour = (cRating <= 5) ? '\u00033 ' : '\u00034 '; + cRating = cColour + String(cRating) + '%\u000f'; + } + + var mString = dbot.t('omdb_film', { + 'title': r.Title, + 'year': r.Year, + 'aRating': aRating, + 'cRating': cRating + }); + + if (_.has(r, 'Director') && r.Director != "N/A") mString += ' [Director: ' + r.Director + ']'; + if (_.has(r, 'Genre') && r.Genre != "N/A") mString += ' [Genre: ' + r.Genre + ']'; + if (_.has(r, 'Plot') && r.Plot != "N/A") { + if (r.Plot.length > 140) r.Plot = r.Plot.substring(0, 140) + '...'; + mString += ' [Plot: ' + r.Plot + ']'; + } + + mString += ' - ' + this.imdbLinkPrefix + r.imdbID; + + return mString; + } + }; + + this.commands = { + '~movie': async event => { + try { + var r = await rp({ + url: this.apiRoot, + qs: { + apikey: this.config.api_key, + t: event.input[1], + plot: 'short', + r: 'json' + }, + json: true + }); + + if (r.Response === 'True') { + event.reply(this.internalAPI.formatLink(r)); + } else { + event.reply(dbot.t('omdb_noresults')); + } + } + catch (e) { + console.log(e); + } + } + }; + + this.commands['~movie'].regex = [/^movie (.+)$/, 2]; +} + + +exports.fetch = dbot => new OMDB(dbot); diff --git a/modules/omdb/strings.json b/modules/omdb/strings.json new file mode 100644 index 0000000..31d2dfb --- /dev/null +++ b/modules/omdb/strings.json @@ -0,0 +1,10 @@ +{ + "omdb_film": { + "en": "[{title} - Audience:{aRating} - Critic:{cRating} - {year}]", + "de": "[{title} - {aRating} - {year}]" + }, + "omdb_noresults": { + "en": "No films found.", + "de": "Kein Film gefunden." + } +} diff --git a/modules/spotify/spotify.js b/modules/spotify/spotify.js index 10db540..e49aaf8 100644 --- a/modules/spotify/spotify.js +++ b/modules/spotify/spotify.js @@ -113,6 +113,8 @@ var spotify = function(dbot) { } } }; + commands['~sp'] = commands['~spotify'].bind(this); + commands['~sp'].regex = [/^sp (.*)/, 2]; commands['~spotify'].regex = [/^spotify (.*)/, 2]; this.commands = commands; diff --git a/modules/youtube/youtube.js b/modules/youtube/youtube.js index a661fe5..94a1d5c 100644 --- a/modules/youtube/youtube.js +++ b/modules/youtube/youtube.js @@ -23,20 +23,21 @@ var youtube = function(dbot) { }, 'json': true }, function(error, response, body) { - callback(body); + callback(body); }.bind(this)); } }; this.internalAPI = { 'formatLink': function(v) { - var time = v.contentDetails.duration.match(/^PT(\d+)?M?(\d+)S$/); + var time = v.contentDetails.duration.match(/^PT(?:(\d+)M)?(\d+)S$/); + if(time) { if(time[1]) { var seconds =((time[2]%60 < 10) ? "0"+time[2]%60 : time[2]%60), minutes = time[1]; } else { - var seconds =((time[1]%60 < 10) ? "0"+time[1]%60 : time[1]%60), + var seconds =((time[2]%60 < 10) ? "0"+time[2]%60 : time[2]%60), minutes = 0; } } else { @@ -61,18 +62,18 @@ var youtube = function(dbot) { return res; }.bind(this), - + 'formatPlaylistLink': function(v) { var res = dbot.t('yt_playlist', { 'title': v.snippet.title, 'author': v.snippet.channelTitle, 'videos': v.contentDetails.itemCount }); - + if (v.id) { res += " - https://www.youtube.com/playlist?list=" + v.id; } - + return res; } }; @@ -101,7 +102,7 @@ var youtube = function(dbot) { } }.bind(this), "video"); }, - + // search for a youtube playlist '~ytpl': function(event) { this.api.search(event.input[1], function(body) {