This repository has been archived by the owner on Aug 20, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
interface.lua
64 lines (57 loc) · 1.77 KB
/
interface.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
local modname = minetest.get_current_modname()
local thismod = _G[modname]
minetest.register_chatcommand('seen', {
param = "<name>",
description = "Tells the last time a player was online",
func = function (name, param)
if param ~= nil then
local t = thismod.get_last_online(param)
if t ~= nil then
local diff = (os.time() - t)
minetest.chat_send_player(name,param.." was last online "..breakdowntime(diff).." ago")
else
minetest.chat_send_player(name,"Sorry, I have no record of "..param)
end
else
minetest.chat_send_player(name,"Usage is /seen <name>")
end
end
})
minetest.register_chatcommand('timeonline', {
param = "<name>",
description = "Shows the cumulative time a player has been online",
func = function (name, param)
if param ~= nil then
local t = thismod.get_time_online(param)
if t ~= nil then
minetest.chat_send_player(name,param.." has been online for "..breakdowntime(t))
else
minetest.chat_send_player(name,"Sorry, I have no record of "..param)
end
else
minetest.chat_send_player(name,"Usage is /timeonline <name>")
end
end
})
function breakdowntime(t)
local countdown = t
local answer = ""
if countdown >= 86400 then
local days = math.floor(countdown / 86400)
countdown = countdown % 86400
answer = days .. " days "
end
if countdown >= 3600 then
local hours = math.floor(countdown / 3600)
countdown = countdown % 3600
answer = answer .. hours .. " hours "
end
if countdown >= 60 then
local minutes = math.floor(countdown / 60)
countdown = countdown % 60
answer = answer .. minutes .. " minutes "
end
local seconds = countdown
answer = answer .. seconds .. " seconds"
return answer
end