Compare commits
	
		
			5 commits
		
	
	
		
			214b621cdf
			...
			1b498be1d6
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
| 1b498be1d6 | |||
| 8421b61a82 | |||
| 5dee01b07b | |||
| 9a9bd56b7d | |||
| 00b15b847b | 
					 7 changed files with 50 additions and 6 deletions
				
			
		|  | @ -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', | ||||
|  |  | |||
|  | @ -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 | ||||
|  |  | |||
|  | @ -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
									
								
							
							
						
						
									
										21
									
								
								src/cmds/reload.lua
									
										
									
									
									
										Normal 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 | ||||
| } | ||||
|  | @ -17,7 +17,7 @@ | |||
|     "ping": { | ||||
|       "desc": "ping pong", | ||||
| 
 | ||||
|       "pat": "Pong! %ds" | ||||
|       "pat": "Pong! %ds. Uptime: %.1f days (%.1fh, %.1fm.)" | ||||
|     }, | ||||
|     "rub": { | ||||
|       "args": "[valute]...", | ||||
|  |  | |||
|  | @ -17,7 +17,7 @@ | |||
|     "ping": { | ||||
|       "desc": "пинг-понг", | ||||
| 
 | ||||
|       "pat": "Понг! %d секунд" | ||||
|       "pat": "Понг! %dс. В сети: %.1f дней (%.1fч, %.1fм.)" | ||||
|     }, | ||||
|     "rub": { | ||||
|       "args": "[валюта]...", | ||||
|  |  | |||
|  | @ -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() | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue