github
Advanced Search
  • Home
  • Pricing and Signup
  • Explore GitHub
  • Blog
  • Login

gf3 / Jerk

  • Admin
  • Watch Unwatch
  • Fork
  • Your Fork
  • Pull Request
  • Download Source
    • 9
    • 1
  • Source
  • Commits
  • Network (1)
  • Issues (0)
  • Downloads (0)
  • Wiki (1)
  • Graphs
  • Branch: master

click here to add a description

click here to add a homepage

  • Switch Branches (1)
    • master ✓
  • Switch Tags (0)
  • Branch List
Sending Request…

Javascript IRC bot library. — Read more

  Cancel

  Cancel
  • Private
  • Read-Only
  • HTTP Read-Only

This URL has Read+Write access

Updated dependency (important). 
gf3 (author)
Mon Apr 05 16:14:20 -0700 2010
commit  0be7b3e55743463c1f38a07306ecc61b1f47968b
tree    3eec1629cd2cc00065fa256639adabdc4e3994fc
parent  40c2ed4b9694e9a770540b645878c27f68af364e
Jerk /
name age
history
message
file .gitignore Sun Feb 28 00:31:40 -0800 2010 Initial commit. Working code. [gf3]
file .gitmodules Sun Feb 28 00:31:40 -0800 2010 Initial commit. Working code. [gf3]
file README.md Mon Mar 01 17:10:19 -0800 2010 Fixed a typo. [gf3]
directory lib/ Sun Feb 28 01:05:54 -0800 2010 Removed a temp vim file, whoops. [gf3]
directory vendor/ Mon Apr 05 16:14:20 -0700 2010 Updated dependency (important). [gf3]
README.md

Jerk

A fun little IRC bot library for node.js. Ridiculously simple to set-up and get going!

OHMYGOD

Seriously, it's stupidly simple.

Your First Bot

Firstly, we're gonna have to clone us some Jerk. So let's do that:

git clone git://github.com/gf3/Jerk.git && cd Jerk && git submodule init && git submodule update

Hoo haa, now that we're locked and loaded, let's write a goddamn bot! We need to include Jerk:

process.mixin(GLOBAL, require("../path/to/Jerk/lib/jerk"));

Now you'll need some options. Jerk takes the exact same options object as the IRC-js library. Let's just go ahead and supply some basic info:

var options = {
  server: "irc.freenode.net",
  nick: "YourBot9001",
  channels: ["#your-channel"]
};

Hah, now you're going to cry once you see how easy this is:

jerk(function(j) {

  j.watch_for("soup", function(message) {
    message.say(message.user + ": soup is good food!");
  });

  j.watch_for(/^(.+) are silly$/, function(message) {
    message.say(message.user + ": " + message.match_data[1] + " are NOT SILLY. Don't joke!");
  });

}).connect(options);

Really. That's it.

The jerk object (j) has only one method: watch_for. Which takes two arguments, the first can be either a string or a regex to match messages against. The second argument is your hollaback function for when a match is found. The hollaback receives only one argument, the message object. It looks like this:

{
  user: String,
  channel: String,
  match_data: Array,
  say: Function
}

I think everything there is pretty self-explanatory, no? One thing I will tell you though, is the say method is smart enough to reply to the context that the message was received, so you don't need to pass it any extra info, just a reply :)

Running Your Bot

node yourBot9001.js

Done.

A Better Example

Here's a more practical example, meet protobot. Protobot hangs out on Freenode#prototype all day – stop by and say hi!

Credit & Junk

Written by Gianni Chiappetta – gf3.ca

I don't want to throw a license on this unless I really have to, they're kinda silly. However you can expect this code to remain free and open.

Blog | Support | Training | Contact | API | Status | Twitter | Help | Security
© 2010 GitHub Inc. All rights reserved. | Terms of Service | Privacy Policy
Powered by the Dedicated Servers and
Cloud Computing of Rackspace Hosting®
Dedicated Server
ZW5kZW5yYWhheXU5QGdtYWlsLmNvbQ==