Compare commits

...

5 commits

Author SHA1 Message Date
Er2
1b498be1d6 now must reload 2022-01-18 19:48:06 +00:00
Er2
8421b61a82 aww 2022-01-18 19:37:23 +00:00
Er2
5dee01b07b reload 2022-01-18 19:34:23 +00:00
Er2
9a9bd56b7d use floats 2022-01-18 19:15:03 +03:00
Er2
00b15b847b add uptime 2022-01-18 18:50:00 +00:00
7 changed files with 50 additions and 6 deletions

View file

@ -3,6 +3,7 @@ return {
owner = 935626920 , -- hehe
cmds = {
'eval',
'reload',
'ping',
'rub',
'start',
@ -10,6 +11,7 @@ return {
events = {
'command',
'ready',
'inlineQuery',
},
parts = {
'locale',

View file

@ -17,6 +17,14 @@ end
function events:on(n,f) self:_add('on', n,f) end
function events:once(n,f) self:_add('once', n,f) end
function events:off(f)
for k, v in pairs(self._ev_) do
if v.fn == f then
table.remove(self._ev_, k)
end
end
end
function events:_ev(t, i, name, ...)
local v = t[i]
if v.name == name then

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
}
}

21
src/cmds/reload.lua Normal file
View file

@ -0,0 +1,21 @@
return {
private = true,
run = function(C, msg)
local cat, sub = table.unpack(msg.args)
if not (cat and sub) then
return C.api:reply(msg, '/reload cmds ping')
end
local path = 'src.'..cat..'.'..sub
package.loaded[path] = nil
local err, m = pcall(require, path)
if not err then return C.api:reply(msg, 'Reload failed. ' .. m)
elseif cat == 'events' then C.api:off(m); C.api:on(sub, m)
elseif cat == 'cmds' then C.cmds[sub] = m
elseif cat == 'parts' then m(C)
end
C.api:reply(msg, 'Reloaded. ' .. tostring(m))
end
}

View file

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

View file

@ -17,7 +17,7 @@
"ping": {
"desc": "пинг-понг",
"pat": "Понг! %d секунд"
"pat": "Понг! %dс. В сети: %.1f дней (%.1fч, %.1fм.)"
},
"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()