Skip to content
This repository was archived by the owner on Nov 10, 2022. It is now read-only.
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 14 additions & 3 deletions lib/isaac/bot.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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"
Expand Down