Class: IrcCat::Bot
- Inherits:
-
Object
- Object
- IrcCat::Bot
- Defined in:
- lib/irc_cat/bot.rb
Overview
The IRC bot
Instance Attribute Summary collapse
-
#channel ⇒ Object
Returns the value of attribute channel.
-
#host ⇒ Object
Returns the value of attribute host.
-
#nick ⇒ Object
Returns the value of attribute nick.
-
#port ⇒ Object
Returns the value of attribute port.
-
#socket ⇒ Object
Returns the value of attribute socket.
Instance Method Summary collapse
-
#announce(msg) ⇒ Object
Announces states.
-
#initialize(constructor = H.new) ⇒ Bot
constructor
Initialize the bot with default values.
- #run ⇒ Object
-
#say(chan, msg) ⇒ Object
Say something funkeh.
Constructor Details
#initialize(constructor = H.new) ⇒ Bot
Initialize the bot with default values
12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/irc_cat/bot.rb', line 12 def initialize(constructor = H.new) @realname = "irc_cat #{IrcCat::VERSION::STRING} - http://irccat.rubyforge.org/" @refresh_rate = 10 constructor.each do |key, val| if val.is_a?(String) instance_eval("@#{key} = '#{val}'") elsif val.is_a?(Array) instance_eval("@#{key} = []") val.each do |v| instance_eval("@#{key}.push('#{v}')") end end end puts "Connecting to IRC #{@host}:#{@port} #{@channel}" end |
Instance Attribute Details
#channel ⇒ Object
Returns the value of attribute channel.
9 10 11 |
# File 'lib/irc_cat/bot.rb', line 9 def channel @channel end |
#host ⇒ Object
Returns the value of attribute host.
9 10 11 |
# File 'lib/irc_cat/bot.rb', line 9 def host @host end |
#nick ⇒ Object
Returns the value of attribute nick.
9 10 11 |
# File 'lib/irc_cat/bot.rb', line 9 def nick @nick end |
#port ⇒ Object
Returns the value of attribute port.
9 10 11 |
# File 'lib/irc_cat/bot.rb', line 9 def port @port end |
#socket ⇒ Object
Returns the value of attribute socket.
9 10 11 |
# File 'lib/irc_cat/bot.rb', line 9 def socket @socket end |
Instance Method Details
#announce(msg) ⇒ Object
Announces states
60 61 62 63 64 |
# File 'lib/irc_cat/bot.rb', line 60 def announce(msg) @channels.each do |channel| say(channel, msg) end end |
#run ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/irc_cat/bot.rb', line 27 def run @socket = TCPSocket.open(@host, @port) login threads=[] threads << Thread.new { begin while line = @socket.gets do # Remove all formatting line.gsub!(/[\x02\x1f\x16\x0f]/,'') # Remove CTCP ASCII line.gsub!(/\001/,'') # Send to event handler handle line # Handle Pings from Server sendln "PONG #{$1}" if /^PING\s(.*)/ =~ line end rescue EOFError err 'Server Reset Connection' rescue Exception => e err e end } threads << Thread.new { } threads.each { |th| th.join } end |
#say(chan, msg) ⇒ Object
Say something funkeh
67 68 69 |
# File 'lib/irc_cat/bot.rb', line 67 def say(chan,msg) sendln "PRIVMSG #{chan} :#{msg}" end |