aboutsummaryrefslogtreecommitdiff
path: root/dinobot.rb
diff options
context:
space:
mode:
authorDavid Vazgenovich Shakaryan <dvshakaryan@gmail.com>2014-04-21 14:30:09 -0700
committerDavid Vazgenovich Shakaryan <dvshakaryan@gmail.com>2014-04-21 14:30:09 -0700
commit211018e2f94c60fdf7a47b87cbcb07432f0fa25d (patch)
treee44d815bab8074e62dd27d411f9bbb47ea8f2228 /dinobot.rb
parented04bd3c0fff100f40ed45d300fcb152723226ef (diff)
downloaddinobot-211018e2f94c60fdf7a47b87cbcb07432f0fa25d.tar.gz
dinobot-211018e2f94c60fdf7a47b87cbcb07432f0fa25d.tar.xz
Clean up code.
Diffstat (limited to 'dinobot.rb')
-rw-r--r--dinobot.rb40
1 files changed, 20 insertions, 20 deletions
diff --git a/dinobot.rb b/dinobot.rb
index 503a3b4..db0440b 100644
--- a/dinobot.rb
+++ b/dinobot.rb
@@ -35,8 +35,8 @@ module Dinobot
@irc.join channel
end
- while str = @irc.gets
- process_in_new_thread(str)
+ while line = @irc.gets
+ process_line(line)
end
@irc.disconnect
@@ -113,11 +113,11 @@ module Dinobot
private
- def process_in_new_thread(str)
+ def process_line(line)
Thread.new do
begin
Timeout.timeout(30) do
- process_line(str.chomp)
+ process_line_thread(line.chomp)
end
rescue => e
@logger.error "Error parsing line. (#{e})"
@@ -126,21 +126,21 @@ module Dinobot
end
end
- def process_line(str)
- @irc.pong str[5..-1] if str =~ /\APING /
+ def process_line_thread(line)
+ @irc.pong line[5..-1] if line =~ /\APING /
- if str =~ /(\S+) PRIVMSG (\S+) :(.*)/
- user, channel, message = str.scan(/(\S+) PRIVMSG (\S+) :(.*)/).first
+ if line =~ /\A(\S+) PRIVMSG (\S+) :(.*)/
+ user, channel, message = line.scan(/\A(\S+) PRIVMSG (\S+) :(.*)/).first
m = Dinobot::Core::MessageInfo.new(user, channel, message)
- return unless message =~ /\A#{Regexp.escape(@config.data[:trigger][:global])}/
- command = message.sub(/\A#{Regexp.escape(@config.data[:trigger][:global])}/, '')
+ return unless message =~
+ /\A#{Regexp.escape(@config.data[:trigger][:global])}/
- exec_command(m, command)
+ command = message
+ .sub(/\A#{Regexp.escape(@config.data[:trigger][:global])}/, '')
- unless m.response.empty?
- process_response(m.response)
- end
+ exec_command(m, command)
+ process_response(m) if m.response?
end
end
@@ -158,9 +158,7 @@ module Dinobot
return unless @modules.keys.map { |x| x.to_s }.include?(mod)
mod = mod.intern
- if m.response.empty?
- @modules[mod].call(m, command)
- else
+ if m.response?
prev = m.response
m.response = []
@@ -168,16 +166,18 @@ module Dinobot
if x.first == :say
@modules[mod].call(m, "#{command} #{x[2]}")
else
- m.response << x
+ m.respond x
end
end
+ else
+ @modules[mod].call(m, command)
end
exec_command(m, remainder) if remainder
end
- def process_response(response)
- response.each do |x|
+ def process_response(m)
+ m.response.each do |x|
@logger.info "Executing method: #{x.inspect}" if @config.data[:debug]
send(*x)
end