0.0
No commit activity in last 3 years
No release in over 3 years
Small DSL for writing IRC bots.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies
 Project Readme

Isaac - the smallish DSL for writing IRC bots¶ ↑

Features¶ ↑

  • Wraps parsing of incoming messages and raw IRC commands in simple constructs.

  • Hides all the ugly regular expressions of matching IRC commands. Leaves only the essentials for you to match.

  • Takes care of dull stuff such as replying to PING-messages and avoiding excess flood.

Getting started¶ ↑

An Isaac-bot needs a few basics:

require 'isaac'
configure do |c|
  c.nick    = "AwesomeBot"
  c.server  = "irc.freenode.net"
  c.port    = 6667
end

That’s it. Run ruby bot.rb and it will connect to the specified server.

Connecting¶ ↑

After the bot has connected to the IRC server you might want to join some channels:

on :connect do
  join "#awesome_channel", "#WesternBar"
end

Responding to messages¶ ↑

Joining a channel and sitting idle is not much fun. Let’s repeat everything being said in these channels:

on :channel do
  msg channel, message
end

Notice the channel and message variables. Additionally nick and match is available for channel-events. nick being the sender of the message, match being an array of captures from the regular expression:

on :channel, /^quote this: (.*)/ do
  msg channel, "Quote: '#{match[0]}' by #{nick}"
end

If you want to match private messages use the +on :private+ event:

on :private, /^login (\S+) (\S+)/ do
  username = match[0]
  password = match[1]
  # do something to authorize or whatevz.
  msg nick, "Login successful!"
end

You can also pass the RegExp captures as block arguments:

on :channel, /catch this: (.*) and this: (.*)/ do |first, last|
  # `first` will contain the first regexp capture,
  # `last` the second.
end

Finally, you can catch QUITs, JOINs, PARTs, and NICK changes with +on :quit+, +on :join+, +on :part+, and +on :nick+. NICK provides the old nick in nick and the new nick in the newnick variable. All three other catchers (QUITs, PARTs, and JOINs) provide the nick variable. JOINs and PARTs also provide the channel variables. Finally, QUITs and PARTS provide a message variable, if the users uses a quit or part message.

Defining helpers¶ ↑

Helpers should not be defined in the top level, but instead using the helpers-constructor:

helpers do
  def rain_check(meeting)
    msg nick, "Can I have a rain check on the #{meeting}?"
  end
end

on :private, /date/ do
  rain_check("romantic date")
end

Errors, errors, errors¶ ↑

Errors, as specified by RFC 1459, can be reacted upon as well. If you e.g. try to send a message to a non-existant nick you will get error 401: “No such nick/channel”.

on :error, 401 do
  # Do something.
end

Available variables: nick and channel.

Contribute¶ ↑

The source is hosted at GitHub: github.com/ichverstehe/isaac

License¶ ↑

The MIT. Google it.