Author Topic: Top Hubbers  (Read 50736 times)

0 Members and 1 Guest are viewing this topic.

Offline jiten

  • Scripter
  • Forum Legend
  • ******
  • Posts: 1 577
  • Karma: +71/-5
Top Hubbers
« on: 21 March, 2006, 18:39:53 »
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: 10 November, 2006, 17:45:07 by jiten »

PtokaX forum

Top Hubbers
« on: 21 March, 2006, 18:39:53 »

Offline -SkA-

  • Double Ace
  • *
  • Posts: 133
  • Karma: +24/-2
Re: Top Hubbers
« Reply #1 on: 21 March, 2006, 21:02:46 »
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 577
  • Karma: +71/-5
Re: Top Hubbers
« Reply #2 on: 21 March, 2006, 21:14:11 »
First post updated with the bugfix.

Offline -SkA-

  • Double Ace
  • *
  • Posts: 133
  • Karma: +24/-2
Re: Top Hubbers
« Reply #3 on: 22 March, 2006, 10:02:58 »
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 577
  • Karma: +71/-5
Re: Top Hubbers
« Reply #4 on: 22 March, 2006, 17:48:03 »
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: 133
  • Karma: +24/-2
Re: Top Hubbers
« Reply #5 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.
???:::??x??em?-N????:::??? ?wN??

BrianzaLand Blog" style="border:0

Offline jiten

  • Scripter
  • Forum Legend
  • ******
  • Posts: 1 577
  • Karma: +71/-5
Re: Top Hubbers
« Reply #6 on: 24 March, 2006, 17:10:57 »
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 577
  • Karma: +71/-5
Re: Top Hubbers
« Reply #7 on: 24 March, 2006, 17:57:37 »
Thank you for your words, mate :)

Offline -SkA-

  • Double Ace
  • *
  • Posts: 133
  • Karma: +24/-2
Re: Top Hubbers
« Reply #8 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
???:::??x??em?-N????:::??? ?wN??

BrianzaLand Blog" style="border:0

Offline jiten

  • Scripter
  • Forum Legend
  • ******
  • Posts: 1 577
  • Karma: +71/-5
Re: Top Hubbers
« Reply #9 on: 26 March, 2006, 20:07:21 »
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 577
  • Karma: +71/-5
Top Hubbers 1.2 - LUA 5.0/5.1
« Reply #10 on: 16 August, 2006, 21:02:43 »
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: 16 August, 2006, 22:07:51 »
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 577
  • Karma: +71/-5
Re: Top Hubbers
« Reply #12 on: 16 August, 2006, 22:17:43 »
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: 16 August, 2006, 22:43:28 »
 :D

Offline speedX

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

speedX

Offline -SkA-

  • Double Ace
  • *
  • Posts: 133
  • Karma: +24/-2
Re: Top Hubbers
« Reply #15 on: 17 August, 2006, 08:06:53 »
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: 17 August, 2006, 08:43:30 »
Possible error :D

Offline jiten

  • Scripter
  • Forum Legend
  • ******
  • Posts: 1 577
  • Karma: +71/-5
Re: Top Hubbers
« Reply #17 on: 17 August, 2006, 11:17:23 »
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 577
  • Karma: +71/-5
TopHubbers 1.21 - LUA 5.0/5.1
« Reply #18 on: 17 August, 2006, 15:48:24 »
First post has been updated with some fixes to the code.

Offline jiten

  • Scripter
  • Forum Legend
  • ******
  • Posts: 1 577
  • Karma: +71/-5
Top Hubbers 1.1x to 1.21 DB Converter
« Reply #19 on: 17 August, 2006, 15:56:26 »
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: 437
  • Karma: +59/-19
Re: Top Hubbers
« Reply #20 on: 19 August, 2006, 19:33:17 »
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: 09 May, 2009, 10:09:44 by speedX »
Thanking You,

speedX

Offline TiMeTrAVelleR

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


greets    TT

Offline jiten

  • Scripter
  • Forum Legend
  • ******
  • Posts: 1 577
  • Karma: +71/-5
Re: Top Hubbers
« Reply #22 on: 20 August, 2006, 10:51:39 »
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: 133
  • Karma: +24/-2
Re: Top Hubbers
« Reply #23 on: 20 August, 2006, 11:52:47 »
Great job Jiten (as usual)  ;D
???:::??x??em?-N????:::??? ?wN??

BrianzaLand Blog" style="border:0

Offline speedX

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

speedX

PtokaX forum

Re: Top Hubbers
« Reply #24 on: 20 August, 2006, 12:24:12 »