OnHub Time Logger V.1.63_LUA5
 

News:

29 December 2022 - PtokaX 0.5.3.0 (20th anniversary edition) released...
11 April 2017 - PtokaX 0.5.2.2 released...
8 April 2015 Anti child and anti pedo pr0n scripts are not allowed anymore on this board!
28 September 2015 - PtokaX 0.5.2.1 for Windows 10 IoT released...
3 September 2015 - PtokaX 0.5.2.1 released...
16 August 2015 - PtokaX 0.5.2.0 released...
1 August 2015 - Crowdfunding for ADC protocol support in PtokaX ended. Clearly nobody want ADC support...
30 June 2015 - PtokaX 0.5.1.0 released...
30 April 2015 Crowdfunding for ADC protocol support in PtokaX
26 April 2015 New support hub!
20 February 2015 - PtokaX 0.5.0.3 released...
13 April 2014 - PtokaX 0.5.0.2 released...
23 March 2014 - PtokaX testing version 0.5.0.1 build 454 is available.
04 March 2014 - PtokaX.org sites were temporary down because of DDOS attacks and issues with hosting service provider.

Main Menu

OnHub Time Logger V.1.63_LUA5

Started by UwV, 05 March, 2005, 14:37:04

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

UwV

Code: lua
--OnHub Time Logger V.1.63_LUA5
--27.9.03 by c h i l l e r
--thx to tezlo for the nice calculation from math.minutes to months, days, etc., and to Nagini, and to RabidWombat
--ChangeLog :
--27.9.03 Added Serialisation.
-- 03-04-05 converted to LUA5 for PtokaX by UwV

-- You will need to create " UserHubTime.txt "  in "txt"  Folder in the PtokaX scripts Folder,
-- ,.. like this ->  your_Ptokaxfolder/scripts/txt/UserHubTime.txt  <-
---------------------------------------------------------------------------------------------------------------------------------------------------

-- settings

bot="-=Rimmer=-"        -- Name this bot to what you want
cmd1 = "!myhubtime"    -- Name the commands to what you like
cmd2 = "!allhubtime"
cmd3 = "!hubtime"
Max = 100  --This number stands for the maximum of displayed users for cmd2  , set it to what U like
Max1 = 60  --This number is for the timespan between each data saving in minutes.
Max2 = 23  --This number stands for time in minutes, a user must be online till he is saved to the file.

---------------------------------------------------------------------------------------------------------------------------------------------------
---------------------------------------------------------------------------------------------------------------------------------------------------

Sec = 1000 
Min = 60 * Sec
var1 = 0
UserHubTime ={
        ["HubUpTime"] = 0,
        }
File1 = "UserHubTime.txt"
dofile("txt/"..File1)
---------------------------------------------------------------------------------------------------------------------------------------------------

function Main()
	SetTimer(1 * Min) 
	StartTimer()
end 
---------------------------------------------------------------------------------------------------------------------------------------------------

function OnTimer()
	for i,v in UserHubTime do
		if GetItemByName(i) or i=="HubUpTime" then
			v=v+1
			UserHubTime[i]=v
		end
	end
	var1 = var1 + 1
	if var1 == Max1 then
		WriteFile(UserHubTime, "UserHubTime", File1)
		var1 = 0
	end
end
---------------------------------------------------------------------------------------------------------------------------------------------------

function NewUserConnected(curUser)
	if UserHubTime[curUser.sName]==nil then
		UserHubTime[curUser.sName]=0
	end
end
OpConnected = NewUserConnected
---------------------------------------------------------------------------------------------------------------------------------------------------

function ChatArrival(curUser,data)
                local _,_,cmd = string.find( data, "%b<>%s+(%S+)|")
		if (cmd and string.lower(cmd) == string.lower(cmd1) and UserHubTime[curUser.sName] ) then
			local tmp = UserHubTime[curUser.sName]
			local months, days, hours, minutes = math.floor(tmp/43200), math.floor(math.mod(tmp/1440, 30)), math.floor(math.mod(tmp/60, 24)), math.floor(math.mod(tmp/1, 60))
			curUser:SendData(bot, "You have been online : "..months.." months, "..days.." days, "..hours.." hours, and "..minutes.." minutes ( "..tmp.." min ). That is "..string.format("%.2f",tmp/UserHubTime["HubUpTime"]*100).." % of the total HubUpTime.")
			return 1

		elseif (cmd and string.lower(cmd) == string.lower(cmd2)) then
			curUser:SendData(bot, "   -= The Top "..Max.." Antennea =-\r\n"..
			GetUserMaxTime().."\r\n")
			return 1

		elseif (cmd and string.lower(cmd) == string.lower(cmd3)) then
			local tmp = UserHubTime["HubUpTime"]
			local months, days, hours, minutes = math.floor(tmp/43200), math.floor(math.mod(tmp/1440, 30)), math.floor(math.mod(tmp/60, 24)), math.floor(math.mod(tmp/1, 60))
			curUser:SendData(bot, "The hub has now been online : "..months.." months, "..days.." days, "..hours.." hours, and "..minutes.." minutes ( "..tmp.." min ).")
			return 1

		end
end
----------------------------------------------------------------------------------------------------------

function WriteFile(table, tablename, filename)
	local handle = io.open("txt/"..filename, "w+")
	handle:write(tablename.." = {\n" )
	for key, value in table do
		if value >= Max2 then
			handle:write("\t"..string.format("[%q]",key).." = "..value..",\n")
		end
	end
	handle:write("}");
  	handle:close()
end
----------------------------------------------------------------------------------------------------------

function GetUserMaxTime()
	local TCopy={}
	for i,v in UserHubTime do
		if i~="HubUpTime" then
			table.insert( TCopy, { tonumber(v),i } )
		end
	end
	table.sort( TCopy, function(a, b) return (a[1] > b[1]) end)
	local msg ="\r\n"
	for i = 1,Max do
		if TCopy[i] then
			local months, days, hours, minutes = math.floor(TCopy[i][1]/43200), math.floor(math.mod(TCopy[i][1]/1440, 30)), math.floor(math.mod(TCopy[i][1]/60, 24)), math.floor(math.mod(TCopy[i][1]/1, 60))
			msg = msg.."\t\t# "..i.."  -  "..TCopy[i][2].."\t::\t"..months.." Months, "..days.." Days, "..hours.." Hours, And "..minutes.." Minutes ( "..TCopy[i][1].." min ).\r\n"
		end
	end
	local TCopy={}
	return msg
end


thanks to this board :-)
\NL   The knowledge and skills you have achieved are meant to be forgotten so you can float comfortably in emptiness, without obstruction.
" Holly loves me,...  . "      ;o)

& don't forget, the motto is :
  -- SUPPORT YOUR LOCAL DJ'S --

SMF spam blocked by CleanTalk