summaryrefslogtreecommitdiff
path: root/lib/rbot
diff options
context:
space:
mode:
authorGiuseppe Bilotta <giuseppe.bilotta@gmail.com>2006-07-20 20:08:26 +0000
committerGiuseppe Bilotta <giuseppe.bilotta@gmail.com>2006-07-20 20:08:26 +0000
commit8c45acb731d8ba8bc07f0934af2d4aeda637b155 (patch)
tree50f9e19cbdfd36a6dfe49284b7607e14c09f16ee /lib/rbot
parentda24f0f90c86a399a716d90c645ab921d03c5f51 (diff)
All lib/rbot files are now upgraded to the new logging feature
Diffstat (limited to 'lib/rbot')
-rw-r--r--lib/rbot/auth.rb12
-rw-r--r--lib/rbot/config.rb8
-rw-r--r--lib/rbot/httputil.rb6
-rw-r--r--lib/rbot/ircsocket.rb8
-rw-r--r--lib/rbot/keywords.rb8
-rw-r--r--lib/rbot/plugins.rb16
-rw-r--r--lib/rbot/rbotconfig.rb2
-rw-r--r--lib/rbot/registry.rb14
-rw-r--r--lib/rbot/utils.rb4
9 files changed, 40 insertions, 38 deletions
diff --git a/lib/rbot/auth.rb b/lib/rbot/auth.rb
index 04e1e98b..ad7283b4 100644
--- a/lib/rbot/auth.rb
+++ b/lib/rbot/auth.rb
@@ -69,9 +69,9 @@ module Irc
File.rename("#{@bot.botclass}/users.yaml.new",
"#{@bot.botclass}/users.yaml")
rescue
- $stderr.puts "failed to write configuration file users.yaml! #{$!}"
- debug "#{e.class}: #{e}"
- debug e.backtrace.join("\n")
+ error "failed to write configuration file users.yaml! #{$!}"
+ error "#{e.class}: #{e}"
+ error e.backtrace.join("\n")
end
begin
debug "Writing new levels.rbot ..."
@@ -84,9 +84,9 @@ module Irc
File.rename("#{@bot.botclass}/levels.rbot.new",
"#{@bot.botclass}/levels.rbot")
rescue
- $stderr.puts "failed to write configuration file levels.rbot! #{$!}"
- debug "#{e.class}: #{e}"
- debug e.backtrace.join("\n")
+ error "failed to write configuration file levels.rbot! #{$!}"
+ error "#{e.class}: #{e}"
+ error e.backtrace.join("\n")
end
end
diff --git a/lib/rbot/config.rb b/lib/rbot/config.rb
index c974c78f..a863c524 100644
--- a/lib/rbot/config.rb
+++ b/lib/rbot/config.rb
@@ -316,7 +316,7 @@ module Irc
@@config.update newconfig
return
rescue
- $stderr.puts "failed to read conf.yaml: #{$!}"
+ error "failed to read conf.yaml: #{$!}"
end
end
# if we got here, we need to run the first-run wizard
@@ -336,9 +336,9 @@ module Irc
File.rename("#{@@bot.botclass}/conf.yaml.new",
"#{@@bot.botclass}/conf.yaml")
rescue => e
- $stderr.puts "failed to write configuration file conf.yaml! #{$!}"
- debug "#{e.class}: #{e}"
- debug e.backtrace.join("\n")
+ error "failed to write configuration file conf.yaml! #{$!}"
+ error "#{e.class}: #{e}"
+ error e.backtrace.join("\n")
end
end
diff --git a/lib/rbot/httputil.rb b/lib/rbot/httputil.rb
index dc128c43..b254a791 100644
--- a/lib/rbot/httputil.rb
+++ b/lib/rbot/httputil.rb
@@ -48,7 +48,7 @@ class HttpUtil
begin
list.concat Resolv.getaddresses(uri.host)
rescue StandardError => err
- puts "warning: couldn't resolve host uri.host"
+ warning "couldn't resolve host uri.host"
end
unless @bot.config["http.proxy_exclude"].empty?
@@ -130,12 +130,12 @@ class HttpUtil
if resp.code == "200"
return resp.body
else
- puts "HttpUtil.get return code #{resp.code} #{resp.body}"
+ log "HttpUtil.get return code #{resp.code} #{resp.body}"
end
return nil
}
rescue StandardError, Timeout::Error => e
- $stderr.puts "HttpUtil.get exception: #{e}, while trying to get #{uri}"
+ error "HttpUtil.get exception: #{e.inspect}, while trying to get #{uri}"
end
return nil
end
diff --git a/lib/rbot/ircsocket.rb b/lib/rbot/ircsocket.rb
index 2a1549a2..5a06c075 100644
--- a/lib/rbot/ircsocket.rb
+++ b/lib/rbot/ircsocket.rb
@@ -93,10 +93,10 @@ module Irc
begin
@sock=TCPSocket.new(@server, @port, @host)
rescue ArgumentError => e
- $stderr.puts "Your version of ruby does not support binding to a "
- $stderr.puts "specific local address, please upgrade if you wish "
- $stderr.puts "to use HOST = foo"
- $stderr.puts "(this option has been disabled in order to continue)"
+ error "Your version of ruby does not support binding to a "
+ error "specific local address, please upgrade if you wish "
+ error "to use HOST = foo"
+ error "(this option has been disabled in order to continue)"
@sock=TCPSocket.new(@server, @port)
end
else
diff --git a/lib/rbot/keywords.rb b/lib/rbot/keywords.rb
index 29eadaac..d65478fe 100644
--- a/lib/rbot/keywords.rb
+++ b/lib/rbot/keywords.rb
@@ -99,7 +99,7 @@ module Irc
# import old format keywords into DBHash
if(File.exist?("#{@bot.botclass}/keywords.rbot"))
- puts "auto importing old keywords.rbot"
+ log "auto importing old keywords.rbot"
IO.foreach("#{@bot.botclass}/keywords.rbot") do |line|
if(line =~ /^(.*?)\s*<=(is|are)?=?>\s*(.*)$/)
lhs = $1
@@ -128,7 +128,7 @@ module Irc
# first scan for old DBHash files, and convert them
Dir["#{@bot.botclass}/keywords/*"].each {|f|
next unless f =~ /\.db$/
- puts "upgrading keyword db #{f} (rbot 0.9.5 or prior) database format"
+ log "upgrading keyword db #{f} (rbot 0.9.5 or prior) database format"
newname = f.gsub(/\.db$/, ".kdb")
old = BDB::Hash.open f, nil,
"r+", 0600
@@ -156,7 +156,7 @@ module Irc
Dir["#{@bot.botclass}/keywords/*"].each {|f|
next if f =~ /\.kdb$/
next if f =~ /CVS$/
- puts "auto converting keywords from #{f}"
+ log "auto converting keywords from #{f}"
key = File.basename(f)
unless @statickeywords.has_key?(key)
@statickeywords[key] = DBHash.new @bot, "#{f}.db", true
@@ -182,7 +182,7 @@ module Irc
# upgrade data files found in old rbot formats to current
def upgrade_data
if File.exist?("#{@bot.botclass}/keywords.db")
- puts "upgrading old keywords (rbot 0.9.5 or prior) database format"
+ log "upgrading old keywords (rbot 0.9.5 or prior) database format"
old = BDB::Hash.open "#{@bot.botclass}/keywords.db", nil,
"r+", 0600
new = BDB::CIBtree.open "#{@bot.botclass}/keyword.db", nil,
diff --git a/lib/rbot/plugins.rb b/lib/rbot/plugins.rb
index 65cca909..bc522300 100644
--- a/lib/rbot/plugins.rb
+++ b/lib/rbot/plugins.rb
@@ -212,8 +212,8 @@ module Plugins
processed << file
rescue Exception => err
# rescue TimeoutError, StandardError, NameError, LoadError, SyntaxError => err
- puts "warning: plugin #{tmpfilename} load failed: " + err
- puts err.backtrace.join("\n")
+ warning "plugin #{tmpfilename} load failed: " + err.inspect
+ warning err.backtrace.join("\n")
end
}
end
@@ -264,8 +264,8 @@ module Plugins
return @@plugins[key].help(key, params)
rescue Exception => err
#rescue TimeoutError, StandardError, NameError, SyntaxError => err
- puts "plugin #{@@plugins[key].name} help() failed: #{err.class}: #{err}"
- puts err.backtrace.join("\n")
+ error "plugin #{@@plugins[key].name} help() failed: #{err.class}: #{err}"
+ error err.backtrace.join("\n")
end
else
return false
@@ -282,8 +282,8 @@ module Plugins
p.send method, *args
rescue Exception => err
#rescue TimeoutError, StandardError, NameError, SyntaxError => err
- puts "plugin #{p.name} #{method}() failed: #{err.class}: #{err}"
- puts err.backtrace.join("\n")
+ error "plugin #{p.name} #{method}() failed: #{err.class}: #{err}"
+ error err.backtrace.join("\n")
end
end
}
@@ -300,8 +300,8 @@ module Plugins
@@plugins[m.plugin].privmsg(m)
rescue Exception => err
#rescue TimeoutError, StandardError, NameError, SyntaxError => err
- puts "plugin #{@@plugins[m.plugin].name} privmsg() failed: #{err.class}: #{err}"
- puts err.backtrace.join("\n")
+ error "plugin #{@@plugins[m.plugin].name} privmsg() failed: #{err.class}: #{err}"
+ error err.backtrace.join("\n")
end
return true
end
diff --git a/lib/rbot/rbotconfig.rb b/lib/rbot/rbotconfig.rb
index de716169..212df990 100644
--- a/lib/rbot/rbotconfig.rb
+++ b/lib/rbot/rbotconfig.rb
@@ -39,7 +39,7 @@ module Irc
require 'rbot/pkgconfig'
@@datadir = PKGConfig::DATADIR
rescue LoadError
- puts "fatal - no way to determine data dir"
+ error "fatal - no way to determine data dir"
exit 2
end
end
diff --git a/lib/rbot/registry.rb b/lib/rbot/registry.rb
index 580bfb5b..2cb28b60 100644
--- a/lib/rbot/registry.rb
+++ b/lib/rbot/registry.rb
@@ -16,7 +16,7 @@ module Irc
# work with is @bot.botclass.
def upgrade_data
if File.exist?("#{@bot.botclass}/registry.db")
- puts "upgrading old-style (rbot 0.9.5 or earlier) plugin registry to new format"
+ log "upgrading old-style (rbot 0.9.5 or earlier) plugin registry to new format"
old = BDB::Hash.open("#{@bot.botclass}/registry.db", nil,
"r+", 0600)
new = BDB::CIBtree.open("#{@bot.botclass}/plugin_registry.db", nil,
@@ -36,14 +36,14 @@ module Irc
Dir.mkdir("#{@bot.botclass}/registry") unless File.exist?("#{@bot.botclass}/registry")
env = BDB::Env.open("#{@bot.botclass}", BDB::INIT_TRANSACTION | BDB::CREATE | BDB::RECOVER)
dbs = Hash.new
- puts "upgrading previous (rbot 0.9.9 or earlier) plugin registry to new split format"
+ log "upgrading previous (rbot 0.9.9 or earlier) plugin registry to new split format"
old = BDB::CIBtree.open("#{@bot.botclass}/plugin_registry.db", nil,
"r+", 0600, "env" => env)
old.each {|k,v|
prefix,key = k.split("/", 2)
prefix.downcase!
unless dbs.has_key?(prefix)
- puts "creating db #{@bot.botclass}/registry/#{prefix}.db"
+ log "creating db #{@bot.botclass}/registry/#{prefix}.db"
dbs[prefix] = BDB::CIBtree.open("#{@bot.botclass}/registry/#{prefix}.db",
nil, BDB::CREATE | BDB::EXCL,
0600, "env" => env)
@@ -54,7 +54,7 @@ module Irc
old.close
File.rename("#{@bot.botclass}/plugin_registry.db", "#{@bot.botclass}/plugin_registry.db.old")
dbs.each {|k,v|
- puts "closing db #{k}"
+ log "closing db #{k}"
v.close
}
env.close
@@ -147,8 +147,10 @@ module Irc
def restore(val)
begin
Marshal.restore(val)
- rescue Exception
- $stderr.puts "failed to restore marshal data, falling back to default"
+ rescue Exception => e
+ warning "failed to restore marshal data for #{val.inspect}, falling back to default"
+ debug e.inspect
+ debug e.backtrace.join("\n")
if @default != nil
begin
return Marshal.restore(@default)
diff --git a/lib/rbot/utils.rb b/lib/rbot/utils.rb
index a1a8c484..75277c51 100644
--- a/lib/rbot/utils.rb
+++ b/lib/rbot/utils.rb
@@ -33,7 +33,7 @@ module Irc
$stderr = $stdout
exec(command, *args)
rescue Exception => e
- puts "exec of #{command} led to exception: #{e}"
+ puts "exec of #{command} led to exception: #{e.inspect}"
Kernel::exit! 0
end
puts "exec of #{command} failed"
@@ -75,7 +75,7 @@ module Irc
}
rescue => e
# cheesy for now
- $stderr.puts "Utils.http_get exception: #{e}, while trying to get #{uristr}"
+ error "Utils.http_get exception: #{e.inspect}, while trying to get #{uristr}"
return nil
end
end