diff --git a/tipbot/modules/tipping.py b/tipbot/modules/tipping.py index c7ec3c6..f6a1cef 100644 --- a/tipbot/modules/tipping.py +++ b/tipbot/modules/tipping.py @@ -281,8 +281,8 @@ def RainActive(nick,chan,cmd): return pipe.execute() - log_info("%s rained %s - %s (total %s, acc %s) on the %d nicks active in the last %f hours" % (nick, AmountToString(minu), AmountToString(maxu), AmountToString(units), AmountToString(rained_units), nnicks, hours)) - SendTo(chan, "%s rained %s - %s on the %d nicks active in the last %f hours" % (nick, AmountToString(minu), AmountToString(maxu), nnicks, hours)) + log_info("%s rained %s - %s (total %s, acc %s) on the %d nicks active in the last %s" % (nick, AmountToString(minu), AmountToString(maxu), AmountToString(units), AmountToString(rained_units), nnicks, TimeToString(seconds))) + SendTo(chan, "%s rained %s - %s on the %d nicks active in the last %s" % (nick, AmountToString(minu), AmountToString(maxu), nnicks, TimeToString(seconds))) except Exception,e: log_error('Rain: exception: %s' % str(e)) diff --git a/tipbot/utils.py b/tipbot/utils.py index 87c4fe2..1a54e34 100644 --- a/tipbot/utils.py +++ b/tipbot/utils.py @@ -78,6 +78,30 @@ def AmountToString(amount): samount = "%.16g %s" % (float(lamount) / coinspecs.atomic_units, coinspecs.name) return samount +def TimeToString(seconds): + seconds=float(seconds) + if seconds < 1e-3: + return "%.2f microseconds" % (seconds*1e6) + if seconds < 1: + return "%.2f milliseconds" % (seconds*1e3) + if seconds < 60: + return "%.2f seconds" % (seconds) + if seconds < 3600: + return "%.2f minutes" % (seconds / 60) + if seconds < 3600 * 24: + return "%.2f hours" % (seconds / 3600) + if seconds < 3600 * 24 * 30.5: + return "%.2f days" % (seconds / (3600*24)) + if seconds < 3600 * 24 * 365.25: + return "%.2f months" % (seconds / (3600*24*30.5)) + if seconds < 3600 * 24 * 365.25 * 100: + return "%.2f years" % (seconds / (3600*24*365.25)) + if seconds < 3600 * 24 * 365.25 * 1000: + return "%.2f centuries" % (seconds / (3600*24*365.25 * 100)) + if seconds < 3600 * 24 * 365.25 * 1000000: + return "%.2f millenia" % (seconds / (3600*24*365.25 * 100)) + return " like, forever, dude" + def SendJSONRPCCommand(host,port,method,params): try: http = httplib.HTTPConnection(host,port,timeout=20)