Top Hubbers
 

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

Top Hubbers

Started by jiten, 21 March, 2006, 18:39:53

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

jiten

--[[

	TopHubbers 2.02 - LUA 5.0/5.1 by jiten
	?????????????????????????????????????
	Based on: OnHub Time Logger 1.65 by chill and Robocop's layout

	Usage: !tophubbers; !tophubbers x-y; !hubtime <nick>; !myhubtime

	CHANGELOG:
	??????????
	Fixed: Typo in table.sort function;
	Added: OnExit (3/21/2006)
	Fixed: Missing pairs() in SaveToFile
	Changed: Removed iGlobalTime and added TotalTime count to OnTimer
	Changed: SecondsToTime function values (3/24/2006)
	Changed: math.floor/mod in TopHubbers' function; (3/5/2006)
	Changed: SecondsToTime month value (4/17/2006);
	Added: !hubtime <nick> - requested by speedX;
	Changed: SecondsToTime function and small code bits (8/16/2006)
	Changed: Table indexes;
	Changed: SecondsToTime function to MinutesToTime;
	Fixed: Inaccurate average uptime stuff (8/17/2006)
	Changed: Average uptime function;
	Changed: Session time for offline users doesn't get reset;
	Added: Average uptime warning on connect - requested by speedX (8/20/2006)
	Added: Customized profiles - requested by Naithif (8/20/2006)
	Added: User Commands - requested by TT;
	Added: Rankings and related commands [!myrank & !topranks] - requested by speedX;
	Added: Toggle rank info on connect - requested by TT;
	Fixed: !tophubbers x-y;
	Added: Comments to the code;
	Changed: Some code bits;
	Added: Toggle between total and average uptime (8/24/2006)
	Fixed: Minimum average uptime warning - reported by speedX;
	Added: Maximum shown hubbers - requested by Naithif (8/29/2006)
	Fixed: LUA 5.0/5.1 compatibility - reported by speedX (11/8/2006)
	Added: string.lower check - requested by SwapY and speedX (11/10/2006)

]]--

-SkA-

Thanks again  ;)
Posted on: 21 March 2006, 20:30:35
hemm jiten, it works fine but when I stop hub, it losts all data  :(
???:::??x??em?-N????:::??? ?wN??

BrianzaLand Blog" style="border:0

jiten

First post updated with the bugfix.

-SkA-

ok  :)
Posted on: 21 March 2006, 22:34:16
Again a problem eheh

When Ptokax run, !tophubbers said:

   =========================================================================================================
   Nr.  Total:               Session:   Entered Hub:   Left Hub:      Status:   Name:
   ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
   1.    0 month(s), 0 day(s), 0 hour(s), 2 minutes(s)   2 min   03/22/06 09:56:53   03/22/06 09:55:26   *Online*   -SkA-
   -----------------------------------------------------------------------------------------------------------------------------------------------------------------

When I close the hub and re-open Ptokax, script losts data:

   =========================================================================================================
   Nr.  Total:               Session:   Entered Hub:   Left Hub:      Status:   Name:
   ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
   1.    0 month(s), 0 day(s), 0 hour(s), 0 minutes(s)   0 min   03/22/06 09:59:31   03/22/06 09:55:26   *Online*   -SkA-
   ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
???:::??x??em?-N????:::??? ?wN??

BrianzaLand Blog" style="border:0

jiten

Quote from: -SkA- on 22 March, 2006, 10:02:58
When I close the hub and re-open Ptokax, script losts data:
The file saving issue was solved in the previous update.
With this one, I've changed the way TotalTime is counted.

Cheers

-SkA-

There is again a problem:

Day(s) count doesn't works: when a user stay online for more than 24 hours then "day(s)" is still "0" and "minutes(s)" and "hour(s)" restart from 0.
???:::??x??em?-N????:::??? ?wN??

BrianzaLand Blog" style="border:0

jiten

