aboutsummaryrefslogtreecommitdiff
path: root/dinobot.rb
diff options
context:
space:
mode:
authorDavid Vazgenovich Shakaryan <dvshakaryan@gmail.com>2014-04-15 06:07:20 -0700
committerDavid Vazgenovich Shakaryan <dvshakaryan@gmail.com>2014-04-15 06:07:20 -0700
commitb6d1cc2f13290970eb2fc0094c5d3f209d450d75 (patch)
treea33fc15ef252c18568e0ed046d0061f885df177a /dinobot.rb
parent687a2b70a1258f7e9129ecf38c9b91f65d3a6ec8 (diff)
downloaddinobot-b6d1cc2f13290970eb2fc0094c5d3f209d450d75.tar.gz
dinobot-b6d1cc2f13290970eb2fc0094c5d3f209d450d75.tar.xz
Cleanup and bug fixes.
Diffstat (limited to 'dinobot.rb')
-rw-r--r--dinobot.rb32
1 files changed, 17 insertions, 15 deletions
diff --git a/dinobot.rb b/dinobot.rb
index 57f980c..cedab9d 100644
--- a/dinobot.rb
+++ b/dinobot.rb
@@ -22,6 +22,8 @@ module Dinobot
end
def connect
+ log :info, "Connecting to #{@server}:#{@port}."
+
@socket = TCPSocket.new(@server, @port)
out "PASS #{@pass}" if @pass
@@ -38,11 +40,9 @@ module Dinobot
end
def run
- log :info, "Connecting to #{@server}:#{@port}."
- connect
+ connect unless connected?
- while str = @socket.gets
- str.chomp!
+ while str = @socket.gets.chomp
log :in, str.inspect
Thread.new do
@@ -52,7 +52,10 @@ module Dinobot
end
rescue => e
log :error, "Error parsing line. (#{e})"
- puts e.backtrace
+
+ e.backtrace.each do |line|
+ puts " #{line}"
+ end
end
end
end
@@ -71,7 +74,6 @@ module Dinobot
message.sub!(@trigger, '')
methods = parse_command(user, channel, message)
-
run_methods(methods) if methods.is_a?(Array)
end
end
@@ -160,17 +162,17 @@ module Dinobot
mod = mod.downcase.intern
log :info, "Unloading module: #{mod}"
- unless @modules.has_key?(mod)
- log :error, "Failed to unload module: #{mod} (module not loaded)"
- return
- end
+ begin
+ raise 'module not loaded' unless @modules.has_key?(mod)
- @modules.delete(mod)
+ @modules.delete(mod)
+ m = Dinobot.send(:remove_const,
+ Dinobot.constants.find { |x| x.downcase == mod })
- Dinobot.send(
- :remove_const,
- Dinobot.constants.find { |x| x.downcase == mod }
- )
+ log :info, "Unloaded module: #{mod} (#{m})"
+ rescue => e
+ log :error, "Failed to unload module: #{mod} (#{e})"
+ end
end
def log(type, str)