determinate determinate

Author Topic: Top Hubbers  (Read 14369 times)

0 Members and 1 Guest are viewing this topic.

Offline jiten

  • Scripter
  • Forum Legend
  • ******
  • Posts: 1 585
  • Karma: +71/-5
Top Hubbers
« on: March 21, 2006, 06:39:53 pm »
Code: [Select]
--[[

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)

]]--
« Last Edit: November 10, 2006, 05:45:07 pm by jiten »

Offline -SkA-

  • Double Ace
  • *
  • Posts: 147
  • Karma: +24/-2
Re: Top Hubbers
« Reply #1 on: March 21, 2006, 09:02:46 pm »
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

Offline jiten

  • Scripter
  • Forum Legend
  • ******
  • Posts: 1 585
  • Karma: +71/-5
Re: Top Hubbers
« Reply #2 on: March 21, 2006, 09:14:11 pm »
First post updated with the bugfix.

Offline -SkA-

  • Double Ace
  • *
  • Posts: 147
  • Karma: +24/-2
Re: Top Hubbers
« Reply #3 on: March 22, 2006, 10:02:58 am »
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

Offline jiten

  • Scripter
  • Forum Legend
  • ******
  • Posts: 1 585
  • Karma: +71/-5
Re: Top Hubbers
« Reply #4 on: March 22, 2006, 05:48:03 pm »
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

Offline -SkA-

  • Double Ace
  • *
  • Posts: 147
  • Karma: +24/-2
Re: Top Hubbers
« Reply #5 on: March 24, 2006, 08:03:29 am »
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

Offline jiten

  • Scripter
  • Forum Legend
  • ******
  • Posts: 1 585
  • Karma: +71/-5
Re: Top Hubbers
« Reply #6 on: March 24, 2006, 05:10:57 pm »
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

Offline jiten

  • Scripter
  • Forum Legend
  • ******
  • Posts: 1 585
  • Karma: +71/-5
Re: Top Hubbers
« Reply #7 on: March 24, 2006, 05:57:37 pm »
Thank you for your words, mate :)

Offline -SkA-

  • Double Ace
  • *
  • Posts: 147
  • Karma: +24/-2
Re: Top Hubbers
« Reply #8 on: March 26, 2006, 06:36:33 pm »
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

Offline jiten

  • Scripter
  • Forum Legend
  • ******
  • Posts: 1 585
  • Karma: +71/-5
Re: Top Hubbers
« Reply #9 on: March 26, 2006, 08:07:21 pm »
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.

Offline jiten

  • Scripter
  • Forum Legend
  • ******
  • Posts: 1 585
  • Karma: +71/-5
Top Hubbers 1.2 - LUA 5.0/5.1
« Reply #10 on: August 16, 2006, 09:02:43 pm »
First post has been updated with some changes in the code.

Offline 6Marilyn6Manson6

  • Scripter
  • King
  • ******
  • Posts: 869
  • Karma: +47/-35
    • http://www.marilynmanson986.altervista.org
Re: Top Hubbers
« Reply #11 on: August 16, 2006, 10:07:51 pm »
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,