Quote from: -SkA- on 24 March, 2006, 08:03:29
There is again a problem:

Day(s) count doesn't works: when a user stay online for more than 24 hours then "day(s)" is still "0" and "minutes(s)" and "hour(s)" restart from 0.

Day count worked. It's just that the function that converted it to a readable format wasn't well defined.
I've updated the code once again.

Cheers

jiten

Thank you for your words, mate :)

-SkA-

Just a little detail:

Session time stop at 59 mins: when a user stay in the hub for more than 1 hours, session time count restart from 0 min (I can suppose "session time hours count" don't works)

Thanks,
bye
???:::??x??em?-N????:::??? ?wN??

BrianzaLand Blog" style="border:0

jiten

Quote from: -SkA- on 26 March, 2006, 18:36:33
Just a little detail:

Session time stop at 59 mins: when a user stay in the hub for more than 1 hours, session time count restart from 0 min (I can suppose "session time hours count" don't works)

Thanks,
bye

First post updated once more.

jiten

First post has been updated with some changes in the code.

6Marilyn6Manson6

jiten use [ CODE] and [ /CODE], because actually is it impossible copy your first post with new script, you can copy but when you paste it you see all script in one line, edit your post with correct form :)
Posted on: 16 August 2006, 23:02:36
I have copied your post jiten with success. I have made quote and I have copied script from it,

--[[

	TopHubbers 1.2 - LUA 5.0/5.1 by jiten

	Based on OnHub Time Logger 1.65 by chill and Robocop's layout 

	Usage: !tophubbers; !tophubbers x-y

	Fixed: Typo in table.sort function;
	Added: OnExit (3/21/2006)
	Fixed: Missing pairs() in SaveToFile
	Changed: Removed iGlobalTime and added TotalTime count to OnTimer
	Changed: SecondsToTime function values (3/24/2006)
	Changed: math.floor/mod in TopHubbers' function; (3/5/2006)
	Changed: SecondsToTime month value (4/17/2006);
	Added: !hubtime <nick> - requested by speedX;
	Changed: SecondsToTime function and small code bits (8/16/2006)

]]--

sBot = frmHub:GetHubBotName()
fOnline = "tOnliners.tbl"
tOnline = {}

Main = function()
	if loadfile(fOnline) then dofile(fOnline) end
	SetTimer(60*1000) StartTimer()
end 

OnTimer = function()
	for i, v in pairs(tOnline) do
		if GetItemByName(i) then
			v.iSessionTime = v.iSessionTime + 1; v.iTotalTime = v.iTotalTime + 1
		end
	end
end

OnExit = function()
	SaveToFile(fOnline, tOnline, "tOnline")
end

NewUserConnected = function(user)
	if user.bRegistered then
		if tOnline[user.sName] then
			tOnline[user.sName].iSessionTime = 0; tOnline[user.sName].sEnter = os.date()
		else
			tOnline[user.sName] = { sEnter = os.date(), iSessionTime = 0, iTotalTime = 0, sLeave = os.date() }
		end
	end
end

OpConnected = NewUserConnected

UserDisconnected = function(user)
	if user.bRegistered and tOnline[user.sName] then
		tOnline[user.sName].iSessionTime = 0; tOnline[user.sName].sLeave = os.date()
	end
end

OpDisconnected = UserDisconnected

ChatArrival = function(user,data)
	local _,_, cmd = string.find(data,"^%b<>%s+%!(%S+).*|$")
	if cmd and tCmds[string.lower(cmd)] then
		cmd = string.lower(cmd)
		if tCmds[cmd].tLevels[user.iProfile] then
			return tCmds[cmd].fFunction(user, data),1
		else
			return user:SendData(sBot, "*** Error: You are not allowed to use this command!"),1
		end
	end
end

tCmds = {
	tophubbers = {
		fFunction = function(user, data)
			if next(tOnline) then
				local _,_, iStart, iEnd = string.find(data, "^%b<>%s+%S+%s+(%d+)%-(%d+)|$")
				iStart, iEnd = (iStart or 1), (iEnd or 20)
				local tCopy, msg = {}, "\r\n\t"..string.rep("=", 105).."\r\n\tNr.  Total:\t\t\t\t\tSession:\t"..
				"Entered Hub:\tLeft Hub:\t\tStatus:\tName:\r\n\t"..string.rep("-", 210).."\r\n"
				for i, v in pairs(tOnline) do
					table.insert(tCopy, { sEnter = v.sEnter, iSessionTime = tonumber(v.iSessionTime), 
					iTotalTime = tonumber(v.iTotalTime), sLeave = v.sLeave, sNick = i } )
				end
				table.sort(tCopy, function(a, b) return (a.iTotalTime > b.iTotalTime) end)
				for i, v in pairs(tCopy) do
					local sStatus = "*Offline*"; 
					if GetItemByName(v.sNick) then sStatus = "*Online*" end
					msg = msg.."\t"..i..".    "..SecondsToTime(v.iTotalTime*60).."\t"..
					v.iSessionTime.." min\t"..v.sEnter.."\t"..v.sLeave.."\t"..sStatus.."\t"..v.sNick.."\r\n"
				end
				msg = msg.."\t"..string.rep("-", 210)
				user:SendPM(sBot, "Current Top Hubbers:\r\n"..msg.."\r\n")
			else
				user:SendData(sBot, "*** Error: Top Hubbers' table is currently empty!")
			end
		end,
		tLevels = {
			[-1] = 0, [0] = 1, [1] = 1, [2] = 1, [3] = 1, [4] = 1, [5] = 1,
		},
	},
	hubtime = {
		fFunction = function(user, data)
			local _,_, nick = string.find(data, "^%b<>%s+%S+%s+(%S+)|$")
			if nick then 
				if tOnline[nick] then
					user:SendData(sBot, "*** "..nick.."'s Total uptime: "..
					SecondsToTime(tOnline[nick].iTotalTime*60, true).."; Daily average uptime: "..
					SecondsToTime(tOnline[nick].iTotalTime/(24*60), true))
				else
					user:SendData(sBot, "*** Error: No record found for '"..nick.."'!")
				end
			else
				user:SendData(sBot, "*** Syntax Error: Type !hubtime <nick>")
			end
		end,
		tLevels = { 
			[0] = 1, [1] = 1, [4] = 1, [5] = 1,
		},
	},
}

SecondsToTime = function(iSeconds, bSmall)
	local T = os.date("!*t", tonumber(iSeconds)); string.gfind = (string.gfind or string.gmatch)
	local sTime = string.format("%i month(s), %i day(s), %i hour(s), %i minute(s)", T.month-1, T.day-1, T.hour, T.min)
	if bSmall then
		for i in string.gfind(sTime, "%d+") do
			if tonumber(i) == 0 then sTime = string.gsub(sTime, "^"..i.."%s(%S+),%s", "") end
		end
	end
	return sTime
end

Serialize = function(tTable, sTableName, hFile, sTab)
	sTab = sTab or "";
	hFile:write(sTab..sTableName.." = {\n");
	for key, value in pairs(tTable) do
		if (type(value) ~= "function") then
			local sKey = (type(key) == "string") and string.format("[%q]", key) or string.format("[%d]", key);
			if(type(value) == "table") then
				Serialize(value, sKey, hFile, sTab.."\t");
			else
				local sValue = (type(value) == "string") and string.format("%q", value) or tostring(value);
				hFile:write(sTab.."\t"..sKey.." = "..sValue);
			end
			hFile:write(",\n");
		end
	end
	hFile:write(sTab.."}");
end

SaveToFile = function(file, table, tablename)
	local hFile = io.open(file, "w+") Serialize(table, tablename, hFile); hFile:close()
end


This is correct form for post script :p

jiten

Quote from: 6Marilyn6Manson6 on 16 August, 2006, 22:02:36
jiten use [ CODE] and [ /CODE], because actually is it impossible copy your first post with new script, you can copy but when you paste it you see all script in one line, edit your post with correct form :)

