--[[
RecordBot 1.7 - LUA 5.0/5.1 by jiten (11/8/2006)
Converted to API 2 by speedX (07/05/2009)
Based on RecordBot vKryFinal written by bonki 2003
Description: Logs and displays a hub's all time share and user record.
- Fixed: Huge users bug and some stuff (thx to T?M??r?V?ll?R)
- Fixed: Stats sending before MOTD
- Added: Top Share and Sharer Record (requested by XPMAN)
- Added: Reg Bot switch (requested by (uk)jay)
- Fixed: Nil Max Sharer (thx Cosmos)
- Added: Ignore List (requested by chettedeboeuf)
- Fixed: User Record Time (11/26/2005)
- Added: Top Sharer and Share validation delay (requested by chettedeboeuf)
- Changed: Command Parsing and profile permission structure
- Fixed: Top Sharer and Share Delay bug (thx to chettedeboeuf)
- Chaged: Some code rewritten
- Added: Time/Date to each record message (requested by Troubadour)
- Changed: Chat and ToArrival structure;
- Removed: !rb.set command;
- Merged: tSettings and Record table;
- Changed: Some code bits and variables;
- Updated: To LUA 5.1 (11/8/2006)
- Updated: To API 2 (07/05/2009) by speedX
]]--
tSettings = {
-- Bot Name
sBot = "RecordBot",
-- Toggle automatically register Bot Name [true = on, false = off]
bRegister = true,
-- RecordBot DB
fRecord = "tRecord.tbl",
-- Ignore table
tIgnore = { ["jiten"] = 1, ["yournick"] = 1, },
-- Top Sharer and Top Share validation delay (minutes)
iDelay = 0,
-- Message settings [ true = on, false = off ]
-- Show report in Main
bMain = true,
-- Show report in PM
bPM = false,
-- Show report on Login
bLogin = true,
-- Commands
sHelp = "rb.help", sShow = "rb.show", sSetup = "rb.set", sReset = "rb.reset"
}
tRecord, tDelay = {}, {}
OnStartup = function()
if (tSettings.sBot ~= SetMan.GetString(21) or tSettings.bRegister) then Core.RegBot(tSettings.sBot,"","",true) end
if loadfile(tSettings.fRecord) then dofile(tSettings.fRecord) end
tSettings.iTimer = TmrMan.AddTimer(1000)
end
ChatArrival = function(user, data)
-- Define vars
local _,_, to = string.find(data, "^$To:%s(%S+)%s+From:")
local _,_, msg = string.find(data, "%b<>%s(.*)|$")
-- Message sent to Bot or in Main
if (to and to == tSettings.sBot) or not to then
-- Parse command
local _,_, cmd = string.find(msg, "^%p(%S+)")
-- Exists
if cmd and tCommands[string.lower(cmd)] then
cmd = string.lower(cmd)
-- If user has permission
if tCommands[cmd].tLevels[user.iProfile] and tCommands[cmd].tLevels[user.iProfile] == 1 then
if to and to == tSettings.sBot then
return Core.SendPmToNick(user.sNick,tSettings.sBot,tCommands[cmd].fFunction(user)), true
else
return Core.SendToNick(user.sNick,"<"..tSettings.sBot.."> "..tCommands[cmd].fFunction(user)), true
end
else
if to and to == tSettings.sBot then
return Core.SendPmToNick(user.sNick,tSettings.sBot,"*** Error: You are not allowed to use this command!"), true
else
return Core.SendToNick(user.sNick,"<"..tSettings.sBot.."> *** Error: You are not allowed to use this command!"), true
end
end
end
end
end
ToArrival = ChatArrival
OnExit = function()
SaveToFile(tRecord, "tRecord", tSettings.fRecord)
end
tCommands = {
[tSettings.sHelp] = {
fFunction = function(user)
-- Header
local sMsg = "\r\n\r\n\t\t\t"..string.rep("=", 80).."\r\n"..string.rep("\t", 6).."RecordBot - LUA 5.1x version by jiten "..
"\t\t\t\r\n\t\t\t"..string.rep("-", 160).."\r\n\t\t\tAvailable Commands:".."\r\n\r\n"
-- Loop through table
for i,v in pairs(tCommands) do
-- If user has permission
if v.tLevels[user.iProfile] and v.tLevels[user.iProfile] == 1 then
-- Populate
sMsg = sMsg.."\t\t\t!"..i.."\t\t"..v.tDesc.."\r\n"
end
end
-- Send
return sMsg.."\t\t\t"..string.rep("-",160);
end,
tLevels = {
[-1] = 1, [0] = 1, [1] = 1, [2] = 1, [3] = 1, [4] = 1, [5] = 1,
},
tDesc = "\tDisplays this help message\t\t\t!"..tSettings.sHelp.."",
},
[tSettings.sShow] = {
fFunction = function(user)
if next(tRecord) then
local msg = "\r\n\r\n\t"..string.rep ("=", 50).."\r\n\tRecord\t\tValue\t\tDate - Time\n\t"..string.rep ("-", 100).."\r\n"..
"\tShare\t\t"..(DoShareUnits(tRecord.iShare) or 0).." \t\t"..(tRecord.tShare or "n/a")..
"\r\n\tUsers\t\t"..(tRecord.iUsers or 0).." user(s)\t\t"..(tRecord.tUsers or "n/a")..
"\r\n\tTop Sharer\t"..(tRecord.sMaxSharer or "n/a").." ("..(DoShareUnits(tRecord.iMaxSharer) or 0)..
")\t"..(tRecord.tMaxSharer or "n/a").."\r\n\t"..string.rep ("-", 100)
return msg
else
return "*** Error: No records have been saved."
end
end,
tLevels = {
[-1] = 1, [0] = 1, [1] = 1, [2] = 1, [3] = 1, [4] = 1, [5] = 1,
},
tDesc = "\tShows this hub's all time share and user record\t!"..tSettings.sShow,
},
[tSettings.sReset] = {
fFunction = function(user)
tRecord = {}; Core.SendToAll("<"..tSettings.sBot.."> *** Hub records have been reset!");
return ""
end,
tLevels = {
[-1] = 0, [0] = 1, [1] = 0, [2] = 0, [3] = 0, [4] = 0, [5] = 1,
},
tDesc = "\tResets all records\t\t\t\t!"..tSettings.sReset,
},
};
UserConnected = function(user)
if not tSettings.tIgnore[user.sNick] then
local iUserCount = Core.GetUsersCount()
tRecord.iUsers, tRecord.tUsers = (tRecord.iUsers or 0), (tRecord.tUsers or "n/a")
if (iUserCount > tRecord.iUsers) then
tRecord.iUsers, tRecord.tUsers = iUserCount, os.date()
if tSettings.bPM then
Core.SendPmToNick(user.sNick,tSettings.sBot,"*** Thanks, buddie. You've just raised the all-time share record!");
end;
if tSettings.bMain then
Core.SendToAll("<"..tSettings.sBot.."> *** "..user.sNick.." has just raised the all-time user record to: "..
tRecord.iUsers.." users at "..os.date().." :)");
end;
end
tDelay[user] = {}
tDelay[user]["iTime"] = tSettings.iDelay*60
end
end
OpConnected,RegConnected = UserConnected,UserConnected
OnTimer = function(iID)
if tSettings.iTimer and iID == tSettings.iTimer then
for nick,v in pairs(tDelay) do
tDelay[nick]["iTime"] = tDelay[nick]["iTime"] - 1
if tDelay[nick]["iTime"] <= 0 then
if Core.GetUser(nick.sNick) then
local iTotalShare, iShare, sNick = Core.GetCurrentSharedSize(), Core.GetUserValue(nick,16) , nick.sNick
tRecord.iShare = (tRecord.iShare or 0)
if (iTotalShare > tRecord.iShare) then
tRecord.iShare, tRecord.tShare = iTotalShare, os.date()
if tSettings.bPM then Core.SendPmToNick(nick.sNick, tSettings.sBot, "*** Thanks, buddie. You have just raised the all-time share record to "..DoShareUnits(iTotalShare).." :)"); end;
if tSettings.bMain then Core.SendToAll("<"..tSettings.sBot.."> *** "..nick.sNick.." has just raised the all-time share record to: "..DoShareUnits(iTotalShare).." on "..os.date("%x")); end;
end
tRecord.iMaxSharer = (tRecord.iMaxSharer or 0)
if (iShare > tRecord.iMaxSharer) then
tRecord.iMaxSharer, tRecord.sMaxSharer, tRecord.tMaxSharer = iShare, nick.sNick, os.date()
if tSettings.bPM then Core.SendPmToNick(nick.sNick,tSettings.sBot,"*** Thanks, buddie. You are our highest sharer with: "..DoShareUnits(iShare).."."); end;
if tSettings.bMain then Core.SendToAll("<"..tSettings.sBot.."> *** "..nick.sNick.." is our all-time biggest sharer with: "..DoShareUnits((iShare)).." since "..os.date("%x").." :)"); end;
end
if tSettings.bLogin then
local sMsg = "\r\n\r\n\t"..string.rep("=", 50).."\r\n\t\t\tStats\r\n\t"..
string.rep("-", 100).."\r\n\r\n\tShare record: "..(DoShareUnits(tonumber(tRecord.iShare)) or 0).." [ "..
(tRecord.tShare or "n/a").." ]\r\n\tUser record: "..(tRecord.iUsers or 0).." users [ "..
(tRecord.tUsers or "n/a").." ]\r\n\tTop Sharer: "..(tRecord.sMaxSharer or "n/a")..
" ("..(DoShareUnits(tRecord.iMaxSharer) or 0)..") [ "..(tRecord.tMaxSharer or "n/a").." ]\r\n"
Core.SendToNick(nick.sNick,"<"..tSettings.sBot.."> "..sMsg)
end;
end
tDelay[nick] = nil
end
end
end
end
-- By kepp and NotRambitWombat
DoShareUnits = function(intSize)
if intSize and intSize ~= 0 then
local tUnits, intSize, sUnits = { "Bytes", "KB", "MB", "GB", "TB" }, tonumber(intSize)
for index in ipairs(tUnits) do
if(intSize < 1024) then sUnits = tUnits[index]; break; else intSize = intSize / 1024; end
end
return string.format("%0.1f %s",intSize, sUnits);
end
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(table,tablename,file)
local hFile = io.open(file,"w+") Serialize(table,tablename,hFile); hFile:close()
end
Very Handy Script speed nice work needed this script from a long time.
Just a small request for Easy RC commands
QuotesHelp = "rb.help", sShow = "rb.show", sSetup = "rb.set", sReset = "rb.reset"
+
Can every record be separated in the right click like user can select any one field to be displayed in main or pm out of Share record ,User Record and Top sharer.
Quote from: TZB on 05 July, 2009, 21:20:28
Very Handy Script speed nice work needed this script from a long time.
Just a small request for Easy RC commands +
Can every record be separated in the right click like user can select any one field to be displayed in main or pm out of Share record ,User Record and Top sharer.
Here you go...
--[[
RecordBot 1.7a - LUA 5.0/5.1 by jiten (11/8/2006)
Converted to API 2 by speedX (07/05/2009)
Based on RecordBot vKryFinal written by bonki 2003
Description: Logs and displays a hub's all time share and user record.
- Fixed: Huge users bug and some stuff (thx to T?M??r?V?ll?R)
- Fixed: Stats sending before MOTD
- Added: Top Share and Sharer Record (requested by XPMAN)
- Added: Reg Bot switch (requested by (uk)jay)
- Fixed: Nil Max Sharer (thx Cosmos)
- Added: Ignore List (requested by chettedeboeuf)
- Fixed: User Record Time (11/26/2005)
- Added: Top Sharer and Share validation delay (requested by chettedeboeuf)
- Changed: Command Parsing and profile permission structure
- Fixed: Top Sharer and Share Delay bug (thx to chettedeboeuf)
- Chaged: Some code rewritten
- Added: Time/Date to each record message (requested by Troubadour)
- Changed: Chat and ToArrival structure;
- Removed: !rb.set command;
- Merged: tSettings and Record table;
- Changed: Some code bits and variables;
- Updated: To LUA 5.1 (11/8/2006)
- Updated: To API 2 (07/05/2009) by speedX
Additions by speedX: (Requested by TZB)
- Added: Rightclick Menu
- Added: Commands for separate Share Record ,User Record and Top Sharer
]]--
tSettings = {
-- Bot Name
sBot = "RecordBot",
-- Toggle automatically register Bot Name [true = on, false = off]
bRegister = true,
-- RecordBot DB
fRecord = "tRecord.txt",
-- Ignore table
tIgnore = { ["jiten"] = 1, ["yournick"] = 1, },
-- Top Sharer and Top Share validation delay (minutes)
iDelay = 0,
-- Message settings [ true = on, false = off ]
-- Show report in Main
bMain = true,
-- Show report in PM
bPM = false,
-- Show report on Login
bLogin = true,
-- Commands
sHelp = "rb.help", sShow = "rb.show", sSetup = "rb.set", sReset = "rb.reset", sShareRecord = "rb.sharerecord", sUserRecord = "rb.userrecord", sTopSharer = "rb.topsharer"
}
tRecord, tDelay = {}, {}
OnStartup = function()
if (tSettings.sBot ~= SetMan.GetString(21) or tSettings.bRegister) then Core.RegBot(tSettings.sBot,"","",true) end
if loadfile(tSettings.fRecord) then dofile(tSettings.fRecord) end
tSettings.iTimer = TmrMan.AddTimer(1000)
end
ChatArrival = function(user, data)
-- Define vars
local _,_, to = string.find(data, "^$To:%s(%S+)%s+From:")
local _,_, msg = string.find(data, "%b<>%s(.*)|$")
-- Message sent to Bot or in Main
if (to and to == tSettings.sBot) or not to then
-- Parse command
local _,_, cmd = string.find(msg, "^%p(%S+)")
-- Exists
if cmd and tCommands[string.lower(cmd)] then
cmd = string.lower(cmd)
-- If user has permission
if tCommands[cmd].tLevels[user.iProfile] and tCommands[cmd].tLevels[user.iProfile] == 1 then
if to and to == tSettings.sBot then
return Core.SendPmToNick(user.sNick,tSettings.sBot,tCommands[cmd].fFunction(user)), true
else
return Core.SendToNick(user.sNick,"<"..tSettings.sBot.."> "..tCommands[cmd].fFunction(user)), true
end
else
if to and to == tSettings.sBot then
return Core.SendPmToNick(user.sNick,tSettings.sBot,"*** Error: You are not allowed to use this command!"), true
else
return Core.SendToNick(user.sNick,"<"..tSettings.sBot.."> *** Error: You are not allowed to use this command!"), true
end
end
end
end
end
ToArrival = ChatArrival
OnExit = function()
SaveToFile(tRecord, "tRecord", tSettings.fRecord)
end
tCommands = {
[tSettings.sHelp] = {
fFunction = function(user)
-- Header
local sMsg = "\r\n\r\n\t\t\t"..string.rep("=", 80).."\r\n"..string.rep("\t", 6).."RecordBot - LUA 5.1x version by jiten "..
"\t\t\t\r\n\t\t\t"..string.rep("-", 160).."\r\n\t\t\tAvailable Commands:".."\r\n\r\n"
-- Loop through table
for i,v in pairs(tCommands) do
-- If user has permission
if v.tLevels[user.iProfile] and v.tLevels[user.iProfile] == 1 then
-- Populate
sMsg = sMsg.."\t\t\t!"..i.."\t\t"..v.tDesc.."\r\n"
end
end
-- Send
return sMsg.."\t\t\t"..string.rep("-",160);
end,
tLevels = {
[-1] = 1, [0] = 1, [1] = 1, [2] = 1, [3] = 1, [4] = 1, [5] = 1,
},
tDesc = "\tDisplays this help message\t\t\t!"..tSettings.sHelp.."",
tRC = {{ "RecordBot Help","" }},
},
[tSettings.sShow] = {
fFunction = function(user)
if next(tRecord) then
local msg = "\r\n\r\n\t"..string.rep ("=", 50).."\r\n\tRecord\t\tValue\t\tDate - Time\n\t"..string.rep ("-", 100).."\r\n"..
"\tShare\t\t"..(DoShareUnits(tRecord.iShare) or 0).." \t\t"..(tRecord.tShare or "n/a")..
"\r\n\tUsers\t\t"..(tRecord.iUsers or 0).." user(s)\t\t"..(tRecord.tUsers or "n/a")..
"\r\n\tTop Sharer\t"..(tRecord.sMaxSharer or "n/a").." ("..(DoShareUnits(tRecord.iMaxSharer) or 0)..
")\t"..(tRecord.tMaxSharer or "n/a").."\r\n\t"..string.rep ("-", 100)
return msg
else
return "*** Error: No records have been saved."
end
end,
tLevels = {
[-1] = 1, [0] = 1, [1] = 1, [2] = 1, [3] = 1, [4] = 1, [5] = 1,
},
tDesc = "\tShows this hub's all time share and user record\t!"..tSettings.sShow,
tRC = {{ "Show All Records","" }},
},
[tSettings.sReset] = {
fFunction = function(user)
tRecord = {}; Core.SendToAll("<"..tSettings.sBot.."> *** Hub records have been reset!");
return "You Have Reset All Records!"
end,
tLevels = {
[-1] = 0, [0] = 1, [1] = 0, [2] = 0, [3] = 0, [4] = 0, [5] = 1,
},
tDesc = "\tResets all records\t\t\t\t!"..tSettings.sReset,
tRC = {{ "Reset Record","" }},
},
[tSettings.sShareRecord] = {
fFunction = function(user)
if next(tRecord) then
local msg = "\r\n\r\n\t"..string.rep ("=", 50).."\r\n\tRecord\t\tValue\t\tDate - Time\n\t"..string.rep ("-", 100).."\r\n"..
"\tShare\t\t"..(DoShareUnits(tRecord.iShare) or 0).." \t\t"..(tRecord.tShare or "n/a")..
"\r\n\t"..string.rep ("-", 100)
return msg
else
return "*** Error: No records have been saved."
end
end,
tLevels = {
[-1] = 1, [0] = 1, [1] = 1, [2] = 1, [3] = 1, [4] = 1, [5] = 1,
},
tDesc = "\tShows hub's all time share record\t!"..tSettings.sShareRecord,
tRC = {{ "Share Record","" }},
},
[tSettings.sUserRecord] = {
fFunction = function(user)
if next(tRecord) then
local msg = "\r\n\r\n\t"..string.rep ("=", 50).."\r\n\tRecord\t\tValue\t\tDate - Time\n\t"..string.rep ("-", 100).."\r\n"..
"\tUsers\t\t"..(tRecord.iUsers or 0).." user(s)\t\t"..(tRecord.tUsers or "n/a")..
"\r\n\t"..string.rep ("-", 100)
return msg
else
return "*** Error: No records have been saved."
end
end,
tLevels = {
[-1] = 1, [0] = 1, [1] = 1, [2] = 1, [3] = 1, [4] = 1, [5] = 1,
},
tDesc = "\tShows hub's all time user record\t!"..tSettings.sUserRecord,
tRC = {{ "User Record","" }},
},
[tSettings.sTopSharer] = {
fFunction = function(user)
if next(tRecord) then
local msg = "\r\n\r\n\t"..string.rep ("=", 50).."\r\n\tRecord\t\tValue\t\tDate - Time\n\t"..string.rep ("-", 100).."\r\n"..
"\tTop Sharer\t"..(tRecord.sMaxSharer or "n/a").." ("..(DoShareUnits(tRecord.iMaxSharer) or 0)..
")\t"..(tRecord.tMaxSharer or "n/a").."\r\n\t"..string.rep ("-", 100)
return msg
else
return "*** Error: No records have been saved."
end
end,
tLevels = {
[-1] = 1, [0] = 1, [1] = 1, [2] = 1, [3] = 1, [4] = 1, [5] = 1,
},
tDesc = "\tShows hub's all time top sharer\t!"..tSettings.sTopSharer,
tRC = {{ "Top Sharer","" }},
},
};
UserConnected = function(user)
if not tSettings.tIgnore[user.sNick] then
local iUserCount = Core.GetUsersCount()
tRecord.iUsers, tRecord.tUsers = (tRecord.iUsers or 0), (tRecord.tUsers or "n/a")
if (iUserCount > tRecord.iUsers) then
tRecord.iUsers, tRecord.tUsers = iUserCount, os.date()
SaveToFile(tRecord, "tRecord", tSettings.fRecord)
if tSettings.bPM then
Core.SendPmToNick(user.sNick,tSettings.sBot,"*** Thanks, buddie. You've just raised the all-time share record!");
end;
if tSettings.bMain then
Core.SendToAll("<"..tSettings.sBot.."> *** "..user.sNick.." has just raised the all-time user record to: "..
tRecord.iUsers.." users at "..os.date().." :)");
end;
end
tDelay[user] = {}
tDelay[user]["iTime"] = tSettings.iDelay*60
end
for i,v in pairs(tCommands) do
if v.tLevels[user.iProfile] and v.tLevels[user.iProfile] == 1 then
for n in ipairs(v.tRC) do
Core.SendToNick(user.sNick, "$UserCommand 1 3 RecordBot\\"..v.tRC[n][1].."$<%[mynick]> +"..i..v.tRC[n][2].."|")
end
end
end
end
OpConnected,RegConnected = UserConnected,UserConnected
OnTimer = function(iID)
if tSettings.iTimer and iID == tSettings.iTimer then
for nick,v in pairs(tDelay) do
tDelay[nick]["iTime"] = tDelay[nick]["iTime"] - 1
if tDelay[nick]["iTime"] <= 0 then
if Core.GetUser(nick.sNick) then
local iTotalShare, iShare, sNick = Core.GetCurrentSharedSize(), Core.GetUserValue(nick,16) , nick.sNick
tRecord.iShare = (tRecord.iShare or 0)
if (iTotalShare > tRecord.iShare) then
tRecord.iShare, tRecord.tShare = iTotalShare, os.date()
SaveToFile(tRecord, "tRecord", tSettings.fRecord)
if tSettings.bPM then Core.SendPmToNick(nick.sNick, tSettings.sBot, "*** Thanks, buddie. You have just raised the all-time share record to "..DoShareUnits(iTotalShare).." :)"); end;
if tSettings.bMain then Core.SendToAll("<"..tSettings.sBot.."> *** "..nick.sNick.." has just raised the all-time share record to: "..DoShareUnits(iTotalShare).." on "..os.date("%x")); end;
end
tRecord.iMaxSharer = (tRecord.iMaxSharer or 0)
if (iShare > tRecord.iMaxSharer) then
tRecord.iMaxSharer, tRecord.sMaxSharer, tRecord.tMaxSharer = iShare, nick.sNick, os.date()
SaveToFile(tRecord, "tRecord", tSettings.fRecord)
if tSettings.bPM then Core.SendPmToNick(nick.sNick,tSettings.sBot,"*** Thanks, buddie. You are our highest sharer with: "..DoShareUnits(iShare).."."); end;
if tSettings.bMain then Core.SendToAll("<"..tSettings.sBot.."> *** "..nick.sNick.." is our all-time biggest sharer with: "..DoShareUnits((iShare)).." since "..os.date("%x").." :)"); end;
end
if tSettings.bLogin then
local sMsg = "\r\n\r\n\t"..string.rep("=", 50).."\r\n\t\t\tStats\r\n\t"..
string.rep("-", 100).."\r\n\r\n\tShare record: "..(DoShareUnits(tonumber(tRecord.iShare)) or 0).." [ "..
(tRecord.tShare or "n/a").." ]\r\n\tUser record: "..(tRecord.iUsers or 0).." users [ "..
(tRecord.tUsers or "n/a").." ]\r\n\tTop Sharer: "..(tRecord.sMaxSharer or "n/a")..
" ("..(DoShareUnits(tRecord.iMaxSharer) or 0)..") [ "..(tRecord.tMaxSharer or "n/a").." ]\r\n"
Core.SendToNick(nick.sNick,"<"..tSettings.sBot.."> "..sMsg)
end;
end
tDelay[nick] = nil
end
end
end
end
-- By kepp and NotRambitWombat
DoShareUnits = function(intSize)
if intSize and intSize ~= 0 then
local tUnits, intSize, sUnits = { "Bytes", "KB", "MB", "GB", "TB" }, tonumber(intSize)
for index in ipairs(tUnits) do
if(intSize < 1024) then sUnits = tUnits[index]; break; else intSize = intSize / 1024; end
end
return string.format("%0.1f %s",intSize, sUnits);
end
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(table,tablename,file)
local hFile = io.open(file,"w+") Serialize(table,tablename,hFile); hFile:close()
end
Thanks a Lot speedX for the addition. ;D
Quote from: TZB on 06 July, 2009, 08:20:47
Thanks a Lot speedX for the addition. ;D
np ;)
This script is not [Strict]
Why put it in the title ? ???
Quote<TotalUpload type="int64">254423472460</TotalUpload>
<TotalDownload type="int64">81692117606</TotalDownload>
There is a DCPlusPlus.xml file in Client.Can this script have a option on pulling the total upload and download string from the client and then making a log into a .dat file with nick every time a user logs in.This string shows how much a user has uploaded and downloaded using the client though am not much sure about it but if somehow the string can be pulled it can be a addition into the script as in Top uploaders and downloaders.Like having a record of it.
Its just a sugesstion on what i saw i hope i am not wrong somewhere if so my apologies.
Thanks.
Only way to see how much user have uploaded, is if THE USER HIMSELF shows it to you.
Thanks Madman.
So its Impossible to be considered.
This is a great script that I was very pleased to see now converted to api2, thanks to those involved.
Is there anyway of getting this script to check the hubshare and topsharer every 5 or 10 minutes?
Currently it seems only to do it on startup. If you hash more files it does not pick up the new record until you restart.
Also the script does not save the data file of records until the script is restarted or exited. Is there anyway of making it update the file upon a new record instead? I leave my hub going 24 hours a day and therefore the script is only restarted if it is done manually or when the hub is rebooted after maintenance (situations that will update the record) but if my computer crashes or the power goes off then the records are not saved.
Even I noticed the same
It now saves the records on update.
Script above updated.
//Edit by CrazyGuy: removed quoting of complete previous post
There's a request to be added into records.Like we have all the user share records and peak it would be great if we have a option where in the longest ptokax Uptime is being logged just as the user share and user peak.
What i meant is this part.
QuoteThis hub is running PtokaX DC Hub 0.4.1.1 (UpTime: 0 days, 0 hours, 0 minutes / Users: 0)
The uptime which will be updated every time it surpasses the previous peak uptime and longest uptime be saved into a log file and rest same as the script above.
Thanks.
nice thought TZB... i will also like to have this feature in record bot
Thanks Yahoo! Wish it done sooner.
Ok...Here it is
--[[
RecordBot 1.7b - LUA 5.0/5.1 by jiten (11/8/2006)
Converted to API 2 by speedX (07/05/2009)
Based on RecordBot vKryFinal written by bonki 2003
Description: Logs and displays a hub's all time share and user record.
- Fixed: Huge users bug and some stuff (thx to T?M??r?V?ll?R)
- Fixed: Stats sending before MOTD
- Added: Top Share and Sharer Record (requested by XPMAN)
- Added: Reg Bot switch (requested by (uk)jay)
- Fixed: Nil Max Sharer (thx Cosmos)
- Added: Ignore List (requested by chettedeboeuf)
- Fixed: User Record Time (11/26/2005)
- Added: Top Sharer and Share validation delay (requested by chettedeboeuf)
- Changed: Command Parsing and profile permission structure
- Fixed: Top Sharer and Share Delay bug (thx to chettedeboeuf)
- Chaged: Some code rewritten
- Added: Time/Date to each record message (requested by Troubadour)
- Changed: Chat and ToArrival structure;
- Removed: !rb.set command;
- Merged: tSettings and Record table;
- Changed: Some code bits and variables;
- Updated: To LUA 5.1 (11/8/2006)
- Updated: To API 2 (07/05/2009) by speedX
Additions by speedX: (Requested by TZB)
- Added: Rightclick Menu
- Added: Commands for separate Share Record ,User Record and Top Sharer
- Added: Command to get Top Hub UpTime
]]--
tSettings = {
-- Bot Name
sBot = "RecordBot",
-- Toggle automatically register Bot Name [true = on, false = off]
bRegister = true,
-- RecordBot DB
fRecord = "tRecord.txt",
-- Ignore table
tIgnore = { ["jiten"] = 1, ["yournick"] = 1, },
-- Top Sharer and Top Share validation delay (minutes)
iDelay = 0,
-- Top Hub Up Time Message Interval (in minutes)
iInterval = 60,
-- Message settings [ true = on, false = off ]
-- Show report in Main
bMain = true,
-- Show report in PM
bPM = false,
-- Show report on Login
bLogin = true,
-- Commands
sHelp = "rb.help", sShow = "rb.show", sSetup = "rb.set", sReset = "rb.reset", sShareRecord = "rb.sharerecord", sUserRecord = "rb.userrecord", sTopSharer = "rb.topsharer", sUpTime = "rb.topuptime"
}
tRecord, tDelay , iCount = {}, {} , 0
OnStartup = function()
if (tSettings.sBot ~= SetMan.GetString(21) or tSettings.bRegister) then Core.RegBot(tSettings.sBot,"","",true) end
if loadfile(tSettings.fRecord) then dofile(tSettings.fRecord) end
tSettings.iTimer = TmrMan.AddTimer(1000)
end
ChatArrival = function(user, data)
-- Define vars
local _,_, to = string.find(data, "^$To:%s(%S+)%s+From:")
local _,_, msg = string.find(data, "%b<>%s(.*)|$")
-- Message sent to Bot or in Main
if (to and to == tSettings.sBot) or not to then
-- Parse command
local _,_, cmd = string.find(msg, "^%p(%S+)")
-- Exists
if cmd and tCommands[string.lower(cmd)] then
cmd = string.lower(cmd)
-- If user has permission
if tCommands[cmd].tLevels[user.iProfile] and tCommands[cmd].tLevels[user.iProfile] == 1 then
if to and to == tSettings.sBot then
return Core.SendPmToNick(user.sNick,tSettings.sBot,tCommands[cmd].fFunction(user)), true
else
return Core.SendToNick(user.sNick,"<"..tSettings.sBot.."> "..tCommands[cmd].fFunction(user)), true
end
else
if to and to == tSettings.sBot then
return Core.SendPmToNick(user.sNick,tSettings.sBot,"*** Error: You are not allowed to use this command!"), true
else
return Core.SendToNick(user.sNick,"<"..tSettings.sBot.."> *** Error: You are not allowed to use this command!"), true
end
end
end
end
end
ToArrival = ChatArrival
OnExit = function()
SaveToFile(tRecord, "tRecord", tSettings.fRecord)
end
tCommands = {
[tSettings.sHelp] = {
fFunction = function(user)
-- Header
local sMsg = "\r\n\r\n\t\t\t"..string.rep("=", 80).."\r\n"..string.rep("\t", 6).."RecordBot - LUA 5.1x version by jiten "..
"\t\t\t\r\n\t\t\t"..string.rep("-", 160).."\r\n\t\t\tAvailable Commands:".."\r\n\r\n"
-- Loop through table
for i,v in pairs(tCommands) do
-- If user has permission
if v.tLevels[user.iProfile] and v.tLevels[user.iProfile] == 1 then
-- Populate
sMsg = sMsg.."\t\t\t!"..i.."\t\t"..v.tDesc.."\r\n"
end
end
-- Send
return sMsg.."\t\t\t"..string.rep("-",160);
end,
tLevels = {
[-1] = 1, [0] = 1, [1] = 1, [2] = 1, [3] = 1, [4] = 1, [5] = 1,
},
tDesc = "\tDisplays this help message\t\t\t!"..tSettings.sHelp.."",
tRC = {{ "RecordBot Help","" }},
},
[tSettings.sShow] = {
fFunction = function(user)
if next(tRecord) then
local msg = "\r\n\r\n\t"..string.rep ("=", 50).."\r\n\tRecord\t\tValue\t\tDate - Time\n\t"..string.rep ("-", 100).."\r\n"..
"\tShare\t\t"..(DoShareUnits(tRecord.iShare) or 0).." \t\t"..(tRecord.tShare or "n/a")..
"\r\n\tUsers\t\t"..(tRecord.iUsers or 0).." user(s)\t\t"..(tRecord.tUsers or "n/a")..
"\r\n\tTop Sharer\t"..(tRecord.sMaxSharer or "n/a").." ("..(DoShareUnits(tRecord.iMaxSharer) or 0)..
")\t"..(tRecord.tMaxSharer or "n/a")..
"\r\n\tTop UpTime\t"..(SecondsToTime(tRecord.iHubTime,true) or "n/a").."\t"..(tRecord.tHubTime or "n/a")..
"\r\n\t"..string.rep ("-", 100)
return msg
else
return "*** Error: No records have been saved."
end
end,
tLevels = {
[-1] = 1, [0] = 1, [1] = 1, [2] = 1, [3] = 1, [4] = 1, [5] = 1,
},
tDesc = "\tShows this hub's all time share and user record\t!"..tSettings.sShow,
tRC = {{ "Show All Records","" }},
},
[tSettings.sReset] = {
fFunction = function(user)
tRecord = {}; Core.SendToAll("<"..tSettings.sBot.."> *** Hub records have been reset!");
return "You Have Reset All Records!"
end,
tLevels = {
[-1] = 0, [0] = 1, [1] = 0, [2] = 0, [3] = 0, [4] = 0, [5] = 1,
},
tDesc = "\tResets all records\t\t\t\t!"..tSettings.sReset,
tRC = {{ "Reset Record","" }},
},
[tSettings.sShareRecord] = {
fFunction = function(user)
if next(tRecord) then
local msg = "\r\n\r\n\t"..string.rep ("=", 50).."\r\n\tRecord\t\tValue\t\tDate - Time\n\t"..string.rep ("-", 100).."\r\n"..
"\tShare\t\t"..(DoShareUnits(tRecord.iShare) or 0).." \t\t"..(tRecord.tShare or "n/a")..
"\r\n\t"..string.rep ("-", 100)
return msg
else
return "*** Error: No records have been saved."
end
end,
tLevels = {
[-1] = 1, [0] = 1, [1] = 1, [2] = 1, [3] = 1, [4] = 1, [5] = 1,
},
tDesc = "\tShows hub's all time share record\t!"..tSettings.sShareRecord,
tRC = {{ "Share Record","" }},
},
[tSettings.sUserRecord] = {
fFunction = function(user)
if next(tRecord) then
local msg = "\r\n\r\n\t"..string.rep ("=", 50).."\r\n\tRecord\t\tValue\t\tDate - Time\n\t"..string.rep ("-", 100).."\r\n"..
"\tUsers\t\t"..(tRecord.iUsers or 0).." user(s)\t\t"..(tRecord.tUsers or "n/a")..
"\r\n\t"..string.rep ("-", 100)
return msg
else
return "*** Error: No records have been saved."
end
end,
tLevels = {
[-1] = 1, [0] = 1, [1] = 1, [2] = 1, [3] = 1, [4] = 1, [5] = 1,
},
tDesc = "\tShows hub's all time user record\t!"..tSettings.sUserRecord,
tRC = {{ "User Record","" }},
},
[tSettings.sTopSharer] = {
fFunction = function(user)
if next(tRecord) then
local msg = "\r\n\r\n\t"..string.rep ("=", 50).."\r\n\tRecord\t\tValue\t\tDate - Time\n\t"..string.rep ("-", 100).."\r\n"..
"\tTop Sharer\t"..(tRecord.sMaxSharer or "n/a").." ("..(DoShareUnits(tRecord.iMaxSharer) or 0)..
")\t"..(tRecord.tMaxSharer or "n/a").."\r\n\t"..string.rep ("-", 100)
return msg
else
return "*** Error: No records have been saved."
end
end,
tLevels = {
[-1] = 1, [0] = 1, [1] = 1, [2] = 1, [3] = 1, [4] = 1, [5] = 1,
},
tDesc = "\tShows hub's all time top sharer\t!"..tSettings.sTopSharer,
tRC = {{ "Top Sharer","" }},
},
[tSettings.sUpTime] = {
fFunction = function(user)
if next(tRecord) then
local msg = "\r\n\r\n\t"..string.rep ("=", 50).."\r\n\tRecord\t\tDate - Time\tValue\n\t"..string.rep ("-", 100).."\r\n"..
"\tTop Uptime\t"..(tRecord.tHubTime or "n/a").."\t"..(SecondsToTime(tRecord.iHubTime,true) or "n/a").."\r\n\t"..string.rep ("-", 100)
return msg
else
return "*** Error: No records have been saved."
end
end,
tLevels = {
[-1] = 1, [0] = 1, [1] = 1, [2] = 1, [3] = 1, [4] = 1, [5] = 1,
},
tDesc = "\tShows hub's Top Uptime\t!"..tSettings.sUpTime,
tRC = {{ "Top Uptime","" }},
},
};
UserConnected = function(user)
if not tSettings.tIgnore[user.sNick] then
local iUserCount = Core.GetUsersCount()
tRecord.iUsers, tRecord.tUsers = (tRecord.iUsers or 0), (tRecord.tUsers or "n/a")
if (iUserCount > tRecord.iUsers) then
tRecord.iUsers, tRecord.tUsers = iUserCount, os.date()
SaveToFile(tRecord, "tRecord", tSettings.fRecord)
if tSettings.bPM then
Core.SendPmToNick(user.sNick,tSettings.sBot,"*** Thanks, buddie. You've just raised the all-time share record!");
end;
if tSettings.bMain then
Core.SendToAll("<"..tSettings.sBot.."> *** "..user.sNick.." has just raised the all-time user record to: "..
tRecord.iUsers.." users at "..os.date().." :)");
end;
end
tDelay[user] = {}
tDelay[user]["iTime"] = tSettings.iDelay*60
end
for i,v in pairs(tCommands) do
if v.tLevels[user.iProfile] and v.tLevels[user.iProfile] == 1 then
for n in ipairs(v.tRC) do
Core.SendToNick(user.sNick, "$UserCommand 1 3 RecordBot\\"..v.tRC[n][1].."$<%[mynick]> +"..i..v.tRC[n][2].."|")
end
end
end
end
OpConnected,RegConnected = UserConnected,UserConnected
OnTimer = function(iID)
if tSettings.iTimer and iID == tSettings.iTimer then
for nick,v in pairs(tDelay) do
tDelay[nick]["iTime"] = tDelay[nick]["iTime"] - 1
if tDelay[nick]["iTime"] <= 0 then
if Core.GetUser(nick.sNick) then
local iTotalShare, iShare, sNick = Core.GetCurrentSharedSize(), Core.GetUserValue(nick,16) , nick.sNick
tRecord.iShare = (tRecord.iShare or 0)
if (iTotalShare > tRecord.iShare) then
tRecord.iShare, tRecord.tShare = iTotalShare, os.date()
SaveToFile(tRecord, "tRecord", tSettings.fRecord)
if tSettings.bPM then Core.SendPmToNick(nick.sNick, tSettings.sBot, "*** Thanks, buddie. You have just raised the all-time share record to "..DoShareUnits(iTotalShare).." :)"); end;
if tSettings.bMain then Core.SendToAll("<"..tSettings.sBot.."> *** "..nick.sNick.." has just raised the all-time share record to: "..DoShareUnits(iTotalShare).." on "..os.date("%x")); end;
end
tRecord.iMaxSharer = (tRecord.iMaxSharer or 0)
if (iShare > tRecord.iMaxSharer) then
tRecord.iMaxSharer, tRecord.sMaxSharer, tRecord.tMaxSharer = iShare, nick.sNick, os.date()
SaveToFile(tRecord, "tRecord", tSettings.fRecord)
if tSettings.bPM then Core.SendPmToNick(nick.sNick,tSettings.sBot,"*** Thanks, buddie. You are our highest sharer with: "..DoShareUnits(iShare).."."); end;
if tSettings.bMain then Core.SendToAll("<"..tSettings.sBot.."> *** "..nick.sNick.." is our all-time biggest sharer with: "..DoShareUnits((iShare)).." since "..os.date("%x").." :)"); end;
end
if tSettings.bLogin then
local sMsg = "\r\n\r\n\t"..string.rep("=", 50).."\r\n\t\t\tStats\r\n\t"..
string.rep("-", 100).."\r\n\r\n\tShare record: "..(DoShareUnits(tonumber(tRecord.iShare)) or 0).." [ "..
(tRecord.tShare or "n/a").." ]\r\n\tUser record: "..(tRecord.iUsers or 0).." users [ "..
(tRecord.tUsers or "n/a").." ]\r\n\tTop Sharer: "..(tRecord.sMaxSharer or "n/a")..
" ("..(DoShareUnits(tRecord.iMaxSharer) or 0)..") [ "..(tRecord.tMaxSharer or "n/a").." ]\r\n\tTop UpTime: "..
(SecondsToTime(tRecord.iHubTime,true) or "n/a").." [ "..(tRecord.tHubTime or "n/a").." ]\r\n"
Core.SendToNick(nick.sNick,"<"..tSettings.sBot.."> "..sMsg)
end;
end
tDelay[nick] = nil
end
end
iTotalUpTime = Core.GetUpTime()
tRecord.iHubTime = (tRecord.iHubTime or 0)
if iTotalUpTime > tRecord.iHubTime then
tRecord.iHubTime , tRecord.tHubTime = iTotalUpTime , os.date()
SaveToFile(tRecord, "tRecord", tSettings.fRecord)
if tSettings.iInterval <= 0 then
if tSettings.bMain then Core.SendToAll("<"..tSettings.sBot.."> *** The Hub has crossed its peak uptime :D : "..SecondsToTime(tRecord.iHubTime,true)); end;
else
if iCount == 0 then
if tSettings.bMain then Core.SendToAll("<"..tSettings.sBot.."> *** The Hub has crossed its peak uptime :D : "..SecondsToTime(tRecord.iHubTime,true)); end;
iCount = iCount + 1
elseif iCount == tSettings.iInterval*60 then
if tSettings.bMain then Core.SendToAll("<"..tSettings.sBot.."> *** The Hub has crossed its peak uptime :D : "..SecondsToTime(tRecord.iHubTime,true)); end;
iCount = 1
else
iCount = iCount + 1
end
end
end
end
end
SecondsToTime = function(iSeconds, bSmall)
-- Build table with time fields
local T = os.date("!*t", tonumber(iSeconds));
-- Format to string
local sTime = string.format("%i year(s), %i month(s), %i day(s), %i hour(s), %i minute(s)", T.year-1970, T.month-1, T.day-1, T.hour, T.min)
-- Small stat?
if bSmall then
-- For each digit
for i in sTime:gmatch("%d+") do
-- Reduce if is preceeded by 0
if tonumber(i) == 0 then sTime = sTime:gsub("^"..i.."%s(%S+),%s", "") end
end
end
-- Return
return sTime
end
-- By kepp and NotRambitWombat
DoShareUnits = function(intSize)
if intSize and intSize ~= 0 then
local tUnits, intSize, sUnits = { "Bytes", "KB", "MB", "GB", "TB" }, tonumber(intSize)
for index in ipairs(tUnits) do
if(intSize < 1024) then sUnits = tUnits[index]; break; else intSize = intSize / 1024; end
end
return string.format("%0.1f %s",intSize, sUnits);
end
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(table,tablename,file)
local hFile = io.open(file,"w+") Serialize(table,tablename,hFile); hFile:close()
collectgarbage("collect")
io.flush()
end
Quote
-- Top Hub Up Time Message Interval (in minutes)
iInterval = 60,
It means that the Top UpTime Record Message will be reported after every iInterval Minutes after the old record has been crossed.
Currently I have set that to 60 minutes to avoid message spam.
Fantastic work speedX.. :)
Thanks SpeedX the scripts working great.
Speed X,
I hope you agree on a addition for this i know theres a similar script but we can have an addition to it in a different way.
There is a Script for user hub time But if we are having the Top Records of everything in this script then i think we should have a record showing The Top Hub time like A user logs in the hub at a stretch for 2 hrs or 3 hrs will be the peak Hub time by the user and if any other user extends and surpasses the previous record it will be a new record. It can be displayed just as the previous records. I hope you understand may be i am not good in explaining,But would surely like to give more explanation if needed.
Thanks for all the updates.Would be thankful if you look into this update also.
Thanks in Advance.
Quote==================================================
Record Value Date - Time
----------------------------------------------------------------------------------------------------
Share 8.8 TB 07/6/09 13:01:55
Users 71 user(s) 07/6/09 13:18:23
Top Sharer ?LighT_AssassiN?? (1.4 TB) 07/12/09 03:15:44
----------------------------------------------------------------------------------------------------
Top Uptime Missing on show all records.:P and also on startup message where user logs in.
Quote from: TZB on 14 July, 2009, 10:30:42
Top Uptime Missing on show all records.:P and also on startup message where user logs in.
Script above updated with changes.....
Quote from: TZB on 14 July, 2009, 08:51:47
There is a Script for user hub time But if we are having the Top Records of everything in this script then i think we should have a record showing The Top Hub time
Since we already have a great script like TopHubbers, which does the same as what you are requesting for then I think we shouldn't mess this script with those additions.
Also I added all your requests as they are Hub Records and not each user record.
Thanks SpeedX for looking into it.
QuoteAlso I added all your requests as they are Hub Records and not each user record.
But this part is not Hub record its user ...
QuoteTop Sharer ?LighT_AssassiN?? (1.4 TB) 07/12/09 03:15:44
Moreover What i wanted is User Peak Login Time to Logout time(in hr.min.sec).And i went through with Hubtime it had Total Hubtime +AHT But it never had this thing (if i have missed i am sorry)
rocking work mate
keep the good work going
Where do i change so that the tRecord gets put in only the script folder in ptokax, now it gets put in ptokax and in the ptokax/script folder.. would be nice with a fix for that =)
Script Updated to store tRecord file in scripts folder.
--[[
RecordBot 1.7b - LUA 5.0/5.1 by jiten (11/8/2006)
Converted to API 2 by speedX (07/05/2009)
Based on RecordBot vKryFinal written by bonki 2003
Description: Logs and displays a hub's all time share and user record.
- Fixed: Huge users bug and some stuff (thx to T?M??r?V?ll?R)
- Fixed: Stats sending before MOTD
- Added: Top Share and Sharer Record (requested by XPMAN)
- Added: Reg Bot switch (requested by (uk)jay)
- Fixed: Nil Max Sharer (thx Cosmos)
- Added: Ignore List (requested by chettedeboeuf)
- Fixed: User Record Time (11/26/2005)
- Added: Top Sharer and Share validation delay (requested by chettedeboeuf)
- Changed: Command Parsing and profile permission structure
- Fixed: Top Sharer and Share Delay bug (thx to chettedeboeuf)
- Chaged: Some code rewritten
- Added: Time/Date to each record message (requested by Troubadour)
- Changed: Chat and ToArrival structure;
- Removed: !rb.set command;
- Merged: tSettings and Record table;
- Changed: Some code bits and variables;
- Updated: To LUA 5.1 (11/8/2006)
- Updated: To API 2 (07/05/2009) by speedX
Additions by speedX: (Requested by TZB)
- Added: Rightclick Menu
- Added: Commands for separate Share Record ,User Record and Top Sharer
- Added: Command to get Top Hub UpTime
]]--
tSettings = {
-- Bot Name
sBot = "RecordBot",
-- Toggle automatically register Bot Name [true = on, false = off]
bRegister = true,
-- RecordBot DB
fRecord = "tRecord.txt",
-- Ignore table
tIgnore = { ["jiten"] = 1, ["yournick"] = 1, },
-- Top Sharer and Top Share validation delay (minutes)
iDelay = 0,
-- Top Hub Up Time Message Interval (in minutes)
iInterval = 60,
-- Message settings [ true = on, false = off ]
-- Show report in Main
bMain = true,
-- Show report in PM
bPM = false,
-- Show report on Login
bLogin = true,
-- Commands
sHelp = "rb.help", sShow = "rb.show", sSetup = "rb.set", sReset = "rb.reset", sShareRecord = "rb.sharerecord", sUserRecord = "rb.userrecord", sTopSharer = "rb.topsharer", sUpTime = "rb.topuptime"
}
tRecord, tDelay , iCount = {}, {} , 0
OnStartup = function()
tSettings.fRecord = Core.GetPtokaXPath().."scripts/"..tSettings.fRecord
if (tSettings.sBot ~= SetMan.GetString(21) or tSettings.bRegister) then Core.RegBot(tSettings.sBot,"","",true) end
if loadfile(tSettings.fRecord) then dofile(tSettings.fRecord) end
tSettings.iTimer = TmrMan.AddTimer(1000)
end
ChatArrival = function(user, data)
-- Define vars
local _,_, to = string.find(data, "^$To:%s(%S+)%s+From:")
local _,_, msg = string.find(data, "%b<>%s(.*)|$")
-- Message sent to Bot or in Main
if (to and to == tSettings.sBot) or not to then
-- Parse command
local _,_, cmd = string.find(msg, "^%p(%S+)")
-- Exists
if cmd and tCommands[string.lower(cmd)] then
cmd = string.lower(cmd)
-- If user has permission
if tCommands[cmd].tLevels[user.iProfile] and tCommands[cmd].tLevels[user.iProfile] == 1 then
if to and to == tSettings.sBot then
return Core.SendPmToNick(user.sNick,tSettings.sBot,tCommands[cmd].fFunction(user)), true
else
return Core.SendToNick(user.sNick,"<"..tSettings.sBot.."> "..tCommands[cmd].fFunction(user)), true
end
else
if to and to == tSettings.sBot then
return Core.SendPmToNick(user.sNick,tSettings.sBot,"*** Error: You are not allowed to use this command!"), true
else
return Core.SendToNick(user.sNick,"<"..tSettings.sBot.."> *** Error: You are not allowed to use this command!"), true
end
end
end
end
end
ToArrival = ChatArrival
OnExit = function()
SaveToFile(tRecord, "tRecord", tSettings.fRecord)
end
tCommands = {
[tSettings.sHelp] = {
fFunction = function(user)
-- Header
local sMsg = "\r\n\r\n\t\t\t"..string.rep("=", 80).."\r\n"..string.rep("\t", 6).."RecordBot - LUA 5.1x version by jiten "..
"\t\t\t\r\n\t\t\t"..string.rep("-", 160).."\r\n\t\t\tAvailable Commands:".."\r\n\r\n"
-- Loop through table
for i,v in pairs(tCommands) do
-- If user has permission
if v.tLevels[user.iProfile] and v.tLevels[user.iProfile] == 1 then
-- Populate
sMsg = sMsg.."\t\t\t!"..i.."\t\t"..v.tDesc.."\r\n"
end
end
-- Send
return sMsg.."\t\t\t"..string.rep("-",160);
end,
tLevels = {
[-1] = 1, [0] = 1, [1] = 1, [2] = 1, [3] = 1, [4] = 1, [5] = 1,
},
tDesc = "\tDisplays this help message\t\t\t!"..tSettings.sHelp.."",
tRC = {{ "RecordBot Help","" }},
},
[tSettings.sShow] = {
fFunction = function(user)
if next(tRecord) then
local msg = "\r\n\r\n\t"..string.rep ("=", 50).."\r\n\tRecord\t\tValue\t\tDate - Time\n\t"..string.rep ("-", 100).."\r\n"..
"\tShare\t\t"..(DoShareUnits(tRecord.iShare) or 0).." \t\t"..(tRecord.tShare or "n/a")..
"\r\n\tUsers\t\t"..(tRecord.iUsers or 0).." user(s)\t\t"..(tRecord.tUsers or "n/a")..
"\r\n\tTop Sharer\t"..(tRecord.sMaxSharer or "n/a").." ("..(DoShareUnits(tRecord.iMaxSharer) or 0)..
")\t"..(tRecord.tMaxSharer or "n/a")..
"\r\n\tTop UpTime\t"..(SecondsToTime(tRecord.iHubTime,true) or "n/a").."\t"..(tRecord.tHubTime or "n/a")..
"\r\n\t"..string.rep ("-", 100)
return msg
else
return "*** Error: No records have been saved."
end
end,
tLevels = {
[-1] = 1, [0] = 1, [1] = 1, [2] = 1, [3] = 1, [4] = 1, [5] = 1,
},
tDesc = "\tShows this hub's all time share and user record\t!"..tSettings.sShow,
tRC = {{ "Show All Records","" }},
},
[tSettings.sReset] = {
fFunction = function(user)
tRecord = {}; Core.SendToAll("<"..tSettings.sBot.."> *** Hub records have been reset!");
return "You Have Reset All Records!"
end,
tLevels = {
[-1] = 0, [0] = 1, [1] = 0, [2] = 0, [3] = 0, [4] = 0, [5] = 1,
},
tDesc = "\tResets all records\t\t\t\t!"..tSettings.sReset,
tRC = {{ "Reset Record","" }},
},
[tSettings.sShareRecord] = {
fFunction = function(user)
if next(tRecord) then
local msg = "\r\n\r\n\t"..string.rep ("=", 50).."\r\n\tRecord\t\tValue\t\tDate - Time\n\t"..string.rep ("-", 100).."\r\n"..
"\tShare\t\t"..(DoShareUnits(tRecord.iShare) or 0).." \t\t"..(tRecord.tShare or "n/a")..
"\r\n\t"..string.rep ("-", 100)
return msg
else
return "*** Error: No records have been saved."
end
end,
tLevels = {
[-1] = 1, [0] = 1, [1] = 1, [2] = 1, [3] = 1, [4] = 1, [5] = 1,
},
tDesc = "\tShows hub's all time share record\t!"..tSettings.sShareRecord,
tRC = {{ "Share Record","" }},
},
[tSettings.sUserRecord] = {
fFunction = function(user)
if next(tRecord) then
local msg = "\r\n\r\n\t"..string.rep ("=", 50).."\r\n\tRecord\t\tValue\t\tDate - Time\n\t"..string.rep ("-", 100).."\r\n"..
"\tUsers\t\t"..(tRecord.iUsers or 0).." user(s)\t\t"..(tRecord.tUsers or "n/a")..
"\r\n\t"..string.rep ("-", 100)
return msg
else
return "*** Error: No records have been saved."
end
end,
tLevels = {
[-1] = 1, [0] = 1, [1] = 1, [2] = 1, [3] = 1, [4] = 1, [5] = 1,
},
tDesc = "\tShows hub's all time user record\t!"..tSettings.sUserRecord,
tRC = {{ "User Record","" }},
},
[tSettings.sTopSharer] = {
fFunction = function(user)
if next(tRecord) then
local msg = "\r\n\r\n\t"..string.rep ("=", 50).."\r\n\tRecord\t\tValue\t\tDate - Time\n\t"..string.rep ("-", 100).."\r\n"..
"\tTop Sharer\t"..(tRecord.sMaxSharer or "n/a").." ("..(DoShareUnits(tRecord.iMaxSharer) or 0)..
")\t"..(tRecord.tMaxSharer or "n/a").."\r\n\t"..string.rep ("-", 100)
return msg
else
return "*** Error: No records have been saved."
end
end,
tLevels = {
[-1] = 1, [0] = 1, [1] = 1, [2] = 1, [3] = 1, [4] = 1, [5] = 1,
},
tDesc = "\tShows hub's all time top sharer\t!"..tSettings.sTopSharer,
tRC = {{ "Top Sharer","" }},
},
[tSettings.sUpTime] = {
fFunction = function(user)
if next(tRecord) then
local msg = "\r\n\r\n\t"..string.rep ("=", 50).."\r\n\tRecord\t\tDate - Time\tValue\n\t"..string.rep ("-", 100).."\r\n"..
"\tTop Uptime\t"..(tRecord.tHubTime or "n/a").."\t"..(SecondsToTime(tRecord.iHubTime,true) or "n/a").."\r\n\t"..string.rep ("-", 100)
return msg
else
return "*** Error: No records have been saved."
end
end,
tLevels = {
[-1] = 1, [0] = 1, [1] = 1, [2] = 1, [3] = 1, [4] = 1, [5] = 1,
},
tDesc = "\tShows hub's Top Uptime\t!"..tSettings.sUpTime,
tRC = {{ "Top Uptime","" }},
},
};
UserConnected = function(user)
if not tSettings.tIgnore[user.sNick] then
local iUserCount = Core.GetUsersCount()
tRecord.iUsers, tRecord.tUsers = (tRecord.iUsers or 0), (tRecord.tUsers or "n/a")
if (iUserCount > tRecord.iUsers) then
tRecord.iUsers, tRecord.tUsers = iUserCount, os.date()
SaveToFile(tRecord, "tRecord", tSettings.fRecord)
if tSettings.bPM then
Core.SendPmToNick(user.sNick,tSettings.sBot,"*** Thanks, buddie. You've just raised the all-time share record!");
end;
if tSettings.bMain then
Core.SendToAll("<"..tSettings.sBot.."> *** "..user.sNick.." has just raised the all-time user record to: "..
tRecord.iUsers.." users at "..os.date().." :)");
end;
end
tDelay[user] = {}
tDelay[user]["iTime"] = tSettings.iDelay*60
end
for i,v in pairs(tCommands) do
if v.tLevels[user.iProfile] and v.tLevels[user.iProfile] == 1 then
for n in ipairs(v.tRC) do
Core.SendToNick(user.sNick, "$UserCommand 1 3 RecordBot\\"..v.tRC[n][1].."$<%[mynick]> +"..i..v.tRC[n][2].."|")
end
end
end
end
OpConnected,RegConnected = UserConnected,UserConnected
OnTimer = function(iID)
if tSettings.iTimer and iID == tSettings.iTimer then
for nick,v in pairs(tDelay) do
tDelay[nick]["iTime"] = tDelay[nick]["iTime"] - 1
if tDelay[nick]["iTime"] <= 0 then
if Core.GetUser(nick.sNick) then
local iTotalShare, iShare, sNick = Core.GetCurrentSharedSize(), Core.GetUserValue(nick,16) , nick.sNick
tRecord.iShare = (tRecord.iShare or 0)
if (iTotalShare > tRecord.iShare) then
tRecord.iShare, tRecord.tShare = iTotalShare, os.date()
SaveToFile(tRecord, "tRecord", tSettings.fRecord)
if tSettings.bPM then Core.SendPmToNick(nick.sNick, tSettings.sBot, "*** Thanks, buddie. You have just raised the all-time share record to "..DoShareUnits(iTotalShare).." :)"); end;
if tSettings.bMain then Core.SendToAll("<"..tSettings.sBot.."> *** "..nick.sNick.." has just raised the all-time share record to: "..DoShareUnits(iTotalShare).." on "..os.date("%x")); end;
end
tRecord.iMaxSharer = (tRecord.iMaxSharer or 0)
if (iShare > tRecord.iMaxSharer) then
tRecord.iMaxSharer, tRecord.sMaxSharer, tRecord.tMaxSharer = iShare, nick.sNick, os.date()
SaveToFile(tRecord, "tRecord", tSettings.fRecord)
if tSettings.bPM then Core.SendPmToNick(nick.sNick,tSettings.sBot,"*** Thanks, buddie. You are our highest sharer with: "..DoShareUnits(iShare).."."); end;
if tSettings.bMain then Core.SendToAll("<"..tSettings.sBot.."> *** "..nick.sNick.." is our all-time biggest sharer with: "..DoShareUnits((iShare)).." since "..os.date("%x").." :)"); end;
end
if tSettings.bLogin then
local sMsg = "\r\n\r\n\t"..string.rep("=", 50).."\r\n\t\t\tStats\r\n\t"..
string.rep("-", 100).."\r\n\r\n\tShare record: "..(DoShareUnits(tonumber(tRecord.iShare)) or 0).." [ "..
(tRecord.tShare or "n/a").." ]\r\n\tUser record: "..(tRecord.iUsers or 0).." users [ "..
(tRecord.tUsers or "n/a").." ]\r\n\tTop Sharer: "..(tRecord.sMaxSharer or "n/a")..
" ("..(DoShareUnits(tRecord.iMaxSharer) or 0)..") [ "..(tRecord.tMaxSharer or "n/a").." ]\r\n\tTop UpTime: "..
(SecondsToTime(tRecord.iHubTime,true) or "n/a").." [ "..(tRecord.tHubTime or "n/a").." ]\r\n"
Core.SendToNick(nick.sNick,"<"..tSettings.sBot.."> "..sMsg)
end;
end
tDelay[nick] = nil
end
end
iTotalUpTime = Core.GetUpTime()
tRecord.iHubTime = (tRecord.iHubTime or 0)
if iTotalUpTime > tRecord.iHubTime then
tRecord.iHubTime , tRecord.tHubTime = iTotalUpTime , os.date()
SaveToFile(tRecord, "tRecord", tSettings.fRecord)
if tSettings.iInterval <= 0 then
if tSettings.bMain then Core.SendToAll("<"..tSettings.sBot.."> *** The Hub has crossed its peak uptime :D : "..SecondsToTime(tRecord.iHubTime,true)); end;
else
if iCount == 0 then
if tSettings.bMain then Core.SendToAll("<"..tSettings.sBot.."> *** The Hub has crossed its peak uptime :D : "..SecondsToTime(tRecord.iHubTime,true)); end;
iCount = iCount + 1
elseif iCount == tSettings.iInterval*60 then
if tSettings.bMain then Core.SendToAll("<"..tSettings.sBot.."> *** The Hub has crossed its peak uptime :D : "..SecondsToTime(tRecord.iHubTime,true)); end;
iCount = 1
else
iCount = iCount + 1
end
end
end
end
end
SecondsToTime = function(iSeconds, bSmall)
-- Build table with time fields
local T = os.date("!*t", tonumber(iSeconds));
-- Format to string
local sTime = string.format("%i year(s), %i month(s), %i day(s), %i hour(s), %i minute(s)", T.year-1970, T.month-1, T.day-1, T.hour, T.min)
-- Small stat?
if bSmall then
-- For each digit
for i in sTime:gmatch("%d+") do
-- Reduce if is preceeded by 0
if tonumber(i) == 0 then sTime = sTime:gsub("^"..i.."%s(%S+),%s", "") end
end
end
-- Return
return sTime
end
-- By kepp and NotRambitWombat
DoShareUnits = function(intSize)
if intSize and intSize ~= 0 then
local tUnits, intSize, sUnits = { "Bytes", "KB", "MB", "GB", "TB" }, tonumber(intSize)
for index in ipairs(tUnits) do
if(intSize < 1024) then sUnits = tUnits[index]; break; else intSize = intSize / 1024; end
end
return string.format("%0.1f %s",intSize, sUnits);
end
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(table,tablename,file)
local hFile = io.open(file,"w+") Serialize(table,tablename,hFile); hFile:close()
collectgarbage("collect")
io.flush()
end
When there are ex. 10 users online, it says that only 9 are online? why is my question? and is there a fix for it =)
Thanks for the Report
--[[
RecordBot 1.7b - LUA 5.0/5.1 by jiten (11/8/2006)
Converted to API 2 by speedX (07/05/2009)
Based on RecordBot vKryFinal written by bonki 2003
Description: Logs and displays a hub's all time share and user record.
- Fixed: Huge users bug and some stuff (thx to T?M??r?V?ll?R)
- Fixed: Stats sending before MOTD
- Added: Top Share and Sharer Record (requested by XPMAN)
- Added: Reg Bot switch (requested by (uk)jay)
- Fixed: Nil Max Sharer (thx Cosmos)
- Added: Ignore List (requested by chettedeboeuf)
- Fixed: User Record Time (11/26/2005)
- Added: Top Sharer and Share validation delay (requested by chettedeboeuf)
- Changed: Command Parsing and profile permission structure
- Fixed: Top Sharer and Share Delay bug (thx to chettedeboeuf)
- Chaged: Some code rewritten
- Added: Time/Date to each record message (requested by Troubadour)
- Changed: Chat and ToArrival structure;
- Removed: !rb.set command;
- Merged: tSettings and Record table;
- Changed: Some code bits and variables;
- Updated: To LUA 5.1 (11/8/2006)
- Updated: To API 2 (07/05/2009) by speedX
+ Changes by speedX:
- Added: Rightclick Menu (Requested by TZB)
- Added: Commands for separate Share Record ,User Record and Top Sharer (Requested by TZB)
- Added: Command to get Top Hub UpTime (Requested by TZB)
- Fixed: User Record (Reported by Dreams)
]]--
tSettings = {
-- Bot Name
sBot = "RecordBot",
-- Toggle automatically register Bot Name [true = on, false = off]
bRegister = true,
-- RecordBot DB
fRecord = "tRecord.txt",
-- Ignore table
tIgnore = { ["jiten"] = 1, ["yournick"] = 1, },
-- Top Sharer and Top Share validation delay (minutes)
iDelay = 0,
-- Top Hub Up Time Message Interval (in minutes)
iInterval = 60,
-- Message settings [ true = on, false = off ]
-- Show report in Main
bMain = true,
-- Show report in PM
bPM = false,
-- Show report on Login
bLogin = true,
-- Commands
sHelp = "rb.help", sShow = "rb.show", sSetup = "rb.set", sReset = "rb.reset", sShareRecord = "rb.sharerecord", sUserRecord = "rb.userrecord", sTopSharer = "rb.topsharer", sUpTime = "rb.topuptime"
}
tRecord, tDelay , tUserC , iCount = {}, {} , {} , 0
OnStartup = function()
tSettings.fRecord = Core.GetPtokaXPath().."scripts/"..tSettings.fRecord
if (tSettings.sBot ~= SetMan.GetString(21) or tSettings.bRegister) then Core.RegBot(tSettings.sBot,"","",true) end
if loadfile(tSettings.fRecord) then dofile(tSettings.fRecord) end
tSettings.iTimer = TmrMan.AddTimer(1000)
end
ChatArrival = function(user, data)
-- Define vars
local _,_, to = string.find(data, "^$To:%s(%S+)%s+From:")
local _,_, msg = string.find(data, "%b<>%s(.*)|$")
-- Message sent to Bot or in Main
if (to and to == tSettings.sBot) or not to then
-- Parse command
local _,_, cmd = string.find(msg, "^%p(%S+)")
-- Exists
if cmd and tCommands[string.lower(cmd)] then
cmd = string.lower(cmd)
-- If user has permission
if tCommands[cmd].tLevels[user.iProfile] and tCommands[cmd].tLevels[user.iProfile] == 1 then
if to and to == tSettings.sBot then
return Core.SendPmToNick(user.sNick,tSettings.sBot,tCommands[cmd].fFunction(user)), true
else
return Core.SendToNick(user.sNick,"<"..tSettings.sBot.."> "..tCommands[cmd].fFunction(user)), true
end
else
if to and to == tSettings.sBot then
return Core.SendPmToNick(user.sNick,tSettings.sBot,"*** Error: You are not allowed to use this command!"), true
else
return Core.SendToNick(user.sNick,"<"..tSettings.sBot.."> *** Error: You are not allowed to use this command!"), true
end
end
end
end
end
ToArrival = ChatArrival
OnExit = function()
SaveToFile(tRecord, "tRecord", tSettings.fRecord)
end
tCommands = {
[tSettings.sHelp] = {
fFunction = function(user)
-- Header
local sMsg = "\r\n\r\n\t\t\t"..string.rep("=", 80).."\r\n"..string.rep("\t", 6).."RecordBot - LUA 5.1x version by jiten "..
"\t\t\t\r\n\t\t\t"..string.rep("-", 160).."\r\n\t\t\tAvailable Commands:".."\r\n\r\n"
-- Loop through table
for i,v in pairs(tCommands) do
-- If user has permission
if v.tLevels[user.iProfile] and v.tLevels[user.iProfile] == 1 then
-- Populate
sMsg = sMsg.."\t\t\t!"..i.."\t\t"..v.tDesc.."\r\n"
end
end
-- Send
return sMsg.."\t\t\t"..string.rep("-",160);
end,
tLevels = {
[-1] = 1, [0] = 1, [1] = 1, [2] = 1, [3] = 1, [4] = 1, [5] = 1,
},
tDesc = "\tDisplays this help message\t\t\t!"..tSettings.sHelp.."",
tRC = {{ "RecordBot Help","" }},
},
[tSettings.sShow] = {
fFunction = function(user)
if next(tRecord) then
local msg = "\r\n\r\n\t"..string.rep ("=", 50).."\r\n\tRecord\t\tValue\t\tDate - Time\n\t"..string.rep ("-", 100).."\r\n"..
"\tShare\t\t"..(DoShareUnits(tRecord.iShare) or 0).." \t\t"..(tRecord.tShare or "n/a")..
"\r\n\tUsers\t\t"..(tRecord.iUsers or 0).." user(s)\t\t"..(tRecord.tUsers or "n/a")..
"\r\n\tTop Sharer\t"..(tRecord.sMaxSharer or "n/a").." ("..(DoShareUnits(tRecord.iMaxSharer) or 0)..
")\t"..(tRecord.tMaxSharer or "n/a")..
"\r\n\tTop UpTime\t"..(SecondsToTime(tRecord.iHubTime,true) or "n/a").."\t"..(tRecord.tHubTime or "n/a")..
"\r\n\t"..string.rep ("-", 100)
return msg
else
return "*** Error: No records have been saved."
end
end,
tLevels = {
[-1] = 1, [0] = 1, [1] = 1, [2] = 1, [3] = 1, [4] = 1, [5] = 1,
},
tDesc = "\tShows this hub's all time share and user record\t!"..tSettings.sShow,
tRC = {{ "Show All Records","" }},
},
[tSettings.sReset] = {
fFunction = function(user)
tRecord = {}; Core.SendToAll("<"..tSettings.sBot.."> *** Hub records have been reset!");
return "You Have Reset All Records!"
end,
tLevels = {
[-1] = 0, [0] = 1, [1] = 0, [2] = 0, [3] = 0, [4] = 0, [5] = 1,
},
tDesc = "\tResets all records\t\t\t\t!"..tSettings.sReset,
tRC = {{ "Reset Record","" }},
},
[tSettings.sShareRecord] = {
fFunction = function(user)
if next(tRecord) then
local msg = "\r\n\r\n\t"..string.rep ("=", 50).."\r\n\tRecord\t\tValue\t\tDate - Time\n\t"..string.rep ("-", 100).."\r\n"..
"\tShare\t\t"..(DoShareUnits(tRecord.iShare) or 0).." \t\t"..(tRecord.tShare or "n/a")..
"\r\n\t"..string.rep ("-", 100)
return msg
else
return "*** Error: No records have been saved."
end
end,
tLevels = {
[-1] = 1, [0] = 1, [1] = 1, [2] = 1, [3] = 1, [4] = 1, [5] = 1,
},
tDesc = "\tShows hub's all time share record\t!"..tSettings.sShareRecord,
tRC = {{ "Share Record","" }},
},
[tSettings.sUserRecord] = {
fFunction = function(user)
if next(tRecord) then
local msg = "\r\n\r\n\t"..string.rep ("=", 50).."\r\n\tRecord\t\tValue\t\tDate - Time\n\t"..string.rep ("-", 100).."\r\n"..
"\tUsers\t\t"..(tRecord.iUsers or 0).." user(s)\t\t"..(tRecord.tUsers or "n/a")..
"\r\n\t"..string.rep ("-", 100)
return msg
else
return "*** Error: No records have been saved."
end
end,
tLevels = {
[-1] = 1, [0] = 1, [1] = 1, [2] = 1, [3] = 1, [4] = 1, [5] = 1,
},
tDesc = "\tShows hub's all time user record\t!"..tSettings.sUserRecord,
tRC = {{ "User Record","" }},
},
[tSettings.sTopSharer] = {
fFunction = function(user)
if next(tRecord) then
local msg = "\r\n\r\n\t"..string.rep ("=", 50).."\r\n\tRecord\t\tValue\t\tDate - Time\n\t"..string.rep ("-", 100).."\r\n"..
"\tTop Sharer\t"..(tRecord.sMaxSharer or "n/a").." ("..(DoShareUnits(tRecord.iMaxSharer) or 0)..
")\t"..(tRecord.tMaxSharer or "n/a").."\r\n\t"..string.rep ("-", 100)
return msg
else
return "*** Error: No records have been saved."
end
end,
tLevels = {
[-1] = 1, [0] = 1, [1] = 1, [2] = 1, [3] = 1, [4] = 1, [5] = 1,
},
tDesc = "\tShows hub's all time top sharer\t!"..tSettings.sTopSharer,
tRC = {{ "Top Sharer","" }},
},
[tSettings.sUpTime] = {
fFunction = function(user)
if next(tRecord) then
local msg = "\r\n\r\n\t"..string.rep ("=", 50).."\r\n\tRecord\t\tDate - Time\tValue\n\t"..string.rep ("-", 100).."\r\n"..
"\tTop Uptime\t"..(tRecord.tHubTime or "n/a").."\t"..(SecondsToTime(tRecord.iHubTime,true) or "n/a").."\r\n\t"..string.rep ("-", 100)
return msg
else
return "*** Error: No records have been saved."
end
end,
tLevels = {
[-1] = 1, [0] = 1, [1] = 1, [2] = 1, [3] = 1, [4] = 1, [5] = 1,
},
tDesc = "\tShows hub's Top Uptime\t!"..tSettings.sUpTime,
tRC = {{ "Top Uptime","" }},
},
};
UserConnected = function(user)
if not tSettings.tIgnore[user.sNick] then
tDelay[user] = {}
tDelay[user]["iTime"] = tSettings.iDelay*60
table.insert(tUserC,user.sNick)
end
for i,v in pairs(tCommands) do
if v.tLevels[user.iProfile] and v.tLevels[user.iProfile] == 1 then
for n in ipairs(v.tRC) do
Core.SendToNick(user.sNick, "$UserCommand 1 3 RecordBot\\"..v.tRC[n][1].."$<%[mynick]> +"..i..v.tRC[n][2].."||")
end
end
end
end
OpConnected,RegConnected = UserConnected,UserConnected
OnTimer = function(iID)
if tSettings.iTimer and iID == tSettings.iTimer then
for nick,v in pairs(tDelay) do
tDelay[nick]["iTime"] = tDelay[nick]["iTime"] - 1
if tDelay[nick]["iTime"] <= 0 then
if Core.GetUser(nick.sNick) then
local iTotalShare, iShare, sNick = Core.GetCurrentSharedSize(), Core.GetUserValue(nick,16) , nick.sNick
tRecord.iShare = (tRecord.iShare or 0)
if (iTotalShare > tRecord.iShare) then
tRecord.iShare, tRecord.tShare = iTotalShare, os.date()
SaveToFile(tRecord, "tRecord", tSettings.fRecord)
if tSettings.bPM then Core.SendPmToNick(nick.sNick, tSettings.sBot, "*** Thanks, buddie. You have just raised the all-time share record to "..DoShareUnits(iTotalShare).." :)"); end;
if tSettings.bMain then Core.SendToAll("<"..tSettings.sBot.."> *** "..nick.sNick.." has just raised the all-time share record to: "..DoShareUnits(iTotalShare).." on "..os.date("%x")); end;
end
tRecord.iMaxSharer = (tRecord.iMaxSharer or 0)
if (iShare > tRecord.iMaxSharer) then
tRecord.iMaxSharer, tRecord.sMaxSharer, tRecord.tMaxSharer = iShare, nick.sNick, os.date()
SaveToFile(tRecord, "tRecord", tSettings.fRecord)
if tSettings.bPM then Core.SendPmToNick(nick.sNick,tSettings.sBot,"*** Thanks, buddie. You are our highest sharer with: "..DoShareUnits(iShare).."."); end;
if tSettings.bMain then Core.SendToAll("<"..tSettings.sBot.."> *** "..nick.sNick.." is our all-time biggest sharer with: "..DoShareUnits((iShare)).." since "..os.date("%x").." :)"); end;
end
if tSettings.bLogin then
local sMsg = "\r\n\r\n\t"..string.rep("=", 50).."\r\n\t\t\tStats\r\n\t"..
string.rep("-", 100).."\r\n\r\n\tShare record: "..(DoShareUnits(tonumber(tRecord.iShare)) or 0).." [ "..
(tRecord.tShare or "n/a").." ]\r\n\tUser record: "..(tRecord.iUsers or 0).." users [ "..
(tRecord.tUsers or "n/a").." ]\r\n\tTop Sharer: "..(tRecord.sMaxSharer or "n/a")..
" ("..(DoShareUnits(tRecord.iMaxSharer) or 0)..") [ "..(tRecord.tMaxSharer or "n/a").." ]\r\n\tTop UpTime: "..
(SecondsToTime(tRecord.iHubTime,true) or "n/a").." [ "..(tRecord.tHubTime or "n/a").." ]\r\n"
Core.SendToNick(nick.sNick,"<"..tSettings.sBot.."> "..sMsg)
end;
end
tDelay[nick] = nil
end
end
iTotalUpTime = Core.GetUpTime()
tRecord.iHubTime = (tRecord.iHubTime or 0)
if iTotalUpTime > tRecord.iHubTime then
tRecord.iHubTime , tRecord.tHubTime = iTotalUpTime , os.date()
SaveToFile(tRecord, "tRecord", tSettings.fRecord)
if tSettings.iInterval <= 0 then
if tSettings.bMain then Core.SendToAll("<"..tSettings.sBot.."> *** The Hub has crossed its peak uptime :D : "..SecondsToTime(tRecord.iHubTime,true)); end;
else
if iCount == 0 then
if tSettings.bMain then Core.SendToAll("<"..tSettings.sBot.."> *** The Hub has crossed its peak uptime :D : "..SecondsToTime(tRecord.iHubTime,true)); end;
iCount = iCount + 1
elseif iCount == tSettings.iInterval*60 then
if tSettings.bMain then Core.SendToAll("<"..tSettings.sBot.."> *** The Hub has crossed its peak uptime :D : "..SecondsToTime(tRecord.iHubTime,true)); end;
iCount = 1
else
iCount = iCount + 1
end
end
end
if table.getn(tUserC) > 0 then
local iUserCount = Core.GetUsersCount()
tRecord.iUsers, tRecord.tUsers = (tRecord.iUsers or 0), (tRecord.tUsers or "n/a")
if (iUserCount > tRecord.iUsers) then
tRecord.iUsers, tRecord.tUsers = iUserCount, os.date()
SaveToFile(tRecord, "tRecord", tSettings.fRecord)
if tSettings.bPM then
Core.SendPmToNick(tUserC[1],tSettings.sBot,"*** Thanks, buddie. You've just raised the all-time share record!");
end;
if tSettings.bMain then
Core.SendToAll("<"..tSettings.sBot.."> *** "..tUserC[1].." has just raised the all-time user record to: "..
tRecord.iUsers.." users at "..os.date().." :)");
end;
end
table.remove(tUserC,1)
end
end
end
SecondsToTime = function(iSeconds, bSmall)
-- Build table with time fields
local T = os.date("!*t", tonumber(iSeconds));
-- Format to string
local sTime = string.format("%i year(s), %i month(s), %i day(s), %i hour(s), %i minute(s)", T.year-1970, T.month-1, T.day-1, T.hour, T.min)
-- Small stat?
if bSmall then
-- For each digit
for i in sTime:gmatch("%d+") do
-- Reduce if is preceeded by 0
if tonumber(i) == 0 then sTime = sTime:gsub("^"..i.."%s(%S+),%s", "") end
end
end
-- Return
return sTime
end
-- By kepp and NotRambitWombat
DoShareUnits = function(intSize)
if intSize and intSize ~= 0 then
local tUnits, intSize, sUnits = { "Bytes", "KB", "MB", "GB", "TB" }, tonumber(intSize)
for index in ipairs(tUnits) do
if(intSize < 1024) then sUnits = tUnits[index]; break; else intSize = intSize / 1024; end
end
return string.format("%0.1f %s",intSize, sUnits);
end
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(table,tablename,file)
local hFile = io.open(file,"w+") Serialize(table,tablename,hFile); hFile:close()
collectgarbage("collect")
io.flush()
end
Thanks, works fine now =)
I believe i found a bug here:
-- Toggle automatically register Bot Name [true = on, false = off]
bRegister = false,
It still shows up in userlist despite false
Try this. Post bugs if any....
--[[
RecordBot 1.7c - LUA 5.0/5.1 by jiten (11/8/2006)
Converted to API 2 by speedX (07/05/2009)
Based on RecordBot vKryFinal written by bonki 2003
Description: Logs and displays a hub's all time share and user record.
- Fixed: Huge users bug and some stuff (thx to T?M??r?V?ll?R)
- Fixed: Stats sending before MOTD
- Added: Top Share and Sharer Record (requested by XPMAN)
- Added: Reg Bot switch (requested by (uk)jay)
- Fixed: Nil Max Sharer (thx Cosmos)
- Added: Ignore List (requested by chettedeboeuf)
- Fixed: User Record Time (11/26/2005)
- Added: Top Sharer and Share validation delay (requested by chettedeboeuf)
- Changed: Command Parsing and profile permission structure
- Fixed: Top Sharer and Share Delay bug (thx to chettedeboeuf)
- Chaged: Some code rewritten
- Added: Time/Date to each record message (requested by Troubadour)
- Changed: Chat and ToArrival structure;
- Removed: !rb.set command;
- Merged: tSettings and Record table;
- Changed: Some code bits and variables;
- Updated: To LUA 5.1 (11/8/2006)
- Updated: To API 2 (07/05/2009) by speedX
+ Changes by speedX:
- Added: Rightclick Menu (Requested by TZB)
- Added: Commands for separate Share Record ,User Record and Top Sharer (Requested by TZB)
- Added: Command to get Top Hub UpTime (Requested by TZB)
- Fixed: User Record (Reported by Dreams)
- Fixed: Bot Registration
]]--
tSettings = {
-- Bot Name
sBot = "RecordBot",
-- Toggle automatically register Bot Name [true = on, false = off]
bRegister = true,
-- RecordBot DB
fRecord = "tRecord.txt",
-- Ignore table
tIgnore = { ["jiten"] = 1, ["yournick"] = 1, },
-- Top Sharer and Top Share validation delay (minutes)
iDelay = 0,
-- Top Hub Up Time Message Interval (in minutes)
iInterval = 60,
-- Message settings [ true = on, false = off ]
-- Show report in Main
bMain = true,
-- Show report in PM
bPM = false,
-- Show report on Login
bLogin = true,
-- Commands
sHelp = "rb.help", sShow = "rb.show", sSetup = "rb.set", sReset = "rb.reset", sShareRecord = "rb.sharerecord", sUserRecord = "rb.userrecord", sTopSharer = "rb.topsharer", sUpTime = "rb.topuptime"
}
tRecord, tDelay , tUserC , iCount = {}, {} , {} , 0
OnStartup = function()
tSettings.fRecord = Core.GetPtokaXPath().."scripts/"..tSettings.fRecord
if tSettings.bRegister then Core.RegBot(tSettings.sBot,"","",true) end
if loadfile(tSettings.fRecord) then dofile(tSettings.fRecord) end
tSettings.iTimer = TmrMan.AddTimer(1000)
end
ChatArrival = function(user, data)
-- Define vars
local _,_, to = string.find(data, "^$To:%s(%S+)%s+From:")
local _,_, msg = string.find(data, "%b<>%s(.*)|$")
-- Message sent to Bot or in Main
if (to and to == tSettings.sBot) or not to then
-- Parse command
local _,_, cmd = string.find(msg, "^%p(%S+)")
-- Exists
if cmd and tCommands[string.lower(cmd)] then
cmd = string.lower(cmd)
-- If user has permission
if tCommands[cmd].tLevels[user.iProfile] and tCommands[cmd].tLevels[user.iProfile] == 1 then
if to and to == tSettings.sBot then
return Core.SendPmToNick(user.sNick,tSettings.sBot,tCommands[cmd].fFunction(user)), true
else
return Core.SendToNick(user.sNick,"<"..tSettings.sBot.."> "..tCommands[cmd].fFunction(user)), true
end
else
if to and to == tSettings.sBot then
return Core.SendPmToNick(user.sNick,tSettings.sBot,"*** Error: You are not allowed to use this command!"), true
else
return Core.SendToNick(user.sNick,"<"..tSettings.sBot.."> *** Error: You are not allowed to use this command!"), true
end
end
end
end
end
ToArrival = ChatArrival
OnExit = function()
SaveToFile(tRecord, "tRecord", tSettings.fRecord)
end
tCommands = {
[tSettings.sHelp] = {
fFunction = function(user)
-- Header
local sMsg = "\r\n\r\n\t\t\t"..string.rep("=", 80).."\r\n"..string.rep("\t", 6).."RecordBot - LUA 5.1x version by jiten "..
"\t\t\t\r\n\t\t\t"..string.rep("-", 160).."\r\n\t\t\tAvailable Commands:".."\r\n\r\n"
-- Loop through table
for i,v in pairs(tCommands) do
-- If user has permission
if v.tLevels[user.iProfile] and v.tLevels[user.iProfile] == 1 then
-- Populate
sMsg = sMsg.."\t\t\t!"..i.."\t\t"..v.tDesc.."\r\n"
end
end
-- Send
return sMsg.."\t\t\t"..string.rep("-",160);
end,
tLevels = {
[-1] = 1, [0] = 1, [1] = 1, [2] = 1, [3] = 1, [4] = 1, [5] = 1,
},
tDesc = "\tDisplays this help message\t\t\t!"..tSettings.sHelp.."",
tRC = {{ "RecordBot Help","" }},
},
[tSettings.sShow] = {
fFunction = function(user)
if next(tRecord) then
local msg = "\r\n\r\n\t"..string.rep ("=", 50).."\r\n\tRecord\t\tValue\t\tDate - Time\n\t"..string.rep ("-", 100).."\r\n"..
"\tShare\t\t"..(DoShareUnits(tRecord.iShare) or 0).." \t\t"..(tRecord.tShare or "n/a")..
"\r\n\tUsers\t\t"..(tRecord.iUsers or 0).." user(s)\t\t"..(tRecord.tUsers or "n/a")..
"\r\n\tTop Sharer\t"..(tRecord.sMaxSharer or "n/a").." ("..(DoShareUnits(tRecord.iMaxSharer) or 0)..
")\t"..(tRecord.tMaxSharer or "n/a")..
"\r\n\tTop UpTime\t"..(SecondsToTime(tRecord.iHubTime,true) or "n/a").."\t"..(tRecord.tHubTime or "n/a")..
"\r\n\t"..string.rep ("-", 100)
return msg
else
return "*** Error: No records have been saved."
end
end,
tLevels = {
[-1] = 1, [0] = 1, [1] = 1, [2] = 1, [3] = 1, [4] = 1, [5] = 1,
},
tDesc = "\tShows this hub's all time share and user record\t!"..tSettings.sShow,
tRC = {{ "Show All Records","" }},
},
[tSettings.sReset] = {
fFunction = function(user)
tRecord = {}; Core.SendToAll("<"..tSettings.sBot.."> *** Hub records have been reset!");
return "You Have Reset All Records!"
end,
tLevels = {
[-1] = 0, [0] = 1, [1] = 0, [2] = 0, [3] = 0, [4] = 0, [5] = 1,
},
tDesc = "\tResets all records\t\t\t\t!"..tSettings.sReset,
tRC = {{ "Reset Record","" }},
},
[tSettings.sShareRecord] = {
fFunction = function(user)
if next(tRecord) then
local msg = "\r\n\r\n\t"..string.rep ("=", 50).."\r\n\tRecord\t\tValue\t\tDate - Time\n\t"..string.rep ("-", 100).."\r\n"..
"\tShare\t\t"..(DoShareUnits(tRecord.iShare) or 0).." \t\t"..(tRecord.tShare or "n/a")..
"\r\n\t"..string.rep ("-", 100)
return msg
else
return "*** Error: No records have been saved."
end
end,
tLevels = {
[-1] = 1, [0] = 1, [1] = 1, [2] = 1, [3] = 1, [4] = 1, [5] = 1,
},
tDesc = "\tShows hub's all time share record\t!"..tSettings.sShareRecord,
tRC = {{ "Share Record","" }},
},
[tSettings.sUserRecord] = {
fFunction = function(user)
if next(tRecord) then
local msg = "\r\n\r\n\t"..string.rep ("=", 50).."\r\n\tRecord\t\tValue\t\tDate - Time\n\t"..string.rep ("-", 100).."\r\n"..
"\tUsers\t\t"..(tRecord.iUsers or 0).." user(s)\t\t"..(tRecord.tUsers or "n/a")..
"\r\n\t"..string.rep ("-", 100)
return msg
else
return "*** Error: No records have been saved."
end
end,
tLevels = {
[-1] = 1, [0] = 1, [1] = 1, [2] = 1, [3] = 1, [4] = 1, [5] = 1,
},
tDesc = "\tShows hub's all time user record\t!"..tSettings.sUserRecord,
tRC = {{ "User Record","" }},
},
[tSettings.sTopSharer] = {
fFunction = function(user)
if next(tRecord) then
local msg = "\r\n\r\n\t"..string.rep ("=", 50).."\r\n\tRecord\t\tValue\t\tDate - Time\n\t"..string.rep ("-", 100).."\r\n"..
"\tTop Sharer\t"..(tRecord.sMaxSharer or "n/a").." ("..(DoShareUnits(tRecord.iMaxSharer) or 0)..
")\t"..(tRecord.tMaxSharer or "n/a").."\r\n\t"..string.rep ("-", 100)
return msg
else
return "*** Error: No records have been saved."
end
end,
tLevels = {
[-1] = 1, [0] = 1, [1] = 1, [2] = 1, [3] = 1, [4] = 1, [5] = 1,
},
tDesc = "\tShows hub's all time top sharer\t!"..tSettings.sTopSharer,
tRC = {{ "Top Sharer","" }},
},
[tSettings.sUpTime] = {
fFunction = function(user)
if next(tRecord) then
local msg = "\r\n\r\n\t"..string.rep ("=", 50).."\r\n\tRecord\t\tDate - Time\tValue\n\t"..string.rep ("-", 100).."\r\n"..
"\tTop Uptime\t"..(tRecord.tHubTime or "n/a").."\t"..(SecondsToTime(tRecord.iHubTime,true) or "n/a").."\r\n\t"..string.rep ("-", 100)
return msg
else
return "*** Error: No records have been saved."
end
end,
tLevels = {
[-1] = 1, [0] = 1, [1] = 1, [2] = 1, [3] = 1, [4] = 1, [5] = 1,
},
tDesc = "\tShows hub's Top Uptime\t!"..tSettings.sUpTime,
tRC = {{ "Top Uptime","" }},
},
};
UserConnected = function(user)
if not tSettings.tIgnore[user.sNick] then
tDelay[user] = {}
tDelay[user]["iTime"] = tSettings.iDelay*60
table.insert(tUserC,user.sNick)
end
for i,v in pairs(tCommands) do
if v.tLevels[user.iProfile] and v.tLevels[user.iProfile] == 1 then
for n in ipairs(v.tRC) do
Core.SendToNick(user.sNick, "$UserCommand 1 3 RecordBot\\"..v.tRC[n][1].."$<%[mynick]> +"..i..v.tRC[n][2].."||")
end
end
end
end
OpConnected,RegConnected = UserConnected,UserConnected
OnTimer = function(iID)
if tSettings.iTimer and iID == tSettings.iTimer then
for nick,v in pairs(tDelay) do
tDelay[nick]["iTime"] = tDelay[nick]["iTime"] - 1
if tDelay[nick]["iTime"] <= 0 then
if Core.GetUser(nick.sNick) then
local iTotalShare, iShare, sNick = Core.GetCurrentSharedSize(), Core.GetUserValue(nick,16) , nick.sNick
tRecord.iShare = (tRecord.iShare or 0)
if (iTotalShare > tRecord.iShare) then
tRecord.iShare, tRecord.tShare = iTotalShare, os.date()
SaveToFile(tRecord, "tRecord", tSettings.fRecord)
if tSettings.bPM then Core.SendPmToNick(nick.sNick, tSettings.sBot, "*** Thanks, buddie. You have just raised the all-time share record to "..DoShareUnits(iTotalShare).." :)"); end;
if tSettings.bMain then Core.SendToAll("<"..tSettings.sBot.."> *** "..nick.sNick.." has just raised the all-time share record to: "..DoShareUnits(iTotalShare).." on "..os.date("%x")); end;
end
tRecord.iMaxSharer = (tRecord.iMaxSharer or 0)
if (iShare > tRecord.iMaxSharer) then
tRecord.iMaxSharer, tRecord.sMaxSharer, tRecord.tMaxSharer = iShare, nick.sNick, os.date()
SaveToFile(tRecord, "tRecord", tSettings.fRecord)
if tSettings.bPM then Core.SendPmToNick(nick.sNick,tSettings.sBot,"*** Thanks, buddie. You are our highest sharer with: "..DoShareUnits(iShare).."."); end;
if tSettings.bMain then Core.SendToAll("<"..tSettings.sBot.."> *** "..nick.sNick.." is our all-time biggest sharer with: "..DoShareUnits((iShare)).." since "..os.date("%x").." :)"); end;
end
if tSettings.bLogin then
local sMsg = "\r\n\r\n\t"..string.rep("=", 50).."\r\n\t\t\tStats\r\n\t"..
string.rep("-", 100).."\r\n\r\n\tShare record: "..(DoShareUnits(tonumber(tRecord.iShare)) or 0).." [ "..
(tRecord.tShare or "n/a").." ]\r\n\tUser record: "..(tRecord.iUsers or 0).." users [ "..
(tRecord.tUsers or "n/a").." ]\r\n\tTop Sharer: "..(tRecord.sMaxSharer or "n/a")..
" ("..(DoShareUnits(tRecord.iMaxSharer) or 0)..") [ "..(tRecord.tMaxSharer or "n/a").." ]\r\n\tTop UpTime: "..
(SecondsToTime(tRecord.iHubTime,true) or "n/a").." [ "..(tRecord.tHubTime or "n/a").." ]\r\n"
Core.SendToNick(nick.sNick,"<"..tSettings.sBot.."> "..sMsg)
end;
end
tDelay[nick] = nil
end
end
iTotalUpTime = Core.GetUpTime()
tRecord.iHubTime = (tRecord.iHubTime or 0)
if iTotalUpTime > tRecord.iHubTime then
tRecord.iHubTime , tRecord.tHubTime = iTotalUpTime , os.date()
SaveToFile(tRecord, "tRecord", tSettings.fRecord)
if tSettings.iInterval <= 0 then
if tSettings.bMain then Core.SendToAll("<"..tSettings.sBot.."> *** The Hub has crossed its peak uptime :D : "..SecondsToTime(tRecord.iHubTime,true)); end;
else
if iCount == 0 then
if tSettings.bMain then Core.SendToAll("<"..tSettings.sBot.."> *** The Hub has crossed its peak uptime :D : "..SecondsToTime(tRecord.iHubTime,true)); end;
iCount = iCount + 1
elseif iCount == tSettings.iInterval*60 then
if tSettings.bMain then Core.SendToAll("<"..tSettings.sBot.."> *** The Hub has crossed its peak uptime :D : "..SecondsToTime(tRecord.iHubTime,true)); end;
iCount = 1
else
iCount = iCount + 1
end
end
end
if table.getn(tUserC) > 0 then
local iUserCount = Core.GetUsersCount()
tRecord.iUsers, tRecord.tUsers = (tRecord.iUsers or 0), (tRecord.tUsers or "n/a")
if (iUserCount > tRecord.iUsers) then
tRecord.iUsers, tRecord.tUsers = iUserCount, os.date()
SaveToFile(tRecord, "tRecord", tSettings.fRecord)
if tSettings.bPM then
Core.SendPmToNick(tUserC[1],tSettings.sBot,"*** Thanks, buddie. You've just raised the all-time share record!");
end;
if tSettings.bMain then
Core.SendToAll("<"..tSettings.sBot.."> *** "..tUserC[1].." has just raised the all-time user record to: "..
tRecord.iUsers.." users at "..os.date().." :)");
end;
end
table.remove(tUserC,1)
end
end
end
SecondsToTime = function(iSeconds, bSmall)
-- Build table with time fields
local T = os.date("!*t", tonumber(iSeconds));
-- Format to string
local sTime = string.format("%i year(s), %i month(s), %i day(s), %i hour(s), %i minute(s)", T.year-1970, T.month-1, T.day-1, T.hour, T.min)
-- Small stat?
if bSmall then
-- For each digit
for i in sTime:gmatch("%d+") do
-- Reduce if is preceeded by 0
if tonumber(i) == 0 then sTime = sTime:gsub("^"..i.."%s(%S+),%s", "") end
end
end
-- Return
return sTime
end
-- By kepp and NotRambitWombat
DoShareUnits = function(intSize)
if intSize and intSize ~= 0 then
local tUnits, intSize, sUnits = { "Bytes", "KB", "MB", "GB", "TB" }, tonumber(intSize)
for index in ipairs(tUnits) do
if(intSize < 1024) then sUnits = tUnits[index]; break; else intSize = intSize / 1024; end
end
return string.format("%0.1f %s",intSize, sUnits);
end
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(table,tablename,file)
local hFile = io.open(file,"w+") Serialize(table,tablename,hFile); hFile:close()
collectgarbage("collect")
io.flush()
end
I think bSmall isn't work for me.
bSmall got true value but i got this: 0 year(s) 0 month(s) 2 day(s) 3 hour(s) 17 minute(s)
I would like to get this: 2 day(s) 3 hour(s) 17 minute(s)
What can I do?
Quote from: cspetee on 10 March, 2011, 03:55:42
I think bSmall isn't work for me.
bSmall got true value but i got this: 0 year(s) 0 month(s) 2 day(s) 3 hour(s) 17 minute(s)
I would like to get this: 2 day(s) 3 hour(s) 17 minute(s)
What can I do?
Its working fine here...
I found the error. I deleted the comma in the string.format but i forgot delete also in the regexp of sTime:gsub.
It's my fault, sorry.
Quote from: cspetee on 10 March, 2011, 12:29:41
I found the error. I deleted the comma in the string.format but i forgot delete also in the regexp of sTime:gsub.
It's my fault, sorry.
No probs