diff options
author | David Vazgenovich Shakaryan <dvshakaryan@gmail.com> | 2014-04-15 06:07:20 -0700 |
---|---|---|
committer | David Vazgenovich Shakaryan <dvshakaryan@gmail.com> | 2014-04-15 06:07:20 -0700 |
commit | b6d1cc2f13290970eb2fc0094c5d3f209d450d75 (patch) | |
tree | a33fc15ef252c18568e0ed046d0061f885df177a | |
parent | 687a2b70a1258f7e9129ecf38c9b91f65d3a6ec8 (diff) | |
download | dinobot-b6d1cc2f13290970eb2fc0094c5d3f209d450d75.tar.gz dinobot-b6d1cc2f13290970eb2fc0094c5d3f209d450d75.tar.xz |
Cleanup and bug fixes.
-rw-r--r-- | admin.rb | 4 | ||||
-rw-r--r-- | dinobot.rb | 32 |
2 files changed, 21 insertions, 15 deletions
@@ -48,6 +48,8 @@ module Dinobot argument.split.each do |x| @bot.load_module x.intern end + + nil end def unload(user, channel, argument) @@ -56,6 +58,8 @@ module Dinobot argument.split.each do |x| @bot.unload_module x.intern end + + nil end def listmodules(user, channel, argument) @@ -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) |