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 |   owner = 935626920 , -- hehe | ||||||
|   cmds = { |   cmds = { | ||||||
|     'eval', |     'eval', | ||||||
|  |     'reload', | ||||||
|     'ping', |     'ping', | ||||||
|     'rub', |     'rub', | ||||||
|     'start', |     'start', | ||||||
|  | @ -10,6 +11,7 @@ return { | ||||||
|   events = { |   events = { | ||||||
|     'command', |     'command', | ||||||
|     'ready', |     'ready', | ||||||
|  |     'inlineQuery', | ||||||
|   }, |   }, | ||||||
|   parts = { |   parts = { | ||||||
|     'locale', |     'locale', | ||||||
|  |  | ||||||
|  | @ -17,6 +17,14 @@ end | ||||||
| function events:on(n,f)   self:_add('on', n,f)   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: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, ...) | function events:_ev(t, i, name, ...) | ||||||
|   local v = t[i] |   local v = t[i] | ||||||
|   if v.name == name then |   if v.name == name then | ||||||
|  |  | ||||||
|  | @ -1,5 +1,11 @@ | ||||||
| return { | return { | ||||||
|   run = function(C, msg) |   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 |   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": { |     "ping": { | ||||||
|       "desc": "ping pong", |       "desc": "ping pong", | ||||||
| 
 | 
 | ||||||
|       "pat": "Pong! %ds" |       "pat": "Pong! %ds. Uptime: %.1f days (%.1fh, %.1fm.)" | ||||||
|     }, |     }, | ||||||
|     "rub": { |     "rub": { | ||||||
|       "args": "[valute]...", |       "args": "[valute]...", | ||||||
|  |  | ||||||
|  | @ -17,7 +17,7 @@ | ||||||
|     "ping": { |     "ping": { | ||||||
|       "desc": "пинг-понг", |       "desc": "пинг-понг", | ||||||
| 
 | 
 | ||||||
|       "pat": "Понг! %d секунд" |       "pat": "Понг! %dс. В сети: %.1f дней (%.1fч, %.1fм.)" | ||||||
|     }, |     }, | ||||||
|     "rub": { |     "rub": { | ||||||
|       "args": "[валюта]...", |       "args": "[валюта]...", | ||||||
|  |  | ||||||
|  | @ -2,6 +2,7 @@ | ||||||
| 
 | 
 | ||||||
| local Core = { | local Core = { | ||||||
|   config = config, |   config = config, | ||||||
|  |   loaded = 0, | ||||||
| } | } | ||||||
| (require 'etc.events')(Core) -- add events | (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)) |     print(('Loading %s (%d / %d) %s...'):format(what:sub(0, -2), i, s, v)) | ||||||
|     -- Lint |     -- Lint | ||||||
|     if true then  |     if pcall(require, 'src.'.. what ..'.'.. v) then | ||||||
|     --pcall(require, 'src.'.. what ..'.'.. v) then |  | ||||||
|       local a=require('src.'.. what ..'.'.. v) |       local a=require('src.'.. what ..'.'.. v) | ||||||
|       if     what == 'events' then self.api:on(v, a) |       if     what == 'events' then self.api:on(v, a) | ||||||
|       elseif what == 'cmds'   then self.cmds[v] = a |       elseif what == 'cmds'   then self.cmds[v] = a | ||||||
|  | @ -23,6 +23,7 @@ function Core:load(what) | ||||||
|     else print 'fail' end |     else print 'fail' end | ||||||
|   end |   end | ||||||
|   print(('Loaded %d %s'):format(s, what)) |   print(('Loaded %d %s'):format(s, what)) | ||||||
|  |   self.loaded = os.time() | ||||||
| end | end | ||||||
| 
 | 
 | ||||||
| function Core:ev(t, i, name, ...) | function Core:ev(t, i, name, ...) | ||||||
|  | @ -44,4 +45,10 @@ function Core:init() | ||||||
|   self:emit 'ready' |   self:emit 'ready' | ||||||
| end | end | ||||||
| 
 | 
 | ||||||
|  | function Core:stop() | ||||||
|  |   self.api:destroy() | ||||||
|  |   print 'Stopped' | ||||||
|  |   print('Uptime: '.. os.time() - self.loaded.. ' seconds') | ||||||
|  | end | ||||||
|  | 
 | ||||||
| Core:init() | Core:init() | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue