Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

update: Add redis k/v store for triggers.

  • Loading branch information...
commit f95d62ae50b241a15ebe4c7d91cbb29e5303db06 1 parent c5efeef
@gf3 gf3 authored
View
1  .gitignore
@@ -1,2 +1,3 @@
*.swp
nohup.out
+node_modules
View
3  .gitmodules
@@ -1,6 +1,3 @@
-[submodule "vendor/Jerk"]
- path = vendor/Jerk
- url = git://github.com/gf3/Jerk.git
[submodule "vendor/sandbox"]
path = vendor/sandbox
url = git://github.com/gf3/sandbox.git
View
11 package.json
@@ -0,0 +1,11 @@
+{ "name": "protobot"
+, "version": "0.0.1"
+, "engines": ["node >= 0.6.0"]
+, "main": "protobot.js"
+, "dependencies":
+ { "groupie": ">= 0"
+ , "hiredis": ">= 0"
+ , "redis": ">= 0"
+ , "jerk": ">= 1.1.17"
+ }
+}
View
70 protobot.js
@@ -1,21 +1,23 @@
/* ------------------------------ Includes && Options ------------------------------ */
require( './vendor/strftime/strftime' )
-var sys = require( 'sys' )
+var util = require( 'util' )
, fs = require( 'fs' )
, path = require( 'path' )
- , util = require( 'util' )
, http = require( 'http' )
, URL = require( 'url' )
- , exec = require('child_process').exec
+ , exec = require( 'child_process' ).exec
, spawn = require( 'child_process' ).spawn
+ , redis = require( 'redis' )
, groupie = require('groupie')
- , jerk = require( './vendor/Jerk/lib/jerk' )
+ , jerk = require( 'jerk' )
, Octo = require( './vendor/octo/octo' )
, Sandbox = require( './vendor/sandbox/lib/sandbox' )
, Google = require( './vendor/google/google' )
, WolframAlpha = require( './vendor/wolframalpha/wolframalpha' )
, unescapeAll = require( './vendor/unescape/unescape' )
+ , bot
+ , rclient
, sandbox
, google
, wa
@@ -26,8 +28,8 @@ var sys = require( 'sys' )
options =
{ server: 'irc.freenode.net'
- , nick: 'david_mark'
- , channels: [ '#runlevel6', '#inimino', '#prototype', '#jquery-ot' ]
+ , nick: 'david_mark2'
+ , channels: [ '#runlevel6' ]//, '#inimino', '#prototype', '#jquery-ot' ]
, user:
{ username: 'david_mark'
, hostname: 'intertubes'
@@ -116,17 +118,25 @@ commands =
, '===': "For any primitive values o and p, o === p if o and p have the same value and type. For any Objects o and p, o === p if mutating o will mutate p in the same way."
}
-for ( c in commands ) {
- jerk( function( j ) {
- var cmd = commands[c]
- j.watch_for( new RegExp( "^" + c + "(?:\\s*@\\s*([-\\[\\]\\{\\}`|_\\w]+))?\\s*$", "i" ), function( message ) {
- message.say( to( message ) + ": " + cmd )
- })
- })
-}
+for ( c in commands )
+ watchForSingle( c, commands[c] )
+
+// Redis
+rclient = redis.createClient( 9307, 'stingfish.redistogo.com' )
+rclient.auth( 'da834e6f78e4ea8c4c25ac20f0c8869a' )
+rclient.on( 'error', function ( err ) {
+ console.log( 'Redis error: ' + err )
+})
+rclient.hgetall( 'triggers', function ( err, obj ) {
+ var i
+ console.log( err, obj )
+ if ( ! err )
+ for ( i in obj )
+ watchForSingle( i, obj[i] )
+})
/* ------------------------------ Protobot ------------------------------ */
-jerk( function( j ) {
+bot = jerk( function( j ) {
// Wat?
j.watch_for( /\b(w[au]t)\b/, function( message ) {
message.say( dynamic_json.wat[ Math.floor( Math.random() * dynamic_json.wat.length ) ] )
@@ -168,6 +178,29 @@ jerk( function( j ) {
liveReload( message )
})
+ // Redis
+ j.watch_for( /^(?:david_mark|protobot|bot-t)[,:]? (\w+) is[,:]? (.+)$/, function( message ) {
+ rclient.hmset( 'triggers', message.match_data[1], message.match_data[2], function( err ) {
+ if ( err )
+ message.say( message.user + ': Oops, there was an error: ' + err )
+ else {
+ message.say( message.user + ': kk' )
+ watchForSingle( message.match_data[1], message.match_data[2] )
+ }
+ })
+ })
+
+ j.watch_for( /^(?:david_mark|protobot|bot-t)[,:]? forget[,:]? (.+)$/, function( message ) {
+ rclient.hdel( 'triggers', message.match_data[1], function( err ) {
+ if ( err )
+ message.say( message.user + ': Oops, there was an error: ' + err )
+ else {
+ message.say( message.user + ': kk' )
+ bot.forget( new RegExp( "^[\\/.`?]" + message.match_data[1] + "(?:\\s*@\\s*([-\\[\\]\\{\\}`|_\\w]+))?\\s*$", "i" ) )
+ }
+ })
+ })
+
// Finger
j.watch_for( /^[\/.`?]?f(?:inger)?(\s+[-\[\]\{\}`|_\w]+)?\s*$/, function( message ) {
var name = to( message, 1 )
@@ -308,6 +341,13 @@ function to ( message, def, idx ) {
return !!message.match_data[idx] ? message.match_data[idx].trim() : def || message.user
}
+function watchForSingle ( trigger, msg ) {
+ jerk( function( j ) {
+ j.watch_for( new RegExp( "^[\\/.`?]" + trigger + "(?:\\s*@\\s*([-\\[\\]\\{\\}`|_\\w]+))?\\s*$", "i" ), function( message ) {
+ message.say( to( message ) + ": " + msg )
+ })
+ })
+}
function reloadJSON ( what, hollaback ) {
hollaback = hollaback || function(){}
1  vendor/Jerk
@@ -1 +0,0 @@
-Subproject commit 0daf17400f35b89e923713dbd54ee0b492589d52
Please sign in to comment.
Something went wrong with that request. Please try again.