Thanks for speedX, yours and T?M??r?V?ll?R's report.

First post has been updated with the correct syntax.

6Marilyn6Manson6


speedX

#14
Yo jiten, u rock dude. This is wat i wantd, it works fine....
well thx again......
Thanking You,

speedX

-SkA-

What happen if I use old tOnline.tbl with this new version?
???:::??x??em?-N????:::??? ?wN??

BrianzaLand Blog" style="border:0

6Marilyn6Manson6


jiten

Quote from: -SkA- on 17 August, 2006, 08:06:53
What happen if I use old tOnline.tbl with this new version?

You'll get some syntax errors [nil value].

I'll post a 1.1x - 1.2x DB converter later today to fix this issue.

jiten

First post has been updated with some fixes to the code.

jiten

This script will convert the database from versions 1.1x to 1.21.

However, for an accurate Daily average uptime, I'd recommend you to start from the beginning.

--[[ 

	Top Hubbers 1.1x to 1.21 DB Converter by jiten (8/17/2006)

	Requested by: -SkA-

	Changelog:

	1. Place your old tOnliners.tbl under your scripts' folder;
	2. Run this script and the new file "tOnliners(new).tbl" will appear in the same folder;
	3. Backup your old DB (just in case) and rename the new one to the default format.
	4. And that's it!

]]--

