uptime: Refactor reply text generation

Mon, 14 Mar 2011 15:38:20 +0000

author
Matthew Wild <mwild1@gmail.com>
date
Mon, 14 Mar 2011 15:38:20 +0000
changeset 73
b9d319376f6d
parent 72
a1c73a366ee0
child 74
65be10a5db6d

uptime: Refactor reply text generation

plugins/uptime.lua file | annotate | diff | comparison | revisions
--- 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

mercurial