Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

added optimist and asciimo, simple command interface

  • Loading branch information...
commit 1689b416575e01ad4892959f3504ad42e73519c6 1 parent ef62e59
@cpetzold authored
Showing with 60 additions and 3 deletions.
  1. +1 −0  .gitignore
  2. +14 −0 commands.js
  3. +42 −1 index.js
  4. +3 −2 package.json
View
1  .gitignore
@@ -1,2 +1,3 @@
config.json
node_modules
+*.swp
View
14 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);
+ }
+
+ };
+};
View
43 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');
+ }
+ }
+
});
+
View
5 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"
}
}

0 comments on commit 1689b41

Please sign in to comment.
Something went wrong with that request. Please try again.