File: uptime.lua

package info (click to toggle)
eiskaltdcpp 2.2.9-3
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 20,372 kB
  • ctags: 12,362
  • sloc: cpp: 94,068; ansic: 8,832; perl: 1,523; xml: 1,378; sh: 685; php: 661; makefile: 101
file content (34 lines) | stat: -rw-r--r-- 918 bytes parent folder | download | duplicates (10)
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
--// vim:ts=4:sw=4:noet
--// uptime.lua -- Record uptime of script (and most likely, BCDC++)

if not uptime then
	uptime = {}
	uptime.start = os.time()
	uptime.diff = function()
		return os.difftime( os.time(), uptime.start )
	end
	uptime.format = function()
		local s = uptime.diff()
		local t = os.date( "!*t", s )
		return string.format( "%i day(s) %02i:%02i:%02i",
				s / 86400, t.hour, t.min, t.sec )
	end
end

dcpp:setListener( "ownChatOut", "uptime",
	function( hub, text )
		local s = string.lower( text )
		if text == "/uptime" then
			hub:addLine(  "Uptime: "..uptime.format() )
			return 1
		elseif text == "/uptime show" then
			hub:sendChat( "My DC++ client uptime is: "..uptime.format() )
			return 1
		elseif string.sub(s, 1, 5) == "/help" then
			hub:addLine( "(uptime.lua) /uptime [show]" )
			return nil
		end
	end
)

DC():PrintDebug( "  ** Loaded uptime.lua **" )