Skip to content

Commit

Permalink
added optimist and asciimo, simple command interface
Browse files Browse the repository at this point in the history
  • Loading branch information
cpetzold committed Oct 17, 2011
1 parent ef62e59 commit 1689b41
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 3 deletions.
1 change: 1 addition & 0 deletions .gitignore
@@ -1,2 +1,3 @@
config.json config.json
node_modules node_modules
*.swp
14 changes: 14 additions & 0 deletions commands.js
@@ -0,0 +1,14 @@
/**
* Bot commands
* Ex: '!say hello world' -> 'pwnbot: hello world'
*/

module.exports = function(bot, config) {
return {

ascii: function(opts) {
console.log(opts);
}

};
};
43 changes: 42 additions & 1 deletion index.js
Expand Up @@ -5,6 +5,8 @@


var irc = require('irc') var irc = require('irc')
, fs = require('fs') , fs = require('fs')
, opt = require('optimist')
, ascii = require('asciimo')


/** /**
* Environment. * Environment.
Expand All @@ -27,6 +29,7 @@ try {
, nickname: 'pwnbot' , nickname: 'pwnbot'
, channels: ['#pwn'] , channels: ['#pwn']
, debug: true , debug: true
, prefix: '!'
}; };
} }


Expand All @@ -40,11 +43,49 @@ var bot = new irc.Client(config.server, config.nickname, {
}); });


/** /**
* Auto-Pwn all channels the bot is connected to. * Include commands
*/ */


var commands = exports.commands = require('./commands')(bot, config);


config.channels.forEach(function (channel) { config.channels.forEach(function (channel) {

/**
* Auto-Pwn all channels the bot is connected to.
*/

bot.on('join' + channel, function (who) { bot.on('join' + channel, function (who) {
bot.say(channel, who + ': pwned!'); bot.say(channel, who + ': pwned!');
}); });

/**
* Call command on pm or with action prefix
*/

bot.on('pm', callCommand);

bot.on('message' + channel, callCommand);

function callCommand(from, message) {
var message = message.trimLeft()
, regex = new RegExp('^' + config.prefix);

if (message.search(regex) == -1) {
return;
}

var options = message.slice(config.prefix.length).split(' ')
, command = options.shift();

options = opt.parse(options);

if (commands[command]) {
commands[command](options);
} else {
bot.say(from, '\'' + command + '\' is not a supported command');
}
}

}); });

5 changes: 3 additions & 2 deletions package.json
Expand Up @@ -9,7 +9,8 @@
"node": "v0.4.9" "node": "v0.4.9"
}, },
"dependencies": { "dependencies": {
"irc": "0.2.1", "irc": "0.2.x",
"github": "0.0.6" "optimist": "0.2.x",
"asciimo": "0.3.x"
} }
} }

0 comments on commit 1689b41

Please sign in to comment.