diff --git a/.gitignore b/.gitignore index 95b863a..cd13ae6 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ config.json node_modules +*.swp diff --git a/commands.js b/commands.js new file mode 100644 index 0000000..9ccb2e9 --- /dev/null +++ b/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); + } + + }; +}; diff --git a/index.js b/index.js index a456272..b660151 100644 --- a/index.js +++ b/index.js @@ -5,6 +5,8 @@ var irc = require('irc') , fs = require('fs') + , opt = require('optimist') + , ascii = require('asciimo') /** * Environment. @@ -27,6 +29,7 @@ try { , nickname: 'pwnbot' , channels: ['#pwn'] , debug: true + , prefix: '!' }; } @@ -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) { + + /** + * Auto-Pwn all channels the bot is connected to. + */ + bot.on('join' + channel, function (who) { 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'); + } + } + }); + diff --git a/package.json b/package.json index 9b1044d..9b88f7b 100644 --- a/package.json +++ b/package.json @@ -9,7 +9,8 @@ "node": "v0.4.9" }, "dependencies": { - "irc": "0.2.1", - "github": "0.0.6" + "irc": "0.2.x", + "optimist": "0.2.x", + "asciimo": "0.3.x" } }