Skip to content

Instantly share code, notes, and snippets.

@rickycodes
Created May 31, 2012 06:13
Show Gist options
  • Save rickycodes/2841461 to your computer and use it in GitHub Desktop.
Save rickycodes/2841461 to your computer and use it in GitHub Desktop.
jQuery API calls for protobot
// jQuery API
j.watch_for( /^\?([^#@]+)(?:\s*#([1-9]))?(?:\s*@\s*([-\[\]|_\w]+))?$/, function( message ) {
// Return if botty is present
if ( message.source.clients.indexOf( 'bot-t' ) >= 0 || message.source.clients.indexOf( 'bot-t1' ) >= 0 )
return
var splat = message.text[ 0 ].split( ' ' )
, s = splat[ 0 ].replace( '?', '' )
, to = ( splat[ 1 ] === '@' && splat[ 2 ] && splat.length === 3 ) ? splat[ 2 ] : ''
, a = jquery_api
, res = ''
if( splat.length ) {
Object.keys( a ).map( function( k ) {
var name = a[ k ].name
, title = a[ k ].title
, desc = a[ k ].desc
, url = a[ k ].url
// search for selector
if ( s.indexOf( ':' ) >= 0 ) {
if( title.indexOf( 'Selector' ) >= 0 && name == s.replace( ':', '' ) ) {
res = title + ': ' + desc + ' ' + url
return
}
// everything else
} else if ( name.toLowerCase() == s.toLowerCase() && title.indexOf( ':' ) == -1 ) {
res = title + ': ' + desc + ' ' + url
return
}
})
}
// say what you need to say
if( res != '' ) {
if ( to ) {
message.say( to + ': ' + res )
} else {
message.say( message.user + ': ' + res )
}
}
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment