add uptime

This commit is contained in:
Er2 2022-01-18 18:50:00 +00:00
parent 214b621cdf
commit 00b15b847b
4 changed files with 19 additions and 6 deletions

View file

@ -1,5 +1,11 @@
return {
run = function(C, msg)
C.api:send(msg, msg.loc.pat:format(os.time() - msg.date))
local t = os.time()
local ps, ls, lm, lh, ld
ps, ls = t - msg.date, t - C.loaded
lm = ls / 60
lh = lm / 60
ld = lh / 24
C.api:send(msg, msg.loc.pat:format(ps, ld, lh, lm, ls))
end
}
}

View file

@ -17,7 +17,7 @@
"ping": {
"desc": "ping pong",
"pat": "Pong! %ds"
"pat": "Pong! %ds. Uptime: %d days (%dh, %dm.)"
},
"rub": {
"args": "[valute]...",

View file

@ -17,7 +17,7 @@
"ping": {
"desc": "пинг-понг",
"pat": "Понг! %d секунд"
"pat": "Понг! %dс. В сети: %d дней (%dч, %dм.)"
},
"rub": {
"args": "[валюта]...",

View file

@ -2,6 +2,7 @@
local Core = {
config = config,
loaded = 0,
}
(require 'etc.events')(Core) -- add events
@ -13,8 +14,7 @@ function Core:load(what)
print(('Loading %s (%d / %d) %s...'):format(what:sub(0, -2), i, s, v))
-- Lint
if true then
--pcall(require, 'src.'.. what ..'.'.. v) then
if pcall(require, 'src.'.. what ..'.'.. v) then
local a=require('src.'.. what ..'.'.. v)
if what == 'events' then self.api:on(v, a)
elseif what == 'cmds' then self.cmds[v] = a
@ -23,6 +23,7 @@ function Core:load(what)
else print 'fail' end
end
print(('Loaded %d %s'):format(s, what))
self.loaded = os.time()
end
function Core:ev(t, i, name, ...)
@ -44,4 +45,10 @@ function Core:init()
self:emit 'ready'
end
function Core:stop()
self.api:destroy()
print 'Stopped'
print('Uptime: '.. os.time() - self.loaded.. ' seconds')
end
Core:init()