From d30940cb5ff75cf7eab81f6a588b3b5297a762ad Mon Sep 17 00:00:00 2001 From: Tom Gilbert Date: Sat, 30 Jul 2005 21:35:57 +0000 Subject: Sat Jul 30 22:33:36 BST 2005 Tom Gilbert * Config items are now objects, various types are available. * The config wizard will now use registered config items if :wizard is set to true for those items. It will ask questions in the order they were registered. * The config module now works for doing runtime configuration. * misc refactoring --- lib/rbot/utils.rb | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'lib/rbot/utils.rb') diff --git a/lib/rbot/utils.rb b/lib/rbot/utils.rb index 4c474ae4..a1a8c484 100644 --- a/lib/rbot/utils.rb +++ b/lib/rbot/utils.rb @@ -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) -- cgit v1.2.3