Author Topic: RecordBot help  (Read 2709 times)

0 Members and 1 Guest are viewing this topic.

Offline Gnuff?

  • Double Ace
  • *
  • Posts: 121
  • Karma: +21/-1
    • ?????Gnuff?s Hideout??????
RecordBot help
« on: 27 January, 2008, 16:52:34 »
Can anyone tell me what?s wrong with this script:

Code: [Select]
--[[

RecordBot 1.6 - LUA 5.0/5.1 by jiten (11/8/2006)

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 PtokaX API 2 (07/12/2007)
* Changed Login message from timer to userconnected =) (08/12/2007)

]]--

tSettings = {

-- Bot Name
sBot = "??????RecordBot?????? ",

-- Toggle automatically register Bot Name [true = on, false = off]
bRegister = false,

-- 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 = false,

-- 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
TmrMan.AddTimer(60*1000,"Timer")
end

ChatArrival = function(user,data)
Core.GetUserAllData(user)
-- 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, user.SendMessage = string.lower(cmd), Core.SendToNick
-- PM
if to == tSettings.sBot then user.SendMessage = Core.SendPMToNick end
-- If user has permission
if tCommands[cmd].tLevels[user.iProfile] and tCommands[cmd].tLevels[user.iProfile] == 1 then
return tCommands[cmd].fFunction(user), true
else
return Core.SendToNick(user.sNick,"<"..tSettings.sBot.."> *** Fejl: Du har ikke tilladelse til at bruge denne kommando!"), 1
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.1 version af 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
Core.SendToNick(user.sNick,"<"..tSettings.sBot.."> "..sMsg.." \t\t\t"..string.rep("-",160));
end,
tLevels = {
[-1] = 1, [0] = 1, [1] = 1, [2] = 1, [3] = 1, [4] = 1, [5] = 1,
},
tDesc = "\tViser denne hj?lpeside\t\t\t!"..tSettings.sHelp,
tRC = "\\Vis hj?lpeside$<%[mynick]> !"..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"..
"\tDeler\t\t"..(DoShareUnits(tRecord.iShare) or 0).." \t\t"..(tRecord.tShare or "n/a")..
"\r\n\tBrugere\t\t"..(tRecord.iUsers or 0).." user(s)\t\t"..(tRecord.tUsers or "n/a")..
"\r\n\tTop Delere\t"..(tRecord.sMaxSharer or "n/a").." ("..(DoShareUnits(tRecord.iMaxSharer) or 0)..
")\t"..(tRecord.tMaxSharer or "n/a").."\r\n\t"..string.rep ("-", 100)
Core.SendToNick(user.sNick,"<"..tSettings.sBot.."> "..msg.."|")
else
Core.SendToNick(user.sNick,"<"..tSettings.sBot.."> *** 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 = "\\Display share and user record$<%[mynick]> !"..tSettings.sShow,
},
[tSettings.sReset] = {
fFunction = function(user)
tRecord = {}; Core.SendToAll("<"..tSettings.sBot.."> *** Hub records have been reset!");
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 records$<%[mynick]> !"..tSettings.sReset,
},
};

UserConnected = function(user)
for _,cmd in pairs(tCommands) do
if cmd.tLevels[user.iProfile] and cmd.tLevels[user.iProfile] == 1 then
Core.SendToNick(user.sNick,"$UserCommand 1 3 "..tSettings.sBot..cmd.tRC.."&#124;")
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(user.sNick,"<"..tSettings.sBot.."> ".. sMsg)
end
Core.GetUserAllData(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, "*** 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 = UserConnected
RegConnected = UserConnected

Timer = function(tmr)
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(), nick.iShareSize, 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, "*** 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
end
tDelay[nick] = nil
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

It resets every time the user wlth topshare disconnects, or hub goes under user record, and as well if the share record goes under top
Gnuff

PtokaX forum

RecordBot help
« on: 27 January, 2008, 16:52:34 »