]> git.netwichtig.de Git - user/henk/code/ruby/rbot.git/blobdiff - lib/rbot/utils.rb
Fix help. For real
[user/henk/code/ruby/rbot.git] / lib / rbot / utils.rb
index 4c474ae4f246291c596c92533d18597a948e3445..75277c514668aca6838088098e48211c500128ac 100644 (file)
@@ -6,6 +6,24 @@ module Irc
   # miscellaneous useful functions
   module Utils
 
+    # turn a number of seconds into a human readable string, e.g
+    # 2 days, 3 hours, 18 minutes, 10 seconds
+    def Utils.secs_to_string(secs)
+      ret = ""
+      days = (secs / (60 * 60 * 24)).to_i
+      secs = secs % (60 * 60 * 24)
+      hours = (secs / (60 * 60)).to_i
+      secs = (secs % (60 * 60))
+      mins = (secs / 60).to_i
+      secs = (secs % 60).to_i
+      ret += "#{days} days, " if days > 0
+      ret += "#{hours} hours, " if hours > 0 || days > 0
+      ret += "#{mins} minutes and " if mins > 0 || hours > 0 || days > 0
+      ret += "#{secs} seconds"
+      return ret
+    end
+
+
     def Utils.safe_exec(command, *args)
       IO.popen("-") {|p|
         if(p)
@@ -15,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"
@@ -57,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