From 292254e96e76272a690dfeb4bd4a763a069a1f54 Mon Sep 17 00:00:00 2001 From: Daniel Llewellyn Date: Fri, 16 Dec 2016 16:56:44 +0000 Subject: [PATCH 1/3] initial attempt at a plugin system - currently only covers commands - some commands which need to maintain state such as seen might not work properly yet! --- bot.js | 819 +------------------------------------- plugins/bitcoin.js | 39 ++ plugins/css.js | 29 ++ plugins/example.js | 40 ++ plugins/google.js | 43 ++ plugins/hookr.js | 29 ++ plugins/ignore.js | 73 ++++ plugins/inbox.js | 88 ++++ plugins/index.js | 12 + plugins/jetpack.js | 34 ++ plugins/jquery.js | 40 ++ plugins/js.js | 29 ++ plugins/kick.js | 31 ++ plugins/math.js | 27 ++ plugins/php.js | 32 ++ plugins/randomiser.js | 174 ++++++++ plugins/scrape.js | 47 +++ plugins/seen.js | 67 ++++ plugins/simple-replies.js | 64 +++ plugins/soundcloud.js | 32 ++ plugins/spotify.js | 51 +++ plugins/weather.js | 36 ++ plugins/wordpressorg.js | 83 ++++ plugins/wpseek.js | 34 ++ plugins/youtube.js | 34 ++ 25 files changed, 1186 insertions(+), 801 deletions(-) create mode 100644 plugins/bitcoin.js create mode 100644 plugins/css.js create mode 100644 plugins/example.js create mode 100644 plugins/google.js create mode 100644 plugins/hookr.js create mode 100644 plugins/ignore.js create mode 100644 plugins/inbox.js create mode 100644 plugins/index.js create mode 100644 plugins/jetpack.js create mode 100644 plugins/jquery.js create mode 100644 plugins/js.js create mode 100644 plugins/kick.js create mode 100644 plugins/math.js create mode 100644 plugins/php.js create mode 100644 plugins/randomiser.js create mode 100644 plugins/scrape.js create mode 100644 plugins/seen.js create mode 100644 plugins/simple-replies.js create mode 100644 plugins/soundcloud.js create mode 100644 plugins/spotify.js create mode 100644 plugins/weather.js create mode 100644 plugins/wordpressorg.js create mode 100644 plugins/wpseek.js create mode 100644 plugins/youtube.js diff --git a/bot.js b/bot.js index 2eb5ead..a8f85e7 100644 --- a/bot.js +++ b/bot.js @@ -1,18 +1,19 @@ +'use strict'; + // Includes var config = require( './config' ); var irc = require( 'irc' ); var nickserv = require( 'nickserv' ); -var google = require( 'google' ); + var request = require( 'request' ); var cheerio = require( 'cheerio' ); var jsdom = require( 'jsdom' ); var moment = require( 'moment-timezone' ); var async = require( 'async' ); +var plugins = require( './plugins' ); + // Initialize global bot variables -google.resultsPerPage = 1; -var tell = []; -var seen = []; var flood = []; // Create the bot @@ -219,807 +220,23 @@ bot.addListener( 'message', function( from, to, text, message ) { console.log( 'who: ' + who ); } - // Process command - switch ( cmd ) { - // Scrape - case 'scrape': - // if ( isAdmin ) { - // // Setup site and selector - // var selector = str.match( /'(.*)'/ ); - // selector = selector[1]; - // var site = str.split( ' ' ); - // site = site[0]; - - // // Scrape the site for contents from selector - // request( site, function( error, response, body ) { - // if ( ! error) { - // // Load jsdom for DOM parsing - // jsdom.env( - // body, - // [ 'http://code.jquery.com/jquery-2.2.3.min.js' ], - // function( err, window ) { - // if ( err ) console.log( 'err:', err ); - // var $ = window.jQuery; - // console.log( 'body:', $('body').html() ); - // var msg = $( selector ).text(); - // bot.say( message.args[0], who ? who + ': ' + msg : msg ); - // } - // ); - // } else { - // console.log( error ); - // } - // }); - // } - break; - - // Ignore - case 'ignore': - // if ( isAdmin ) { - // var msg = ''; - // // Ignore the ignore request if they're trying to ignore an admin - // if ( config.admins.length ) { - // config.admins.forEach( function( value, index, array ) { - // if ( value.trim().toLowerCase() == str.toLowerCase() ) { - // msg = str + ' is an admin and admins cannot be ignored'; - // } - // }); - // } - - // // Ignore them if they're not an admin, let the user know they're already ignored otherwise - // if ( ! msg.length && config.ignore.length ) { - // if ( config.ignore.indexOf( str ) > -1 ) { - // msg = str + ' is already being ignored'; - // } else { - // config.ignore.push( str ); - // msg = str + ' is now being ignored'; - // } - // } - - // // Send ignored message - // bot.say( message.args[0], msg ); - // } - break; - - // Unignore - case 'unignore': - // if ( isAdmin ) { - // var msg = ''; - // // Ignore the ignore request if they're trying to ignore an admin - // if ( config.admins.length ) { - // config.admins.forEach( function( value, index, array ) { - // if ( value.trim().toLowerCase() == str.toLowerCase() ) { - // msg = str + ' is an admin and admins cannot be ignored'; - // } - // }); - // } - - // // Unignore them if they're not an admin, let the user know they're already unignored otherwise - // if ( ! msg.length && config.ignore.length ) { - // if ( config.ignore.indexOf( str ) > -1 ) { - // config.ignore.splice( config.ignore.indexOf( str ), 1 ); - // msg = str + ' is no longer being ignored'; - // } else { - // msg = str + ' is not being ignored'; - // } - // } - - // // Send ignored message - // bot.say( message.args[0], msg ); - // } - break; - - // Kick - case 'kick': - // if ( isAdmin ) { - // // Grab the kick message from the end of the string - // msg = str.split(' '); - // if ( msg.length > 1 ) { - // str = msg[0]; - // msg.splice( 0, 1 ); - // msg = msg.join(' '); - // } - - // // Kick the user - // console.log( 'KICK ' + message.args[0] + ' ' + str + ' ' + msg ); - // bot.send( 'KICK ' + message.args[0] + ' ' + str + ' ' + msg ); - // } - break; - - // Inbox - case 'inbox': - // Check for pending .tell commands for this user - var msg = ''; - var told = []; - var inbox = []; - - // Loop through each message and build one big message to deliver to the user - tell.forEach( function( value, index, array ) { - if ( value.from == from && told.length < 4 ) { - if ( config.debug ) console.log( 'Delivering .tell message #' + index + ' to ' + from ); - msg = '[' + value.from + ' ' + value.date + ']: ' + value.message; - inbox.push( msg ); - told.push( index ); - } - }); - - // Display their messages without flooding the channel - if ( inbox.length > 4 ) { - if ( config.debug ) console.log( '> 4 messages in inbox' ); - for ( var i = 0; i < 4; i++ ) { - bot.say( message.args[0], from + ': ' + inbox[ i ] ); - } - for ( var i = 0; i < 4; i++ ) { - inbox.shift(); - } - } else if ( ! inbox.length ) { - bot.say( message.args[0], from + ': you have no messages in your inbox' ); - } else { - if ( config.debug ) console.log( inbox.length + ' messages in inbox' ); - inbox.forEach( function( value, index, array ) { - bot.say( message.args[0], from + ': ' + inbox[ index ] ); - }); - } - - // Remove the messages that have been delivered - if ( told.length ) { - told.forEach( function( value, index, array ) { - tell.splice( value, 1 ); - }); - } - break; - - // Help - case 'help': - var commands = [ '.g', '.c', '.p', '.seen', '.tell', '.first', '.paste', '.hierarchy', '._', '.blame', '.ask', '.say' ]; - var helpstr = 'Available Commands: ' + commands.join( ', ' ); - bot.say( who ? who : from, helpstr ); - console.log( 'sending help message to: ' + who ? who : from ); - break; - - // Codex search - case 'c': - case 'codex': - if ( config.debug ) console.log( '[Codex search] for: ' + str ); - - // // Scrape the site for contents from selector - // var site = 'http://google.com/search?q=' + encodeURIComponent( str + ' site:wordpress.org inurl:("codex.wordpress.org"|"developer.wordpress.org")' ); - // request( site, function( error, response, body ) { - // if ( ! error) { - // // Load jsdom for DOM parsing - // jsdom.env( - // body, - // [ 'http://code.jquery.com/jquery-2.2.3.min.js' ], - // function( err, window ) { - // if ( err ) console.log( 'err:', err ); - // var $ = window.jQuery; - // console.log($('#ires .g:first .kv')); - // var msg = $('#ires .g:first .kv').text(); - // bot.say( message.args[0], who ? who + ': ' + msg : msg ); - // } - // ); - // } else { - // console.log( error ); - // } - // }); - - - google( str + ' site:wordpress.org inurl:("codex.wordpress.org"|"developer.wordpress.org")', function ( err, next, links ) { - if ( err && config.debug ) console.error( err ); - // Show the search results - if ( links && links[0].hasOwnProperty('link') ) { - bot.say( to, who ? who + ': ' + links[0].link : from + ': ' + links[0].link ); - } else { - bot.say( to, from + ': weird... your search for: "' + str + ' site:wordpress.org inurl:("codex.wordpress.org"|"developer.wordpress.org")" yielded this: ' + JSON.stringify( links ) ); - } - }); - break; - - // CSS search - case 'css': - if ( config.debug ) console.log( '[CSS search] for: ' + str ); - google( str + ' site:https://developer.mozilla.org/en-US/docs/Web/CSS', function ( err, next, links ) { - if ( err && config.debug ) console.error( err ); - // Show the search results - bot.say( to, who ? who + ': ' + links[0].link : from + ': ' + links[0].link ); - }); - break; - - // JS search - case 'js': - if ( config.debug ) console.log( '[JS search] for: ' + str ); - google( str + ' site:https://developer.mozilla.org/en-US/docs/Web/JavaScript/', function ( err, next, links ) { - if ( err && config.debug ) console.error( err ); - // Show the search results - bot.say( to, who ? who + ': ' + links[0].link : from + ': ' + links[0].link ); - }); - break; - - // BAH command - case 'bah': - var answers = [ 'http://xn--rh8hj8g.ws/bah-bloody.gif', 'http://xn--rh8hj8g.ws/bah-brave.gif' ]; - var answer = answers[ Math.floor( Math.random() * answers.length ) ]; - var msg = who ? who + ': ' + answer : from + ': ' + answer; - bot.say( message.args[0], msg ); - break; - - // YAY command - case 'yay': - var answers = [ 'http://xn--rh8hj8g.ws/yay-homer.jpg' ]; - var answer = answers[ Math.floor( Math.random() * answers.length ) ]; - var msg = who ? who + ': ' + answer : from + ': ' + answer; - bot.say( message.args[0], msg ); - break; - - // Fine command - case 'fine': - var answers = [ 'http://xn--rh8hj8g.ws/fine-wednesday.gif' ]; - var answer = answers[ Math.floor( Math.random() * answers.length ) ]; - var msg = who ? who + ': ' + answer : from + ': ' + answer; - bot.say( message.args[0], msg ); - break; - - // FML command - case 'fml': - var answers = [ 'http://s2.quickmeme.com/img/03/0353203cbc2e18150f8c7f45cb7d64efa57d8ac5bd1059add3576fc94ca702f2.jpg', 'http://i3.kym-cdn.com/photos/images/facebook/000/089/506/128989967490130539.jpg', 'http://img.memecdn.com/fml_o_577538.jpg', 'http://img.memecdn.com/FML-horse_o_141347.jpg', 'http://i0.kym-cdn.com/entries/icons/facebook/000/004/706/FML.jpg', 'http://don.citarella.net/wp-content/uploads/2012/05/sml.jpg', 'https://cdn.meme.am/instances/500x/55087958.jpg', 'https://cdn.meme.am/instances/500x/10377021.jpg', 'http://i2.kym-cdn.com/photos/images/list/000/478/993/5b1.jpg' ]; - var answer = answers[ Math.floor( Math.random() * answers.length ) ]; - var msg = who ? who + ': ' + answer : from + ': ' + answer; - bot.say( message.args[0], msg ); - break; - - // Google search - case 'g': - if ( config.debug ) console.log( '[Google search] for: ' + str ); - google( str, function ( err, next, links ) { - if ( err && config.debug ) console.error( err ); - // Show the search results - if ( links && links[0].hasOwnProperty('link') ) { - var msg = who ? who + ': ' + links[0].link : from + ': ' + links[0].link; - } else { - var msg = who ? who + ': no Google results found for "' + str + '"' : from + ': no Google results found for "' + str + '"'; - } - bot.say( to, msg ); - }); - break; - - // Hookr.io search - case 'h': - case 'hookr': - if ( config.debug ) console.log( '[Hookr search] for: ' + str ); - google( str + ' site:hookr.io', function ( err, next, links ) { - if ( err && config.debug ) console.error( err ); - // Show the search results - bot.say( to, who ? who + ': ' + links[0].link : from + ': ' + links[0].link ); - }); - break; - - // JetPack search - case 'jetpack': - if ( config.debug ) console.log( '[JetPack search] for: ' + str ); - google( str + ' site:developer.jetpack.com', function ( err, next, links ) { - if ( err && config.debug ) console.error( err ); - // Show the search results - if ( typeof links[0] == 'undefined' ) { - var msg = who ? who + ': no results found for "' + str + '" on developer.jetpack.com' : from + ': no results found for "' + str + '" on developer.jetpack.com'; - } else { - var msg = who ? who + ': ' + links[0].link : from + ': ' + links[0].link; - } - bot.say( to, msg ); - }); - break; - - // jQuery API search - case 'jquery': - if ( config.debug ) console.log( '[jQuery API search] for: ' + str ); - google( str + ' site:api.jquery.com', function ( err, next, links ) { - if ( err && config.debug ) console.error( err ); - // Show the search results - bot.say( to, who ? who + ': ' + links[0].link : from + ': ' + links[0].link ); - }); - break; - - // jQuery UI API search - case 'jqueryui': - if ( config.debug ) console.log( '[jQuery UI API search] for: ' + str ); - google( str + ' site:jqueryui.com', function ( err, next, links ) { - if ( err && config.debug ) console.error( err ); - // Show the search results - bot.say( to, who ? who + ': ' + links[0].link : from + ': ' + links[0].link ); - }); - break; - - // lmgtfy.com search - case 'l': - case 'lmgtfy': - if ( config.debug ) console.log( '[lmgtfy.com search] for: ' + str ); - // Show the search results - var link = 'http://lmgtfy.com/?q=' + encodeURIComponent( str ); - bot.say( to, who ? who + ': ' + link : from + ': ' + link ); - break; - - // Plugin search - case 'p': - if ( config.debug ) console.log( '[Plugin search] for: ' + str ); - google( str + ' wordpress plugin site:https://wordpress.org/plugins', function ( err, next, links ) { - if ( err && config.debug ) console.error( err ); - if ( config.debug ) console.log( links ); - // Show the search results - if ( links.length ) { - bot.say( to, who ? who + ': ' + links[0].link : from + ': ' + links[0].link ); - } - }); - break; - - // Plugin search - case 'php': - if ( config.debug ) console.log( '[PHP search] for: ' + str ); - google( str + ' site:http://php.net', function ( err, next, links ) { - if ( err && config.debug ) console.error( err ); - if ( config.debug ) console.log( links ); - // Show the search results - if ( links.length ) { - bot.say( to, who ? who + ': ' + links[0].link : from + ': ' + links[0].link ); - } - }); - break; - - // Soundcloud command - case 'soundcloud': - if ( config.debug ) console.log( '[SoundCloud search] for: ' + str ); - google( str + ' site:soundcloud.com', function ( err, next, links ) { - if ( err && config.debug ) console.error( err ); - if ( config.debug ) console.log( links ); - // Show the search results - if ( links.length ) { - bot.say( to, who ? who + ': ' + links[0].link : from + ': ' + links[0].link ); - } - }); - break; - - // Spotify command - case 'spotify': - if ( config.debug ) console.log( '[Spotify search] for: ' + str ); - google( str + ' site:open.spotify.com', function ( err, next, links ) { - if ( err && config.debug ) console.error( err ); - if ( config.debug ) console.log( links ); - // Show the search results - if ( links.length ) { - bot.say( to, who ? who + ': ' + links[0].link : from + ': ' + links[0].link ); - } - }); - break; - - // Spotify command - case 'spotifyuri': - if ( config.debug ) console.log( '[Spotify URI search] for: ' + str ); - google( str + ' site:open.spotify.com', function ( err, next, links ) { - if ( err && config.debug ) console.error( err ); - if ( config.debug ) console.log( links ); - // Show the search results - if ( links.length ) { - var link = links[0].link.split('/'); - link = 'spotify:track:' + link[ link.length - 1 ]; - bot.say( to, who ? who + ': ' + link : from + ': ' + link ); - } - }); - break; - - // wpseek.com search - case 'wps': - case 'wpseek': - if ( config.debug ) console.log( '[wpseek.com search] for: ' + str ); - google( str + ' site:wpseek.com', function ( err, next, links ) { - if ( err && config.debug ) console.error( err ); - // Show the search results - if ( links && links[0].hasOwnProperty('link') ) { - var msg = links[0].link; - } else { - var msg = 'weird... I had troubles getting a link for "' + str + ' site:wpseek.com"'; - } - bot.say( to, who ? who + ': ' + msg : from + ': ' + msg ); - }); - break; - - // YouTube search - case 'y': - case 'youtube': - if ( config.debug ) console.log( '[YouTube search] for: ' + str ); - google( str + ' site:youtube.com', function ( err, next, links ) { - if ( err && config.debug ) console.error( err ); - if ( config.debug ) console.log( links ); - // Show the search results - if ( links[0].link ) { - bot.say( to, who ? who + ': ' + links[0].link : from + ': ' + links[0].link ); - } else { - bot.say( to, from + ': weird... your search for: "' + str + ' site:youtube.com" yielded this: ' + JSON.stringify( links ) ); - } - }); - break; - - // Seen command - case 'seen': - if ( from != str ) { - var none = true; - if ( config.debug ) { - console.log( '[Seen search] for: ' + str ); - console.log( bot.chans ); - console.log( 'search through:' ); - console.log( config.channels ); - } - // Check channels first - config.channels.forEach( function( pvalue, pindex, parray ) { - // Normalize the case of each user for case insensitive checking - var chanusers = []; - for ( var user in bot.chans[ pvalue ].users ) { - chanusers.push( user.toLowerCase() ); - } - - // Loop through case normalized usernames - for ( var user in bot.chans[ pvalue ].users ) { - if ( none && bot.chans[ pvalue ].users.hasOwnProperty( str ) ) { - bot.say( to, who ? who + ': ' + str + ' is currently in ' + pvalue : from + ': ' + str + ' is currently in ' + pvalue ); - none = false; - } - } - }); - // search through seen array - seen.forEach( function( value, index, array ) { - if ( value.nick == str ) { - // Setup the seen message - var msg = 'Last seen ' + value.nick + ' '; - var time = ' on ' + value.time; - switch ( value.event ) { - case 'nick': - msg += 'changing their nick to ' + value.newnick + time; - break; - case 'part': - msg += 'parting ' + value.channel + time; - if ( value.message ) msg += ' with the message: ' + value.message; - break; - case 'quit': - msg += 'quitting IRC with the message: "' + value.reason + '"' + time; - break; - } - bot.say( to, msg ); - none = false; - } - }); - if ( none ) bot.say( to, who ? who + ': ' + 'I haven\'t seen ' + str : from + ': ' + 'I haven\'t seen ' + str ); - } else { - bot.say( to, 'That\'s hilarious ' + from + '...' ); - } - break; - - // SMH command - case 'smh': - var answers = [ 'http://xn--rh8hj8g.ws/smh-mjf.png', 'http://xn--rh8hj8g.ws/smh-today.gif', 'http://xn--rh8hj8g.ws/smh-kanye.gif', 'http://xn--rh8hj8g.ws/smh-bbad.gif', 'http://xn--rh8hj8g.ws/smh-drag.gif' ]; - var answer = answers[ Math.floor( Math.random() * answers.length ) ]; - var msg = who ? who + ': ' + answer : from + ': ' + answer; - bot.say( message.args[0], msg ); - break; - - // Tell command - case 'tell': - // Make sure their message is setup correctly - var sendto = str.split(' ')[0]; - // Add .tell message to the tell array - if ( config.debug ) console.log( '[Tell ' + sendto + '] ' + str ); - if ( tell.length ) { - var already = false; - tell.forEach( function( value, index, array ) { - if ( value.from == from && value.message == str ) { - already = true; + for ( var plugin of plugins ) { + if ( !! plugin['commands'] ) { + for ( var command of plugin.commands ) { + if ( !! command['name'] ) { + if ( command.name === cmd || ( command.name instanceof Array && command.name.findIndex( cmd ) > -1 ) ) { + command.handler( bot, from, to, message, who, str ); } - }); - if ( ! already ) { - msg = 'I\'ll deliver your message to ' + sendto + ' the next time they join.'; - tell.push({ from: from, message: str.replace( sendto + ' ', '' ), date: moment().tz( 'America/New_York' ).format( 'M/DD/YY h:mm:ssa z' ) }); } - } else { - msg = 'I\'ll deliver your message to ' + sendto + ' the next time they join.'; - tell.push({ from: from, message: str.replace( sendto + ' ', '' ), date: moment().tz( 'America/New_York' ).format( 'M/DD/YY h:mm:ssa z' ) }); - } - var msg = who ? who + ': ' + msg : from + ': ' + msg; - bot.say( message.args[0], msg ); - break; - - // Bitcoin command - case 'bitcoin': - if ( config.debug ) console.log( '[Bitcoin Exchange Rate]' ); - // Check if they want a specific exchange rate - if ( str.indexOf('.bitcoin:') == 0 ) { - var currency = str.split(' '); - currency = currency[0].split(':'); - currency = currency[1].toUpperCase(); - } else { - var currency = 'USD'; } - // Grab the blockchain information for the current currency type - request( 'https://blockchain.info/ticker', function( error, response, body ) { - if ( ! error) { - body = JSON.parse( body ); - if ( body.hasOwnProperty( currency ) ) { - body = body[ currency ]; - var msg = 'Current ' + currency + ' Bitcoin Value: ' + body.symbol + body.last + '. [Buy @ ' + body.symbol + body.buy + ' and Sell @ ' + body.symbol + body.sell + ']'; - } else { - var msg = 'Unable to read blockchain information for the "' + currency + '" currency type. Please try again later :('; - } - bot.say( message.args[0], who ? who + ': ' + msg : from + ': ' + msg ); - } - }); - break; - - // Math command - case 'math': - if ( config.debug ) console.log( '[Math Command]' ); - // Get the endpoint - var endpoint = 'http://api.mathjs.org/v1/?expr=' + encodeURIComponent( str ); - // Grab the blockchain information for the current currency type - request( endpoint, function( error, response, body ) { - if ( ! error) { - var msg = body; - bot.say( message.args[0], who ? who + ': ' + msg : from + ': ' + msg ); - } - }); - break; - - // // Weather command - // case 'weather': - // if ( config.hasOwnProperty('openweathermap_api_key') ) { - // if ( config.debug ) console.log( '[Weather Command]' ); - // // Set the API endpoint - // var endpoint = 'http://api.openweathermap.org/data/2.5/weather?q=London&APPID=' + config.openweathermap_api_key; - // // Grab the blockchain information for the current currency type - // request( endpoint, function( error, response, body ) { - // if ( ! error) { - // body = JSON.parse( body ); - // if ( body.hasOwnProperty('name') ) { - // var wind = body.wind.speed; - // var msg = 'Current weather for ' + body.name + ': ' - // var msg = 'Current ' + currency + ' Bitcoin Value: ' + body.symbol + body.last + '. [Buy @ ' + body.symbol + body.buy + ' and Sell @ ' + body.symbol + body.sell + ']'; - // } else { - // var msg = 'Unable to read blockchain information for the "' + currency + '" currency type. Please try again later :('; - // } - // bot.say( message.args[0], who ? who + ': ' + msg : from + ': ' + msg ); - // } - // }); - // } - // break; - - // Count command - case 'count': - if ( config.debug ) console.log( '[WordPress Count]' ); - request( 'https://wordpress.org/download/counter/?ajaxupdate=1', function( error, response, body ) { - if ( ! error) { - var msg = 'WordPress has been downloaded ' + body + ' times.'; - bot.say( message.args[0], who ? who + ': ' + msg : from + ': ' + msg ); - } - }); - break; - - // Facepalm command - case 'facepalm': - var answers = [ 'http://4.bp.blogspot.com/-mgnWPcZJcz0/U9K0TnmdyWI/AAAAAAAAD2Q/fpaFlMU5ZOo/s1600/homer_facepalm.jpg', 'http://static.giantbomb.com/uploads/original/8/88747/1772665-pope_facepalm.jpg', 'http://memesvault.com/wp-content/uploads/Extreme-Facepalm-Gif-06.png', 'http://i.imgur.com/wY9Mn.png' ]; - var answer = answers[ Math.floor( Math.random() * answers.length ) ]; - var msg = who ? who + ': ' + answer : from + ': ' + answer; - bot.say( message.args[0], msg ); - break; - - // First command - case 'first': - var msg = 'Please attempt to disable all plugins, and use one of the default (Twenty*) themes. If the problem goes away, enable them one by one to identify the source of your troubles.'; - bot.say( message.args[0], who ? who + ': ' + msg : from + ': ' + msg ); - break; - - // Moving command - case 'moving': - case 'move': - var msg = 'If you rename the WordPress directory on your server, switch ports or change the hostname http://codex.wordpress.org/Moving_WordPress applies'; - bot.say( message.args[0], who ? who + ': ' + msg : from + ': ' + msg ); - break; - - // Inspect command - case 'inspect': - var msg = 'Please use the built-in Developer Tools of your browser to fix problems with your website. Right click your page and pick “Inspect Element” (Cr, FF, Op) or press F12-button (IE) to track down CSS problems. Use the console to see JavaScript bugs.'; - bot.say( message.args[0], who ? who + ': ' + msg : from + ': ' + msg ); - break; - - // Paste command - case 'paste': - var msg = 'Please use http://wpbin.io to paste your multi-line code samples'; - bot.say( message.args[0], who ? who + ': ' + msg : from + ': ' + msg ); - break; - - // Asking command - case 'asking': - var msg = 'When asking a question make sure to include the following information: 1) What you want to achieve. 2) How you are attempting to achieve it. 3) What you expect to happen. 4) What is actually happening.'; - bot.say( message.args[0], who ? who + ': ' + msg : from + ': ' + msg ); - break; - - // Linking command - case 'linking': - var msg = 'When linking to your website while asking for help, please tell us specifically where to look on the website and what to click to initiate the interaction you are trying to fix'; - bot.say( message.args[0], who ? who + ': ' + msg : from + ': ' + msg ); - break; - - // Hierarchy command - case 'hierarchy': - var msg = 'Please refer to the WordPress template hierarchy https://developer.wordpress.org/themes/basics/template-hierarchy/'; - bot.say( message.args[0], who ? who + ': ' + msg : from + ': ' + msg ); - break; - - // Underscores command - case '_': - var msg = 'Check out the Underscores base theme http://underscores.me'; - bot.say( message.args[0], who ? who + ': ' + msg : from + ': ' + msg ); - break; - - // 8ball - case '8ball': - var answers = [ 'Nope', 'Fat chance', 'Most definitely!', 'Yep', 'Try again later', 'How the hell am I supposed to know?', 'Most likely', 'Indeed', 'Not in this lifetime', 'Pffft... what do you think?', 'Obviously!' ]; - var answer = answers[ Math.floor( Math.random() * answers.length ) ]; - var msg = who ? who + ': ' + answer : from + ': ' + answer; - bot.say( message.args[0], msg ); - break; - - // Cry command - case 'cry': - var prefix = who ? who + ': ' : ''; - var msg = prefix + '(╯︵╰,)'; - bot.say( message.args[0], msg ); - break; - - // Blame command - case 'blame': - if ( str == bot.nick ) { - var msg = "That's hilarious..."; - } else { - var msg = who ? who + ': ' + 'It\'s all ' + str + '\'s fault!' : 'It\'s all ' + str + '\'s fault!'; - } - bot.say( message.args[0], msg ); - break; - - // Flip command - case 'flip': - var prefix = who ? who + ': ' : ''; - if ( str == '.flip!' ) { - var msg = prefix + '┻━┻︵ \\(°□°)/ ︵ ┻━┻'; - } else { - var msg = prefix + '(╯°□°)╯︵ ┻━┻'; - } - bot.say( message.args[0], msg ); - break; - - // Chill command - case 'calm': - case 'chill': - var prefix = who ? who + ': ' : ''; - var msg = prefix + '┬──┬ ノ(゜-゜ノ)'; - bot.say( message.args[0], msg ); - break; - - // Shrug command - case 'shrug': - var prefix = who ? who + ': ' : ''; - var msg = prefix + '¯\\_(ツ)_/¯'; - bot.say( message.args[0], msg ); - break; - - // YOLO command - case 'yolo': - var prefix = who ? who + ': ' : ''; - var msg = prefix + 'Yᵒᵘ Oᶰˡʸ Lᶤᵛᵉ Oᶰᶜᵉ'; - bot.say( message.args[0], msg ); - break; - - // Pfft command - case 'pfft': - case 'pff': - case 'pft': - case 'pf': - var answers = [ 'https://s-media-cache-ak0.pinimg.com/736x/a9/26/8f/a9268f451c95945e928121cd91c41281.jpg', 'http://reactiongif.org/wp-content/uploads/GIF/2014/08/GIF-bfd-big-deal-dwight-meh-sarcastic-the-office-uncaring-whatever-GIF.gif', 'https://static1.fjcdn.com/thumbnails/comments/Pfft+that+horrible+tattoo+does+_5e04cac8f2e8f5a827be0b3123a888b1.png', 'http://data.whicdn.com/images/196440384/large.jpg', 'https://coydavidson.files.wordpress.com/2012/06/pfft.jpg', 'https://tromoticons.files.wordpress.com/2012/11/yao-ming-pff.png', 'https://cdn.meme.am/instances/500x/50075843.jpg' ]; - var answer = answers[ Math.floor( Math.random() * answers.length ) ]; - var msg = who ? who + ': ' + answer : from + ': ' + answer; - bot.say( message.args[0], msg ); - break; - - // Hi command - case 'hi': - var answers = [ 'http://xn--rh8hj8g.ws/hi-queen.gif', 'http://xn--rh8hj8g.ws/hi-goofy.gif', 'http://xn--rh8hj8g.ws/hi-forestgump.gif', 'http://xn--rh8hj8g.ws/hi-picard.gif', 'http://xn--rh8hj8g.ws/hi-ironman.gif' ]; - var answer = answers[ Math.floor( Math.random() * answers.length ) ]; - var msg = who ? who + ': ' + answer : from + ': ' + answer; - bot.say( message.args[0], msg ); - break; - - // Bye command - case 'bye': - var answers = [ 'http://xn--rh8hj8g.ws/bye-jezebel.gif', 'http://xn--rh8hj8g.ws/bye-jezebel.gif', 'http://xn--rh8hj8g.ws/bye-bitch.gif', 'http://xn--rh8hj8g.ws/bye-woody.gif', 'http://xn--rh8hj8g.ws/bye-clarissa.gif', 'http://xn--rh8hj8g.ws/bye-harrypotter.gif', 'http://xn--rh8hj8g.ws/bye-random.gif' ]; - var answer = answers[ Math.floor( Math.random() * answers.length ) ]; - var msg = who ? who + ': ' + answer : from + ': ' + answer; - // This allows the user to add a message on top of - // msg = ( str ? str + ' ' : '' ) + msg; - bot.say( message.args[0], msg ); - break; - - // Party command - case 'dance': - case 'party': - case 'boogie': - var prefix = who ? who + ': ' : ''; - var msg = prefix + '┏(-_-)┛┗(-_-)┓┗(-_-)┛┏(-_-)┓'; - bot.say( message.args[0], msg ); - break; - - // Finger command - case 'finger': - var prefix = who ? who + ': ' : ''; - var msg = prefix + '╭∩╮(︶︿︶)╭∩╮'; - bot.say( message.args[0], msg ); - break; - - // Emojis #1 - case 'emojis': - var msg = '😀😬😁😂😃😄😅😆😌😋🙃🙂😊😉😇😍😘😗😙😚😜😝😛😑😐😶😏🤗😎🤓🤑😒🙄🤔😳😞😟😠😡😩😫😖😣☹🙁😕😔😤😮😱😨😰😯😦😧😢😥😪😓😭😵😲🤐👿😈💩💤😴🤕🤒😷👹👺💀👻👽🤖😺😸🙌😾😿🙀😽😼😻😹🙌🏻🙌🏼🙌🏽🙌🏾🙌🏿👏👏🏻👏🏼👏🏽👏🏾👏🏿'; - bot.say( message.args[0], msg ); - break; - - // Poop emoji - case 'poop': - var prefix = who ? who + ': ' : ''; - var msg = prefix + '💩'; - bot.say( message.args[0], msg ); - break; - - // Fart emojis - case 'fart': - var prefix = who ? who + ': ' : ''; - var msg = prefix + '💩💨💨💨💨'; - bot.say( message.args[0], msg ); - break; - - // Trollollolloll - case 'trollolloll': - case 'trollsong' : - case 'troll' : - var prefix = who ? who + ': ' : ''; - var msg = prefix + 'https://youtu.be/9zYP8_5IBmU?t=1m47s'; - bot.say( message.args[0], msg ); - break; - - // Ask command - case 'ask': - var msg = 'Go ahead and ask your question and someone will assist if they are able.'; - bot.say( message.args[0], who ? who + ': ' + msg : from + ': ' + msg ); - break; - - // Just a say command - case 'say': - bot.say( message.args[0], who ? who + ': ' + str : str ); - break; - - // WAT command - case 'wat': - var answers = [ 'http://xn--rh8hj8g.ws/wat-shrunkenface.jpg' ]; - var answer = answers[ Math.floor( Math.random() * answers.length ) ]; - var msg = who ? who + ': ' + answer : from + ': ' + answer; - bot.say( message.args[0], msg ); - break; - - // WTF command - case 'wtf': - var answers = [ 'http://xn--rh8hj8g.ws/wtf-baby.png' ]; - var answer = answers[ Math.floor( Math.random() * answers.length ) ]; - var msg = who ? who + ': ' + answer : from + ': ' + answer; - bot.say( message.args[0], msg ); - break; - - // Yas command - case 'yas': - var answers = [ 'http://xn--rh8hj8g.ws/yas-werk.gif' ]; - var answer = answers[ Math.floor( Math.random() * answers.length ) ]; - var msg = who ? who + ': ' + answer : from + ': ' + answer; - bot.say( message.args[0], msg ); - break; + } + } + if ( cmd === 'help' ) { + var commands = [ '.g', '.c', '.p', '.seen', '.tell', '.first', '.paste', '.hierarchy', '._', '.blame', '.ask', '.say' ]; + var helpstr = 'Available Commands: ' + commands.join( ', ' ); + bot.say( who ? who : from, helpstr ); + console.log( 'sending help message to: ' + who ? who : from ); } } else { // React to parts of their string if it contains certain text diff --git a/plugins/bitcoin.js b/plugins/bitcoin.js new file mode 100644 index 0000000..f39dbfe --- /dev/null +++ b/plugins/bitcoin.js @@ -0,0 +1,39 @@ +var config = require( '../config' ); + +var request = require( 'request' ); + +module.exports = {}; + +/** + * this is an array of objects. + * each object needs a `name` parameter and a `handler` parameter. + */ +module.exports.commands = [ + { + name: 'bitcoin', + handler: function( bot, from, to, message, who, str ) { + if ( config.debug ) console.log( '[Bitcoin Exchange Rate]' ); + // Check if they want a specific exchange rate + if ( str.indexOf('.bitcoin:') == 0 ) { + var currency = str.split(' '); + currency = currency[0].split(':'); + currency = currency[1].toUpperCase(); + } else { + var currency = 'USD'; + } + // Grab the blockchain information for the current currency type + request( 'https://blockchain.info/ticker', function( error, response, body ) { + if ( ! error) { + body = JSON.parse( body ); + if ( body.hasOwnProperty( currency ) ) { + body = body[ currency ]; + var msg = 'Current ' + currency + ' Bitcoin Value: ' + body.symbol + body.last + '. [Buy @ ' + body.symbol + body.buy + ' and Sell @ ' + body.symbol + body.sell + ']'; + } else { + var msg = 'Unable to read blockchain information for the "' + currency + '" currency type. Please try again later :('; + } + bot.say( message.args[0], who ? who + ': ' + msg : from + ': ' + msg ); + } + }); + } + } +]; diff --git a/plugins/css.js b/plugins/css.js new file mode 100644 index 0000000..aa43490 --- /dev/null +++ b/plugins/css.js @@ -0,0 +1,29 @@ +var config = require( '../config' ); + +var google = require( 'google' ); +google.resultsPerPage = 1; + +module.exports = {}; + +/** + * this is an array of objects. + * each object needs a `name` parameter and a `handler` parameter. + */ +module.exports.commands = [ + { + name: 'css', + handler: function( bot, from, to, message, who, str ) { + if ( config.debug ) console.log( '[CSS search] for: ' + str ); + google( str + ' site:https://developer.mozilla.org/en-US/docs/Web/CSS', function ( err, next, links ) { + if ( err && config.debug ) console.error( err ); + // Show the search results + bot.say( to, who ? who + ': ' + links[0].link : from + ': ' + links[0].link ); + }); + } + } +]; + +/** + * this is an array of functions. + */ +module.exports.filters = []; diff --git a/plugins/example.js b/plugins/example.js new file mode 100644 index 0000000..4e6a294 --- /dev/null +++ b/plugins/example.js @@ -0,0 +1,40 @@ +module.exports = {}; + +/** + * this is an array of objects. + * each object needs a `name` parameter and a `handler` parameter. + */ +module.exports.commands = [ + { + /** + * command invokation text without leading dot + */ + name: 'command', + + /** + * handler function to be executed for this command + */ + handler: function( bot, from, to, message, who, str ) {} + }, + /** + * futher commands as needed for this plugin + */ + { + name: 'command2', + handler: function( bot, from, to, message, who, str ) {} + } +]; + +/** + * this is an array of functions. + */ +module.exports.filters = [ + /** + * handler function for filter + */ + function(bot, data) {}, + /** + * another filter function + */ + function(bot, data) {} +]; diff --git a/plugins/google.js b/plugins/google.js new file mode 100644 index 0000000..dbc5ff5 --- /dev/null +++ b/plugins/google.js @@ -0,0 +1,43 @@ +var config = require( '../config' ); + +var google = require( 'google' ); +google.resultsPerPage = 1; + +module.exports = {}; + +/** + * this is an array of objects. + * each object needs a `name` parameter and a `handler` parameter. + */ +module.exports.commands = [ + { + name: [ 'g', 'google' ], + handler: function( bot, from, to, message, who, str ) { + if ( config.debug ) console.log( '[Google search] for: ' + str ); + google( str, function ( err, next, links ) { + if ( err && config.debug ) console.error( err ); + // Show the search results + if ( links && links[0].hasOwnProperty('link') ) { + var msg = who ? who + ': ' + links[0].link : from + ': ' + links[0].link; + } else { + var msg = who ? who + ': no Google results found for "' + str + '"' : from + ': no Google results found for "' + str + '"'; + } + bot.say( to, msg ); + }); + } + }, + { + name: ['l', 'lmgtfy'], + handler: function( bot, from, to, message, who, str ) { + if ( config.debug ) console.log( '[lmgtfy.com search] for: ' + str ); + // Show the search results + var link = 'http://lmgtfy.com/?q=' + encodeURIComponent( str ); + bot.say( to, who ? who + ': ' + link : from + ': ' + link ); + } + } +]; + +/** + * this is an array of functions. + */ +module.exports.filters = []; diff --git a/plugins/hookr.js b/plugins/hookr.js new file mode 100644 index 0000000..a3a12f8 --- /dev/null +++ b/plugins/hookr.js @@ -0,0 +1,29 @@ +var config = require( '../config' ); + +var google = require( 'google' ); +google.resultsPerPage = 1; + +module.exports = {}; + +/** + * this is an array of objects. + * each object needs a `name` parameter and a `handler` parameter. + */ +module.exports.commands = [ + { + name: [ 'h', 'hookr' ], + handler: function( bot, from, to, message, who, str ) { + if ( config.debug ) console.log( '[Hookr search] for: ' + str ); + google( str + ' site:hookr.io', function ( err, next, links ) { + if ( err && config.debug ) console.error( err ); + // Show the search results + bot.say( to, who ? who + ': ' + links[0].link : from + ': ' + links[0].link ); + }); + } + } +]; + +/** + * this is an array of functions. + */ +module.exports.filters = []; diff --git a/plugins/ignore.js b/plugins/ignore.js new file mode 100644 index 0000000..7854791 --- /dev/null +++ b/plugins/ignore.js @@ -0,0 +1,73 @@ +var config = require( '../config' ); + +module.exports = {}; + +/** + * this is an array of objects. + * each object needs a `name` parameter and a `handler` parameter. + */ +module.exports.commands = [ + { + name: 'ignore', + handler: function( bot, from, to, message, who, str ) { + // if ( isAdmin ) { + // var msg = ''; + // // Ignore the ignore request if they're trying to ignore an admin + // if ( config.admins.length ) { + // config.admins.forEach( function( value, index, array ) { + // if ( value.trim().toLowerCase() == str.toLowerCase() ) { + // msg = str + ' is an admin and admins cannot be ignored'; + // } + // }); + // } + + // // Ignore them if they're not an admin, let the user know they're already ignored otherwise + // if ( ! msg.length && config.ignore.length ) { + // if ( config.ignore.indexOf( str ) > -1 ) { + // msg = str + ' is already being ignored'; + // } else { + // config.ignore.push( str ); + // msg = str + ' is now being ignored'; + // } + // } + + // // Send ignored message + // bot.say( message.args[0], msg ); + // } + } + }, + { + name: 'unignore', + handler: function( bot, from, to, message, who, str ) { + // if ( isAdmin ) { + // var msg = ''; + // // Ignore the ignore request if they're trying to ignore an admin + // if ( config.admins.length ) { + // config.admins.forEach( function( value, index, array ) { + // if ( value.trim().toLowerCase() == str.toLowerCase() ) { + // msg = str + ' is an admin and admins cannot be ignored'; + // } + // }); + // } + + // // Unignore them if they're not an admin, let the user know they're already unignored otherwise + // if ( ! msg.length && config.ignore.length ) { + // if ( config.ignore.indexOf( str ) > -1 ) { + // config.ignore.splice( config.ignore.indexOf( str ), 1 ); + // msg = str + ' is no longer being ignored'; + // } else { + // msg = str + ' is not being ignored'; + // } + // } + + // // Send ignored message + // bot.say( message.args[0], msg ); + // } + } + } +]; + +/** + * this is an array of functions. + */ +module.exports.filters = []; diff --git a/plugins/inbox.js b/plugins/inbox.js new file mode 100644 index 0000000..c572f3d --- /dev/null +++ b/plugins/inbox.js @@ -0,0 +1,88 @@ +var config = require( '../config' ); + +module.exports = {}; + +var tell = []; + +/** + * this is an array of objects. + * each object needs a `name` parameter and a `handler` parameter. + */ +module.exports.commands = [ + { + name: 'inbox', + handler: function( bot, from, to, message, who, str ) { + // Check for pending .tell commands for this user + var msg = ''; + var told = []; + var inbox = []; + + // Loop through each message and build one big message to deliver to the user + tell.forEach( function( value, index, array ) { + if ( value.from == from && told.length < 4 ) { + if ( config.debug ) console.log( 'Delivering .tell message #' + index + ' to ' + from ); + msg = '[' + value.from + ' ' + value.date + ']: ' + value.message; + inbox.push( msg ); + told.push( index ); + } + }); + + // Display their messages without flooding the channel + if ( inbox.length > 4 ) { + if ( config.debug ) console.log( '> 4 messages in inbox' ); + for ( var i = 0; i < 4; i++ ) { + bot.say( message.args[0], from + ': ' + inbox[ i ] ); + } + for ( var i = 0; i < 4; i++ ) { + inbox.shift(); + } + } else if ( ! inbox.length ) { + bot.say( message.args[0], from + ': you have no messages in your inbox' ); + } else { + if ( config.debug ) console.log( inbox.length + ' messages in inbox' ); + inbox.forEach( function( value, index, array ) { + bot.say( message.args[0], from + ': ' + inbox[ index ] ); + }); + } + + // Remove the messages that have been delivered + if ( told.length ) { + told.forEach( function( value, index, array ) { + tell.splice( value, 1 ); + }); + } + } + }, + { + name: 'tell', + handler: function( bot, from, to, message, who, str ) { + // Tell command + // Make sure their message is setup correctly + var sendto = str.split(' ')[0]; + // Add .tell message to the tell array + if ( config.debug ) console.log( '[Tell ' + sendto + '] ' + str ); + if ( tell.length ) { + var already = false; + tell.forEach( function( value, index, array ) { + if ( value.from == from && value.message == str ) { + already = true; + } + }); + if ( ! already ) { + msg = 'I\'ll deliver your message to ' + sendto + ' the next time they join.'; + tell.push({ from: from, message: str.replace( sendto + ' ', '' ), date: moment().tz( 'America/New_York' ).format( 'M/DD/YY h:mm:ssa z' ) }); + } + } else { + msg = 'I\'ll deliver your message to ' + sendto + ' the next time they join.'; + tell.push({ from: from, message: str.replace( sendto + ' ', '' ), date: moment().tz( 'America/New_York' ).format( 'M/DD/YY h:mm:ssa z' ) }); + } + var msg = who ? who + ': ' + msg : from + ': ' + msg; + bot.say( message.args[0], msg ); + } + } +]; + +/** + * this is an array of functions. + */ +module.exports.filters = []; diff --git a/plugins/index.js b/plugins/index.js new file mode 100644 index 0000000..4bfaeaa --- /dev/null +++ b/plugins/index.js @@ -0,0 +1,12 @@ +var fs = require( 'fs' ); + +var files = fs.readdirSync( __dirname ); + +module.exports = [] + +var re = /\.js$/; +files.forEach( function(file) { + if ( file.match( re ) ) { + module.exports.push( require( './' + file ) ); + } +} ); diff --git a/plugins/jetpack.js b/plugins/jetpack.js new file mode 100644 index 0000000..14a2da1 --- /dev/null +++ b/plugins/jetpack.js @@ -0,0 +1,34 @@ +var config = require( '../config' ); + +var google = require( 'google' ); +google.resultsPerPage = 1; + +module.exports = {}; + +/** + * this is an array of objects. + * each object needs a `name` parameter and a `handler` parameter. + */ +module.exports.commands = [ + { + name: 'jetpack', + handler: function( bot, from, to, message, who, str ) { + if ( config.debug ) console.log( '[JetPack search] for: ' + str ); + google( str + ' site:developer.jetpack.com', function ( err, next, links ) { + if ( err && config.debug ) console.error( err ); + // Show the search results + if ( typeof links[0] == 'undefined' ) { + var msg = who ? who + ': no results found for "' + str + '" on developer.jetpack.com' : from + ': no results found for "' + str + '" on developer.jetpack.com'; + } else { + var msg = who ? who + ': ' + links[0].link : from + ': ' + links[0].link; + } + bot.say( to, msg ); + }); + } + } +]; + +/** + * this is an array of functions. + */ +module.exports.filters = []; diff --git a/plugins/jquery.js b/plugins/jquery.js new file mode 100644 index 0000000..1f2884a --- /dev/null +++ b/plugins/jquery.js @@ -0,0 +1,40 @@ +var config = require( '../config' ); + +var google = require( 'google' ); +google.resultsPerPage = 1; + +module.exports = {}; + +/** + * this is an array of objects. + * each object needs a `name` parameter and a `handler` parameter. + */ +module.exports.commands = [ + { + name: 'jquery', + handler: function( bot, from, to, message, who, str ) { + if ( config.debug ) console.log( '[jQuery API search] for: ' + str ); + google( str + ' site:api.jquery.com', function ( err, next, links ) { + if ( err && config.debug ) console.error( err ); + // Show the search results + bot.say( to, who ? who + ': ' + links[0].link : from + ': ' + links[0].link ); + }); + } + }, + { + name: 'jqueryui', + handler: function( bot, from, to, message, who, str ) { + if ( config.debug ) console.log( '[jQuery UI API search] for: ' + str ); + google( str + ' site:jqueryui.com', function ( err, next, links ) { + if ( err && config.debug ) console.error( err ); + // Show the search results + bot.say( to, who ? who + ': ' + links[0].link : from + ': ' + links[0].link ); + }); + } + } +]; + +/** + * this is an array of functions. + */ +module.exports.filters = []; diff --git a/plugins/js.js b/plugins/js.js new file mode 100644 index 0000000..62cb292 --- /dev/null +++ b/plugins/js.js @@ -0,0 +1,29 @@ +var config = require( '../config' ); + +var google = require( 'google' ); +google.resultsPerPage = 1; + +module.exports = {}; + +/** + * this is an array of objects. + * each object needs a `name` parameter and a `handler` parameter. + */ +module.exports.commands = [ + { + name: 'js', + handler: function( bot, from, to, message, who, str ) { + if ( config.debug ) console.log( '[JS search] for: ' + str ); + google( str + ' site:https://developer.mozilla.org/en-US/docs/Web/JavaScript/', function ( err, next, links ) { + if ( err && config.debug ) console.error( err ); + // Show the search results + bot.say( to, who ? who + ': ' + links[0].link : from + ': ' + links[0].link ); + }); + } + } +]; + +/** + * this is an array of functions. + */ +module.exports.filters = []; diff --git a/plugins/kick.js b/plugins/kick.js new file mode 100644 index 0000000..70f113e --- /dev/null +++ b/plugins/kick.js @@ -0,0 +1,31 @@ +module.exports = {}; + +/** + * this is an array of objects. + * each object needs a `name` parameter and a `handler` parameter. + */ +module.exports.commands = [ + { + name: 'kick', + handler: function( bot, from, to, message, who, str ) { + // if ( isAdmin ) { + // // Grab the kick message from the end of the string + // msg = str.split(' '); + // if ( msg.length > 1 ) { + // str = msg[0]; + // msg.splice( 0, 1 ); + // msg = msg.join(' '); + // } + + // // Kick the user + // console.log( 'KICK ' + message.args[0] + ' ' + str + ' ' + msg ); + // bot.send( 'KICK ' + message.args[0] + ' ' + str + ' ' + msg ); + // } + } + } +]; + +/** + * this is an array of functions. + */ +module.exports.filters = []; diff --git a/plugins/math.js b/plugins/math.js new file mode 100644 index 0000000..7e05dd3 --- /dev/null +++ b/plugins/math.js @@ -0,0 +1,27 @@ +var config = require( '../config' ); + +var request = require( 'request' ); + +module.exports = {}; + +/** + * this is an array of objects. + * each object needs a `name` parameter and a `handler` parameter. + */ +module.exports.commands = [ + { + name: 'math', + handler: function( bot, from, to, message, who, str ) { + if ( config.debug ) console.log( '[Math Command]' ); + // Get the endpoint + var endpoint = 'http://api.mathjs.org/v1/?expr=' + encodeURIComponent( str ); + // Grab the blockchain information for the current currency type + request( endpoint, function( error, response, body ) { + if ( ! error) { + var msg = body; + bot.say( message.args[0], who ? who + ': ' + msg : from + ': ' + msg ); + } + }); + } + } +]; diff --git a/plugins/php.js b/plugins/php.js new file mode 100644 index 0000000..5b4b76a --- /dev/null +++ b/plugins/php.js @@ -0,0 +1,32 @@ +var config = require( '../config' ); + +var google = require( 'google' ); +google.resultsPerPage = 1; + +module.exports = {}; + +/** + * this is an array of objects. + * each object needs a `name` parameter and a `handler` parameter. + */ +module.exports.commands = [ + { + name: 'php', + handler: function( bot, from, to, message, who, str ) { + if ( config.debug ) console.log( '[PHP search] for: ' + str ); + google( str + ' site:http://php.net', function ( err, next, links ) { + if ( err && config.debug ) console.error( err ); + if ( config.debug ) console.log( links ); + // Show the search results + if ( links.length ) { + bot.say( to, who ? who + ': ' + links[0].link : from + ': ' + links[0].link ); + } + }); + } + } +]; + +/** + * this is an array of functions. + */ +module.exports.filters = []; diff --git a/plugins/randomiser.js b/plugins/randomiser.js new file mode 100644 index 0000000..b72e575 --- /dev/null +++ b/plugins/randomiser.js @@ -0,0 +1,174 @@ +module.exports = {}; + +function randomise(bot, from, to, message, who, answers) { + var answer = answers[ Math.floor( Math.random() * answers.length ) ]; + var msg = who ? who + ': ' + answer : from + ': ' + answer; + bot.say( message.args[0], msg ); +} +/** + * this is an array of objects. + * each object needs a `name` parameter and a `handler` parameter. + */ +module.exports.commands = [ + { + name: '8ball', + handler: function( bot, from, to, message, who, str ) { + var answers = [ + 'Nope', + 'Fat chance', + 'Most definitely!', + 'Yep', + 'Try again later', + 'How the hell am I supposed to know?', + 'Most likely', + 'Indeed', + 'Not in this lifetime', + 'Pffft... what do you think?', + 'Obviously!' + ]; + randomise(bot, from, to, message, who, answers); + } + }, + { + name: 'bah', + handler: function( bot, from, to, message, who, str ) { + var answers = [ + 'http://xn--rh8hj8g.ws/bah-bloody.gif', + 'http://xn--rh8hj8g.ws/bah-brave.gif' + ]; + randomise(bot, from, to, message, who, answers); + } + }, + { + name: 'bye', + handler: function( bot, from, to, message, who, str ) { + var answers = [ + 'http://xn--rh8hj8g.ws/bye-jezebel.gif', + 'http://xn--rh8hj8g.ws/bye-jezebel.gif', + 'http://xn--rh8hj8g.ws/bye-bitch.gif', + 'http://xn--rh8hj8g.ws/bye-woody.gif', + 'http://xn--rh8hj8g.ws/bye-clarissa.gif', + 'http://xn--rh8hj8g.ws/bye-harrypotter.gif', + 'http://xn--rh8hj8g.ws/bye-random.gif' + ]; + randomise(bot, from, to, message, who, answers); + } + }, + { + name: 'facepalm', + handler: function( bot, from, to, message, who, str ) { + var answers = [ + 'http://4.bp.blogspot.com/-mgnWPcZJcz0/U9K0TnmdyWI/AAAAAAAAD2Q/fpaFlMU5ZOo/s1600/homer_facepalm.jpg', + 'http://static.giantbomb.com/uploads/original/8/88747/1772665-pope_facepalm.jpg', + 'http://memesvault.com/wp-content/uploads/Extreme-Facepalm-Gif-06.png', + 'http://i.imgur.com/wY9Mn.png' + ]; + randomise(bot, from, to, message, who, answers); + } + }, + { + name: 'fine', + handler: function( bot, from, to, message, who, str ) { + var answers = [ 'http://xn--rh8hj8g.ws/fine-wednesday.gif' ]; + randomise(bot, from, to, message, who, answers); + } + }, + { + name: 'fml', + handler: function( bot, from, to, message, who, str ) { + var answers = [ + 'http://s2.quickmeme.com/img/03/0353203cbc2e18150f8c7f45cb7d64efa57d8ac5bd1059add3576fc94ca702f2.jpg', + 'http://i3.kym-cdn.com/photos/images/facebook/000/089/506/128989967490130539.jpg', + 'http://img.memecdn.com/fml_o_577538.jpg', + 'http://img.memecdn.com/FML-horse_o_141347.jpg', + 'http://i0.kym-cdn.com/entries/icons/facebook/000/004/706/FML.jpg', + 'http://don.citarella.net/wp-content/uploads/2012/05/sml.jpg', + 'https://cdn.meme.am/instances/500x/55087958.jpg', + 'https://cdn.meme.am/instances/500x/10377021.jpg', + 'http://i2.kym-cdn.com/photos/images/list/000/478/993/5b1.jpg' + ]; + randomise(bot, from, to, message, who, answers); + } + }, + { + name: 'hi', + handler: function( bot, from, to, message, who, str ) { + var answers = [ + 'http://xn--rh8hj8g.ws/hi-queen.gif', + 'http://xn--rh8hj8g.ws/hi-goofy.gif', + 'http://xn--rh8hj8g.ws/hi-forestgump.gif', + 'http://xn--rh8hj8g.ws/hi-picard.gif', + 'http://xn--rh8hj8g.ws/hi-ironman.gif' + ]; + randomise(bot, from, to, message, who, answers); + } + }, + { + name: ['trollolloll', 'trollsong', 'troll'], + handler: function( bot, from, to, message, who, str ) { + var answers = [ 'https://youtu.be/9zYP8_5IBmU?t=1m47s' ]; + randomise(bot, from, to, message, who, answers); + } + }, + { + name: [ 'pfft', 'pff', 'pft', 'pf' ], + handler: function( bot, from, to, message, who, str ) { + var answers = [ + 'https://s-media-cache-ak0.pinimg.com/736x/a9/26/8f/a9268f451c95945e928121cd91c41281.jpg', + 'http://reactiongif.org/wp-content/uploads/GIF/2014/08/GIF-bfd-big-deal-dwight-meh-sarcastic-the-office-uncaring-whatever-GIF.gif', + 'https://static1.fjcdn.com/thumbnails/comments/Pfft+that+horrible+tattoo+does+_5e04cac8f2e8f5a827be0b3123a888b1.png', + 'http://data.whicdn.com/images/196440384/large.jpg', + 'https://coydavidson.files.wordpress.com/2012/06/pfft.jpg', + 'https://tromoticons.files.wordpress.com/2012/11/yao-ming-pff.png', + 'https://cdn.meme.am/instances/500x/50075843.jpg' + ]; + randomise(bot, from, to, message, who, answers); + } + }, + { + name: 'smh', + handler: function( bot, from, to, message, who, str ) { + var answers = [ + 'http://xn--rh8hj8g.ws/smh-mjf.png', + 'http://xn--rh8hj8g.ws/smh-today.gif', + 'http://xn--rh8hj8g.ws/smh-kanye.gif', + 'http://xn--rh8hj8g.ws/smh-bbad.gif', + 'http://xn--rh8hj8g.ws/smh-drag.gif' + ]; + randomise(bot, from, to, message, who, answers); + } + }, + { + name: 'wat', + handler: function( bot, from, to, message, who, str ) { + var answers = [ 'http://xn--rh8hj8g.ws/wat-shrunkenface.jpg' ]; + randomise(bot, from, to, message, who, answers); + } + }, + { + name: 'wtf', + handler: function( bot, from, to, message, who, str ) { + var answers = [ 'http://xn--rh8hj8g.ws/wtf-baby.png' ]; + randomise(bot, from, to, message, who, answers); + } + }, + { + name: 'yas', + handler: function( bot, from, to, message, who, str ) { + var answers = [ 'http://xn--rh8hj8g.ws/yas-werk.gif' ]; + randomise(bot, from, to, message, who, answers); + } + }, + { + name: [ 'yay', 'yey' ], + handler: function( bot, from, to, message, who, str ) { + var answers = [ 'http://xn--rh8hj8g.ws/yay-homer.jpg' ]; + randomise(bot, from, to, message, who, answers); + } + } +]; + +/** + * this is an array of functions. + */ +module.exports.filters = []; diff --git a/plugins/scrape.js b/plugins/scrape.js new file mode 100644 index 0000000..3bd970a --- /dev/null +++ b/plugins/scrape.js @@ -0,0 +1,47 @@ +var request = require( 'request' ); + +module.exports = {}; + +/** + * this is an array of objects. + * each object needs a `name` parameter and a `handler` parameter. + */ +module.exports.commands = [ + { + name: 'scrape', + handler: function( bot, from, to, message, who, str ) { + // if ( isAdmin ) { + // // Setup site and selector + // var selector = str.match( /'(.*)'/ ); + // selector = selector[1]; + // var site = str.split( ' ' ); + // site = site[0]; + + // // Scrape the site for contents from selector + // request( site, function( error, response, body ) { + // if ( ! error) { + // // Load jsdom for DOM parsing + // jsdom.env( + // body, + // [ 'http://code.jquery.com/jquery-2.2.3.min.js' ], + // function( err, window ) { + // if ( err ) console.log( 'err:', err ); + // var $ = window.jQuery; + // console.log( 'body:', $('body').html() ); + // var msg = $( selector ).text(); + // bot.say( message.args[0], who ? who + ': ' + msg : msg ); + // } + // ); + // } else { + // console.log( error ); + // } + // }); + // } + } + } +]; + +/** + * this is an array of functions. + */ +module.exports.filters = []; diff --git a/plugins/seen.js b/plugins/seen.js new file mode 100644 index 0000000..f159467 --- /dev/null +++ b/plugins/seen.js @@ -0,0 +1,67 @@ +var config = require( '../config' ); + +module.exports = {}; + +var seen = []; + +/** + * this is an array of objects. + * each object needs a `name` parameter and a `handler` parameter. + */ +module.exports.commands = [ + { + name: 'seen', + handler: function( bot, from, to, message, who, str ) { + if ( from != str ) { + var none = true; + if ( config.debug ) { + console.log( '[Seen search] for: ' + str ); + console.log( bot.chans ); + console.log( 'search through:' ); + console.log( config.channels ); + } + // Check channels first + config.channels.forEach( function( pvalue, pindex, parray ) { + // Normalize the case of each user for case insensitive checking + var chanusers = []; + for ( var user in bot.chans[ pvalue ].users ) { + chanusers.push( user.toLowerCase() ); + } + + // Loop through case normalized usernames + for ( var user in bot.chans[ pvalue ].users ) { + if ( none && bot.chans[ pvalue ].users.hasOwnProperty( str ) ) { + bot.say( to, who ? who + ': ' + str + ' is currently in ' + pvalue : from + ': ' + str + ' is currently in ' + pvalue ); + none = false; + } + } + }); + // search through seen array + seen.forEach( function( value, index, array ) { + if ( value.nick == str ) { + // Setup the seen message + var msg = 'Last seen ' + value.nick + ' '; + var time = ' on ' + value.time; + switch ( value.event ) { + case 'nick': + msg += 'changing their nick to ' + value.newnick + time; + break; + case 'part': + msg += 'parting ' + value.channel + time; + if ( value.message ) msg += ' with the message: ' + value.message; + break; + case 'quit': + msg += 'quitting IRC with the message: "' + value.reason + '"' + time; + break; + } + bot.say( to, msg ); + none = false; + } + }); + if ( none ) bot.say( to, who ? who + ': ' + 'I haven\'t seen ' + str : from + ': ' + 'I haven\'t seen ' + str ); + } else { + bot.say( to, 'That\'s hilarious ' + from + '...' ); + } + } + } +]; diff --git a/plugins/simple-replies.js b/plugins/simple-replies.js new file mode 100644 index 0000000..06ca4e4 --- /dev/null +++ b/plugins/simple-replies.js @@ -0,0 +1,64 @@ +module.exports = {}; + +function sayit( msg ) { { + return funtion( bot, from, to, message, who, str ) { + if (!msg) { + msg = str; + } + bot.say( message.args[0], who ? who + ': ' + msg : from + ': ' + msg ); + } +} +/** + * this is an array of objects. + * each object needs a `name` parameter and a `handler` parameter. + */ +module.exports.commands = [ + { name: '_', handler: sayit('Check out the Underscores base theme http://underscores.me') }, + { name: 'ask', handler: sayit('Go ahead and ask your question and someone will assist if they are able.') }, + { name: 'asking', handler: sayit('When asking a question make sure to include the following information: 1) What you want to achieve. 2) How you are attempting to achieve it. 3) What you expect to happen. 4) What is actually happening.') }, + { name: 'cry', handler: sayit('(╯︵╰,)') }, + { name: 'fart', handler: sayit('💩💨💨💨💨') }, + { name: 'finger', handler: sayit('╭∩╮(︶︿︶)╭∩╮') }, + { name: 'first', handler: sayit('Please attempt to disable all plugins, and use one of the default (Twenty*) themes. If the problem goes away, enable them one by one to identify the source of your troubles.') }, + { name: 'hierarchy', handler: sayit('Please refer to the WordPress template hierarchy https://developer.wordpress.org/themes/basics/template-hierarchy/') }, + { name: 'inspect', handler: sayit('Please use the built-in Developer Tools of your browser to fix problems with your website. Right click your page and pick “Inspect Element” (Cr, FF, Op) or press F12-button (IE) to track down CSS problems. Use the console to see JavaScript bugs.') }, + { name: 'linking', handler: sayit('When linking to your website while asking for help, please tell us specifically where to look on the website and what to click to initiate the interaction you are trying to fix') }, + { name: 'paste', handler: sayit('Please use http://wpbin.io to paste your multi-line code samples') }, + { name: 'poop', handler: sayit('💩') }, + { name: 'say', handler: sayit(false) }, + { name: 'shrug', handler: sayit('¯\\_(ツ)_/¯') }, + { name: 'wmojis', handler: sayit('😀😬😁😂😃😄😅😆😌😋🙃🙂😊😉😇😍😘😗😙😚😜😝😛😑😐😶😏🤗😎🤓🤑😒🙄🤔😳😞😟😠😡😩😫😖😣☹🙁😕😔😤😮😱😨😰😯😦😧😢😥😪😓😭😵😲🤐👿😈💩💤😴🤕🤒😷👹👺💀👻👽🤖😺😸🙌😾😿🙀😽😼😻😹🙌🏻🙌🏼🙌🏽🙌🏾🙌🏿👏👏🏻👏🏼👏🏽👏🏾👏🏿') }, + { name: 'yolo', handler: sayit('Yᵒᵘ Oᶰˡʸ Lᶤᵛᵉ Oᶰᶜᵉ') }, + { name: ['calm', 'chill'], handler: sayit('┬──┬ ノ(゜-゜ノ)') }, + { name: ['dance', 'party', 'boogie'], handler: sayit('┏(-_-)┛┗(-_-)┓┗(-_-)┛┏(-_-)┓') }, + { name: ['moving', 'move'], handler: sayit('If you rename the WordPress directory on your server, switch ports or change the hostname http://codex.wordpress.org/Moving_WordPress applies') }, + + { + name: 'blame', + handler: function(bot, from, to, message, who, str) { + if ( str == bot.nick ) { + var msg = "That's hilarious..."; + } else { + var msg = who ? who + ': ' + 'It\'s all ' + str + '\'s fault!' : 'It\'s all ' + str + '\'s fault!'; + } + bot.say( message.args[0], msg ); + } + }, + { + name: 'flip', + handler: function(bot, from, to, message, who, str) { + var prefix = who ? who + ': ' : ''; + if ( str == '.flip!' ) { + var msg = prefix + '┻━┻︵ \\(°□°)/ ︵ ┻━┻'; + } else { + var msg = prefix + '(╯°□°)╯︵ ┻━┻'; + } + bot.say( message.args[0], msg ); + } + } +]; + +/** + * this is an array of functions. + */ +module.exports.filters = []; diff --git a/plugins/soundcloud.js b/plugins/soundcloud.js new file mode 100644 index 0000000..be94ee1 --- /dev/null +++ b/plugins/soundcloud.js @@ -0,0 +1,32 @@ +var config = require( '../config' ); + +var google = require( 'google' ); +google.resultsPerPage = 1; + +module.exports = {}; + +/** + * this is an array of objects. + * each object needs a `name` parameter and a `handler` parameter. + */ +module.exports.commands = [ + { + name: 'soundcloud', + handler: function( bot, from, to, message, who, str ) { + if ( config.debug ) console.log( '[SoundCloud search] for: ' + str ); + google( str + ' site:soundcloud.com', function ( err, next, links ) { + if ( err && config.debug ) console.error( err ); + if ( config.debug ) console.log( links ); + // Show the search results + if ( links.length ) { + bot.say( to, who ? who + ': ' + links[0].link : from + ': ' + links[0].link ); + } + }); + } + } +]; + +/** + * this is an array of functions. + */ +module.exports.filters = []; diff --git a/plugins/spotify.js b/plugins/spotify.js new file mode 100644 index 0000000..9aedb25 --- /dev/null +++ b/plugins/spotify.js @@ -0,0 +1,51 @@ +var config = require( '../config' ); + +var google = require( 'google' ); +google.resultsPerPage = 1; + +module.exports = {}; + +/** + * this is an array of objects. + * each object needs a `name` parameter and a `handler` parameter. + */ +module.exports.commands = [ + { + name: 'spotify', + handler: function( bot, from, to, message, who, str ) { + if ( config.debug ) console.log( '[Spotify search] for: ' + str ); + google( str + ' site:open.spotify.com', function ( err, next, links ) { + if ( err && config.debug ) console.error( err ); + if ( config.debug ) console.log( links ); + // Show the search results + if ( links.length ) { + bot.say( to, who ? who + ': ' + links[0].link : from + ': ' + links[0].link ); + } + }); + } + }, + /** + * futher commands as needed for this plugin + */ + { + name: 'spotifyuri', + handler: function( bot, from, to, message, who, str ) { + if ( config.debug ) console.log( '[Spotify URI search] for: ' + str ); + google( str + ' site:open.spotify.com', function ( err, next, links ) { + if ( err && config.debug ) console.error( err ); + if ( config.debug ) console.log( links ); + // Show the search results + if ( links.length ) { + var link = links[0].link.split('/'); + link = 'spotify:track:' + link[ link.length - 1 ]; + bot.say( to, who ? who + ': ' + link : from + ': ' + link ); + } + }); + } + } +]; + +/** + * this is an array of functions. + */ +module.exports.filters = []; diff --git a/plugins/weather.js b/plugins/weather.js new file mode 100644 index 0000000..0fdd5a8 --- /dev/null +++ b/plugins/weather.js @@ -0,0 +1,36 @@ +var config = require( '../config' ); + +var request = require( 'request' ); + +module.exports = {}; + +/** + * this is an array of objects. + * each object needs a `name` parameter and a `handler` parameter. + */ +module.exports.commands = [ + { + name: 'weather', + handler: function( bot, from, to, message, who, str ) { + // if ( config.hasOwnProperty('openweathermap_api_key') ) { + // if ( config.debug ) console.log( '[Weather Command]' ); + // // Set the API endpoint + // var endpoint = 'http://api.openweathermap.org/data/2.5/weather?q=London&APPID=' + config.openweathermap_api_key; + // // Grab the blockchain information for the current currency type + // request( endpoint, function( error, response, body ) { + // if ( ! error) { + // body = JSON.parse( body ); + // if ( body.hasOwnProperty('name') ) { + // var wind = body.wind.speed; + // var msg = 'Current weather for ' + body.name + ': ' + // var msg = 'Current ' + currency + ' Bitcoin Value: ' + body.symbol + body.last + '. [Buy @ ' + body.symbol + body.buy + ' and Sell @ ' + body.symbol + body.sell + ']'; + // } else { + // var msg = 'Unable to read blockchain information for the "' + currency + '" currency type. Please try again later :('; + // } + // bot.say( message.args[0], who ? who + ': ' + msg : from + ': ' + msg ); + // } + // }); + // } + } + } +]; diff --git a/plugins/wordpressorg.js b/plugins/wordpressorg.js new file mode 100644 index 0000000..5b2ae88 --- /dev/null +++ b/plugins/wordpressorg.js @@ -0,0 +1,83 @@ +var config = require( '../config' ); + +var request = require( 'request' ); +var google = require( 'google' ); +google.resultsPerPage = 1; + +module.exports = {}; + +/** + * this is an array of objects. + * each object needs a `name` parameter and a `handler` parameter. + */ +module.exports.commands = [ + { + name: [ 'codex', 'c' ], + handler: function( bot, from, to, message, who, str ) { + if ( config.debug ) console.log( '[Codex search] for: ' + str ); + + // // Scrape the site for contents from selector + // var site = 'http://google.com/search?q=' + encodeURIComponent( str + ' site:wordpress.org inurl:("codex.wordpress.org"|"developer.wordpress.org")' ); + // request( site, function( error, response, body ) { + // if ( ! error) { + // // Load jsdom for DOM parsing + // jsdom.env( + // body, + // [ 'http://code.jquery.com/jquery-2.2.3.min.js' ], + // function( err, window ) { + // if ( err ) console.log( 'err:', err ); + // var $ = window.jQuery; + // console.log($('#ires .g:first .kv')); + // var msg = $('#ires .g:first .kv').text(); + // bot.say( message.args[0], who ? who + ': ' + msg : msg ); + // } + // ); + // } else { + // console.log( error ); + // } + // }); + + + google( str + ' site:wordpress.org inurl:("codex.wordpress.org"|"developer.wordpress.org")', function ( err, next, links ) { + if ( err && config.debug ) console.error( err ); + // Show the search results + if ( links && links[0].hasOwnProperty('link') ) { + bot.say( to, who ? who + ': ' + links[0].link : from + ': ' + links[0].link ); + } else { + bot.say( to, from + ': weird... your search for: "' + str + ' site:wordpress.org inurl:("codex.wordpress.org"|"developer.wordpress.org")" yielded this: ' + JSON.stringify( links ) ); + } + }); + } + }, + { + name: 'count', + handler: function( bot, from, to, message, who, str ) { + if ( config.debug ) console.log( '[WordPress Count]' ); + request( 'https://wordpress.org/download/counter/?ajaxupdate=1', function( error, response, body ) { + if ( ! error) { + var msg = 'WordPress has been downloaded ' + body + ' times.'; + bot.say( message.args[0], who ? who + ': ' + msg : from + ': ' + msg ); + } + }); + } + }, + { + name: 'p', + handler: function( bot, from, to, message, who, str ) { + if ( config.debug ) console.log( '[Plugin search] for: ' + str ); + google( str + ' wordpress plugin site:https://wordpress.org/plugins', function ( err, next, links ) { + if ( err && config.debug ) console.error( err ); + if ( config.debug ) console.log( links ); + // Show the search results + if ( links.length ) { + bot.say( to, who ? who + ': ' + links[0].link : from + ': ' + links[0].link ); + } + }); + } + } +]; + +/** + * this is an array of functions. + */ +module.exports.filters = []; diff --git a/plugins/wpseek.js b/plugins/wpseek.js new file mode 100644 index 0000000..65e4b82 --- /dev/null +++ b/plugins/wpseek.js @@ -0,0 +1,34 @@ +var config = require( '../config' ); + +var google = require( 'google' ); +google.resultsPerPage = 1; + +module.exports = {}; + +/** + * this is an array of objects. + * each object needs a `name` parameter and a `handler` parameter. + */ +module.exports.commands = [ + { + name: ['wps', 'wpseek'], + handler: function( bot, from, to, message, who, str ) { + if ( config.debug ) console.log( '[wpseek.com search] for: ' + str ); + google( str + ' site:wpseek.com', function ( err, next, links ) { + if ( err && config.debug ) console.error( err ); + // Show the search results + if ( links && links[0].hasOwnProperty('link') ) { + var msg = links[0].link; + } else { + var msg = 'weird... I had troubles getting a link for "' + str + ' site:wpseek.com"'; + } + bot.say( to, who ? who + ': ' + msg : from + ': ' + msg ); + }); + } + } +]; + +/** + * this is an array of functions. + */ +module.exports.filters = []; diff --git a/plugins/youtube.js b/plugins/youtube.js new file mode 100644 index 0000000..0778691 --- /dev/null +++ b/plugins/youtube.js @@ -0,0 +1,34 @@ +var config = require( '../config' ); + +var google = require( 'google' ); +google.resultsPerPage = 1; + +module.exports = {}; + +/** + * this is an array of objects. + * each object needs a `name` parameter and a `handler` parameter. + */ +module.exports.commands = [ + { + name: ['y', 'youtube'], + handler: function( bot, from, to, message, who, str ) { + if ( config.debug ) console.log( '[YouTube search] for: ' + str ); + google( str + ' site:youtube.com', function ( err, next, links ) { + if ( err && config.debug ) console.error( err ); + if ( config.debug ) console.log( links ); + // Show the search results + if ( links[0].link ) { + bot.say( to, who ? who + ': ' + links[0].link : from + ': ' + links[0].link ); + } else { + bot.say( to, from + ': weird... your search for: "' + str + ' site:youtube.com" yielded this: ' + JSON.stringify( links ) ); + } + }); + } + } +]; + +/** + * this is an array of functions. + */ +module.exports.filters = []; From e24b14ef56c8f94ecca35411a0d5f121b3fc42e8 Mon Sep 17 00:00:00 2001 From: Daniel Llewellyn Date: Sun, 18 Dec 2016 21:31:41 +0000 Subject: [PATCH 2/3] add filters plugins now handle filtering (kinda) --- bot.js | 231 +++--------------------------------------- plugins/bugs.js | 24 +++++ plugins/inbox.js | 48 +++++++++ plugins/randomiser.js | 129 +++++++++++++++++------ plugins/reactions.js | 111 ++++++++++++++++++++ plugins/seen.js | 35 +++++++ 6 files changed, 328 insertions(+), 250 deletions(-) create mode 100644 plugins/bugs.js create mode 100644 plugins/reactions.js diff --git a/bot.js b/bot.js index a8f85e7..e692f95 100644 --- a/bot.js +++ b/bot.js @@ -50,94 +50,25 @@ bot.addListener( 'error', function ( message ) { } }); -// Join events -bot.addListener( 'join', function( channel, who ) { - if ( config.debug ) console.log( who + ' joined ' + channel ); - // When other users join the channel (not the bot) - if ( bot.nick != who ) { - // Check for pending .tell commands for this user - var msg = ''; - var told = []; - var inbox = []; - var different = []; - // Loop through each message and build one big message to deliver to the user - tell.forEach( function( value, index, array ) { - if ( value.from == who ) { - if ( config.debug ) console.log( 'Delivering .tell message #' + index + ' to ' + who ); - var date = moment().tz( 'America/New_York' ).format( 'M/DD/YY h:mm:ssa z' ); - msg = '[' + value.from + ' ' + date + ']: ' + value.message; - inbox.push( msg ); - told.push( index ); - if ( different.indexOf( value.from ) < 0 ) different.push( value.from ); - } - }); - - // Display their messages without flooding the channel - if ( inbox.length > 4 ) { - var plural = { - inbox: ( inbox.length > 1 ? 's' : '' ), - different: ( different.length > 1 ? 's' : '' ) - }; - var msg = 'You have ' + inbox.length + ' message' + plural.inbox + ' in your inbox from ' + different.length + ' user' + plural.different + '. Type .inbox to access your messages one page at a time while trying not to flood the channel ;)'; - bot.say( channel, msg ); - } else { - inbox.forEach( function( value, index, array ) { - bot.say( channel, who + ': ' + value ); - }); - } - - // Remove the messages that have been delivered - if ( told.length ) { - told.forEach( function( value, index, array ) { - tell.splice( value, 1 ); - }); - } - } else { - // Actions to perform when the bot joins the channel - } -}); - // Part events bot.addListener( 'part', function( channel, who ) { if ( config.debug ) { console.log( 'Part Handler!!' ); console.log( channel ); } - // Add parting user to the seen array - seen.push({ - event: 'part', - nick: who, - channel: channel, - time: moment().tz( 'America/New_York' ).format( 'MMMM Do YYYY, h:mm:ss a z' ) - }); }); // Quit events bot.addListener( 'quit', function( nick, reason, channels, message ) { if ( config.debug ) console.log( message ); - // Add parting user to the seen array - seen.push({ - event: 'quit', - nick: nick, - channel: channels, - reason: reason, - message: message, - time: moment().tz( 'America/New_York' ).format( 'MMMM Do YYYY, h:mm:ss a z' ) - }); }); -// Nick change events -bot.addListener( 'nick', function ( oldnick, newnick, channels, message ) { - // Update seen array if necessary - seen.push({ - event: 'nick', - nick: oldnick, - newnick: newnick, - channel: channels, - message: message, - time: moment().tz( 'America/New_York' ).format( 'MMMM Do YYYY, h:mm:ss a z' ) - }); -}); +// Allow plugins to set-up their own listeners for events +for (let plugin of plugins) { + if (!!plugin.listen) { + plugin.listen(bot); + } +} // Message events bot.addListener( 'message', function( from, to, text, message ) { @@ -239,151 +170,15 @@ bot.addListener( 'message', function( from, to, text, message ) { console.log( 'sending help message to: ' + who ? who : from ); } } else { - // React to parts of their string if it contains certain text - var msg = ''; - var prefix = who ? who + ': ' : ''; - var reactions = text.match( /(\w+)/g ); - if ( reactions !== null && reactions.length ) { - reactions.forEach( function( value, index, array ) { - // In case we need to check the next word too - var nextword = reactions[ index + 1 ]; - // Loop through all words encompassed in colons :something: like :this: in the whole string - switch ( value.toLowerCase() ) { - case 'cry': - case 'tear': - case 'tears': - case ':~(': - case ':(': - msg += msg.length ? ' (╯︵╰,)' : '(╯︵╰,)'; - break; - case 'party': - case 'dance': - case 'boogie': - msg += msg.length ? ' ┏(-_-)┛┗(-_-)┓┗(-_-)┛┏(-_-)┓' : '┏(-_-)┛┗(-_-)┓┗(-_-)┛┏(-_-)┓'; - break; - case 'fuck': - case 'finger': - if ( value != 'fuck' || ( nextword == 'you' || nextword == 'off' ) ) { - msg += msg.length ? ' ╭∩╮(︶︿︶)╭∩╮' : '╭∩╮(︶︿︶)╭∩╮'; - } else if ( value == 'fuck' && ( nextword == 'this' || nextword == 'life' ) ) { - msg += msg.length ? ' (╯°□°)╯︵ ┻━┻' : '(╯°□°)╯︵ ┻━┻'; - } else if ( value == 'fuck' ) { - msg += msg.length ? ' 🍆🍆' : '🍆🍆'; - } - break; - case 'poop': - case 'crap': - case 'shit': - case 'crappy': - case 'shitty': - msg += msg.length ? ' 💩💩' : '💩💩'; - break; - case 'dead': - case 'skull': - case 'skulls': - msg += msg.length ? ' 💀💀' : '💀💀'; - break; - case 'troll': - case 'trolls': - case 'trolling': - if ( msg.indexOf('https://youtu.be/9zYP8_5IBmU?t=1m47s') == -1 ) { - msg += msg.length ? ' ' : 'https://youtu.be/9zYP8_5IBmU?t=1m47s'; - } - break; - case 'shade': - case 'shades': - msg += msg.length ? ' 😎😎' : '😎😎'; - break; - case 'ghost': - case 'ghosts': - case 'halloween': - msg += msg.length ? ' 👻👻' : '👻👻'; - break; - case 'nerd': - case 'nerds': - case 'nerdy': - msg += msg.length ? ' 🤓🤓' : '🤓🤓'; - break; - case 'bah': - case 'frustrated': - msg += msg.length ? ' (╯°□°)╯︵ ┻━┻' : '(╯°□°)╯︵ ┻━┻'; - break; - case 'chill': - case 'calm': - if ( ( value == 'calm' && nextword == 'down' ) || ( value == 'chill' && nextword == 'out' ) || value == 'chill' ) { - msg += msg.length ? ' ┬──┬ ノ(゜-゜ノ)' : '┬──┬ ノ(゜-゜ノ)'; - } - break; - case 'hmm': - case 'wonder': - case 'thinking': - msg += msg.length ? ' 🤔🤔' : '🤔🤔'; - break; - case 'angel': - case 'innocent': - case 'harmless': - msg += msg.length ? ' 😇😇' : '😇😇'; - break; - case 'shrug': - case 'shrugs': - msg += msg.length ? ' ¯\\_(ツ)_/¯' : '¯\\_(ツ)_/¯'; - break; - case 'yolo': - msg += msg.length ? ' Yᵒᵘ Oᶰˡʸ Lᶤᵛᵉ Oᶰᶜᵉ' : 'Yᵒᵘ Oᶰˡʸ Lᶤᵛᵉ Oᶰᶜᵉ'; - break; - case 'hi': - case 'waves': - case 'hello': - case 'greetings': - var answers = [ 'http://xn--rh8hj8g.ws/hi-queen.gif', 'http://xn--rh8hj8g.ws/hi-goofy.gif', 'http://xn--rh8hj8g.ws/hi-forestgump.gif', 'http://xn--rh8hj8g.ws/hi-picard.gif', 'http://xn--rh8hj8g.ws/hi-ironman.gif' ]; - var answer = answers[ Math.floor( Math.random() * answers.length ) ]; - msg += msg.length ? ' ' + answer : answer; - break; - case 'bye': - case 'goodbye': - case 'farewell': - var answers = [ 'http://xn--rh8hj8g.ws/bye-jezebel.gif', 'http://xn--rh8hj8g.ws/bye-jezebel.gif', 'http://xn--rh8hj8g.ws/bye-bitch.gif', 'http://xn--rh8hj8g.ws/bye-woody.gif', 'http://xn--rh8hj8g.ws/bye-clarissa.gif', 'http://xn--rh8hj8g.ws/bye-harrypotter.gif', 'http://xn--rh8hj8g.ws/bye-random.gif' ]; - var answer = answers[ Math.floor( Math.random() * answers.length ) ]; - msg += msg.length ? ' ' + answer : answer; - break; - case 'wtf': - case 'dafuq': - var answers = [ 'http://xn--rh8hj8g.ws/wtf-baby.png' ]; - var answer = answers[ Math.floor( Math.random() * answers.length ) ]; - msg += msg.length ? ' ' + answer : answer; - break; - case 'yas': - case 'werk': - var answers = [ 'http://xn--rh8hj8g.ws/yas-werk.gif' ]; - var answer = answers[ Math.floor( Math.random() * answers.length ) ]; - msg += msg.length ? ' ' + answer : answer; - break; - case 'smh': - var answers = [ 'http://xn--rh8hj8g.ws/smh-mjf.png', 'http://xn--rh8hj8g.ws/smh-today.gif', 'http://xn--rh8hj8g.ws/smh-kanye.gif', 'http://xn--rh8hj8g.ws/smh-bbad.gif', 'http://xn--rh8hj8g.ws/smh-drag.gif' ]; - var answer = answers[ Math.floor( Math.random() * answers.length ) ]; - msg += msg.length ? ' ' + answer : answer; - break; - } - }); - } - // bug reporting - var bugs = text.match( /(#|(bug\s+)|(https?:\/\/core\.trac\.wordpress\.org\/ticket\/))(\d+)/ig ); - if ( bugs !== null && bugs.length ) { - if ( config.debug ) console.log( bugs ); - bugs.forEach( function( bug ) { - if ( config.debug ) console.log(bug); - bug = bug.replace( /(#|(bug\s+)|(https?:\/\/core\.trac\.wordpress\.org\/ticket\/))/i, '' ); - request( 'https://core.trac.wordpress.org/ticket/' + bug + '?format=rss', function( error, response, body ) { - if ( error ) { - return; + for (plugin of plugins) { + if (!!filters) { + for (filter of plugin.filters) { + if (typeof filter === 'function') { + filter(bot, from, to, message); } - var title = body.match( /(.*?)<\/title>/i ); - if ( config.debug ) console.log( title[1] ); - bot.say( message.args[0], title[1] ); - }); - }); + } + } } - if ( msg.length ) bot.say( message.args[0], msg ); } } }); diff --git a/plugins/bugs.js b/plugins/bugs.js new file mode 100644 index 0000000..017c1c3 --- /dev/null +++ b/plugins/bugs.js @@ -0,0 +1,24 @@ +var config = require( '../config' ); + +var request = require( 'request' ); + +module.exports.filters = []; + +module.exports.filters.push( function( bot, message, text ) { + var bugs = text.match( /(#|(bug\s+)|(https?:\/\/core\.trac\.wordpress\.org\/ticket\/))(\d+)/ig ); + if ( bugs !== null && bugs.length ) { + if ( config.debug ) console.log( bugs ); + bugs.forEach( function( bug ) { + if ( config.debug ) console.log(bug); + bug = bug.replace( /(#|(bug\s+)|(https?:\/\/core\.trac\.wordpress\.org\/ticket\/))/i, '' ); + request( 'https://core.trac.wordpress.org/ticket/' + bug + '?format=rss', function( error, response, body ) { + if ( error ) { + return; + } + var title = body.match( /<title>(.*?)<\/title>/i ); + if ( config.debug ) console.log( title[1] ); + bot.say( message.args[0], title[1] ); + }); + }); + } +}); diff --git a/plugins/inbox.js b/plugins/inbox.js index c572f3d..4a78b31 100644 --- a/plugins/inbox.js +++ b/plugins/inbox.js @@ -86,3 +86,51 @@ module.exports.commands = [ * this is an array of functions. */ module.exports.filters = []; + +module.exports.listen = function(bot) { + bot.addListener( 'join', function( channel, who ) { + if ( config.debug ) console.log( who + ' joined ' + channel ); + // When other users join the channel (not the bot) + if ( bot.nick != who ) { + // Check for pending .tell commands for this user + var msg = ''; + var told = []; + var inbox = []; + var different = []; + // Loop through each message and build one big message to deliver to the user + tell.forEach( function( value, index, array ) { + if ( value.from == who ) { + if ( config.debug ) console.log( 'Delivering .tell message #' + index + ' to ' + who ); + var date = moment().tz( 'America/New_York' ).format( 'M/DD/YY h:mm:ssa z' ); + msg = '[' + value.from + ' ' + date + ']: ' + value.message; + inbox.push( msg ); + told.push( index ); + if ( different.indexOf( value.from ) < 0 ) different.push( value.from ); + } + }); + + // Display their messages without flooding the channel + if ( inbox.length > 4 ) { + var plural = { + inbox: ( inbox.length > 1 ? 's' : '' ), + different: ( different.length > 1 ? 's' : '' ) + }; + var msg = 'You have ' + inbox.length + ' message' + plural.inbox + ' in your inbox from ' + different.length + ' user' + plural.different + '. Type .inbox to access your messages one page at a time while trying not to flood the channel ;)'; + bot.say( channel, msg ); + } else { + inbox.forEach( function( value, index, array ) { + bot.say( channel, who + ': ' + value ); + }); + } + + // Remove the messages that have been delivered + if ( told.length ) { + told.forEach( function( value, index, array ) { + tell.splice( value, 1 ); + }); + } + } else { + // Actions to perform when the bot joins the channel + } + }); +} diff --git a/plugins/randomiser.js b/plugins/randomiser.js index b72e575..bc706f6 100644 --- a/plugins/randomiser.js +++ b/plugins/randomiser.js @@ -1,8 +1,11 @@ module.exports = {}; -function randomise(bot, from, to, message, who, answers) { - var answer = answers[ Math.floor( Math.random() * answers.length ) ]; - var msg = who ? who + ': ' + answer : from + ': ' + answer; +function randomise( answers ) { + return answers[ Math.floor( Math.random() * answers.length ) ]; +} +function randomiseAndSay( bot, from, to, message, who, answers ) { + let msg = ( !!who ) ? who : from; + msg += ': ' + randomise( answers ); bot.say( message.args[0], msg ); } /** @@ -13,7 +16,7 @@ module.exports.commands = [ { name: '8ball', handler: function( bot, from, to, message, who, str ) { - var answers = [ + let answers = [ 'Nope', 'Fat chance', 'Most definitely!', @@ -26,23 +29,23 @@ module.exports.commands = [ 'Pffft... what do you think?', 'Obviously!' ]; - randomise(bot, from, to, message, who, answers); + randomiseAndSay( bot, from, to, message, who, answers ); } }, { name: 'bah', handler: function( bot, from, to, message, who, str ) { - var answers = [ + let answers = [ 'http://xn--rh8hj8g.ws/bah-bloody.gif', 'http://xn--rh8hj8g.ws/bah-brave.gif' ]; - randomise(bot, from, to, message, who, answers); + randomiseAndSay( bot, from, to, message, who, answers ); } }, { name: 'bye', handler: function( bot, from, to, message, who, str ) { - var answers = [ + let answers = [ 'http://xn--rh8hj8g.ws/bye-jezebel.gif', 'http://xn--rh8hj8g.ws/bye-jezebel.gif', 'http://xn--rh8hj8g.ws/bye-bitch.gif', @@ -51,32 +54,32 @@ module.exports.commands = [ 'http://xn--rh8hj8g.ws/bye-harrypotter.gif', 'http://xn--rh8hj8g.ws/bye-random.gif' ]; - randomise(bot, from, to, message, who, answers); + randomiseAndSay( bot, from, to, message, who, answers ); } }, { name: 'facepalm', handler: function( bot, from, to, message, who, str ) { - var answers = [ + let answers = [ 'http://4.bp.blogspot.com/-mgnWPcZJcz0/U9K0TnmdyWI/AAAAAAAAD2Q/fpaFlMU5ZOo/s1600/homer_facepalm.jpg', 'http://static.giantbomb.com/uploads/original/8/88747/1772665-pope_facepalm.jpg', 'http://memesvault.com/wp-content/uploads/Extreme-Facepalm-Gif-06.png', 'http://i.imgur.com/wY9Mn.png' ]; - randomise(bot, from, to, message, who, answers); + randomiseAndSay( bot, from, to, message, who, answers ); } }, { name: 'fine', handler: function( bot, from, to, message, who, str ) { - var answers = [ 'http://xn--rh8hj8g.ws/fine-wednesday.gif' ]; - randomise(bot, from, to, message, who, answers); + let answers = [ 'http://xn--rh8hj8g.ws/fine-wednesday.gif' ]; + randomiseAndSay( bot, from, to, message, who, answers ); } }, { name: 'fml', handler: function( bot, from, to, message, who, str ) { - var answers = [ + let answers = [ 'http://s2.quickmeme.com/img/03/0353203cbc2e18150f8c7f45cb7d64efa57d8ac5bd1059add3576fc94ca702f2.jpg', 'http://i3.kym-cdn.com/photos/images/facebook/000/089/506/128989967490130539.jpg', 'http://img.memecdn.com/fml_o_577538.jpg', @@ -87,33 +90,33 @@ module.exports.commands = [ 'https://cdn.meme.am/instances/500x/10377021.jpg', 'http://i2.kym-cdn.com/photos/images/list/000/478/993/5b1.jpg' ]; - randomise(bot, from, to, message, who, answers); + randomiseAndSay( bot, from, to, message, who, answers ); } }, { name: 'hi', handler: function( bot, from, to, message, who, str ) { - var answers = [ + let answers = [ 'http://xn--rh8hj8g.ws/hi-queen.gif', 'http://xn--rh8hj8g.ws/hi-goofy.gif', 'http://xn--rh8hj8g.ws/hi-forestgump.gif', 'http://xn--rh8hj8g.ws/hi-picard.gif', 'http://xn--rh8hj8g.ws/hi-ironman.gif' ]; - randomise(bot, from, to, message, who, answers); + randomiseAndSay( bot, from, to, message, who, answers ); } }, { name: ['trollolloll', 'trollsong', 'troll'], handler: function( bot, from, to, message, who, str ) { - var answers = [ 'https://youtu.be/9zYP8_5IBmU?t=1m47s' ]; - randomise(bot, from, to, message, who, answers); + let answers = [ 'https://youtu.be/9zYP8_5IBmU?t=1m47s' ]; + randomiseAndSay( bot, from, to, message, who, answers ); } }, { name: [ 'pfft', 'pff', 'pft', 'pf' ], handler: function( bot, from, to, message, who, str ) { - var answers = [ + let answers = [ 'https://s-media-cache-ak0.pinimg.com/736x/a9/26/8f/a9268f451c95945e928121cd91c41281.jpg', 'http://reactiongif.org/wp-content/uploads/GIF/2014/08/GIF-bfd-big-deal-dwight-meh-sarcastic-the-office-uncaring-whatever-GIF.gif', 'https://static1.fjcdn.com/thumbnails/comments/Pfft+that+horrible+tattoo+does+_5e04cac8f2e8f5a827be0b3123a888b1.png', @@ -122,48 +125,48 @@ module.exports.commands = [ 'https://tromoticons.files.wordpress.com/2012/11/yao-ming-pff.png', 'https://cdn.meme.am/instances/500x/50075843.jpg' ]; - randomise(bot, from, to, message, who, answers); + randomiseAndSay( bot, from, to, message, who, answers ); } }, { name: 'smh', handler: function( bot, from, to, message, who, str ) { - var answers = [ + let answers = [ 'http://xn--rh8hj8g.ws/smh-mjf.png', 'http://xn--rh8hj8g.ws/smh-today.gif', 'http://xn--rh8hj8g.ws/smh-kanye.gif', 'http://xn--rh8hj8g.ws/smh-bbad.gif', 'http://xn--rh8hj8g.ws/smh-drag.gif' ]; - randomise(bot, from, to, message, who, answers); + randomiseAndSay( bot, from, to, message, who, answers ); } }, { name: 'wat', handler: function( bot, from, to, message, who, str ) { - var answers = [ 'http://xn--rh8hj8g.ws/wat-shrunkenface.jpg' ]; - randomise(bot, from, to, message, who, answers); + let answers = [ 'http://xn--rh8hj8g.ws/wat-shrunkenface.jpg' ]; + randomiseAndSay( bot, from, to, message, who, answers ); } }, { name: 'wtf', handler: function( bot, from, to, message, who, str ) { - var answers = [ 'http://xn--rh8hj8g.ws/wtf-baby.png' ]; - randomise(bot, from, to, message, who, answers); + let answers = [ 'http://xn--rh8hj8g.ws/wtf-baby.png' ]; + randomiseAndSay( bot, from, to, message, who, answers ); } }, { name: 'yas', handler: function( bot, from, to, message, who, str ) { - var answers = [ 'http://xn--rh8hj8g.ws/yas-werk.gif' ]; - randomise(bot, from, to, message, who, answers); + let answers = [ 'http://xn--rh8hj8g.ws/yas-werk.gif' ]; + randomiseAndSay( bot, from, to, message, who, answers ); } }, { name: [ 'yay', 'yey' ], handler: function( bot, from, to, message, who, str ) { - var answers = [ 'http://xn--rh8hj8g.ws/yay-homer.jpg' ]; - randomise(bot, from, to, message, who, answers); + let answers = [ 'http://xn--rh8hj8g.ws/yay-homer.jpg' ]; + randomiseAndSay( bot, from, to, message, who, answers ); } } ]; @@ -171,4 +174,66 @@ module.exports.commands = [ /** * this is an array of functions. */ -module.exports.filters = []; +module.exports.filters = [ + function( bot, from, to, message, who, text ) { + // React to parts of their string if it contains certain text + let msg = ''; + let prefix = ( !!who ) ? who + ': ' : ''; + let reactions = text.match( /(\w+)/g ); + + for ( reaction of reactions ) { + switch ( reaction ) { + case 'hi': + case 'waves': + case 'hello': + case 'greetings': + let answers = [ + 'http://xn--rh8hj8g.ws/hi-queen.gif', + 'http://xn--rh8hj8g.ws/hi-goofy.gif', + 'http://xn--rh8hj8g.ws/hi-forestgump.gif', + 'http://xn--rh8hj8g.ws/hi-picard.gif', + 'http://xn--rh8hj8g.ws/hi-ironman.gif' + ]; + msg += answer + ' '; + break; + case 'bye': + case 'goodbye': + case 'farewell': + let answers = [ + 'http://xn--rh8hj8g.ws/bye-jezebel.gif', + 'http://xn--rh8hj8g.ws/bye-jezebel.gif', + 'http://xn--rh8hj8g.ws/bye-bitch.gif', + 'http://xn--rh8hj8g.ws/bye-woody.gif', + 'http://xn--rh8hj8g.ws/bye-clarissa.gif', + 'http://xn--rh8hj8g.ws/bye-harrypotter.gif', + 'http://xn--rh8hj8g.ws/bye-random.gif' + ]; + msg += randomise( answers ) + ' '; + break; + case 'wtf': + case 'dafuq': + let answers = [ 'http://xn--rh8hj8g.ws/wtf-baby.png' ]; + msg += randomise( answers ) + ' '; + break; + case 'yas': + case 'werk': + let answers = [ 'http://xn--rh8hj8g.ws/yas-werk.gif' ] + msg += randomise( answers ) + ' '; + break; + case 'smh': + let answers = [ + 'http://xn--rh8hj8g.ws/smh-mjf.png', + 'http://xn--rh8hj8g.ws/smh-today.gif', + 'http://xn--rh8hj8g.ws/smh-kanye.gif', + 'http://xn--rh8hj8g.ws/smh-bbad.gif', + 'http://xn--rh8hj8g.ws/smh-drag.gif' + ]; + msg += randomise( answers ) + ' '; + break; + } + } + if ( !!msg ) { + bot.say( message[0], prefix + msg ); + } + } +]; diff --git a/plugins/reactions.js b/plugins/reactions.js new file mode 100644 index 0000000..4e5533f --- /dev/null +++ b/plugins/reactions.js @@ -0,0 +1,111 @@ +var config = require( '../config' ); + +module.exports.filters = []; + +module.exports.filters.push( function( bot, from, to, message, who, text ) { + // React to parts of their string if it contains certain text + var msg = ''; + var prefix = who ? who + ': ' : ''; + var reactions = text.match( /(\w+)/g ); + + function addMsg( text ) { + if (!!text) { + msg += text + ' '; + } + } + + if ( reactions !== null && reactions.length ) { + reactions.forEach( function( value, index, array ) { + // In case we need to check the next word too + var nextword = reactions[ index + 1 ]; + // Loop through all words encompassed in colons :something: like :this: in the whole string + switch ( value.toLowerCase() ) { + case 'cry': + case 'tear': + case 'tears': + case ':~(': + case ':(': + addMsg('(╯︵╰,)'); + break; + case 'party': + case 'dance': + case 'boogie': + addMsg('┏(-_-)┛┗(-_-)┓┗(-_-)┛┏(-_-)┓'); + break; + case 'fuck': + case 'finger': + if ( value != 'fuck' || ( nextword == 'you' || nextword == 'off' ) ) { + addMsg('╭∩╮(︶︿︶)╭∩╮'); + } else if ( value == 'fuck' && ( nextword == 'this' || nextword == 'life' ) ) { + addMsg('(╯°□°)╯︵ ┻━┻'); + } else if ( value == 'fuck' ) { + addMsg('🍆🍆'); + } + break; + case 'poop': + case 'crap': + case 'shit': + case 'crappy': + case 'shitty': + addMsg('💩💩'); + break; + case 'dead': + case 'skull': + case 'skulls': + addMsg('💀💀'); + break; + case 'troll': + case 'trolls': + case 'trolling': + if ( msg.indexOf('https://youtu.be/9zYP8_5IBmU?t=1m47s') == -1 ) { + addMsg('https://youtu.be/9zYP8_5IBmU?t=1m47s'); + } + break; + case 'shade': + case 'shades': + addMsg('😎😎'); + break; + case 'ghost': + case 'ghosts': + case 'halloween': + addMsg('👻👻'); + break; + case 'nerd': + case 'nerds': + case 'nerdy': + addMsg('🤓🤓'); + break; + case 'bah': + case 'frustrated': + addMsg('(╯°□°)╯︵ ┻━┻'); + break; + case 'chill': + case 'calm': + if ( ( value == 'calm' && nextword == 'down' ) || ( value == 'chill' && nextword == 'out' ) || value == 'chill' ) { + addMsg('┬──┬ ノ(゜-゜ノ)'); + } + break; + case 'hmm': + case 'wonder': + case 'thinking': + addMsg('🤔🤔'); + break; + case 'angel': + case 'innocent': + case 'harmless': + addMsg('😇😇'); + break; + case 'shrug': + case 'shrugs': + addMSg('¯\\_(ツ)_/¯'); + break; + case 'yolo': + addMsg('Yᵒᵘ Oᶰˡʸ Lᶤᵛᵉ Oᶰᶜᵉ'); + break; + } + }); + if (!!msg) { + bot.say( message[0], prefix + msg ); + } + } +}); diff --git a/plugins/seen.js b/plugins/seen.js index f159467..2891bd6 100644 --- a/plugins/seen.js +++ b/plugins/seen.js @@ -65,3 +65,38 @@ module.exports.commands = [ } } ]; + +module.exports.listen = function(bot) { + bot.addListener('part', function(channel, who) { + // Add parting user to the seen array + seen.push({ + event: 'part', + nick: who, + channel: channel, + time: moment().tz( 'America/New_York' ).format( 'MMMM Do YYYY, h:mm:ss a z' ) + }); + }); + + bot.addListener( 'quit', function( nick, reason, channels, message ) { + // Add parting user to the seen array + seen.push({ + event: 'quit', + nick: nick, + channel: channels, + reason: reason, + message: message, + time: moment().tz( 'America/New_York' ).format( 'MMMM Do YYYY, h:mm:ss a z' ) + }); + }); + + bot.addListener( 'nick', function ( oldnick, newnick, channels, message ) { + seen.push({ + event: 'nick', + nick: oldnick, + newnick: newnick, + channel: channels, + message: message, + time: moment().tz( 'America/New_York' ).format( 'MMMM Do YYYY, h:mm:ss a z' ) + }); + }); +} From c71aba72d67a599214abc04dfe8ccafdaea42be2 Mon Sep 17 00:00:00 2001 From: Daniel Llewellyn <daniel@bowlhat.net> Date: Fri, 19 May 2017 07:55:00 +0100 Subject: [PATCH 3/3] directory plugins! this is awesome. and won't eat your babies! --- bot.js | 211 ---------------------------- bot.ts | 38 +++++ package.json | 35 +++-- plugins/bitcoin.js | 39 ------ plugins/bugs.js | 24 ---- plugins/commands.ts | 31 +++++ plugins/css.js | 29 ---- plugins/error/log.ts | 12 ++ plugins/example.js | 40 ------ plugins/google.js | 43 ------ plugins/hookr.js | 29 ---- plugins/ignore.js | 73 ---------- plugins/inbox.js | 136 ------------------ plugins/index.js | 12 -- plugins/index.ts | 79 +++++++++++ plugins/jetpack.js | 34 ----- plugins/jquery.js | 40 ------ plugins/js.js | 29 ---- plugins/kick.js | 31 ----- plugins/math.js | 27 ---- plugins/message/0_ignored.ts | 25 ++++ plugins/message/1_private.ts | 18 +++ plugins/message/bitcoin.ts | 50 +++++++ plugins/message/blame.ts | 33 +++++ plugins/message/css.ts | 24 ++++ plugins/message/flip.ts | 29 ++++ plugins/message/google.ts | 25 ++++ plugins/message/help.ts | 21 +++ plugins/message/hookr.ts | 24 ++++ plugins/message/jetpack.ts | 24 ++++ plugins/message/jquery.ts | 24 ++++ plugins/message/jqueryui.ts | 24 ++++ plugins/message/js.ts | 24 ++++ plugins/message/lmgtfy.ts | 28 ++++ plugins/message/log.ts | 28 ++++ plugins/message/math.ts | 37 +++++ plugins/message/php.ts | 24 ++++ plugins/message/reactions.ts | 127 +++++++++++++++++ plugins/message/soundcloud.ts | 24 ++++ plugins/message/spotify.ts | 24 ++++ plugins/message/spotifyuri.ts | 24 ++++ plugins/message/wporg_bugs.ts | 50 +++++++ plugins/message/wporg_codex.ts | 24 ++++ plugins/message/wporg_count.ts | 34 +++++ plugins/message/wporg_plugin.ts | 24 ++++ plugins/message/wpseek.ts | 26 ++++ plugins/message/youtube.ts | 24 ++++ plugins/part/log.ts | 12 ++ plugins/php.js | 32 ----- plugins/quit/log.ts | 11 ++ plugins/randomiser.js | 239 -------------------------------- plugins/reactions.js | 111 --------------- plugins/registered/nickserv.ts | 25 ++++ plugins/scrape.js | 47 ------- plugins/seen.js | 102 -------------- plugins/simple-replies.js | 64 --------- plugins/soundcloud.js | 32 ----- plugins/spotify.js | 51 ------- plugins/weather.js | 36 ----- plugins/wordpressorg.js | 83 ----------- plugins/wpseek.js | 34 ----- plugins/youtube.js | 34 ----- tsconfig.json | 14 ++ tslint.json | 11 ++ 64 files changed, 1099 insertions(+), 1674 deletions(-) delete mode 100644 bot.js create mode 100644 bot.ts delete mode 100644 plugins/bitcoin.js delete mode 100644 plugins/bugs.js create mode 100644 plugins/commands.ts delete mode 100644 plugins/css.js create mode 100644 plugins/error/log.ts delete mode 100644 plugins/example.js delete mode 100644 plugins/google.js delete mode 100644 plugins/hookr.js delete mode 100644 plugins/ignore.js delete mode 100644 plugins/inbox.js delete mode 100644 plugins/index.js create mode 100644 plugins/index.ts delete mode 100644 plugins/jetpack.js delete mode 100644 plugins/jquery.js delete mode 100644 plugins/js.js delete mode 100644 plugins/kick.js delete mode 100644 plugins/math.js create mode 100644 plugins/message/0_ignored.ts create mode 100644 plugins/message/1_private.ts create mode 100644 plugins/message/bitcoin.ts create mode 100644 plugins/message/blame.ts create mode 100644 plugins/message/css.ts create mode 100644 plugins/message/flip.ts create mode 100644 plugins/message/google.ts create mode 100644 plugins/message/help.ts create mode 100644 plugins/message/hookr.ts create mode 100644 plugins/message/jetpack.ts create mode 100644 plugins/message/jquery.ts create mode 100644 plugins/message/jqueryui.ts create mode 100644 plugins/message/js.ts create mode 100644 plugins/message/lmgtfy.ts create mode 100644 plugins/message/log.ts create mode 100644 plugins/message/math.ts create mode 100644 plugins/message/php.ts create mode 100644 plugins/message/reactions.ts create mode 100644 plugins/message/soundcloud.ts create mode 100644 plugins/message/spotify.ts create mode 100644 plugins/message/spotifyuri.ts create mode 100644 plugins/message/wporg_bugs.ts create mode 100644 plugins/message/wporg_codex.ts create mode 100644 plugins/message/wporg_count.ts create mode 100644 plugins/message/wporg_plugin.ts create mode 100644 plugins/message/wpseek.ts create mode 100644 plugins/message/youtube.ts create mode 100644 plugins/part/log.ts delete mode 100644 plugins/php.js create mode 100644 plugins/quit/log.ts delete mode 100644 plugins/randomiser.js delete mode 100644 plugins/reactions.js create mode 100644 plugins/registered/nickserv.ts delete mode 100644 plugins/scrape.js delete mode 100644 plugins/seen.js delete mode 100644 plugins/simple-replies.js delete mode 100644 plugins/soundcloud.js delete mode 100644 plugins/spotify.js delete mode 100644 plugins/weather.js delete mode 100644 plugins/wordpressorg.js delete mode 100644 plugins/wpseek.js delete mode 100644 plugins/youtube.js create mode 100644 tsconfig.json create mode 100644 tslint.json diff --git a/bot.js b/bot.js deleted file mode 100644 index e692f95..0000000 --- a/bot.js +++ /dev/null @@ -1,211 +0,0 @@ -'use strict'; - -// Includes -var config = require( './config' ); -var irc = require( 'irc' ); -var nickserv = require( 'nickserv' ); - -var request = require( 'request' ); -var cheerio = require( 'cheerio' ); -var jsdom = require( 'jsdom' ); -var moment = require( 'moment-timezone' ); -var async = require( 'async' ); - -var plugins = require( './plugins' ); - -// Initialize global bot variables -var flood = []; - -// Create the bot -var bot = new irc.Client( config.server, config.name, { - // channels: config.channels, - localAddress: config.localAddress, - realName: config.realName, - autoRejoin: true -}); - -// Instantiate nickserv to handle communication between bot and services -var ns = new nickserv( config.name, { - password: config.pass, - email: config.email -}); -ns.attach( 'irc', bot ); - -// Connected events -bot.addListener( 'registered', function ( message ) { - ns.identify( config.pass, function( err ) { - if ( err && config.debug ) console.log( 'nickserv error:' + err ); - config.channels.forEach( function( value, index, array ) { - bot.join( value + ' ' + config.pass ); - bot.send( '/msg chanserv op ' + value + ' ' + config.name ); - }); - }); -}); - -// Error handler -bot.addListener( 'error', function ( message ) { - if ( config.log ) { - console.log( 'BOT ERROR: ' ); - console.log( message ); - } -}); - -// Part events -bot.addListener( 'part', function( channel, who ) { - if ( config.debug ) { - console.log( 'Part Handler!!' ); - console.log( channel ); - } -}); - -// Quit events -bot.addListener( 'quit', function( nick, reason, channels, message ) { - if ( config.debug ) console.log( message ); -}); - -// Allow plugins to set-up their own listeners for events -for (let plugin of plugins) { - if (!!plugin.listen) { - plugin.listen(bot); - } -} - -// Message events -bot.addListener( 'message', function( from, to, text, message ) { - // Debug incoming messages - if ( config.debug ) { - console.log( '============ From ============' ); - console.log( from ); - console.log( '============ To ============' ); - console.log( to ); - console.log( '============ Text ============' ); - console.log( text ); - console.log( '============ MESG ============' ); - console.log( message ); - console.log( '==============================' ); - } - - // Check messages - if ( to == bot.nick ) { - // Private message handler - if ( config.debug ) console.log( 'Private Message Handler!!' ); - bot.say( from, 'Hey ' + from + '... I\'m a bot and I\'m not currently programmed to handle your private messages. Check back soon.' ); - } else { - // Public message handler - - // Check for flooding - // floodCheck( message ); - - // Check for admin - var isAdmin = false; - if ( config.admins.length ) { - config.admins.forEach( function( value, index, array ) { - if ( value.trim().toLowerCase() == from.trim().toLowerCase() ) { - isAdmin = true; - } - }); - } - - // Check for ignored - var isIgnored = false; - if ( config.ignore.length ) { - config.ignore.forEach( function( value, index, array ) { - if ( value.trim().toLowerCase() == from.trim().toLowerCase() ) { - isIgnored = true; - } - }); - } - - // Break up command string - var command = text.match( /^\.(\w+)/ ); - if ( config.debug ) console.log( 'Public Message Handler!!' ); - if ( config.debug ) console.log( command ); - - // Log all channel messages - if ( config.log ) console.log( '[' + to + '] ' + from + ': ' + text + ' - ' + moment().format() ); - - // Check if this message needs to be ignored - if ( ( isIgnored && ! isAdmin ) || config.muted.indexOf( message.args[0] ) > -1 ) { - return; - } else if ( config.debug ) { - console.log( 'ignored:', isIgnored, 'admin:', isAdmin ); - } - - // Parse commands - if ( command && command.length && command[0].charAt(0) == '.' ) { - // Initialize - var cmd = command[1]; - var str = command.input.replace( command[0] + ' ', '' ); - var who = str.split( '> ' ); - if ( who.length == 1 ) { - who = false; - } else { - who = who.pop(); - str = str.replace( ' > ' + who, '' ); - } - - // Debug - if ( config.debug ) { - console.log( 'cmd: ' + cmd ); - console.log( 'str: ' + str ); - console.log( 'who: ' + who ); - } - - for ( var plugin of plugins ) { - if ( !! plugin['commands'] ) { - for ( var command of plugin.commands ) { - if ( !! command['name'] ) { - if ( command.name === cmd || ( command.name instanceof Array && command.name.findIndex( cmd ) > -1 ) ) { - command.handler( bot, from, to, message, who, str ); - } - } - } - } - } - - if ( cmd === 'help' ) { - var commands = [ '.g', '.c', '.p', '.seen', '.tell', '.first', '.paste', '.hierarchy', '._', '.blame', '.ask', '.say' ]; - var helpstr = 'Available Commands: ' + commands.join( ', ' ); - bot.say( who ? who : from, helpstr ); - console.log( 'sending help message to: ' + who ? who : from ); - } - } else { - for (plugin of plugins) { - if (!!filters) { - for (filter of plugin.filters) { - if (typeof filter === 'function') { - filter(bot, from, to, message); - } - } - } - } - } - } -}); - -// Flood protection function (under construction) -function floodCheck( msg ) { - if ( Array.isArray( flood ) && Array.isArray( flood[ msg.nick ] ) ) { - var msgs = flood[ msg.nick ]; - // console.log( 'CHECKING EXISTING FLOOD ITEMS' ); - // if ( msgs.length + 1 == config.floodMessages ) { - // // Kick the user or something and clear the array - // } else { - // // Make an array of times for testing against duration - // var times = []; - // msgs.forEach( function( value, index, array ) { - // times.push( value.time ); - // }); - - // console.log( times ); - // } - } else { - // console.log( 'ADDING NEW FLOOD ITEM' ); - flood[ msg.nick ] = []; - flood[ msg.nick ].push({ time: moment(), nick: msg.nick, user: msg.user, host: msg.host, args: msg.args }); - } - if ( config.debug ) { - // console.log( '==============================' ); - // console.log( flood ); - } -} diff --git a/bot.ts b/bot.ts new file mode 100644 index 0000000..707e118 --- /dev/null +++ b/bot.ts @@ -0,0 +1,38 @@ +import Plugins from './plugins'; +import * as irc from 'irc'; +import * as moment from 'moment'; +import * as config from './config'; + +let bot: irc.Client; +Plugins().then((plugins) => { + // Create the bot + var bot = new irc.Client(config.server, config.name, { + // channels: config.channels, + localAddress: config.localAddress, + realName: config.realName, + autoRejoin: true + }); + + for (let messageType in plugins) { + if (config.debug) { + console.log(`registering plugins for ${messageType}`) + } + bot.addListener(messageType, (...args) => { + var isAdmin = false; + if (config.admins.length) { + config.admins.forEach(function (value, index, array) { + if (value.trim().toLowerCase() === args[0].trim().toLowerCase()) { + isAdmin = true; + } + }); + } + + const p: Promise<any[]> = Promise.resolve(args); + for (let plugin of plugins[messageType]) { + p.then(plugin(bot, isAdmin)); + } + }); + } +}, (reason) => { + console.log(`Failed to load any plugins, quitting: ${reason}`); +}); diff --git a/package.json b/package.json index 10aad21..bd3c1d0 100644 --- a/package.json +++ b/package.json @@ -4,20 +4,31 @@ "description": "An IRC bot to do anything we determine is useful", "main": "bot.js", "dependencies": { - "async": "^1.5.2", - "cheerio": "^0.19.0", - "google": "^1.4.0", - "google-search": "0.0.3", - "irc": "^0.4.0", - "jsdom": "^9.8.3", - "moment": "^2.11.2", - "moment-timezone": "^0.5.0", - "nickserv": "^0.4.1", - "request": "^2.67.0" + "async": "^2.4.0", + "cheerio": "^0.22.0", + "google": "^1.5.0", + "google-search": "^0.0.5", + "irc": "^0.5.2", + "jsdom": "^10.1.0", + "moment": "^2.18.1", + "moment-timezone": "^0.5.13", + "nickserv": "^0.4.4", + "request": "^2.81.0", + "ts-node": "^3.0.4" + }, + "devDependencies": { + "@types/async": "^2.0.40", + "@types/cheerio": "^0.22.1", + "@types/core-js": "^0.9.41", + "@types/irc": "^0.3.32", + "@types/jsdom": "^2.0.30", + "@types/moment": "^2.13.0", + "@types/moment-timezone": "^0.2.34", + "@types/node": "^7.0.18", + "@types/request": "0.0.43" }, - "devDependencies": {}, "scripts": { - "test": "node bot" + "test": "node bot.js" }, "repository": { "type": "git", diff --git a/plugins/bitcoin.js b/plugins/bitcoin.js deleted file mode 100644 index f39dbfe..0000000 --- a/plugins/bitcoin.js +++ /dev/null @@ -1,39 +0,0 @@ -var config = require( '../config' ); - -var request = require( 'request' ); - -module.exports = {}; - -/** - * this is an array of objects. - * each object needs a `name` parameter and a `handler` parameter. - */ -module.exports.commands = [ - { - name: 'bitcoin', - handler: function( bot, from, to, message, who, str ) { - if ( config.debug ) console.log( '[Bitcoin Exchange Rate]' ); - // Check if they want a specific exchange rate - if ( str.indexOf('.bitcoin:') == 0 ) { - var currency = str.split(' '); - currency = currency[0].split(':'); - currency = currency[1].toUpperCase(); - } else { - var currency = 'USD'; - } - // Grab the blockchain information for the current currency type - request( 'https://blockchain.info/ticker', function( error, response, body ) { - if ( ! error) { - body = JSON.parse( body ); - if ( body.hasOwnProperty( currency ) ) { - body = body[ currency ]; - var msg = 'Current ' + currency + ' Bitcoin Value: ' + body.symbol + body.last + '. [Buy @ ' + body.symbol + body.buy + ' and Sell @ ' + body.symbol + body.sell + ']'; - } else { - var msg = 'Unable to read blockchain information for the "' + currency + '" currency type. Please try again later :('; - } - bot.say( message.args[0], who ? who + ': ' + msg : from + ': ' + msg ); - } - }); - } - } -]; diff --git a/plugins/bugs.js b/plugins/bugs.js deleted file mode 100644 index 017c1c3..0000000 --- a/plugins/bugs.js +++ /dev/null @@ -1,24 +0,0 @@ -var config = require( '../config' ); - -var request = require( 'request' ); - -module.exports.filters = []; - -module.exports.filters.push( function( bot, message, text ) { - var bugs = text.match( /(#|(bug\s+)|(https?:\/\/core\.trac\.wordpress\.org\/ticket\/))(\d+)/ig ); - if ( bugs !== null && bugs.length ) { - if ( config.debug ) console.log( bugs ); - bugs.forEach( function( bug ) { - if ( config.debug ) console.log(bug); - bug = bug.replace( /(#|(bug\s+)|(https?:\/\/core\.trac\.wordpress\.org\/ticket\/))/i, '' ); - request( 'https://core.trac.wordpress.org/ticket/' + bug + '?format=rss', function( error, response, body ) { - if ( error ) { - return; - } - var title = body.match( /<title>(.*?)<\/title>/i ); - if ( config.debug ) console.log( title[1] ); - bot.say( message.args[0], title[1] ); - }); - }); - } -}); diff --git a/plugins/commands.ts b/plugins/commands.ts new file mode 100644 index 0000000..bed8d5c --- /dev/null +++ b/plugins/commands.ts @@ -0,0 +1,31 @@ +import * as config from '../config'; + +export function getCommand(text: any): [string, string, string] { + // Break up command string + const command = text.match(/^\.(\S+)/); + if (config.debug) { + console.log(command); + } + + let cmd: string, str: string, who: string; + + // Parse commands + if (command && command.length) { + // Initialize + cmd = command[1]; + str = command.input.replace(`${command[0]} `, ''); + [, who] = str.split('> '); + if (who) { + str = str.replace(` > ${who}`, ''); + } + + // Debug + if (config.debug) { + console.log('cmd: ' + cmd); + console.log('str: ' + str); + console.log('who: ' + who); + } + } + + return [cmd, who, str]; +} diff --git a/plugins/css.js b/plugins/css.js deleted file mode 100644 index aa43490..0000000 --- a/plugins/css.js +++ /dev/null @@ -1,29 +0,0 @@ -var config = require( '../config' ); - -var google = require( 'google' ); -google.resultsPerPage = 1; - -module.exports = {}; - -/** - * this is an array of objects. - * each object needs a `name` parameter and a `handler` parameter. - */ -module.exports.commands = [ - { - name: 'css', - handler: function( bot, from, to, message, who, str ) { - if ( config.debug ) console.log( '[CSS search] for: ' + str ); - google( str + ' site:https://developer.mozilla.org/en-US/docs/Web/CSS', function ( err, next, links ) { - if ( err && config.debug ) console.error( err ); - // Show the search results - bot.say( to, who ? who + ': ' + links[0].link : from + ': ' + links[0].link ); - }); - } - } -]; - -/** - * this is an array of functions. - */ -module.exports.filters = []; diff --git a/plugins/error/log.ts b/plugins/error/log.ts new file mode 100644 index 0000000..e7cf602 --- /dev/null +++ b/plugins/error/log.ts @@ -0,0 +1,12 @@ +import * as config from '../../config'; +import * as console from 'console'; +import * as irc from 'irc'; + +export default (bot: irc.Client) => { + return ([message]: [string]) => { + if (config.log) { + console.log('BOT ERROR: '); + console.log(message); + } + }; +}; diff --git a/plugins/example.js b/plugins/example.js deleted file mode 100644 index 4e6a294..0000000 --- a/plugins/example.js +++ /dev/null @@ -1,40 +0,0 @@ -module.exports = {}; - -/** - * this is an array of objects. - * each object needs a `name` parameter and a `handler` parameter. - */ -module.exports.commands = [ - { - /** - * command invokation text without leading dot - */ - name: 'command', - - /** - * handler function to be executed for this command - */ - handler: function( bot, from, to, message, who, str ) {} - }, - /** - * futher commands as needed for this plugin - */ - { - name: 'command2', - handler: function( bot, from, to, message, who, str ) {} - } -]; - -/** - * this is an array of functions. - */ -module.exports.filters = [ - /** - * handler function for filter - */ - function(bot, data) {}, - /** - * another filter function - */ - function(bot, data) {} -]; diff --git a/plugins/google.js b/plugins/google.js deleted file mode 100644 index dbc5ff5..0000000 --- a/plugins/google.js +++ /dev/null @@ -1,43 +0,0 @@ -var config = require( '../config' ); - -var google = require( 'google' ); -google.resultsPerPage = 1; - -module.exports = {}; - -/** - * this is an array of objects. - * each object needs a `name` parameter and a `handler` parameter. - */ -module.exports.commands = [ - { - name: [ 'g', 'google' ], - handler: function( bot, from, to, message, who, str ) { - if ( config.debug ) console.log( '[Google search] for: ' + str ); - google( str, function ( err, next, links ) { - if ( err && config.debug ) console.error( err ); - // Show the search results - if ( links && links[0].hasOwnProperty('link') ) { - var msg = who ? who + ': ' + links[0].link : from + ': ' + links[0].link; - } else { - var msg = who ? who + ': no Google results found for "' + str + '"' : from + ': no Google results found for "' + str + '"'; - } - bot.say( to, msg ); - }); - } - }, - { - name: ['l', 'lmgtfy'], - handler: function( bot, from, to, message, who, str ) { - if ( config.debug ) console.log( '[lmgtfy.com search] for: ' + str ); - // Show the search results - var link = 'http://lmgtfy.com/?q=' + encodeURIComponent( str ); - bot.say( to, who ? who + ': ' + link : from + ': ' + link ); - } - } -]; - -/** - * this is an array of functions. - */ -module.exports.filters = []; diff --git a/plugins/hookr.js b/plugins/hookr.js deleted file mode 100644 index a3a12f8..0000000 --- a/plugins/hookr.js +++ /dev/null @@ -1,29 +0,0 @@ -var config = require( '../config' ); - -var google = require( 'google' ); -google.resultsPerPage = 1; - -module.exports = {}; - -/** - * this is an array of objects. - * each object needs a `name` parameter and a `handler` parameter. - */ -module.exports.commands = [ - { - name: [ 'h', 'hookr' ], - handler: function( bot, from, to, message, who, str ) { - if ( config.debug ) console.log( '[Hookr search] for: ' + str ); - google( str + ' site:hookr.io', function ( err, next, links ) { - if ( err && config.debug ) console.error( err ); - // Show the search results - bot.say( to, who ? who + ': ' + links[0].link : from + ': ' + links[0].link ); - }); - } - } -]; - -/** - * this is an array of functions. - */ -module.exports.filters = []; diff --git a/plugins/ignore.js b/plugins/ignore.js deleted file mode 100644 index 7854791..0000000 --- a/plugins/ignore.js +++ /dev/null @@ -1,73 +0,0 @@ -var config = require( '../config' ); - -module.exports = {}; - -/** - * this is an array of objects. - * each object needs a `name` parameter and a `handler` parameter. - */ -module.exports.commands = [ - { - name: 'ignore', - handler: function( bot, from, to, message, who, str ) { - // if ( isAdmin ) { - // var msg = ''; - // // Ignore the ignore request if they're trying to ignore an admin - // if ( config.admins.length ) { - // config.admins.forEach( function( value, index, array ) { - // if ( value.trim().toLowerCase() == str.toLowerCase() ) { - // msg = str + ' is an admin and admins cannot be ignored'; - // } - // }); - // } - - // // Ignore them if they're not an admin, let the user know they're already ignored otherwise - // if ( ! msg.length && config.ignore.length ) { - // if ( config.ignore.indexOf( str ) > -1 ) { - // msg = str + ' is already being ignored'; - // } else { - // config.ignore.push( str ); - // msg = str + ' is now being ignored'; - // } - // } - - // // Send ignored message - // bot.say( message.args[0], msg ); - // } - } - }, - { - name: 'unignore', - handler: function( bot, from, to, message, who, str ) { - // if ( isAdmin ) { - // var msg = ''; - // // Ignore the ignore request if they're trying to ignore an admin - // if ( config.admins.length ) { - // config.admins.forEach( function( value, index, array ) { - // if ( value.trim().toLowerCase() == str.toLowerCase() ) { - // msg = str + ' is an admin and admins cannot be ignored'; - // } - // }); - // } - - // // Unignore them if they're not an admin, let the user know they're already unignored otherwise - // if ( ! msg.length && config.ignore.length ) { - // if ( config.ignore.indexOf( str ) > -1 ) { - // config.ignore.splice( config.ignore.indexOf( str ), 1 ); - // msg = str + ' is no longer being ignored'; - // } else { - // msg = str + ' is not being ignored'; - // } - // } - - // // Send ignored message - // bot.say( message.args[0], msg ); - // } - } - } -]; - -/** - * this is an array of functions. - */ -module.exports.filters = []; diff --git a/plugins/inbox.js b/plugins/inbox.js deleted file mode 100644 index 4a78b31..0000000 --- a/plugins/inbox.js +++ /dev/null @@ -1,136 +0,0 @@ -var config = require( '../config' ); - -module.exports = {}; - -var tell = []; - -/** - * this is an array of objects. - * each object needs a `name` parameter and a `handler` parameter. - */ -module.exports.commands = [ - { - name: 'inbox', - handler: function( bot, from, to, message, who, str ) { - // Check for pending .tell commands for this user - var msg = ''; - var told = []; - var inbox = []; - - // Loop through each message and build one big message to deliver to the user - tell.forEach( function( value, index, array ) { - if ( value.from == from && told.length < 4 ) { - if ( config.debug ) console.log( 'Delivering .tell message #' + index + ' to ' + from ); - msg = '[' + value.from + ' ' + value.date + ']: ' + value.message; - inbox.push( msg ); - told.push( index ); - } - }); - - // Display their messages without flooding the channel - if ( inbox.length > 4 ) { - if ( config.debug ) console.log( '> 4 messages in inbox' ); - for ( var i = 0; i < 4; i++ ) { - bot.say( message.args[0], from + ': ' + inbox[ i ] ); - } - for ( var i = 0; i < 4; i++ ) { - inbox.shift(); - } - } else if ( ! inbox.length ) { - bot.say( message.args[0], from + ': you have no messages in your inbox' ); - } else { - if ( config.debug ) console.log( inbox.length + ' messages in inbox' ); - inbox.forEach( function( value, index, array ) { - bot.say( message.args[0], from + ': ' + inbox[ index ] ); - }); - } - - // Remove the messages that have been delivered - if ( told.length ) { - told.forEach( function( value, index, array ) { - tell.splice( value, 1 ); - }); - } - } - }, - { - name: 'tell', - handler: function( bot, from, to, message, who, str ) { - // Tell command - // Make sure their message is setup correctly - var sendto = str.split(' ')[0]; - // Add .tell message to the tell array - if ( config.debug ) console.log( '[Tell ' + sendto + '] ' + str ); - if ( tell.length ) { - var already = false; - tell.forEach( function( value, index, array ) { - if ( value.from == from && value.message == str ) { - already = true; - } - }); - if ( ! already ) { - msg = 'I\'ll deliver your message to ' + sendto + ' the next time they join.'; - tell.push({ from: from, message: str.replace( sendto + ' ', '' ), date: moment().tz( 'America/New_York' ).format( 'M/DD/YY h:mm:ssa z' ) }); - } - } else { - msg = 'I\'ll deliver your message to ' + sendto + ' the next time they join.'; - tell.push({ from: from, message: str.replace( sendto + ' ', '' ), date: moment().tz( 'America/New_York' ).format( 'M/DD/YY h:mm:ssa z' ) }); - } - var msg = who ? who + ': ' + msg : from + ': ' + msg; - bot.say( message.args[0], msg ); - } - } -]; - -/** - * this is an array of functions. - */ -module.exports.filters = []; - -module.exports.listen = function(bot) { - bot.addListener( 'join', function( channel, who ) { - if ( config.debug ) console.log( who + ' joined ' + channel ); - // When other users join the channel (not the bot) - if ( bot.nick != who ) { - // Check for pending .tell commands for this user - var msg = ''; - var told = []; - var inbox = []; - var different = []; - // Loop through each message and build one big message to deliver to the user - tell.forEach( function( value, index, array ) { - if ( value.from == who ) { - if ( config.debug ) console.log( 'Delivering .tell message #' + index + ' to ' + who ); - var date = moment().tz( 'America/New_York' ).format( 'M/DD/YY h:mm:ssa z' ); - msg = '[' + value.from + ' ' + date + ']: ' + value.message; - inbox.push( msg ); - told.push( index ); - if ( different.indexOf( value.from ) < 0 ) different.push( value.from ); - } - }); - - // Display their messages without flooding the channel - if ( inbox.length > 4 ) { - var plural = { - inbox: ( inbox.length > 1 ? 's' : '' ), - different: ( different.length > 1 ? 's' : '' ) - }; - var msg = 'You have ' + inbox.length + ' message' + plural.inbox + ' in your inbox from ' + different.length + ' user' + plural.different + '. Type .inbox to access your messages one page at a time while trying not to flood the channel ;)'; - bot.say( channel, msg ); - } else { - inbox.forEach( function( value, index, array ) { - bot.say( channel, who + ': ' + value ); - }); - } - - // Remove the messages that have been delivered - if ( told.length ) { - told.forEach( function( value, index, array ) { - tell.splice( value, 1 ); - }); - } - } else { - // Actions to perform when the bot joins the channel - } - }); -} diff --git a/plugins/index.js b/plugins/index.js deleted file mode 100644 index 4bfaeaa..0000000 --- a/plugins/index.js +++ /dev/null @@ -1,12 +0,0 @@ -var fs = require( 'fs' ); - -var files = fs.readdirSync( __dirname ); - -module.exports = [] - -var re = /\.js$/; -files.forEach( function(file) { - if ( file.match( re ) ) { - module.exports.push( require( './' + file ) ); - } -} ); diff --git a/plugins/index.ts b/plugins/index.ts new file mode 100644 index 0000000..9941357 --- /dev/null +++ b/plugins/index.ts @@ -0,0 +1,79 @@ +import * as config from '../config'; +import * as console from 'console'; +import * as fs from 'fs'; + +class PluginFuncs { + [key: string]: Function[]; +} + +export default function() { + const re = /(\.js)$/; + + return new Promise<PluginFuncs>((resolve, reject) => { + fs.readdir(__dirname, (err, files) => { + if (err) { + reject(err); + return; + } + + let promises: Promise<PluginFuncs>[] = new Array<Promise<PluginFuncs>>(); + + files.forEach((file) => { + promises.push(new Promise<PluginFuncs>((resolve, reject) => { + const filepath = `${__dirname}/${file}`; + fs.stat(filepath, (err, stats) => { + if (err) { + if (config.debug) { + console.log(`${filepath}: ${err}`) + } + resolve(); + return; + } + + if (stats.isDirectory()) { + fs.readdir(filepath, (err, files) => { + if (err) { + if (config.debug) { + console.log(`${filepath}: ${err}`) + } + resolve(); + return; + } + + let plugins: PluginFuncs = new PluginFuncs(); + files.forEach((plugin) => { + if (plugin.match(re)) { + if (config.debug) { + console.log(`adding plugin ${file}/${plugin}`); + } + if (!plugins[file]) { + plugins[file] = new Array<Function>(); + } + plugins[file].push(require(`./${file}/${plugin}`).default); + } + }); + resolve(plugins); + }); + } else { + resolve(); + } + }); + })); + }); + + Promise.all(promises).then((values) => { + let plugins = new PluginFuncs(); + for (let p of values) { + for (let key in p) { + if (key && p[key]) { + plugins[key] = p[key]; + } + } + } + resolve(plugins); + }).catch((reason) => { + reject(reason); + }); + }); + }) +} diff --git a/plugins/jetpack.js b/plugins/jetpack.js deleted file mode 100644 index 14a2da1..0000000 --- a/plugins/jetpack.js +++ /dev/null @@ -1,34 +0,0 @@ -var config = require( '../config' ); - -var google = require( 'google' ); -google.resultsPerPage = 1; - -module.exports = {}; - -/** - * this is an array of objects. - * each object needs a `name` parameter and a `handler` parameter. - */ -module.exports.commands = [ - { - name: 'jetpack', - handler: function( bot, from, to, message, who, str ) { - if ( config.debug ) console.log( '[JetPack search] for: ' + str ); - google( str + ' site:developer.jetpack.com', function ( err, next, links ) { - if ( err && config.debug ) console.error( err ); - // Show the search results - if ( typeof links[0] == 'undefined' ) { - var msg = who ? who + ': no results found for "' + str + '" on developer.jetpack.com' : from + ': no results found for "' + str + '" on developer.jetpack.com'; - } else { - var msg = who ? who + ': ' + links[0].link : from + ': ' + links[0].link; - } - bot.say( to, msg ); - }); - } - } -]; - -/** - * this is an array of functions. - */ -module.exports.filters = []; diff --git a/plugins/jquery.js b/plugins/jquery.js deleted file mode 100644 index 1f2884a..0000000 --- a/plugins/jquery.js +++ /dev/null @@ -1,40 +0,0 @@ -var config = require( '../config' ); - -var google = require( 'google' ); -google.resultsPerPage = 1; - -module.exports = {}; - -/** - * this is an array of objects. - * each object needs a `name` parameter and a `handler` parameter. - */ -module.exports.commands = [ - { - name: 'jquery', - handler: function( bot, from, to, message, who, str ) { - if ( config.debug ) console.log( '[jQuery API search] for: ' + str ); - google( str + ' site:api.jquery.com', function ( err, next, links ) { - if ( err && config.debug ) console.error( err ); - // Show the search results - bot.say( to, who ? who + ': ' + links[0].link : from + ': ' + links[0].link ); - }); - } - }, - { - name: 'jqueryui', - handler: function( bot, from, to, message, who, str ) { - if ( config.debug ) console.log( '[jQuery UI API search] for: ' + str ); - google( str + ' site:jqueryui.com', function ( err, next, links ) { - if ( err && config.debug ) console.error( err ); - // Show the search results - bot.say( to, who ? who + ': ' + links[0].link : from + ': ' + links[0].link ); - }); - } - } -]; - -/** - * this is an array of functions. - */ -module.exports.filters = []; diff --git a/plugins/js.js b/plugins/js.js deleted file mode 100644 index 62cb292..0000000 --- a/plugins/js.js +++ /dev/null @@ -1,29 +0,0 @@ -var config = require( '../config' ); - -var google = require( 'google' ); -google.resultsPerPage = 1; - -module.exports = {}; - -/** - * this is an array of objects. - * each object needs a `name` parameter and a `handler` parameter. - */ -module.exports.commands = [ - { - name: 'js', - handler: function( bot, from, to, message, who, str ) { - if ( config.debug ) console.log( '[JS search] for: ' + str ); - google( str + ' site:https://developer.mozilla.org/en-US/docs/Web/JavaScript/', function ( err, next, links ) { - if ( err && config.debug ) console.error( err ); - // Show the search results - bot.say( to, who ? who + ': ' + links[0].link : from + ': ' + links[0].link ); - }); - } - } -]; - -/** - * this is an array of functions. - */ -module.exports.filters = []; diff --git a/plugins/kick.js b/plugins/kick.js deleted file mode 100644 index 70f113e..0000000 --- a/plugins/kick.js +++ /dev/null @@ -1,31 +0,0 @@ -module.exports = {}; - -/** - * this is an array of objects. - * each object needs a `name` parameter and a `handler` parameter. - */ -module.exports.commands = [ - { - name: 'kick', - handler: function( bot, from, to, message, who, str ) { - // if ( isAdmin ) { - // // Grab the kick message from the end of the string - // msg = str.split(' '); - // if ( msg.length > 1 ) { - // str = msg[0]; - // msg.splice( 0, 1 ); - // msg = msg.join(' '); - // } - - // // Kick the user - // console.log( 'KICK ' + message.args[0] + ' ' + str + ' ' + msg ); - // bot.send( 'KICK ' + message.args[0] + ' ' + str + ' ' + msg ); - // } - } - } -]; - -/** - * this is an array of functions. - */ -module.exports.filters = []; diff --git a/plugins/math.js b/plugins/math.js deleted file mode 100644 index 7e05dd3..0000000 --- a/plugins/math.js +++ /dev/null @@ -1,27 +0,0 @@ -var config = require( '../config' ); - -var request = require( 'request' ); - -module.exports = {}; - -/** - * this is an array of objects. - * each object needs a `name` parameter and a `handler` parameter. - */ -module.exports.commands = [ - { - name: 'math', - handler: function( bot, from, to, message, who, str ) { - if ( config.debug ) console.log( '[Math Command]' ); - // Get the endpoint - var endpoint = 'http://api.mathjs.org/v1/?expr=' + encodeURIComponent( str ); - // Grab the blockchain information for the current currency type - request( endpoint, function( error, response, body ) { - if ( ! error) { - var msg = body; - bot.say( message.args[0], who ? who + ': ' + msg : from + ': ' + msg ); - } - }); - } - } -]; diff --git a/plugins/message/0_ignored.ts b/plugins/message/0_ignored.ts new file mode 100644 index 0000000..31f47e2 --- /dev/null +++ b/plugins/message/0_ignored.ts @@ -0,0 +1,25 @@ +import * as config from '../../config'; +import * as irc from 'irc'; + +export default (bot: irc.Client, isAdmin: boolean) => { + return ([from, to, text, message]: [string, string, string, object]) => { + // Admins are never ignored + if (isAdmin) { + return [from, to, text, message]; + } + + from = from.trim().toLowerCase(); + + // Check for ignored + if (config.ignore.indexOf(from) > -1) { + return Promise.reject(`${from} has been ignored by an admin`); + } + + // Check for muted + if (config.muted.indexOf(from) > -1) { + return Promise.reject(`${from} has been automatically muted`); + } + + return Promise.resolve([from, to, text, message]); + }; +}; diff --git a/plugins/message/1_private.ts b/plugins/message/1_private.ts new file mode 100644 index 0000000..ea514fe --- /dev/null +++ b/plugins/message/1_private.ts @@ -0,0 +1,18 @@ +import * as config from '../../config'; +import * as console from 'console'; +import * as irc from 'irc'; + +export default (bot: irc.Client, isAdmin: boolean) => { + return ([from, to, text, message]: [string, string, string, object]) => { + if (to === bot.nick) { + // Private message handler + if (config.debug) { + console.log('Private Message Handler!!'); + } + bot.say(from, `Hey ${from}... I'm a bot and I'm not currently programmed to handle your private messages. Check back soon.`); + return Promise.reject('Private messages to the bot are not allowed.'); + } + + return Promise.resolve([from, to, text, message]); + } +} diff --git a/plugins/message/bitcoin.ts b/plugins/message/bitcoin.ts new file mode 100644 index 0000000..6ec82a3 --- /dev/null +++ b/plugins/message/bitcoin.ts @@ -0,0 +1,50 @@ +import * as config from '../../config'; +import { getCommand } from '../commands'; +import * as console from 'console'; +import * as irc from 'irc'; +import * as request from 'request'; + +export default (bot: irc.Client) => { + return ([from, to, text, message]: [string, string, string, object]) => { + return new Promise<any[]>((resolve, reject) => { + let [cmd, who, trimmed] = getCommand(text); + + if (!cmd || cmd !== 'bitcoin' && !cmd.startsWith('bitcoin:')) { + return resolve([from, to, text, message]); + } + + if (config.debug) { + console.log('[Bitcoin Exchange Rate]'); + } + + let currency: string = 'USD'; + // Check if they want a specific exchange rate + if (text.indexOf('.bitcoin:') === 0) { + let s = text.split(' '); + s = s[0].split(':'); + currency = s[1].toUpperCase(); + } + + // Grab the blockchain information for the current currency type + request('https://blockchain.info/ticker', (error, response, body) => { + if (error) { + resolve([from, to, text, message]); + return; + } + + let msg = `Unable to read blockchain information for the "${currency}" currency type. Please try again later :(`; + + body = JSON.parse(body); + if (body.hasOwnProperty(currency)) { + body = body[currency]; + msg = `Current ${currency} Bitcoin Value: ${body.symbol}${body.last}. [Buy @ ${body.symbol}${body.buy} and Sell @ ${body.symbol}${body.sell}]`; + } + + const replyTo: string = who || from; + bot.say(to, `${replyTo}: ${msg}`); + + resolve([from, to, text, message]); + }); + }) + } +} diff --git a/plugins/message/blame.ts b/plugins/message/blame.ts new file mode 100644 index 0000000..03d554f --- /dev/null +++ b/plugins/message/blame.ts @@ -0,0 +1,33 @@ +import * as config from '../../config'; +import { getCommand } from '../commands'; +import * as console from 'console'; +import * as irc from 'irc'; + +export default (bot: irc.Client) => { + return ([from, to, text, message]: [string, string, string, object]) => { + return new Promise<any[]>((resolve, reject) => { + let [cmd, who, trimmed] = getCommand(text); + + if (cmd !== 'jquery') { + return resolve([from, to, text, message]); + } + + if (config.debug) { + console.log(`[jQuery API search] for: ${trimmed}`); + } + + let prefix = ''; + if (who) { + prefix = `${who}: `; + } + + let msg = `${prefix}It's all ${trimmed}'s fault!`; + if (trimmed === bot.nick) { + msg = "That's hilarious..."; + } + + bot.say(to, msg); + resolve([from, to, text, message]) + }) + } +} diff --git a/plugins/message/css.ts b/plugins/message/css.ts new file mode 100644 index 0000000..f3aba74 --- /dev/null +++ b/plugins/message/css.ts @@ -0,0 +1,24 @@ +import * as config from '../../config'; +import { getCommand } from '../commands'; +import * as console from 'console'; +import * as google from '../googleHelper'; +import * as irc from 'irc'; + +export default (bot: irc.Client) => { + return ([from, to, text, message]: [string, string, string, object]) => { + return new Promise<any[]>((resolve, reject) => { + let [cmd, who, trimmed] = getCommand(text); + + if (cmd !== 'css') { + return resolve([from, to, text, message]); + } + + if (config.debug) { + console.log(`[CSS search] for: ${trimmed}`); + } + + const query = `${trimmed} site:https://developer.mozilla.org/en-US/docs/Web/CSS`; + google.query(resolve, bot, query, from, to, who, text, message) + }); + } +} diff --git a/plugins/message/flip.ts b/plugins/message/flip.ts new file mode 100644 index 0000000..5963869 --- /dev/null +++ b/plugins/message/flip.ts @@ -0,0 +1,29 @@ +import { getCommand } from '../commands'; +import * as irc from 'irc'; + +export default (bot: irc.Client) => { + return ([from, to, text, message]: [string, string, string, object]) => { + return new Promise<any[]>((resolve, reject) => { + let [cmd, who, trimmed] = getCommand(text); + + if (cmd !== 'flip' && cmd !== 'flip!') { + return resolve([from, to, text, message]); + } + + let prefix = ''; + if (who) { + prefix = `${who}: `; + } + + let msg = ''; + if (cmd === 'flip!') { + msg = '┻━┻︵ \\(°□°)/ ︵ ┻━┻'; + } else if (cmd === 'flip') { + msg = '(╯°□°)╯︵ ┻━┻'; + } + + bot.say(to, `${prefix}${msg}`); + resolve([from, to, text, message]); + }); + } +} diff --git a/plugins/message/google.ts b/plugins/message/google.ts new file mode 100644 index 0000000..20f4f90 --- /dev/null +++ b/plugins/message/google.ts @@ -0,0 +1,25 @@ +import * as config from '../../config'; +import { getCommand } from '../commands'; +import * as console from 'console'; +import * as google from 'google'; +import * as irc from 'irc'; + +google.resultsPerPage = 1; + +export default (bot: irc.Client) => { + return ([from, to, text, message]: [string, string, string, object]) => { + return new Promise<any[]>((resolve, reject) => { + let [cmd, who, trimmed] = getCommand(text); + + if (cmd !== 'g' && cmd !== 'google') { + return resolve([from, to, text, message]); + } + + if (config.debug) { + console.log(`[Google search] for: ${trimmed}`); + } + + google.query(resolve, bot, trimmed, from, to, who, text, message) + }) + } +} diff --git a/plugins/message/help.ts b/plugins/message/help.ts new file mode 100644 index 0000000..d5bedde --- /dev/null +++ b/plugins/message/help.ts @@ -0,0 +1,21 @@ +import { getCommand } from '../commands'; +import * as console from 'console'; +import * as irc from 'irc'; + +export default (bot: irc.Client) => { + return ([from, to, text, message]: [string, string, string, object]) => { + let [cmd, who, trimmed] = getCommand(text); + + if (cmd === 'help') { + const commands = ['.g', '.c', '.p', '.seen', '.tell', '.first', '.paste', '.hierarchy', '._', '.blame', '.ask', '.say']; + const cmdStr = commands.join(', '); + + const replyTo: string = who || from; + + bot.say(replyTo, `Available Commands: ${cmdStr}`); + console.log(`sending help message to: ${replyTo}`); + } + + return Promise.resolve([from, to, text, message]); + } +} diff --git a/plugins/message/hookr.ts b/plugins/message/hookr.ts new file mode 100644 index 0000000..1e8f7af --- /dev/null +++ b/plugins/message/hookr.ts @@ -0,0 +1,24 @@ +import * as config from '../../config'; +import { getCommand } from '../commands'; +import * as console from 'console'; +import * as google from '../googleHelper'; +import * as irc from 'irc'; + +export default (bot: irc.Client) => { + return ([from, to, text, message]: [string, string, string, object]) => { + return new Promise<any[]>((resolve, reject) => { + let [cmd, who, trimmed] = getCommand(text); + + if (cmd !== 'h' && cmd !== 'hookr') { + return resolve([from, to, text, message]); + } + + if (config.debug) { + console.log(`[Hookr search] for: ${trimmed}`); + } + + const query: string = `${trimmed} site:hookr.io`; + google.query(resolve, bot, query, from, to, who, text, message) + }) + } +} diff --git a/plugins/message/jetpack.ts b/plugins/message/jetpack.ts new file mode 100644 index 0000000..108933f --- /dev/null +++ b/plugins/message/jetpack.ts @@ -0,0 +1,24 @@ +import * as config from '../../config'; +import { getCommand } from '../commands'; +import * as console from 'console'; +import * as google from '../googleHelper'; +import * as irc from 'irc'; + +export default (bot: irc.Client) => { + return ([from, to, text, message]: [string, string, string, object]) => { + return new Promise<any[]>((resolve, reject) => { + let [cmd, who, trimmed] = getCommand(text); + + if (cmd !== 'jetpack') { + return resolve([from, to, text, message]); + } + + if (config.debug) { + console.log(`[JetPack search] for: ${trimmed}`); + } + + const query: string = `${trimmed} site:developer.jetpack.com`; + google.query(resolve, bot, query, from, to, who, text, message) + }) + } +} diff --git a/plugins/message/jquery.ts b/plugins/message/jquery.ts new file mode 100644 index 0000000..0d45208 --- /dev/null +++ b/plugins/message/jquery.ts @@ -0,0 +1,24 @@ +import * as config from '../../config'; +import { getCommand } from '../commands'; +import * as console from 'console'; +import * as google from '../googleHelper'; +import * as irc from 'irc'; + +export default (bot: irc.Client) => { + return ([from, to, text, message]: [string, string, string, object]) => { + return new Promise<any[]>((resolve, reject) => { + let [cmd, who, trimmed] = getCommand(text); + + if (cmd !== 'jquery') { + return resolve([from, to, text, message]); + } + + if (config.debug) { + console.log(`[jQuery API search] for: ${trimmed}`); + } + + const query: string = `${trimmed} site:api.jquery.com`; + google.query(resolve, bot, query, from, to, who, text, message) + }) + } +} diff --git a/plugins/message/jqueryui.ts b/plugins/message/jqueryui.ts new file mode 100644 index 0000000..864ec1e --- /dev/null +++ b/plugins/message/jqueryui.ts @@ -0,0 +1,24 @@ +import * as config from '../../config'; +import { getCommand } from '../commands'; +import * as console from 'console'; +import * as google from '../googleHelper'; +import * as irc from 'irc'; + +export default (bot: irc.Client) => { + return ([from, to, text, message]: [string, string, string, object]) => { + return new Promise<any[]>((resolve, reject) => { + let [cmd, who, trimmed] = getCommand(text); + + if (cmd !== 'jqueryui') { + return resolve([from, to, text, message]); + } + + if (config.debug) { + console.log(`[jQuery UI API search] for: ${trimmed}`); + } + + const query: string = `${trimmed} site:jqueryui.com`; + google.query(resolve, bot, query, from, to, who, text, message) + }); + } +} diff --git a/plugins/message/js.ts b/plugins/message/js.ts new file mode 100644 index 0000000..e6a32b1 --- /dev/null +++ b/plugins/message/js.ts @@ -0,0 +1,24 @@ +import * as config from '../../config'; +import { getCommand } from '../commands'; +import * as console from 'console'; +import * as google from '../googleHelper'; +import * as irc from 'irc'; + +export default (bot: irc.Client) => { + return ([from, to, text, message]: [string, string, string, object]) => { + return new Promise<any[]>((resolve, reject) => { + let [cmd, who, trimmed] = getCommand(text); + + if (cmd !== 'js') { + return resolve([from, to, text, message]); + } + + if (config.debug) { + console.log(`[JS search] for: ${trimmed}`); + } + + const query: string = `${trimmed} site:https://developer.mozilla.org/en-US/docs/Web/JavaScript/`; + google.query(resolve, bot, query, from, to, who, text, message) + }) + } +} diff --git a/plugins/message/lmgtfy.ts b/plugins/message/lmgtfy.ts new file mode 100644 index 0000000..1f0ab36 --- /dev/null +++ b/plugins/message/lmgtfy.ts @@ -0,0 +1,28 @@ +import * as config from '../../config'; +import { getCommand } from '../commands'; +import * as console from 'console'; +import * as irc from 'irc'; + +export default (bot: irc.Client) => { + return ([from, to, text, message]: [string, string, string, object]) => { + return new Promise<any[]>((resolve, reject) => { + let [cmd, who, trimmed] = getCommand(text); + + if (cmd !== 'lmgtfy') { + return resolve([from, to, text, message]); + } + + if (config.debug) { + console.log(`[lmgtfy.com search] for: ${trimmed}`); + } + + // Show the search results + const query: string = encodeURIComponent(trimmed); + const link: string = `http://lmgtfy.com/?q=${query}`; + const replyTo: string = who || from; + + bot.say(to, `${replyTo}: ${link}`); + return resolve([from, to, text, message]); + }) + } +} diff --git a/plugins/message/log.ts b/plugins/message/log.ts new file mode 100644 index 0000000..edd666a --- /dev/null +++ b/plugins/message/log.ts @@ -0,0 +1,28 @@ +import * as config from '../../config'; +import * as console from 'console'; +import * as irc from 'irc'; +import * as moment from 'moment'; + +export default (bot: irc.Client) => { + return ([from, to, text, message]: [string, string, string, object]) => { + // Debug incoming messages + if (config.debug) { + console.log('============ From ============'); + console.log(from); + console.log('============ To ============'); + console.log(to); + console.log('============ Text ============'); + console.log(text); + console.log('============ MESG ============'); + console.log(message); + console.log('=============================='); + } + + // Log all channel messages + if (config.log) { + console.log(`[${to}] ${from}: ${text} - ${moment().format()}`); + } + + return Promise.resolve([from, to, text, message]); + }; +}; diff --git a/plugins/message/math.ts b/plugins/message/math.ts new file mode 100644 index 0000000..8af4fce --- /dev/null +++ b/plugins/message/math.ts @@ -0,0 +1,37 @@ +import * as config from '../../config'; +import { getCommand } from '../commands'; +import * as console from 'console'; +import * as irc from 'irc'; +import * as request from 'request'; + +export default (bot: irc.Client) => { + return ([from, to, text, message]: [string, string, string, object]) => { + return new Promise<any[]>((resolve, reject) => { + let [cmd, who, trimmed] = getCommand(text); + + if (cmd !== 'math') { + return resolve([from, to, text, message]); + } + + if (config.debug) { + console.log('[Math Command]'); + } + + // Get the endpoint + const query: string = encodeURIComponent(trimmed); + const endpoint: string = `http://api.mathjs.org/v1/?expr=${query}`; + // Grab the blockchain information for the current currency type + request(endpoint, (error, response, body) => { + if (error) { + resolve([from, to, text, message]); + return; + } + + const replyTo: string = who || from; + bot.say(from, `${replyTo}: ${body}`); + resolve([from, to, text, message]) + }); + }) + } +} + diff --git a/plugins/message/php.ts b/plugins/message/php.ts new file mode 100644 index 0000000..aafc0b2 --- /dev/null +++ b/plugins/message/php.ts @@ -0,0 +1,24 @@ +import * as config from '../../config'; +import { getCommand } from '../commands'; +import * as console from 'console'; +import * as google from '../googleHelper'; +import * as irc from 'irc'; + +export default (bot: irc.Client) => { + return ([from, to, text, message]: [string, string, string, object]) => { + return new Promise<any[]>((resolve, reject) => { + let [cmd, who, trimmed] = getCommand(text); + + if (cmd !== 'php') { + return resolve([from, to, text, message]); + } + + if (config.debug) { + console.log(`[PHP search] for: ${trimmed}`); + } + + const query: string = `${trimmed} site:http://php.net` + google.query(resolve, bot, query, from, to, who, text, message) + }) + } +} diff --git a/plugins/message/reactions.ts b/plugins/message/reactions.ts new file mode 100644 index 0000000..c1e28e9 --- /dev/null +++ b/plugins/message/reactions.ts @@ -0,0 +1,127 @@ +import * as irc from 'irc'; + +export default (bot: irc.Client) => { + return ([from, to, text, message]: [string, string, string, object]) => { + return new Promise<any[]>((resolve, reject) => { + let [, who] = text.split('> '); + if (who) { + text = text.replace(` > ${who}`, ''); + } + + // React to parts of their string if it contains certain text + let msg = ''; + let prefix = ''; + if (who) { + prefix = `${who}: `; + } + const reactions = text.match(/(\w+)/g); + + function addMsg(text) { + if (!!text) { + msg += text + ' '; + } + } + + if (reactions === null || !reactions.length) { + return resolve([from, to, text, message]); + } + + reactions.forEach(function (value, index, array) { + // In case we need to check the next word too + let nextword = reactions[index + 1]; + + // Loop through all words encompassed in colons :something: like :this: in the whole string + switch (value.toLowerCase()) { + case 'cry': + case 'tear': + case 'tears': + case ':~(': + case ':(': + addMsg('(╯︵╰,)'); + break; + case 'party': + case 'dance': + case 'boogie': + addMsg('┏(-_-)┛┗(-_-)┓┗(-_-)┛┏(-_-)┓'); + break; + case 'fuck': + case 'finger': + if (value !== 'fuck' || (nextword === 'you' || nextword === 'off')) { + addMsg('╭∩╮(︶︿︶)╭∩╮'); + } else if (value === 'fuck' && (nextword === 'this' || nextword === 'life')) { + addMsg('(╯°□°)╯︵ ┻━┻'); + } else if (value === 'fuck') { + addMsg('🍆🍆'); + } + break; + case 'poop': + case 'crap': + case 'shit': + case 'crappy': + case 'shitty': + addMsg('💩💩'); + break; + case 'dead': + case 'skull': + case 'skulls': + addMsg('💀💀'); + break; + case 'troll': + case 'trolls': + case 'trolling': + if (msg.indexOf('https://youtu.be/9zYP8_5IBmU?t=1m47s') === -1) { + addMsg('https://youtu.be/9zYP8_5IBmU?t=1m47s'); + } + break; + case 'shade': + case 'shades': + addMsg('😎😎'); + break; + case 'ghost': + case 'ghosts': + case 'halloween': + addMsg('👻👻'); + break; + case 'nerd': + case 'nerds': + case 'nerdy': + addMsg('🤓🤓'); + break; + case 'bah': + case 'frustrated': + addMsg('(╯°□°)╯︵ ┻━┻'); + break; + case 'chill': + case 'calm': + if ((value === 'calm' && nextword === 'down') || (value === 'chill' && nextword === 'out') || value === 'chill') { + addMsg('┬──┬ ノ(゜-゜ノ)'); + } + break; + case 'hmm': + case 'wonder': + case 'thinking': + addMsg('🤔🤔'); + break; + case 'angel': + case 'innocent': + case 'harmless': + addMsg('😇😇'); + break; + case 'shrug': + case 'shrugs': + addMsg('¯\\_(ツ)_/¯'); + break; + case 'yolo': + addMsg('Yᵒᵘ Oᶰˡʸ Lᶤᵛᵉ Oᶰᶜᵉ'); + break; + } + }); + + if (msg) { + bot.say(to, `${prefix}${msg}`); + } + + return resolve([from, to, text, message]); + }); + } +} diff --git a/plugins/message/soundcloud.ts b/plugins/message/soundcloud.ts new file mode 100644 index 0000000..cbc6c67 --- /dev/null +++ b/plugins/message/soundcloud.ts @@ -0,0 +1,24 @@ +import * as config from '../../config'; +import { getCommand } from '../commands'; +import * as console from 'console'; +import * as google from '../googleHelper'; +import * as irc from 'irc'; + +export default (bot: irc.Client) => { + return ([from, to, text, message]: [string, string, string, object]) => { + return new Promise<any[]>((resolve, reject) => { + let [cmd, who, trimmed] = getCommand(text); + + if (cmd !== 'soundcloud') { + return resolve([from, to, text, message]); + } + + if (config.debug) { + console.log(`[SoundCloud search] for: ${trimmed}`); + } + + const query = `${trimmed} site:soundcloud.com`; + google.query(resolve, bot, query, from, to, who, text, message) + }) + } +} diff --git a/plugins/message/spotify.ts b/plugins/message/spotify.ts new file mode 100644 index 0000000..ba85377 --- /dev/null +++ b/plugins/message/spotify.ts @@ -0,0 +1,24 @@ +import * as config from '../../config'; +import { getCommand } from '../commands'; +import * as console from 'console'; +import * as google from '../googleHelper'; +import * as irc from 'irc'; + +export default (bot: irc.Client) => { + return ([from, to, text, message]: [string, string, string, object]) => { + return new Promise<any[]>((resolve, reject) => { + let [cmd, who, trimmed] = getCommand(text); + + if (cmd !== 'spotify') { + return resolve([from, to, text, message]); + } + + if (config.debug) { + console.log(`[Spotify search] for: ${trimmed}`); + } + + const query = `${trimmed} site:open.spotify.com`; + google.query(resolve, bot, query, from, to, who, text, message) + }) + } +} diff --git a/plugins/message/spotifyuri.ts b/plugins/message/spotifyuri.ts new file mode 100644 index 0000000..3e20b2e --- /dev/null +++ b/plugins/message/spotifyuri.ts @@ -0,0 +1,24 @@ +import * as config from '../../config'; +import { getCommand } from '../commands'; +import * as console from 'console'; +import * as google from '../googleHelper'; +import * as irc from 'irc'; + +export default (bot: irc.Client) => { + return ([from, to, text, message]: [string, string, string, object]) => { + return new Promise<any[]>((resolve, reject) => { + let [cmd, who, trimmed] = getCommand(text); + + if (cmd !== 'spotifyuri') { + return resolve([from, to, text, message]); + } + + if (config.debug) { + console.log(`[Spotify URI search] for: ${trimmed}`); + } + + const query = `${trimmed} site:open.spotify.com` + google.query(resolve, bot, query, from, to, who, text, message) + }) + } +} diff --git a/plugins/message/wporg_bugs.ts b/plugins/message/wporg_bugs.ts new file mode 100644 index 0000000..06ff5b9 --- /dev/null +++ b/plugins/message/wporg_bugs.ts @@ -0,0 +1,50 @@ +import * as config from '../../config'; +import * as console from 'console'; +import * as irc from 'irc'; +import * as request from 'request'; + +export default (bot: irc.Client) => { + return ([from, to, text, message]: [string, string, string, object]) => { + return new Promise<any[]>((resolve, reject) => { + const bugs = text.match(/(#|(bug\s+)|(https?:\/\/core\.trac\.wordpress\.org\/ticket\/))(\d+)/ig); + + if (bugs === null || !bugs.length) { + return Promise.resolve([from, to, text, message]); + } + + if (config.debug) { + console.log(bugs); + } + + let promises: Promise<void>[] = new Array<Promise<void>>(); + bugs.forEach((bug) => { + if (config.debug) { + console.log(bug); + } + + bug = bug.replace(/(#|(bug\s+)|(https?:\/\/core\.trac\.wordpress\.org\/ticket\/))/i, ''); + + promises.push(new Promise<void>((resolve, reject) => { + request(`https://core.trac.wordpress.org/ticket/${bug}?format=rss`, (error, response, body) => { + if (error) { + resolve(); + return; + } + + var title = body.match(/<title>(.*?)<\/title>/i); + if (config.debug) { + console.log(title[1]); + } + + bot.say(to, title[1]); + resolve(); + }); + })) + }) + + Promise.all(promises).then(() => { + return resolve([from, to, text, message]); + }); + }); + } +} diff --git a/plugins/message/wporg_codex.ts b/plugins/message/wporg_codex.ts new file mode 100644 index 0000000..1c2c4df --- /dev/null +++ b/plugins/message/wporg_codex.ts @@ -0,0 +1,24 @@ +import * as config from '../../config'; +import { getCommand } from '../commands'; +import * as google from '../googleHelper'; +import * as console from 'console'; +import * as irc from 'irc'; + +export default (bot: irc.Client) => { + return ([from, to, text, message]: [string, string, string, object]) => { + return new Promise<any[]>((resolve, reject) => { + let [cmd, who, trimmed] = getCommand(text); + + if (cmd !== 'c' && cmd !== 'codex') { + return resolve([from, to, text, message]); + } + + if (config.debug) { + console.log(`[Codex search] for: ${trimmed}`); + } + + const query = `${trimmed} site:wordpress.org inurl:("codex.wordpress.org"|"developer.wordpress.org")`; + google.query(resolve, bot, query, from, to, who, text, message) + }) + } +} diff --git a/plugins/message/wporg_count.ts b/plugins/message/wporg_count.ts new file mode 100644 index 0000000..f376db6 --- /dev/null +++ b/plugins/message/wporg_count.ts @@ -0,0 +1,34 @@ +import * as config from '../../config'; +import { getCommand } from '../commands'; +import * as console from 'console'; +import * as irc from 'irc'; +import * as request from 'request'; + +export default (bot: irc.Client) => { + return ([from, to, text, message]: [string, string, string, object]) => { + return new Promise<any[]>((resolve, reject) => { + let [cmd, who, trimmed] = getCommand(text); + + if (cmd !== 'count') { + return resolve([from, to, text, message]); + } + + if (config.debug) { + console.log('[WordPress Count]'); + } + + request('https://wordpress.org/download/counter/?ajaxupdate=1', (error, response, body) => { + if (error) { + resolve([from, to, text, message]); + return; + } + + const msg: string = `WordPress has been downloaded ${body} times.`; + const replyTo: string = who || from; + bot.say(to, `${replyTo}: ${msg}`); + + resolve([from, to, text, message]); + }); + }) + } +} diff --git a/plugins/message/wporg_plugin.ts b/plugins/message/wporg_plugin.ts new file mode 100644 index 0000000..0435c01 --- /dev/null +++ b/plugins/message/wporg_plugin.ts @@ -0,0 +1,24 @@ +import * as config from '../../config'; +import { getCommand } from '../commands'; +import * as console from 'console'; +import * as google from '../googleHelper'; +import * as irc from 'irc'; + +export default (bot: irc.Client) => { + return ([from, to, text, message]: [string, string, string, object]) => { + return new Promise<any[]>((resolve, reject) => { + let [cmd, who, trimmed] = getCommand(text); + + if (cmd !== 'p') { + return resolve([from, to, text, message]);; + } + + if (config.debug) { + console.log(`[Plugin search] for: ${trimmed}`); + } + + const query: string = `${trimmed} wordpress plugin site:https://wordpress.org/plugins`; + google.query(resolve, bot, query, from, to, who, text, message) + }) + } +} diff --git a/plugins/message/wpseek.ts b/plugins/message/wpseek.ts new file mode 100644 index 0000000..c229cf9 --- /dev/null +++ b/plugins/message/wpseek.ts @@ -0,0 +1,26 @@ +import * as config from '../../config'; +import { getCommand } from '../commands'; +import * as console from 'console'; +import * as google from 'google'; +import * as irc from 'irc'; + +google.resultsPerPage = 1; + +export default (bot: irc.Client) => { + return ([from, to, text, message]: [string, string, string, object]) => { + return new Promise<any[]>((resolve, reject) => { + let [cmd, who, trimmed] = getCommand(text); + + if (cmd !== 'wps' && cmd !== 'wpseek') { + return resolve([from, to, text, message]);; + } + + if (config.debug) { + console.log(`[wpseek.com search] for: ${trimmed}`); + } + + const query = `${trimmed} site:wpseek.com`; + google.query(resolve, bot, query, from, to, who, text, message) + }); + } +} diff --git a/plugins/message/youtube.ts b/plugins/message/youtube.ts new file mode 100644 index 0000000..dbc74bf --- /dev/null +++ b/plugins/message/youtube.ts @@ -0,0 +1,24 @@ +import * as config from '../../config'; +import { getCommand } from '../commands'; +import * as console from 'console'; +import * as google from '../googleHelper'; +import * as irc from 'irc'; + +export default (bot: irc.Client) => { + return ([from, to, text, message]: [string, string, string, object]) => { + return new Promise<any[]>((resolve, reject) => { + let [cmd, who, trimmed] = getCommand(text); + + if (cmd !== 'y' && cmd !== 'youtube') { + return resolve([from, to, text, message]); + } + + if (config.debug) { + console.log(`[YouTube search] for: ${trimmed}`); + } + + const query = `${trimmed} site:youtube.com`; + google.query(resolve, bot, query, from, to, who, text, message) + }); + } +} diff --git a/plugins/part/log.ts b/plugins/part/log.ts new file mode 100644 index 0000000..e2c5d8e --- /dev/null +++ b/plugins/part/log.ts @@ -0,0 +1,12 @@ +import * as config from '../../config'; +import * as console from 'console'; +import * as irc from 'irc'; + +export default (bot: irc.Client) => { + return ([channel, who]: [string, string]) => { + if (config.debug) { + console.log('Part Handler!!'); + console.log(channel); + } + }; +}; diff --git a/plugins/php.js b/plugins/php.js deleted file mode 100644 index 5b4b76a..0000000 --- a/plugins/php.js +++ /dev/null @@ -1,32 +0,0 @@ -var config = require( '../config' ); - -var google = require( 'google' ); -google.resultsPerPage = 1; - -module.exports = {}; - -/** - * this is an array of objects. - * each object needs a `name` parameter and a `handler` parameter. - */ -module.exports.commands = [ - { - name: 'php', - handler: function( bot, from, to, message, who, str ) { - if ( config.debug ) console.log( '[PHP search] for: ' + str ); - google( str + ' site:http://php.net', function ( err, next, links ) { - if ( err && config.debug ) console.error( err ); - if ( config.debug ) console.log( links ); - // Show the search results - if ( links.length ) { - bot.say( to, who ? who + ': ' + links[0].link : from + ': ' + links[0].link ); - } - }); - } - } -]; - -/** - * this is an array of functions. - */ -module.exports.filters = []; diff --git a/plugins/quit/log.ts b/plugins/quit/log.ts new file mode 100644 index 0000000..8912805 --- /dev/null +++ b/plugins/quit/log.ts @@ -0,0 +1,11 @@ +import * as config from '../../config'; +import * as console from 'console'; +import * as irc from 'irc'; + +export default (bot: irc.Client) => { + return ([nick, reason, channels, message]: [string, string, string, string]) => { + if (config.debug) { + console.log(message); + } + }; +}; diff --git a/plugins/randomiser.js b/plugins/randomiser.js deleted file mode 100644 index bc706f6..0000000 --- a/plugins/randomiser.js +++ /dev/null @@ -1,239 +0,0 @@ -module.exports = {}; - -function randomise( answers ) { - return answers[ Math.floor( Math.random() * answers.length ) ]; -} -function randomiseAndSay( bot, from, to, message, who, answers ) { - let msg = ( !!who ) ? who : from; - msg += ': ' + randomise( answers ); - bot.say( message.args[0], msg ); -} -/** - * this is an array of objects. - * each object needs a `name` parameter and a `handler` parameter. - */ -module.exports.commands = [ - { - name: '8ball', - handler: function( bot, from, to, message, who, str ) { - let answers = [ - 'Nope', - 'Fat chance', - 'Most definitely!', - 'Yep', - 'Try again later', - 'How the hell am I supposed to know?', - 'Most likely', - 'Indeed', - 'Not in this lifetime', - 'Pffft... what do you think?', - 'Obviously!' - ]; - randomiseAndSay( bot, from, to, message, who, answers ); - } - }, - { - name: 'bah', - handler: function( bot, from, to, message, who, str ) { - let answers = [ - 'http://xn--rh8hj8g.ws/bah-bloody.gif', - 'http://xn--rh8hj8g.ws/bah-brave.gif' - ]; - randomiseAndSay( bot, from, to, message, who, answers ); - } - }, - { - name: 'bye', - handler: function( bot, from, to, message, who, str ) { - let answers = [ - 'http://xn--rh8hj8g.ws/bye-jezebel.gif', - 'http://xn--rh8hj8g.ws/bye-jezebel.gif', - 'http://xn--rh8hj8g.ws/bye-bitch.gif', - 'http://xn--rh8hj8g.ws/bye-woody.gif', - 'http://xn--rh8hj8g.ws/bye-clarissa.gif', - 'http://xn--rh8hj8g.ws/bye-harrypotter.gif', - 'http://xn--rh8hj8g.ws/bye-random.gif' - ]; - randomiseAndSay( bot, from, to, message, who, answers ); - } - }, - { - name: 'facepalm', - handler: function( bot, from, to, message, who, str ) { - let answers = [ - 'http://4.bp.blogspot.com/-mgnWPcZJcz0/U9K0TnmdyWI/AAAAAAAAD2Q/fpaFlMU5ZOo/s1600/homer_facepalm.jpg', - 'http://static.giantbomb.com/uploads/original/8/88747/1772665-pope_facepalm.jpg', - 'http://memesvault.com/wp-content/uploads/Extreme-Facepalm-Gif-06.png', - 'http://i.imgur.com/wY9Mn.png' - ]; - randomiseAndSay( bot, from, to, message, who, answers ); - } - }, - { - name: 'fine', - handler: function( bot, from, to, message, who, str ) { - let answers = [ 'http://xn--rh8hj8g.ws/fine-wednesday.gif' ]; - randomiseAndSay( bot, from, to, message, who, answers ); - } - }, - { - name: 'fml', - handler: function( bot, from, to, message, who, str ) { - let answers = [ - 'http://s2.quickmeme.com/img/03/0353203cbc2e18150f8c7f45cb7d64efa57d8ac5bd1059add3576fc94ca702f2.jpg', - 'http://i3.kym-cdn.com/photos/images/facebook/000/089/506/128989967490130539.jpg', - 'http://img.memecdn.com/fml_o_577538.jpg', - 'http://img.memecdn.com/FML-horse_o_141347.jpg', - 'http://i0.kym-cdn.com/entries/icons/facebook/000/004/706/FML.jpg', - 'http://don.citarella.net/wp-content/uploads/2012/05/sml.jpg', - 'https://cdn.meme.am/instances/500x/55087958.jpg', - 'https://cdn.meme.am/instances/500x/10377021.jpg', - 'http://i2.kym-cdn.com/photos/images/list/000/478/993/5b1.jpg' - ]; - randomiseAndSay( bot, from, to, message, who, answers ); - } - }, - { - name: 'hi', - handler: function( bot, from, to, message, who, str ) { - let answers = [ - 'http://xn--rh8hj8g.ws/hi-queen.gif', - 'http://xn--rh8hj8g.ws/hi-goofy.gif', - 'http://xn--rh8hj8g.ws/hi-forestgump.gif', - 'http://xn--rh8hj8g.ws/hi-picard.gif', - 'http://xn--rh8hj8g.ws/hi-ironman.gif' - ]; - randomiseAndSay( bot, from, to, message, who, answers ); - } - }, - { - name: ['trollolloll', 'trollsong', 'troll'], - handler: function( bot, from, to, message, who, str ) { - let answers = [ 'https://youtu.be/9zYP8_5IBmU?t=1m47s' ]; - randomiseAndSay( bot, from, to, message, who, answers ); - } - }, - { - name: [ 'pfft', 'pff', 'pft', 'pf' ], - handler: function( bot, from, to, message, who, str ) { - let answers = [ - 'https://s-media-cache-ak0.pinimg.com/736x/a9/26/8f/a9268f451c95945e928121cd91c41281.jpg', - 'http://reactiongif.org/wp-content/uploads/GIF/2014/08/GIF-bfd-big-deal-dwight-meh-sarcastic-the-office-uncaring-whatever-GIF.gif', - 'https://static1.fjcdn.com/thumbnails/comments/Pfft+that+horrible+tattoo+does+_5e04cac8f2e8f5a827be0b3123a888b1.png', - 'http://data.whicdn.com/images/196440384/large.jpg', - 'https://coydavidson.files.wordpress.com/2012/06/pfft.jpg', - 'https://tromoticons.files.wordpress.com/2012/11/yao-ming-pff.png', - 'https://cdn.meme.am/instances/500x/50075843.jpg' - ]; - randomiseAndSay( bot, from, to, message, who, answers ); - } - }, - { - name: 'smh', - handler: function( bot, from, to, message, who, str ) { - let answers = [ - 'http://xn--rh8hj8g.ws/smh-mjf.png', - 'http://xn--rh8hj8g.ws/smh-today.gif', - 'http://xn--rh8hj8g.ws/smh-kanye.gif', - 'http://xn--rh8hj8g.ws/smh-bbad.gif', - 'http://xn--rh8hj8g.ws/smh-drag.gif' - ]; - randomiseAndSay( bot, from, to, message, who, answers ); - } - }, - { - name: 'wat', - handler: function( bot, from, to, message, who, str ) { - let answers = [ 'http://xn--rh8hj8g.ws/wat-shrunkenface.jpg' ]; - randomiseAndSay( bot, from, to, message, who, answers ); - } - }, - { - name: 'wtf', - handler: function( bot, from, to, message, who, str ) { - let answers = [ 'http://xn--rh8hj8g.ws/wtf-baby.png' ]; - randomiseAndSay( bot, from, to, message, who, answers ); - } - }, - { - name: 'yas', - handler: function( bot, from, to, message, who, str ) { - let answers = [ 'http://xn--rh8hj8g.ws/yas-werk.gif' ]; - randomiseAndSay( bot, from, to, message, who, answers ); - } - }, - { - name: [ 'yay', 'yey' ], - handler: function( bot, from, to, message, who, str ) { - let answers = [ 'http://xn--rh8hj8g.ws/yay-homer.jpg' ]; - randomiseAndSay( bot, from, to, message, who, answers ); - } - } -]; - -/** - * this is an array of functions. - */ -module.exports.filters = [ - function( bot, from, to, message, who, text ) { - // React to parts of their string if it contains certain text - let msg = ''; - let prefix = ( !!who ) ? who + ': ' : ''; - let reactions = text.match( /(\w+)/g ); - - for ( reaction of reactions ) { - switch ( reaction ) { - case 'hi': - case 'waves': - case 'hello': - case 'greetings': - let answers = [ - 'http://xn--rh8hj8g.ws/hi-queen.gif', - 'http://xn--rh8hj8g.ws/hi-goofy.gif', - 'http://xn--rh8hj8g.ws/hi-forestgump.gif', - 'http://xn--rh8hj8g.ws/hi-picard.gif', - 'http://xn--rh8hj8g.ws/hi-ironman.gif' - ]; - msg += answer + ' '; - break; - case 'bye': - case 'goodbye': - case 'farewell': - let answers = [ - 'http://xn--rh8hj8g.ws/bye-jezebel.gif', - 'http://xn--rh8hj8g.ws/bye-jezebel.gif', - 'http://xn--rh8hj8g.ws/bye-bitch.gif', - 'http://xn--rh8hj8g.ws/bye-woody.gif', - 'http://xn--rh8hj8g.ws/bye-clarissa.gif', - 'http://xn--rh8hj8g.ws/bye-harrypotter.gif', - 'http://xn--rh8hj8g.ws/bye-random.gif' - ]; - msg += randomise( answers ) + ' '; - break; - case 'wtf': - case 'dafuq': - let answers = [ 'http://xn--rh8hj8g.ws/wtf-baby.png' ]; - msg += randomise( answers ) + ' '; - break; - case 'yas': - case 'werk': - let answers = [ 'http://xn--rh8hj8g.ws/yas-werk.gif' ] - msg += randomise( answers ) + ' '; - break; - case 'smh': - let answers = [ - 'http://xn--rh8hj8g.ws/smh-mjf.png', - 'http://xn--rh8hj8g.ws/smh-today.gif', - 'http://xn--rh8hj8g.ws/smh-kanye.gif', - 'http://xn--rh8hj8g.ws/smh-bbad.gif', - 'http://xn--rh8hj8g.ws/smh-drag.gif' - ]; - msg += randomise( answers ) + ' '; - break; - } - } - if ( !!msg ) { - bot.say( message[0], prefix + msg ); - } - } -]; diff --git a/plugins/reactions.js b/plugins/reactions.js deleted file mode 100644 index 4e5533f..0000000 --- a/plugins/reactions.js +++ /dev/null @@ -1,111 +0,0 @@ -var config = require( '../config' ); - -module.exports.filters = []; - -module.exports.filters.push( function( bot, from, to, message, who, text ) { - // React to parts of their string if it contains certain text - var msg = ''; - var prefix = who ? who + ': ' : ''; - var reactions = text.match( /(\w+)/g ); - - function addMsg( text ) { - if (!!text) { - msg += text + ' '; - } - } - - if ( reactions !== null && reactions.length ) { - reactions.forEach( function( value, index, array ) { - // In case we need to check the next word too - var nextword = reactions[ index + 1 ]; - // Loop through all words encompassed in colons :something: like :this: in the whole string - switch ( value.toLowerCase() ) { - case 'cry': - case 'tear': - case 'tears': - case ':~(': - case ':(': - addMsg('(╯︵╰,)'); - break; - case 'party': - case 'dance': - case 'boogie': - addMsg('┏(-_-)┛┗(-_-)┓┗(-_-)┛┏(-_-)┓'); - break; - case 'fuck': - case 'finger': - if ( value != 'fuck' || ( nextword == 'you' || nextword == 'off' ) ) { - addMsg('╭∩╮(︶︿︶)╭∩╮'); - } else if ( value == 'fuck' && ( nextword == 'this' || nextword == 'life' ) ) { - addMsg('(╯°□°)╯︵ ┻━┻'); - } else if ( value == 'fuck' ) { - addMsg('🍆🍆'); - } - break; - case 'poop': - case 'crap': - case 'shit': - case 'crappy': - case 'shitty': - addMsg('💩💩'); - break; - case 'dead': - case 'skull': - case 'skulls': - addMsg('💀💀'); - break; - case 'troll': - case 'trolls': - case 'trolling': - if ( msg.indexOf('https://youtu.be/9zYP8_5IBmU?t=1m47s') == -1 ) { - addMsg('https://youtu.be/9zYP8_5IBmU?t=1m47s'); - } - break; - case 'shade': - case 'shades': - addMsg('😎😎'); - break; - case 'ghost': - case 'ghosts': - case 'halloween': - addMsg('👻👻'); - break; - case 'nerd': - case 'nerds': - case 'nerdy': - addMsg('🤓🤓'); - break; - case 'bah': - case 'frustrated': - addMsg('(╯°□°)╯︵ ┻━┻'); - break; - case 'chill': - case 'calm': - if ( ( value == 'calm' && nextword == 'down' ) || ( value == 'chill' && nextword == 'out' ) || value == 'chill' ) { - addMsg('┬──┬ ノ(゜-゜ノ)'); - } - break; - case 'hmm': - case 'wonder': - case 'thinking': - addMsg('🤔🤔'); - break; - case 'angel': - case 'innocent': - case 'harmless': - addMsg('😇😇'); - break; - case 'shrug': - case 'shrugs': - addMSg('¯\\_(ツ)_/¯'); - break; - case 'yolo': - addMsg('Yᵒᵘ Oᶰˡʸ Lᶤᵛᵉ Oᶰᶜᵉ'); - break; - } - }); - if (!!msg) { - bot.say( message[0], prefix + msg ); - } - } -}); diff --git a/plugins/registered/nickserv.ts b/plugins/registered/nickserv.ts new file mode 100644 index 0000000..aec2db0 --- /dev/null +++ b/plugins/registered/nickserv.ts @@ -0,0 +1,25 @@ +import * as config from '../../config'; +import * as console from 'console'; +import * as irc from 'irc'; +import * as nickserv from 'nickserv'; + +export default (bot: irc.Client) => { + // Instantiate nickserv to handle communication between bot and services + const ns: nickserv = new nickserv(config.name, { + password: config.pass, + email: config.email + }); + ns.attach('irc', bot); + + return ([message]: [string]) => { + ns.identify(config.pass, function (err) { + if (err && config.debug) { + console.log(`nickserv error: ${err}`); + } + config.channels.forEach(function (value, index, array) { + bot.join(`${value} ${config.pass}`); + bot.send(`/msg chanserv op ${value} ${config.name}`); + }); + }); + }; +}; diff --git a/plugins/scrape.js b/plugins/scrape.js deleted file mode 100644 index 3bd970a..0000000 --- a/plugins/scrape.js +++ /dev/null @@ -1,47 +0,0 @@ -var request = require( 'request' ); - -module.exports = {}; - -/** - * this is an array of objects. - * each object needs a `name` parameter and a `handler` parameter. - */ -module.exports.commands = [ - { - name: 'scrape', - handler: function( bot, from, to, message, who, str ) { - // if ( isAdmin ) { - // // Setup site and selector - // var selector = str.match( /'(.*)'/ ); - // selector = selector[1]; - // var site = str.split( ' ' ); - // site = site[0]; - - // // Scrape the site for contents from selector - // request( site, function( error, response, body ) { - // if ( ! error) { - // // Load jsdom for DOM parsing - // jsdom.env( - // body, - // [ 'http://code.jquery.com/jquery-2.2.3.min.js' ], - // function( err, window ) { - // if ( err ) console.log( 'err:', err ); - // var $ = window.jQuery; - // console.log( 'body:', $('body').html() ); - // var msg = $( selector ).text(); - // bot.say( message.args[0], who ? who + ': ' + msg : msg ); - // } - // ); - // } else { - // console.log( error ); - // } - // }); - // } - } - } -]; - -/** - * this is an array of functions. - */ -module.exports.filters = []; diff --git a/plugins/seen.js b/plugins/seen.js deleted file mode 100644 index 2891bd6..0000000 --- a/plugins/seen.js +++ /dev/null @@ -1,102 +0,0 @@ -var config = require( '../config' ); - -module.exports = {}; - -var seen = []; - -/** - * this is an array of objects. - * each object needs a `name` parameter and a `handler` parameter. - */ -module.exports.commands = [ - { - name: 'seen', - handler: function( bot, from, to, message, who, str ) { - if ( from != str ) { - var none = true; - if ( config.debug ) { - console.log( '[Seen search] for: ' + str ); - console.log( bot.chans ); - console.log( 'search through:' ); - console.log( config.channels ); - } - // Check channels first - config.channels.forEach( function( pvalue, pindex, parray ) { - // Normalize the case of each user for case insensitive checking - var chanusers = []; - for ( var user in bot.chans[ pvalue ].users ) { - chanusers.push( user.toLowerCase() ); - } - - // Loop through case normalized usernames - for ( var user in bot.chans[ pvalue ].users ) { - if ( none && bot.chans[ pvalue ].users.hasOwnProperty( str ) ) { - bot.say( to, who ? who + ': ' + str + ' is currently in ' + pvalue : from + ': ' + str + ' is currently in ' + pvalue ); - none = false; - } - } - }); - // search through seen array - seen.forEach( function( value, index, array ) { - if ( value.nick == str ) { - // Setup the seen message - var msg = 'Last seen ' + value.nick + ' '; - var time = ' on ' + value.time; - switch ( value.event ) { - case 'nick': - msg += 'changing their nick to ' + value.newnick + time; - break; - case 'part': - msg += 'parting ' + value.channel + time; - if ( value.message ) msg += ' with the message: ' + value.message; - break; - case 'quit': - msg += 'quitting IRC with the message: "' + value.reason + '"' + time; - break; - } - bot.say( to, msg ); - none = false; - } - }); - if ( none ) bot.say( to, who ? who + ': ' + 'I haven\'t seen ' + str : from + ': ' + 'I haven\'t seen ' + str ); - } else { - bot.say( to, 'That\'s hilarious ' + from + '...' ); - } - } - } -]; - -module.exports.listen = function(bot) { - bot.addListener('part', function(channel, who) { - // Add parting user to the seen array - seen.push({ - event: 'part', - nick: who, - channel: channel, - time: moment().tz( 'America/New_York' ).format( 'MMMM Do YYYY, h:mm:ss a z' ) - }); - }); - - bot.addListener( 'quit', function( nick, reason, channels, message ) { - // Add parting user to the seen array - seen.push({ - event: 'quit', - nick: nick, - channel: channels, - reason: reason, - message: message, - time: moment().tz( 'America/New_York' ).format( 'MMMM Do YYYY, h:mm:ss a z' ) - }); - }); - - bot.addListener( 'nick', function ( oldnick, newnick, channels, message ) { - seen.push({ - event: 'nick', - nick: oldnick, - newnick: newnick, - channel: channels, - message: message, - time: moment().tz( 'America/New_York' ).format( 'MMMM Do YYYY, h:mm:ss a z' ) - }); - }); -} diff --git a/plugins/simple-replies.js b/plugins/simple-replies.js deleted file mode 100644 index 06ca4e4..0000000 --- a/plugins/simple-replies.js +++ /dev/null @@ -1,64 +0,0 @@ -module.exports = {}; - -function sayit( msg ) { { - return funtion( bot, from, to, message, who, str ) { - if (!msg) { - msg = str; - } - bot.say( message.args[0], who ? who + ': ' + msg : from + ': ' + msg ); - } -} -/** - * this is an array of objects. - * each object needs a `name` parameter and a `handler` parameter. - */ -module.exports.commands = [ - { name: '_', handler: sayit('Check out the Underscores base theme http://underscores.me') }, - { name: 'ask', handler: sayit('Go ahead and ask your question and someone will assist if they are able.') }, - { name: 'asking', handler: sayit('When asking a question make sure to include the following information: 1) What you want to achieve. 2) How you are attempting to achieve it. 3) What you expect to happen. 4) What is actually happening.') }, - { name: 'cry', handler: sayit('(╯︵╰,)') }, - { name: 'fart', handler: sayit('💩💨💨💨💨') }, - { name: 'finger', handler: sayit('╭∩╮(︶︿︶)╭∩╮') }, - { name: 'first', handler: sayit('Please attempt to disable all plugins, and use one of the default (Twenty*) themes. If the problem goes away, enable them one by one to identify the source of your troubles.') }, - { name: 'hierarchy', handler: sayit('Please refer to the WordPress template hierarchy https://developer.wordpress.org/themes/basics/template-hierarchy/') }, - { name: 'inspect', handler: sayit('Please use the built-in Developer Tools of your browser to fix problems with your website. Right click your page and pick “Inspect Element” (Cr, FF, Op) or press F12-button (IE) to track down CSS problems. Use the console to see JavaScript bugs.') }, - { name: 'linking', handler: sayit('When linking to your website while asking for help, please tell us specifically where to look on the website and what to click to initiate the interaction you are trying to fix') }, - { name: 'paste', handler: sayit('Please use http://wpbin.io to paste your multi-line code samples') }, - { name: 'poop', handler: sayit('💩') }, - { name: 'say', handler: sayit(false) }, - { name: 'shrug', handler: sayit('¯\\_(ツ)_/¯') }, - { name: 'wmojis', handler: sayit('😀😬😁😂😃😄😅😆😌😋🙃🙂😊😉😇😍😘😗😙😚😜😝😛😑😐😶😏🤗😎🤓🤑😒🙄🤔😳😞😟😠😡😩😫😖😣☹🙁😕😔😤😮😱😨😰😯😦😧😢😥😪😓😭😵😲🤐👿😈💩💤😴🤕🤒😷👹👺💀👻👽🤖😺😸🙌😾😿🙀😽😼😻😹🙌🏻🙌🏼🙌🏽🙌🏾🙌🏿👏👏🏻👏🏼👏🏽👏🏾👏🏿') }, - { name: 'yolo', handler: sayit('Yᵒᵘ Oᶰˡʸ Lᶤᵛᵉ Oᶰᶜᵉ') }, - { name: ['calm', 'chill'], handler: sayit('┬──┬ ノ(゜-゜ノ)') }, - { name: ['dance', 'party', 'boogie'], handler: sayit('┏(-_-)┛┗(-_-)┓┗(-_-)┛┏(-_-)┓') }, - { name: ['moving', 'move'], handler: sayit('If you rename the WordPress directory on your server, switch ports or change the hostname http://codex.wordpress.org/Moving_WordPress applies') }, - - { - name: 'blame', - handler: function(bot, from, to, message, who, str) { - if ( str == bot.nick ) { - var msg = "That's hilarious..."; - } else { - var msg = who ? who + ': ' + 'It\'s all ' + str + '\'s fault!' : 'It\'s all ' + str + '\'s fault!'; - } - bot.say( message.args[0], msg ); - } - }, - { - name: 'flip', - handler: function(bot, from, to, message, who, str) { - var prefix = who ? who + ': ' : ''; - if ( str == '.flip!' ) { - var msg = prefix + '┻━┻︵ \\(°□°)/ ︵ ┻━┻'; - } else { - var msg = prefix + '(╯°□°)╯︵ ┻━┻'; - } - bot.say( message.args[0], msg ); - } - } -]; - -/** - * this is an array of functions. - */ -module.exports.filters = []; diff --git a/plugins/soundcloud.js b/plugins/soundcloud.js deleted file mode 100644 index be94ee1..0000000 --- a/plugins/soundcloud.js +++ /dev/null @@ -1,32 +0,0 @@ -var config = require( '../config' ); - -var google = require( 'google' ); -google.resultsPerPage = 1; - -module.exports = {}; - -/** - * this is an array of objects. - * each object needs a `name` parameter and a `handler` parameter. - */ -module.exports.commands = [ - { - name: 'soundcloud', - handler: function( bot, from, to, message, who, str ) { - if ( config.debug ) console.log( '[SoundCloud search] for: ' + str ); - google( str + ' site:soundcloud.com', function ( err, next, links ) { - if ( err && config.debug ) console.error( err ); - if ( config.debug ) console.log( links ); - // Show the search results - if ( links.length ) { - bot.say( to, who ? who + ': ' + links[0].link : from + ': ' + links[0].link ); - } - }); - } - } -]; - -/** - * this is an array of functions. - */ -module.exports.filters = []; diff --git a/plugins/spotify.js b/plugins/spotify.js deleted file mode 100644 index 9aedb25..0000000 --- a/plugins/spotify.js +++ /dev/null @@ -1,51 +0,0 @@ -var config = require( '../config' ); - -var google = require( 'google' ); -google.resultsPerPage = 1; - -module.exports = {}; - -/** - * this is an array of objects. - * each object needs a `name` parameter and a `handler` parameter. - */ -module.exports.commands = [ - { - name: 'spotify', - handler: function( bot, from, to, message, who, str ) { - if ( config.debug ) console.log( '[Spotify search] for: ' + str ); - google( str + ' site:open.spotify.com', function ( err, next, links ) { - if ( err && config.debug ) console.error( err ); - if ( config.debug ) console.log( links ); - // Show the search results - if ( links.length ) { - bot.say( to, who ? who + ': ' + links[0].link : from + ': ' + links[0].link ); - } - }); - } - }, - /** - * futher commands as needed for this plugin - */ - { - name: 'spotifyuri', - handler: function( bot, from, to, message, who, str ) { - if ( config.debug ) console.log( '[Spotify URI search] for: ' + str ); - google( str + ' site:open.spotify.com', function ( err, next, links ) { - if ( err && config.debug ) console.error( err ); - if ( config.debug ) console.log( links ); - // Show the search results - if ( links.length ) { - var link = links[0].link.split('/'); - link = 'spotify:track:' + link[ link.length - 1 ]; - bot.say( to, who ? who + ': ' + link : from + ': ' + link ); - } - }); - } - } -]; - -/** - * this is an array of functions. - */ -module.exports.filters = []; diff --git a/plugins/weather.js b/plugins/weather.js deleted file mode 100644 index 0fdd5a8..0000000 --- a/plugins/weather.js +++ /dev/null @@ -1,36 +0,0 @@ -var config = require( '../config' ); - -var request = require( 'request' ); - -module.exports = {}; - -/** - * this is an array of objects. - * each object needs a `name` parameter and a `handler` parameter. - */ -module.exports.commands = [ - { - name: 'weather', - handler: function( bot, from, to, message, who, str ) { - // if ( config.hasOwnProperty('openweathermap_api_key') ) { - // if ( config.debug ) console.log( '[Weather Command]' ); - // // Set the API endpoint - // var endpoint = 'http://api.openweathermap.org/data/2.5/weather?q=London&APPID=' + config.openweathermap_api_key; - // // Grab the blockchain information for the current currency type - // request( endpoint, function( error, response, body ) { - // if ( ! error) { - // body = JSON.parse( body ); - // if ( body.hasOwnProperty('name') ) { - // var wind = body.wind.speed; - // var msg = 'Current weather for ' + body.name + ': ' - // var msg = 'Current ' + currency + ' Bitcoin Value: ' + body.symbol + body.last + '. [Buy @ ' + body.symbol + body.buy + ' and Sell @ ' + body.symbol + body.sell + ']'; - // } else { - // var msg = 'Unable to read blockchain information for the "' + currency + '" currency type. Please try again later :('; - // } - // bot.say( message.args[0], who ? who + ': ' + msg : from + ': ' + msg ); - // } - // }); - // } - } - } -]; diff --git a/plugins/wordpressorg.js b/plugins/wordpressorg.js deleted file mode 100644 index 5b2ae88..0000000 --- a/plugins/wordpressorg.js +++ /dev/null @@ -1,83 +0,0 @@ -var config = require( '../config' ); - -var request = require( 'request' ); -var google = require( 'google' ); -google.resultsPerPage = 1; - -module.exports = {}; - -/** - * this is an array of objects. - * each object needs a `name` parameter and a `handler` parameter. - */ -module.exports.commands = [ - { - name: [ 'codex', 'c' ], - handler: function( bot, from, to, message, who, str ) { - if ( config.debug ) console.log( '[Codex search] for: ' + str ); - - // // Scrape the site for contents from selector - // var site = 'http://google.com/search?q=' + encodeURIComponent( str + ' site:wordpress.org inurl:("codex.wordpress.org"|"developer.wordpress.org")' ); - // request( site, function( error, response, body ) { - // if ( ! error) { - // // Load jsdom for DOM parsing - // jsdom.env( - // body, - // [ 'http://code.jquery.com/jquery-2.2.3.min.js' ], - // function( err, window ) { - // if ( err ) console.log( 'err:', err ); - // var $ = window.jQuery; - // console.log($('#ires .g:first .kv')); - // var msg = $('#ires .g:first .kv').text(); - // bot.say( message.args[0], who ? who + ': ' + msg : msg ); - // } - // ); - // } else { - // console.log( error ); - // } - // }); - - - google( str + ' site:wordpress.org inurl:("codex.wordpress.org"|"developer.wordpress.org")', function ( err, next, links ) { - if ( err && config.debug ) console.error( err ); - // Show the search results - if ( links && links[0].hasOwnProperty('link') ) { - bot.say( to, who ? who + ': ' + links[0].link : from + ': ' + links[0].link ); - } else { - bot.say( to, from + ': weird... your search for: "' + str + ' site:wordpress.org inurl:("codex.wordpress.org"|"developer.wordpress.org")" yielded this: ' + JSON.stringify( links ) ); - } - }); - } - }, - { - name: 'count', - handler: function( bot, from, to, message, who, str ) { - if ( config.debug ) console.log( '[WordPress Count]' ); - request( 'https://wordpress.org/download/counter/?ajaxupdate=1', function( error, response, body ) { - if ( ! error) { - var msg = 'WordPress has been downloaded ' + body + ' times.'; - bot.say( message.args[0], who ? who + ': ' + msg : from + ': ' + msg ); - } - }); - } - }, - { - name: 'p', - handler: function( bot, from, to, message, who, str ) { - if ( config.debug ) console.log( '[Plugin search] for: ' + str ); - google( str + ' wordpress plugin site:https://wordpress.org/plugins', function ( err, next, links ) { - if ( err && config.debug ) console.error( err ); - if ( config.debug ) console.log( links ); - // Show the search results - if ( links.length ) { - bot.say( to, who ? who + ': ' + links[0].link : from + ': ' + links[0].link ); - } - }); - } - } -]; - -/** - * this is an array of functions. - */ -module.exports.filters = []; diff --git a/plugins/wpseek.js b/plugins/wpseek.js deleted file mode 100644 index 65e4b82..0000000 --- a/plugins/wpseek.js +++ /dev/null @@ -1,34 +0,0 @@ -var config = require( '../config' ); - -var google = require( 'google' ); -google.resultsPerPage = 1; - -module.exports = {}; - -/** - * this is an array of objects. - * each object needs a `name` parameter and a `handler` parameter. - */ -module.exports.commands = [ - { - name: ['wps', 'wpseek'], - handler: function( bot, from, to, message, who, str ) { - if ( config.debug ) console.log( '[wpseek.com search] for: ' + str ); - google( str + ' site:wpseek.com', function ( err, next, links ) { - if ( err && config.debug ) console.error( err ); - // Show the search results - if ( links && links[0].hasOwnProperty('link') ) { - var msg = links[0].link; - } else { - var msg = 'weird... I had troubles getting a link for "' + str + ' site:wpseek.com"'; - } - bot.say( to, who ? who + ': ' + msg : from + ': ' + msg ); - }); - } - } -]; - -/** - * this is an array of functions. - */ -module.exports.filters = []; diff --git a/plugins/youtube.js b/plugins/youtube.js deleted file mode 100644 index 0778691..0000000 --- a/plugins/youtube.js +++ /dev/null @@ -1,34 +0,0 @@ -var config = require( '../config' ); - -var google = require( 'google' ); -google.resultsPerPage = 1; - -module.exports = {}; - -/** - * this is an array of objects. - * each object needs a `name` parameter and a `handler` parameter. - */ -module.exports.commands = [ - { - name: ['y', 'youtube'], - handler: function( bot, from, to, message, who, str ) { - if ( config.debug ) console.log( '[YouTube search] for: ' + str ); - google( str + ' site:youtube.com', function ( err, next, links ) { - if ( err && config.debug ) console.error( err ); - if ( config.debug ) console.log( links ); - // Show the search results - if ( links[0].link ) { - bot.say( to, who ? who + ': ' + links[0].link : from + ': ' + links[0].link ); - } else { - bot.say( to, from + ': weird... your search for: "' + str + ' site:youtube.com" yielded this: ' + JSON.stringify( links ) ); - } - }); - } - } -]; - -/** - * this is an array of functions. - */ -module.exports.filters = []; diff --git a/tsconfig.json b/tsconfig.json new file mode 100644 index 0000000..914b394 --- /dev/null +++ b/tsconfig.json @@ -0,0 +1,14 @@ +{ + "compilerOptions": { + "module": "commonjs", + "target": "es5", + "moduleResolution": "Node", + "allowJs": true, + "sourceMap": true, + "lib": [ + "dom", + "es2015", + "es5" + ] + } +} diff --git a/tslint.json b/tslint.json new file mode 100644 index 0000000..5694204 --- /dev/null +++ b/tslint.json @@ -0,0 +1,11 @@ +{ + "rules": { + "no-unused-expression": true, + "no-duplicate-variable": true, + "no-unused-variable": true, + "curly": true, + "class-name": true, + "semicolon": ["always"], + "triple-equals": true + } +} \ No newline at end of file