Project

irc

0.01
Low commit activity in last 3 years
No release in over a year
a simple ruby irc (bot) framework
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies
 Project Readme

Installation

Simply install the gem:

gem install irc

Usage

Quickstart

require 'irc'

host    'localhost'
nick    'MyBot'
channel '#MyChannel', '#OtherChannel'

# Say hi when somebody joins the channel:
on :join do
  say "Hi #{nick}!"
end

# Tell the time and date:
match /^!(?:time|now)/ do
  reply Time.now
end

# mention_match requires messages to start with the name of the bot
mention_match /join (?<chan>.+)/ do
  channels = chan.split(/[, ]+/)
  connection.join channels
  reply "I joined #{channels.to_sentence}."
end

start!

Then, run with ruby bot.rb

Subclass

Polluting the global namespace is bad. Instead, you can require 'irc/base' and subclass IRC::Bot:

require 'irc/base'

class MyBot < IRC::Bot
 host    'localhost'
 nick    'MyBot'
 channel '#MyChannel'

 start!
end

You can re-load the bot to update its callbacks without disconnecting:

mention_match /reload!/ do
  self.class.reset!

  load __FILE__
end