From 0f0877f27a2757bbcf9a61e4790f4c1ef95cc16d Mon Sep 17 00:00:00 2001 From: Scritches Date: Thu, 26 Apr 2018 16:50:21 -0400 Subject: [PATCH 1/6] Fixed YouTube video duration reporting --- modules/youtube/youtube.js | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) 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) { From c298813b28418d867328a220db50b67a0e24e621 Mon Sep 17 00:00:00 2001 From: Scritches Date: Thu, 26 Apr 2018 16:58:15 -0400 Subject: [PATCH 2/6] Adds OMDB module to replace the RottenTomatoes module. ~movie command replaces ~rt command. API key from http://www.omdbapi.com/apikey.aspx --- modules/omdb/config.json | 6 +++ modules/omdb/omdb.js | 83 +++++++++++++++++++++++++++++++++++++++ modules/omdb/strings.json | 10 +++++ 3 files changed, 99 insertions(+) create mode 100644 modules/omdb/config.json create mode 100644 modules/omdb/omdb.js create mode 100644 modules/omdb/strings.json 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." + } +} From 0c8c377b08f3f6c3d3f5c14c9c15cafe07936d23 Mon Sep 17 00:00:00 2001 From: Scritches Date: Thu, 26 Apr 2018 17:14:18 -0400 Subject: [PATCH 3/6] ~xkcd command now finds relevant XKCDs when given text instead of a number --- modules/link/link.js | 54 ++++++++++++++++++++++++++++++++------------ 1 file changed, 39 insertions(+), 15 deletions(-) diff --git a/modules/link/link.js b/modules/link/link.js index 2d077ab..d9550be 100644 --- a/modules/link/link.js +++ b/modules/link/link.js @@ -110,23 +110,47 @@ var link = function(dbot) { } catch(err) { }; }); } 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")); + if (isNaN(parseInt(comicId))) { + var relevantUrl = 'https://relevantxkcd.appspot.com/process'; + request({ + url: relevantUrl, + qs: { + action:'xkcd', + query: comicId } - } catch(err) { }; - }); + }, function(err, res, body) { + comicId = body.split(' ').slice(2)[0].trim(); + + 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 { + 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) { From bbfc4c18a6dd49694799d4833b03631f6049644c Mon Sep 17 00:00:00 2001 From: Scritches Date: Thu, 26 Apr 2018 19:12:20 -0400 Subject: [PATCH 4/6] xkcd title / relevent text search feature done right. --- modules/link/link.js | 82 +++++++++++++++++++++++++++++++------------- 1 file changed, 59 insertions(+), 23 deletions(-) diff --git a/modules/link/link.js b/modules/link/link.js index d9550be..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) { @@ -132,6 +163,11 @@ var link = function(dbot) { } } catch(err) { }; }); + + + } else { + event.reply(dbot.t("no-hits")); + } }); } else { if(comicId !== "") { @@ -152,7 +188,7 @@ var link = function(dbot) { } } }, - + '~ud': function(event) { var query = event.input[1]; @@ -175,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); }); } } From d544dcf017c9b19d45fd546f85b6effabbf24d91 Mon Sep 17 00:00:00 2001 From: Scritches Date: Tue, 1 May 2018 16:47:25 -0400 Subject: [PATCH 5/6] clikill spares SASL-authenticated users from match kills --- modules/kill_namespam/kill_namespam.js | 31 +++++++++++++++++--------- modules/kill_namespam/strings.json | 3 +++ modules/nickserv/nickserv.js | 18 +++++++++------ 3 files changed, 35 insertions(+), 17 deletions(-) diff --git a/modules/kill_namespam/kill_namespam.js b/modules/kill_namespam/kill_namespam.js index 635c39b..04da04c 100644 --- a/modules/kill_namespam/kill_namespam.js +++ b/modules/kill_namespam/kill_namespam.js @@ -18,18 +18,29 @@ var kill_namespam = function(dbot) { if(event.message.match('▶')) { var matchedPattern = _.find(this.config.cliconn_patterns, function(p) { return event.message.match(p); }) 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/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); } From a5f9998872141f8faf77c88435ddd861478237ad Mon Sep 17 00:00:00 2001 From: Scritches Date: Tue, 1 May 2018 16:58:52 -0400 Subject: [PATCH 6/6] Added ~sp as alias to ~spotify --- modules/spotify/spotify.js | 2 ++ 1 file changed, 2 insertions(+) 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;