Permalink
Browse files

refactor

  • Loading branch information...
1 parent f18667d commit 906dff0b0bfa3a4f76478f6d5ce4ce11439f6ce0 @vangberg committed Dec 4, 2009
Showing with 29 additions and 21 deletions.
  1. +29 −21 lib/isaac/bot.rb
View
@@ -140,39 +140,47 @@ def parse(input)
@bot.dispatch(:connect)
end
elsif msg.command == "PRIVMSG"
- if msg.params.last == "\001VERSION\001"
- message "NOTICE #{msg.nick} :\001VERSION #{@bot.config.version}\001"
- end
-
- env = {
- :nick => msg.nick,
- :user => msg.user,
- :host => msg.host,
- :channel => msg.params.first,
- :message => msg.params.last
- }
- type = env[:channel].match(/^#/) ? :channel : :private
- @bot.dispatch(type, env)
+ dispatch_privmsg(msg)
+ elsif msg.numeric_reply? && msg.command =~ /^[45]/
+ dispatch_error
elsif msg.command == "PING"
@queue.unlock
message "PONG :#{msg.params.first}"
elsif msg.command == "PONG"
@queue.unlock
- elsif msg.numeric_reply? && msg.command =~ /^[45]/
- env = {
- :error => msg.command.to_i,
- :message => msg.command,
- :nick => msg.params.first,
- :channel => msg.params.first
- }
- @bot.dispatch(:error, env)
end
end
def registered?
(("001".."004").to_a - @registration).empty?
end
+ def dispatch_privmsg(msg)
+ if msg.params.last == "\001VERSION\001"
+ message "NOTICE #{msg.nick} :\001VERSION #{@bot.config.version}\001"
+ end
+
+ env = {
+ :nick => msg.nick,
+ :user => msg.user,
+ :host => msg.host,
+ :channel => msg.params.first,
+ :message => msg.params.last
+ }
+ type = env[:channel].match(/^#/) ? :channel : :private
+ @bot.dispatch(type, env)
+ end
+
+ def dispatch_error
+ env = {
+ :error => msg.command.to_i,
+ :message => msg.command,
+ :nick => msg.params.first,
+ :channel => msg.params.first
+ }
+ @bot.dispatch(:error, env)
+ end
+
def message(msg)
@queue << msg
end

0 comments on commit 906dff0

Please sign in to comment.