• Stars
    star
    106
  • Rank 318,227 (Top 7 %)
  • Language
    JavaScript
  • License
    The Unlicense
  • Created over 14 years ago
  • Updated about 12 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Stupidly simple IRC bots in Javascript.

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'll need to grab Jerk. If you use npm it's as easy as:

npm install jerk

If you prefer straight-up git:

git clone git://github.com/gf3/Jerk.git

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

var jerk = require( 'jerk' )

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.

ADVANCED USER OF THE INTERNETS

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
, source:     Channel
, match_data: Array
, say:        Function( message )
, msg:        Function( message )
}

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 :) However, the msg method can be used if you'd like to force sending a message directly to a user (aka a PM).

Cast source to a string to return the channel name. You can also work out who is in a channel by iterating over source.clients.

The connect method returns an object with some handy methods that you can use outside of your watch_fors:

{ say:    Function( destination, message )
, action: Function( destination, action )
, forget: Function( pattern )
, part:   Function( channel )
, join:   Function( channel )
, quit:   Function( message )
}

Example:

var superBot = jerk( ... ).connect( options )
// Later...
superBot.say( '#myChan', 'Soup noobs?' )
superBot.join( '#haters' )
superBot.action( '#hates', 'hates all of you!' )

I think everything there is pretty self-explanatory, no?

Running Your Bot

node yourBot9001.js

Run your bot on a remote server:

nohup node yourBot9001.js &

Although I recommend using something like forever to keep your bot running for a while.

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!

A few bots using Jerk:

Wrote a bot with Jerk? Email me and I'll add it to the list!

Credit & Junk

{ "author" : "Gianni Chiappetta <[email protected]> (http://gf3.ca)"
, "contributors" :
  [ "Isaac Z. Schlueter <[email protected]> (http://blog.izs.me)"
  , "Arnaud Berthomier <[email protected]> (http://wtf.cyprio.net)"
  , "Suresh Harikrishnan <[email protected]> (http://www.activesphere.com)"
  , "Tomás Senart <[email protected]> http://about.me/tsenart"
  ]
}

Jerk is UNLICENSED.

More Repositories

1

dotfiles

Configurations for the tools I use every day
Emacs Lisp
1,040
star
2

sandbox

A nifty JavaScript sandbox for Node.js
JavaScript
836
star
3

Levenshtein

Javascript implementation of the L-diggity.
JavaScript
278
star
4

IRC-js

The best IRC library for node.js
JavaScript
179
star
5

WAT

LOLWAT?
107
star
6

protobot

Prototype IRC Bot
JavaScript
57
star
7

haml.mode

HAML syntax definition for Coda & SubEthaEdit
44
star
8

texpand

Textarea auto-expander.
JavaScript
33
star
9

CLJBIN

A Clojure pastebin with code evaluation.
Clojure
33
star
10

TRNSFR

A Transmit 4-inspired multi progress bar.
JavaScript
22
star
11

butts

#butts
21
star
12

JS-strftime

Ruby-like strftime for javascript, because date-formatting is a pain.
JavaScript
18
star
13

hinttext

Hint text the right way.
JavaScript
14
star
14

peg.vim

PEG Syntax for Vim
Vim Script
14
star
15

coloured

Pretty colours in your terminal.
JavaScript
9
star
16

twatlr.com

Twatlr web service
JavaScript
8
star
17

molotov

The exciting colour scheme that will make you code goodâ„¢
Vim Script
6
star
18

Get-Off-My-Lawn

Safari version of Mike Taylor's "Get Off My Lawn" extension for Opera.
JavaScript
5
star
19

Rumen

Data extraction.
Ruby
5
star
20

butt.zone

What a nice place for a website.
HTML
5
star
21

oxpecker

Sandboxed javascript in ruby.
Ruby
4
star
22

docker-mongosh

Docker image for mongosh
Dockerfile
4
star
23

pancake

A user style to simplify waffle.io
CSS
4
star
24

clavatar-js

A ClojureScript port of Rayne's clavatar. This is a library to generate Gravatar URLs from email addresses.
JavaScript
4
star
25

snack

Please ignore
C
3
star
26

akahn-slash-asterisk

akahn/*
3
star
27

dom.js

Functional DOM-ination
JavaScript
3
star
28

Twatlr

Easy Twitter threads.
Racket
3
star
29

crapshot

crappy web screenshots (html → pdf)
C++
2
star
30

ring-cssgen

Ring middleware to automatically compile and regenerate your cssgen stylesheets.
Clojure
2
star
31

proto-misc

Miscellaneous tasty paste.
JavaScript
2
star
32

SCRLLR

Make great scrollings of the elements!!!
JavaScript
2
star
33

readthefuckingspec

Read the fucking spec.
Ruby
2
star
34

ring-anti-forgery

Ring middleware to prevent CSRF attacks
Clojure
2
star
35

jennmoney.biz

the official site of olive garden's favorite twitter account
1
star
36

musex

Ruby
1
star
37

gf3

Private!
1
star
38

Resume

Curriculum Vitae
1
star
39

api-extractor-issue

TypeScript
1
star
40

ember-load-helpers

Autoload and register ember helpers
JavaScript
1
star
41

ember-cli

JavaScript
1
star