-- File to convert
fConvert = "tOnliners.tbl"
-- Output file
fConverted = "tOnliners(new).tbl"

tConvert = {}

Main = function()
	if loadfile(fConvert) then dofile(fConvert) end; tConvert = tOnline
	for i, v in pairs(tOnline) do tConvert[i].Julian = os.time(os.date("!*t")) end
	local hFile = io.open(fConverted, "w+") Serialize(tConvert, "tOnline", hFile); hFile:close() 
end

Serialize = function(tTable, sTableName, hFile, sTab)
	sTab = sTab or "";
	hFile:write(sTab..sTableName.." = {\n");
	for key, value in pairs(tTable) do
		if (type(value) ~= "function") then
			local sKey = (type(key) == "string") and string.format("[%q]", key) or string.format("[%d]", key);
			if(type(value) == "table") then
				Serialize(value, sKey, hFile, sTab.."\t");
			else
				local sValue = (type(value) == "string") and string.format("%q", value) or tostring(value);
				hFile:write(sTab.."\t"..sKey.." = "..sValue);
			end
			hFile:write(",\n");
		end
	end
	hFile:write(sTab.."}");
end

speedX

#20
hey actually i would like some addition in this script......

This script contains AHT (Average hub time). The addition would be like, if a users AHT is less than 1 hour then when that user logins in the hub, he will get this message in PM..

Quote
Your AHT is less then 1 hr....we are planning to impose restrictions to users with AHT less than 1 hr

......THANK YOU
Thanking You,

speedX

TiMeTrAVelleR

great script jitten  i build  it into  leviathan 2.8     and  works  great :)


greets    TT

jiten

Quote from: speedX on 19 August, 2006, 19:33:17
The addition would be like......if a users AHT is less than 1 hour.... then when tht user logins in the hub......he will get this message in PM..

I'll be posting this extra feature later today.

Quote from: T?M?†r?V?ll?R on 19 August, 2006, 21:44:03
great script jitten  i build  it into  leviathan 2.8     and  works  great :)

I'm glad you like it :P

-SkA-

Great job Jiten (as usual)  ;D
???:::??x??em?-N????:::??? ?wN??

BrianzaLand Blog" style="border:0

speedX

yup u rock jiten dude...
Thanking You,

speedX

SMF spam blocked by CleanTalk