# HG changeset patch # User Matthew Wild # Date 1300117100 0 # Node ID b9d319376f6d1e96cb630b61aed73a61aca165ab # Parent a1c73a366ee062678c4292eaf2e64f55499090cc uptime: Refactor reply text generation diff -r a1c73a366ee0 -r b9d319376f6d plugins/uptime.lua --- a/plugins/uptime.lua Mon Mar 14 14:18:16 2011 +0000 +++ b/plugins/uptime.lua Mon Mar 14 15:38:20 2011 +0000 @@ -1,7 +1,5 @@ local st = require "util.stanza"; -local xmlns_last = "jabber:iq:last"; - function riddim.plugins.uptime(bot) bot.stream:add_plugin("uptime"); bot.stream.uptime:set{ @@ -10,20 +8,23 @@ bot:hook("commands/uptime", function (command) local who, param = bot.stream.jid, command.param; + local reply_prefix = "I have been running for "; if param then if command.room and command.room.occupants[param] then who = command.room.occupants[param].jid; + reply_prefix = param.." has been idle for "; elseif command.room and command.room.occupants[param:gsub("%s$", "")] then who = command.room.occupants[param:gsub("%s$", "")].jid; + reply_prefix = param.." has been idle for "; else who = param; + reply_prefix = param.." has been running for "; end end bot.stream:query_uptime(who, function (reply) if not reply.error then - local saywho = (who == command.sender.jid and "You are") or (param and param.." is" or "I am"); - command:reply(saywho..convert_time(reply.seconds)); + command:reply(reply_prefix..convert_time(reply.seconds)); else local type, condition, text = reply.type, reply.condition, reply.text; local r = "There was an error requesting "..param.."'s version"; @@ -54,7 +55,7 @@ local hours = t%24; t = (t - hours)/24; local days = t; - return string.format(" up from %d day%s, %d hour%s and %d minute%s", + return string.format("%d day%s, %d hour%s and %d minute%s", days, (days ~= 1 and "s") or "", hours, (hours ~= 1 and "s") or "", minutes, (minutes ~= 1 and "s") or ""); end