Browse files

Initial Commit

  • Loading branch information...
0 parents commit 5cade502a7179d129a2f74c4d716b8bc18ddee34 @davglass committed Aug 31, 2010
Showing with 173 additions and 0 deletions.
  1. +1 −0 .gitignore
  2. +3 −0 .gitmodules
  3. +4 −0 README
  4. +37 −0 lib/config.js.sample
  5. +4 −0 lib/google/README
  6. +15 −0 lib/google/google.js
  7. +1 −0 lib/jerk
  8. +1 −0 lib/yui3-docs.js
  9. +107 −0 lib/yuibot.js
1 .gitignore
@@ -0,0 +1 @@
+lib/config.js
3 .gitmodules
@@ -0,0 +1,3 @@
+[submodule "lib/jerk"]
+ path = lib/jerk
+ url = git://github.com/gf3/Jerk.git
4 README
@@ -0,0 +1,4 @@
+
+Loosely based on protobot: http://github.com/gf3/protobot
+
+
37 lib/config.js.sample
@@ -0,0 +1,37 @@
+/*
+
+Change these settings and make this /lib/config.js
+
+*/
+exports.config = {
+ mysql: {
+ username: 'username',
+ password: 'password',
+ db: 'dbname'
+ },
+ irc: {
+ server: 'irc.freenode.net',
+ nick: 'botname',
+ channels: ['#yui'],
+ user: {
+ username: 'yuibot',
+ hostname: 'yuilibrary.com',
+ servername: 'yuilibrary.com',
+ realname: 'YBot'
+ }
+ }
+};
+
+/*
+CREATE TABLE IF NOT EXISTS chat (
+ id int(11) NOT NULL auto_increment,
+ channel varchar(255) NOT NULL,
+ stamp timestamp NOT NULL default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP,
+ utterance text,
+ who varchar(32) default NULL,
+ PRIMARY KEY (id),
+ KEY chat_stamp (stamp),
+ KEY chat_who (who),
+ FULLTEXT KEY chat_utterance (utterance)
+) ENGINE=MyISAM DEFAULT CHARSET=latin1;
+*/
4 lib/google/README
@@ -0,0 +1,4 @@
+
+Snagged from protobot: http://github.com/gf3/protobot
+
+
15 lib/google/google.js
@@ -0,0 +1,15 @@
+/* ------------------------------ Includes && Options ------------------------------ */
+var exec = require('child_process').exec;
+
+/* ------------------------------ Google ------------------------------ */
+function Google() {
+ this.search = function(query, hollaback) {
+ exec("curl -e 'http://gf3.ca' 'http://ajax.googleapis.com/ajax/services/search/web?v=1.0&q=" + escape(query) + "'", function (err, stdout, stderr) {
+ hollaback.call(this, JSON.parse(stdout)["responseData"]["results"]);
+ });
+ };
+}
+
+/* ------------------------------ Export ------------------------------ */
+module.exports = Google;
+
1 lib/jerk
@@ -0,0 +1 @@
+Subproject commit df825031b95a5385c45c1c934d012ef3d3a66135
1 lib/yui3-docs.js
1 addition, 0 deletions not shown because the diff is too large. Please use a local Git client to view these changes.
107 lib/yuibot.js
@@ -0,0 +1,107 @@
+#!/usr/bin/env node
+
+var sys = require('sys'),
+ jerk = require('./jerk/lib/jerk'),
+ Google = require('./google/google'),
+ mysql_client = require('mysql').Client,
+ mysql = new mysql_client(),
+ YUI3 = require('./yui3-docs').YUI3,
+ // Google
+ google = new Google(),
+ config = require('./config').config;
+
+
+mysql.user = config.mysql.username;
+mysql.password = config.mysql.password;
+mysql.database = config.mysql.db;
+mysql.connect();
+
+
+jerk(function(j) {
+
+ j.watch_for(/^(?:hi|hello|hey)$/i, function( message ) {
+ message.say( message.user + ": oh hai!" )
+ });
+
+ j.watch_for( /^(?:it )?doesn(?:')?t work(?:\s*@\s*([-\[\]|_\w]+))?/, function( message ) {
+ message.say( to( message, "doesn't work" ) + ": What do you mean it doesn't work? What happens when you try to run it? What's the output? What's the error message? Saying \"it doesn't work\" is pointless." )
+ });
+
+ j.watch_for( /^g(?:oogle)? ([^#@]+)(?:\s*#([1-9]))?(?:\s*@\s*([-\[\]|_\w]+))?$/, function( message ) {
+ var user = to( message, 3 ),
+ res = +message.match_data[2]-1 || 0;
+
+ google.search( message.match_data[1], function( results ) {
+ if ( results.length ) {
+ message.say( user + ": " + results[res].titleNoFormatting + " - " + results[res].unescapedUrl );
+ } else {
+ message.say( user + ": Sorry, no results for '" + message.match_data[1] + "'" );
+ }
+ });
+ });
+
+ j.watch_for( /^mdc ([^#@]+)(?:\s*#([1-9]))?(?:\s*@\s*([-\[\]|_\w]+))?$/, function( message ) {
+ var user = to( message, 3 ),
+ res = +message.match_data[2]-1 || 0;
+
+ google.search( message.match_data[1] + ' site:developer.mozilla.org', function( results ) {
+ if ( results.length ) {
+ message.say( user + ": " + results[res].titleNoFormatting + " - " + results[res].unescapedUrl );
+ } else {
+ message.say( user + ": Sorry, no results for '" + message.match_data[1] + "'" );
+ }
+ });
+ });
+
+ j.watch_for( /^api ([$\w]+(?:[\.#]\w+)*)(?:\s+@\s*([-\[\]|_\w]+))?/, function( message ) {
+ //console.log(message);
+ message.say( to( message, 2 ) + ": Sorry, the `api` command is temporarily disabled." )
+ });
+
+ j.watch_for( /^module ([$\w]+(?:[\.#]\w+)*)(?:\s+@\s*([-\[\]|_\w]+))?/, function( message ) {
+ //console.log(message);
+ var mod = message.match_data[1],
+ info = YUI3.modules[mod];
+
+ if (info) {
+ message.say( to( message, 2 ) + ": " + mod + ": " + info.description + "." );
+ if (info.submodules.length) {
+ message.say( to( message, 2 ) + ": " + mod + ": Contains the following submodules: " + info.submodules.join(', ') + "." );
+ }
+ if (info.classlist) {
+ message.say( to( message, 2 ) + ": " + mod + ": Contains the following classes: " + info.classlist.join(', ') + "." );
+ }
+
+ } else {
+ message.say( to( message, 2 ) + ": Could not find a module named: " + mod + "." );
+ }
+ });
+
+ j.watch_for(/./, function(message) {
+ var log = false;
+ config.irc.channels.forEach(function(v) {
+ if (v === message.source) {
+ log = true;
+ }
+ });
+ if (log) {
+ mysql.query("insert into chat (channel, who, utterance) values (?, ?, ?)", [
+ message.source,
+ message.user,
+ message.text[0]
+ ]);
+ }
+ });
+
+}).connect( config.irc );
+
+
+function to(message, def, idx) {
+ if ( typeof idx === 'undefined' && typeof def === 'number' ) {
+ idx = def, def = null
+ } else {
+ idx = idx || 1
+ }
+ return !!message.match_data[idx] ? message.match_data[idx] : def || message.user
+}
+

0 comments on commit 5cade50

Please sign in to comment.