changeset 1048:50bed746aa16

mod_lastlog: Fix command
author Kim Alvefur <zash@zash.se>
date Mon, 03 Jun 2013 19:35:13 +0200
parents 38781835c911
children 59f031d1cd38
files mod_lastlog/mod_lastlog.lua
diffstat 1 files changed, 10 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/mod_lastlog/mod_lastlog.lua	Mon Jun 03 19:03:42 2013 +0200
+++ b/mod_lastlog/mod_lastlog.lua	Mon Jun 03 19:35:13 2013 +0200
@@ -27,10 +27,16 @@
 
 function module.command(arg)
 	local user, host = require "util.jid".prepped_split(table.remove(arg, 1));
-	local lastlog = datamanager.load(user, host, "lastlog") or {};
-	print("Last login: "..(lastlog and os.date("%Y-%m-%d %H:%m:%s", datamanager.load(user, host, "lastlog").time) or "<unknown>"));
-	if lastlog.ip then
-		print("IP address: "..lastlog.ip);
+	require"core.storagemanager".initialize_host(host);
+	local lastlog = assert(datamanager.load(user, host, "lastlog"));
+	if lastlog then
+		print(("Last %s: %s"):format(lastlog.event or "login",
+		lastlog.timestamp and os.date("%Y-%m-%d %H:%M:%S", lastlog.timestamp) or "<unknown>"));
+		if lastlog.ip then
+			print("IP address: "..lastlog.ip);
+		end
+	else
+		print("No record found");
 	end
 	return 0;
 end