class Botrb::Bot
This is the class that does most of the legwork of the bot.
Attributes
channels[RW]
host[RW]
name[RW]
port[RW]
socket[RW]
Public Class Methods
new(config = {})
click to toggle source
initialize expects a hash
# File lib/botrb/bot.rb, line 10 def initialize(config = {}) @name = config[:name] || '' @host = config[:host] || 'irc.freenode.com' @port = config[:port] || 6667 @channels = config[:channels] || [] end
Public Instance Methods
connect()
click to toggle source
# File lib/botrb/bot.rb, line 17 def connect @socket = TCPSocket.open @host, @port say "NICK #{@name}" say "USER #{@name} 0 * #{@name}" @channels.each do |channel| say "JOIN ##{channel}" end end
run()
click to toggle source
# File lib/botrb/bot.rb, line 26 def run connect while (out = @socket.gets) if out =~ /^PING :(.*)$/ say "PONG #{$~[1]}" next end puts out end end
say(msg)
click to toggle source
# File lib/botrb/bot.rb, line 37 def say(msg) @socket.puts msg end