From ac80d0bebde93feaf2c746abfbf78f1fd9ba10de Mon Sep 17 00:00:00 2001 From: Michael Behan Date: Wed, 17 Aug 2011 10:12:36 -0400 Subject: [PATCH] on method can take multiple event. Added recipient instance var. Added :any event --- lib/isaac/bot.rb | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/lib/isaac/bot.rb b/lib/isaac/bot.rb index 21fa31e..01c777d 100644 --- a/lib/isaac/bot.rb +++ b/lib/isaac/bot.rb @@ -6,7 +6,7 @@ module Isaac Config = Struct.new(:server, :port, :ssl, :password, :nick, :realname, :version, :environment, :verbose, :encoding) class Bot - attr_accessor :config, :irc, :nick, :channel, :message, :user, :host, :match, + attr_accessor :config, :irc, :recipient, :nick, :channel, :message, :user, :host, :match, :error def initialize(&b) @@ -22,7 +22,13 @@ def configure(&b) def on(event, match=//, &block) match = match.to_s if match.is_a? Integer - (@events[event] ||= []) << [Regexp.new(match), block] + if event.is_a? Array + event.each {|e| + (@events[e] ||= []) << [Regexp.new(match), block] + } + else + (@events[event] ||= []) << [Regexp.new(match), block] + end end def helpers(&b) @@ -79,9 +85,13 @@ def message @message ||= "" end + def recipient + @channel||@nick + end + def dispatch(event, msg=nil) if msg - @nick, @user, @host, @channel, @error, @message = + @nick, @user, @host, @channel, @error, @message = msg.nick, msg.user, msg.host, msg.channel, msg.error, msg.message end @@ -163,6 +173,7 @@ def parse(input) type = msg.channel? ? :channel : :private @bot.dispatch(type, msg) + @bot.dispatch(:any, msg) elsif msg.error? @bot.dispatch(:error, msg) elsif msg.command == "PING"