Code: [Select]
--[[

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

Offline jiten

  • Scripter
  • Forum Legend
  • ******
  • Posts: 1 585
  • Karma: +71/-5
Re: Top Hubbers
« Reply #12 on: August 16, 2006, 10:17:43 pm »
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.

Offline 6Marilyn6Manson6

  • Scripter
  • King
  • ******
  • Posts: 869
  • Karma: +47/-35
    • http://www.marilynmanson986.altervista.org
Re: Top Hubbers
« Reply #13 on: August 16, 2006, 10:43:28 pm »
 :D

Offline speedX

  • Lord
  • ***
  • Posts: 436
  • Karma: +57/-19
Re: Top Hubbers
« Reply #14 on: August 17, 2006, 05:36:12 am »
Yo jiten, u rock dude. This is wat i wantd, it works fine....
well thx again......
« Last Edit: May 09, 2009, 10:07:59 am by speedX »
Thanking You,

speedX

Offline -SkA-

  • Double Ace
  • *
  • Posts: 147
  • Karma: +24/-2
Re: Top Hubbers
« Reply #15 on: August 17, 2006, 08:06:53 am »
What happen if I use old tOnline.tbl with this new version?
«««:::•€x†®em€-N€†•™:::»»» ØwN€®

BrianzaLand Blog" style="border:0

Offline 6Marilyn6Manson6

  • Scripter
  • King
  • ******
  • Posts: 869
  • Karma: +47/-35
    • http://www.marilynmanson986.altervista.org
Re: Top Hubbers
« Reply #16 on: August 17, 2006, 08:43:30 am »
Possible error :D

Offline jiten

  • Scripter
  • Forum Legend
  • ******
  • Posts: 1 585
  • Karma: +71/-5
Re: Top Hubbers
« Reply #17 on: August 17, 2006, 11:17:23 am »
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.

Offline jiten

  • Scripter
  • Forum Legend
  • ******
  • Posts: 1 585
  • Karma: +71/-5
TopHubbers 1.21 - LUA 5.0/5.1
« Reply #18 on: August 17, 2006, 03:48:24 pm »
First post has been updated with some fixes to the code.

Offline jiten

  • Scripter
  • Forum Legend
  • ******
  • Posts: 1 585
  • Karma: +71/-5
Top Hubbers 1.1x to 1.21 DB Converter
« Reply #19 on: August 17, 2006, 03:56:26 pm »
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.

Code: [Select]
--[[

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

Offline speedX

  • Lord
  • ***
  • Posts: 436
  • Karma: +57/-19
Re: Top Hubbers
« Reply #20 on: August 19, 2006, 07:33:17 pm »
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
« Last Edit: May 09, 2009, 10:09:44 am by speedX »
Thanking You,

speedX

Offline TïMê†råVêlléR

  • Scripter
  • Lord
  • ******
  • Posts: 317
  • Karma: +16/-0
Re: Top Hubbers
« Reply #21 on: August 19, 2006, 09:44:03 pm »
great script jitten  i build  it into  leviathan 2.8     and  works  great :)


greets    TT

Offline jiten

  • Scripter
  • Forum Legend
  • ******
  • Posts: 1 585
  • Karma: +71/-5
Re: Top Hubbers
« Reply #22 on: August 20, 2006, 10:51:39 am »
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.

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

I'm glad you like it :P

Offline -SkA-

  • Double Ace
  • *
  • Posts: 147
  • Karma: +24/-2
Re: Top Hubbers
« Reply #23 on: August 20, 2006, 11:52:47 am »
Great job Jiten (as usual)  ;D
«««:::•€x†®em€-N€†•™:::»»» ØwN€®

BrianzaLand Blog" style="border:0

Offline speedX

  • Lord
  • ***
  • Posts: 436
  • Karma: +57/-19
Re: Top Hubbers
« Reply #24 on: August 20, 2006, 12:24:12 pm »
yup u rock jiten dude...
Thanking You,

speedX

Offline jiten

  • Scripter
  • Forum Legend
  • ******
  • Posts: 1 585
  • Karma: +71/-5
TopHubbers 1.22 - LUA 5.0/5.1
« Reply #25 on: August 20, 2006, 01:00:30 pm »
First post has been updated once more with some changes.

Offline speedX

  • Lord
  • ***
  • Posts: 436
  • Karma: +57/-19
Re: Top Hubbers
« Reply #26 on: August 21, 2006, 03:42:49 pm »
Man Jiten.....wat should i say....u have proved ur self dude...u r a cool scripter  8)
Posted on: 20 August 2006, 18:31:59
Hey jiten....jus have a look here

http://luaboard.sytes.net/index.php?topic=6274.msg62067;topicseen#msg62067
Thanking You,

speedX

Offline Naithif

  • Triple Ace
  • **
  • Posts: 200
  • Karma: +32/-13
Re: Top Hubbers
« Reply #27 on: August 21, 2006, 08:20:30 pm »
Hi all

It would be nice if it would be toggleable if it registers reg's only or users too
Another nice option if the above can be done that - Can there be a selectable min time for the script, so that won't log user's under a that min. time?

Thanks for any reply, nice script

Offline jiten

  • Scripter
  • Forum Legend
  • ******
  • Posts: 1 585
  • Karma: +71/-5
Re: Top Hubbers
« Reply #28 on: August 22, 2006, 02:29:37 pm »
It would be nice if it would be toggleable if it registers reg's only or users too

It will be added in the next release.

Can there be a selectable min time for the script, so that won't log user's under a that min. time?

That's a nice feature for an upcoming version.
However, it won't be part of the next release, as I need to add the Rankings' request first.

Offline Naithif

  • Triple Ace
  • **
  • Posts: 200
  • Karma: +32/-13
Re: Top Hubbers
« Reply #29 on: August 22, 2006, 05:34:34 pm »
Hi

Thanks for the reply, i like this script  :)
Good work  ;D

Offline jiten

  • Scripter
  • Forum Legend
  • ******
  • Posts: 1 585
  • Karma: +71/-5
Re: Top Hubbers
« Reply #30 on: August 23, 2006, 06:19:52 pm »
I have a question for you guys:

Should the ranking system be based on Total uptime or Average uptime in days?

Offline speedX

  • Lord
  • ***
  • Posts: 436
  • Karma: +57/-19
Re: Top Hubbers
« Reply #31 on: August 24, 2006, 05:13:27 pm »
According to AHT, coz it is daily uptime and it is easy to select the time also as AHT is less. But in THT u will get promoted faster, tht's y....
« Last Edit: May 09, 2009, 10:14:25 am by speedX »
Thanking You,

speedX

Offline jiten

  • Scripter
  • Forum Legend
  • ******
  • Posts: 1 585
  • Karma: +71/-5
Re: Top Hubbers
« Reply #32 on: August 24, 2006, 05:27:25 pm »
according to AHT...coz it is daily uptime....and it is easy to select the time also...as AHT is less......but in THT u will get promoted faster.....tht's y....

Well, with AHT the rank limit can't be higher than 24 hours.

However, with THT it's easier to establish a fixed limit for every rank [just like it happens in both PX LUA boards].

More thoughts?

Offline speedX

  • Lord
  • ***
  • Posts: 436
  • Karma: +57/-19
Re: Top Hubbers
« Reply #33 on: August 24, 2006, 05:32:40 pm »
actually its not tht easy to attain an AHT of 24 hrs....coz in one of my hubs ....my hubtime is....

Quote
Nick: speedX   THT: 1 weeks, 2 days, 13 hours, 41 minutes   AHT: 1 hours, 12 minutes

I am reg here for more than an year..
Thanking You,

speedX

Offline jiten

  • Scripter
  • Forum Legend
  • ******
  • Posts: 1 585
  • Karma: +71/-5
Re: Top Hubbers
« Reply #34 on: August 24, 2006, 09:16:46 pm »
actually its not tht easy to attain an AHT of 24 hrs....coz in one of my hubs ....my hubtime is....

I am reg here for more than an year..

Well, I'll release a version that supports both Average and Total uptime rank system then.

 

determinate determinate