determinate determinate

Author Topic: Record Bot  (Read 9681 times)

0 Members and 1 Guest are viewing this topic.

Offline jiten

  • Scripter
  • Forum Legend
  • ******
  • Posts: 1 585
  • Karma: +71/-5
Record Bot
« on: May 10, 2005, 03:38:22 pm »
Code: [Select]
--[[

RecordBot 1.5 - Lua 5 version by jiten

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)

]]--

tSettings = {
-- Bot Name, Mail and Description
Bot = { sName = "RecordBot", sMail = "bonki@no-spam.net", sDesc = "RecordBot - LUA 5 version by jiten" },
-- RecordBot Database
fRecord = "tRecord.tbl",
-- true: Register Automatically, false: don't
bRegister = true,
-- Top Sharer and Top Share validation delay in minutes
iDelay = 0,
-- Ignore table
tIgnore = { ["jiten"] = 1, ["yournick"] = 1, },
-- Commands
sHelp = "rb.help", sShow = "rb.show", sSetup = "rb.set", sReset = "rb.reset"
}

Record = {
-- RecordBot DB
tDB = {},
-- RecordBot message settings
tSetup = {
-- Show report in Main
main = 1,
-- Show report in PM
pm = 0,
-- Show report on Login
login = 1
},
}

-- Delay table (don't change this)
tDelay = {}

Main = function()
if tSettings.bRegister then frmHub:RegBot(tSettings.Bot.sName, 1, tSettings.Bot.sDesc, tSettings.Bot.sMail) end
if loadfile(tSettings.fRecord) then dofile(tSettings.fRecord) end;
SetTimer(1000); StartTimer()
end

ChatArrival = function(user, data)
local data = string.sub(data,1,-2)
local s,e,cmd = string.find(data, "%b<>%s+[%!%+](%S+)" )
if cmd and tCmds[cmd] then
cmd = string.lower(cmd);
if tCmds[cmd].tLevels[user.iProfile] then
return tCmds[cmd].tFunc(user,data), 1
else
return user:SendData(tSettings.Bot.sName, "*** Error: You do not have sufficient rights to run that command!"), 1;
end
end
end

OnExit = function()
SaveToFile(Record,"Record",tSettings.fRecord)
end

tCmds = {
[tSettings.sHelp] = {
tFunc = function(user)
local sMsg = "\r\n\t\r\n\t\t\t\t\t"..tSettings.Bot.sDesc.."\r\n\r\n\t\t\t\tLogs and displays a hub's all"..
"time share and user record.\r\n\t\r\n\tAvailable Commands:".."\r\n\r\n";
for cmd, v in tCmds do
if tCmds[cmd].tLevels[user.iProfile] then sMsg = sMsg.."\t!"..cmd.."\t "..v.tDesc.."\r\n"; end
end
user:SendData(tSettings.Bot.sName,sMsg);
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] = {
tFunc = function(user)
local tTable = Record.tDB
if next(tTable) then
local border = string.rep ("-", 100)
local msg = "\r\n\t"..border.."\r\n\tRecord\t\tValue\t\tDate - Time\n\t"..border.."\r\n"..
"\tShare\t\t"..(DoShareUnits(tTable.iShare) or 0).." \t\t"..(tTable.tShare or "*not available*")..
"\r\n\tUsers\t\t"..(tTable.iUsers or 0).." user(s)\t\t"..(tTable.tUsers or "*not available*")..
"\r\n\tTop Sharer\t"..(tTable.sMaxSharer or "*not available*").." ("..(DoShareUnits(tTable.iMaxSharer) or 0)..
")\t"..(tTable.tMaxSharer or "*not available*").."\r\n\t"..border
user:SendData(tSettings.Bot.sName,msg)
else
user:SendData(tSettings.Bot.sName, "*** 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.sSetup] = {
tFunc = function(user, args)
local s,e,type,flag = string.find(args,"^%S+%s+%S+%s+(%S+)%s+(%S+)")
if type and Record.tSetup[string.lower(type)] then
local tTable = { ["enable"] = 1, ["disable"] = 0 }
if flag and tTable[string.lower(flag)] then
Record.tSetup[string.lower(type)] = tTable[string.lower(flag)]
user:SendData(tSettings.Bot.sName, "*** Show in "..string.upper(string.sub(type,1,1))..
string.lower(string.sub(type,2,string.len(type))).." Mode has been "..flag.."d!");
end
else
user:SendData(tSettings.Bot.sName, "*** Syntax Error: Type !"..tSettings.sSetup.." <login/pm/main> <enable/disable>");
end
end,
tLevels = {
[0] = 1,
[5] = 1,
},
tDesc = "\tSetup RecordBot\t\t\t\t!"..tSettings.sSetup.." <main/login/pm> <enable/disable>",
},
[tSettings.sReset] = {
tFunc = function(user)
Record.tDB = {}
SendToAll(tSettings.Bot.sName, "*** Hub records have been reset!");
end,
tLevels = {
[0] = 1,
[5] = 1,
},
tDesc = "\tResets all records\t\t\t\t!"..tSettings.sReset,
},
};

NewUserConnected = function(user)
if tSettings.tIgnore[user.sName] ~= 1 then
local iUserCount, tTable = frmHub:GetUsersCount(), Record.tDB
tTable.iUsers = tTable.iUsers or 0; tTable.tUsers = tTable.tUsers or "*not available*"
if (iUserCount > tTable.iUsers) then
tTable.iUsers = iUserCount; tTable.tUsers = os.date()
if (Record.tSetup.pm == 1) then
SendPmToNick(user.sName, "*** Thanks, buddie. You've just raised the all-time share record!");
end;
if (Record.tSetup.main == 1) then
SendToAll(tSettings.Bot.sName, "*** "..user.sName.." has just raised the all-time user record to: "..
tTable.iUsers.." users at "..os.date().." :)");
end;
end
tDelay[user] = {}
tDelay[user]["iTime"] = tSettings.iDelay*60
end
end

OpConnected = NewUserConnected

OnTimer = function()
for nick,v in tDelay do
tDelay[nick]["iTime"] = tDelay[nick]["iTime"] - 1
if tDelay[nick]["iTime"] <= 0 then
if GetItemByName(nick.sName) then
local iTotalShare, iShare, sNick, tTable = frmHub:GetCurrentShareAmount(), nick.iShareSize, nick.sName, Record.tDB
tTable.iShare = tTable.iShare or 0
if (iTotalShare > tTable.iShare) then
tTable.iShare = iTotalShare; tTable.tShare = os.date()
if (Record.tSetup.pm == 1) then SendPmToNick(nick.sName, tSettings.Bot.sName, "*** Thanks, buddie. You have just raised the all-time share record to "..DoShareUnits(iTotalShare).." :)"); end;
if (Record.tSetup.main == 1) then SendToAll(tSettings.Bot.sName, "*** "..nick.sName.." has just raised the all-time share record to: "..DoShareUnits(iTotalShare).." on "..os.date("%x")); end;
end

tTable.iMaxSharer = tTable.iMaxSharer or 0
if (iShare > tTable.iMaxSharer) then
tTable.iMaxSharer = iShare; tTable.sMaxSharer = nick.sName; tTable.tMaxSharer = os.date()
if (Record.tSetup.pm == 1) then SendPmToNick(nick.sName, "*** Thanks, buddie. You are our highest sharer with: "..DoShareUnits(iShare).."."); end;
if (Record.tSetup.main == 1) then SendToAll(tSettings.Bot.sName, "*** "..nick.sName.." is our all-time biggest sharer with: "..DoShareUnits((iShare)).." since "..os.date("%x").." :)"); end;
end

if (Record.tSetup.login == 1) then
local sMsg = "\r\n\r\n\tShare record: "..(DoShareUnits(tonumber(tTable.iShare)) or 0).." at "..
(tTable.tShare or "*not available*").."\r\n\tUser record: "..(tTable.iUsers or 0).." users at "..
(tTable.tUsers or "*not available*").."\r\n\tTop Sharer: "..(tTable.sMaxSharer or "*not available*")..
" ("..(DoShareUnits(tTable.iMaxSharer) or 0)..") at "..(tTable.tMaxSharer or "*not available*").."\r\n"
nick:SendData(tSettings.Bot.sName,sMsg)
end;
end
tDelay[nick] = nil
end
end
end

-- By kepp and NotRambitWombat
DoShareUnits = function(intSize)
if intSize and intSize ~= 0 then
local tUnits = { "Bytes", "KB", "MB", "GB", "TB" }; intSize = tonumber(intSize);
local sUnits;
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 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
« Last Edit: March 08, 2006, 08:00:11 pm by jiten »

Offline dkt

  • Forum Ace
  • *****
  • Posts: 91
  • Karma: +1/-0
(No subject)
« Reply #1 on: May 10, 2005, 08:08:57 pm »
nice script jiten keep it up m8 !!!

Offline jiten

  • Scripter
  • Forum Legend
  • ******
  • Posts: 1 585
  • Karma: +71/-5
(No subject)
« Reply #2 on: May 10, 2005, 08:14:54 pm »
It surely needs some testing :D

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

  • Scripter
  • Lord
  • ******
  • Posts: 317
  • Karma: +16/-0
(No subject)
« Reply #3 on: May 10, 2005, 08:37:09 pm »
When reconecting i got some users it seems  ;)

[20:33:55] TïMê†råVêlléR has just raised the all-time share record to: 636.5 GB
[20:33:55] Share record: 636.5 GB
[20:33:55] User record: 683441533803 users


greetzz   TT

Offline jiten

  • Scripter
  • Forum Legend
  • ******
  • Posts: 1 585
  • Karma: +71/-5
(No subject)
« Reply #4 on: May 10, 2005, 08:59:04 pm »
Quote
Originally posted by TïMê†råVêlléR
When reconecting i got some users it seems  ;)

[20:33:55] TïMê†råVêlléR has just raised the all-time share record to: 636.5 GB
[20:33:55] Share record: 636.5 GB
[20:33:55] User record: 683441533803 users


greetzz   TT

First post updated.
Please delete the old .tbl files before using this one.
Btw, that would be an all-time record :D

Cheers

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

  • Scripter
  • Lord
  • ******
  • Posts: 317
  • Karma: +16/-0
(No subject)
« Reply #5 on: May 10, 2005, 09:07:38 pm »
Shame  lost all my users  ;)

works fine now  :)

Greetzz TT

Offline dkt

  • Forum Ace
  • *****
  • Posts: 91
  • Karma: +1/-0
(No subject)
« Reply #6 on: May 10, 2005, 09:33:54 pm »
lol ------> lost all users

Offline jiten

  • Scripter
  • Forum Legend
  • ******
  • Posts: 1 585
  • Karma: +71/-5
(No subject)
« Reply #7 on: May 11, 2005, 12:51:14 pm »
Quote
Originally posted by TïMê†råVêlléR
Shame  lost all my users  ;)

works fine now  :)

Greetzz TT

Cool :D

Offline uffetjur

  • Lord
  • ***
  • Posts: 289
  • Karma: +4/-0
(No subject)
« Reply #8 on: May 11, 2005, 02:15:17 pm »
had to delete config.tbl to get recordbot to show up in mainchat

so not so good to use recordbots cmd's for settings

running ptokax 17.05 and robocop 10.01e


Might be a bug to... dont sure chatarrival is used in the complete script,
getting users refused from hub to trigger the script...


NewUserConnected = function(curUser)

   local aShare,aUsers = frmHub:GetCurrentShareAmount(),frmHub:GetUsersCount()

   if Record.Share == nil then Record.Share = 0 end

etc etc
« Last Edit: May 11, 2005, 03:39:18 pm by uffetjur »
Somewhere in Cyberspace

Offline jiten

  • Scripter
  • Forum Legend
  • ******
  • Posts: 1 585
  • Karma: +71/-5
(No subject)
« Reply #9 on: May 11, 2005, 05:06:03 pm »
Quote
Originally posted by uffetjur
had to delete config.tbl to get recordbot to show up in mainchat

Indeed, as you could see in a previous post: "First post updated. Please delete the old .tbl files before using this one."

Quote
Might be a bug to... dont sure chatarrival is used in the complete script,
getting users refused from hub to trigger the script...

Hopefully fixed.

First post updated.

Best regards.

Offline uffetjur

  • Lord
  • ***
  • Posts: 289
  • Karma: +4/-0
(No subject)
« Reply #10 on: May 11, 2005, 05:14:09 pm »
i did used the updated script
Somewhere in Cyberspace

Offline jiten

  • Scripter
  • Forum Legend
  • ******
  • Posts: 1 585
  • Karma: +71/-5
(No subject)
« Reply #11 on: May 11, 2005, 05:21:13 pm »
Quote
Originally posted by uffetjur
i did used the updated script

My guess was that you had the updated one but, didn't delete the .tbl files before using it.

Anyway, let's see if it that problem is solved ;)

Offline uffetjur

  • Lord
  • ***
  • Posts: 289
  • Karma: +4/-0
(No subject)
« Reply #12 on: May 11, 2005, 05:53:02 pm »
Zitat:Originally posted by uffetjur
    i did used the updated script


My guess was that you had the updated one but, didn't delete the .tbl files before using it.

Anyway, let's see if it that problem is solved
______________________________________

did a clean install using the updated script,
now testing the latest update!
cheers m8
Somewhere in Cyberspace

Offline kash©

  • Double Ace
  • *
  • Posts: 101
  • Karma: +0/-1
(No subject)
« Reply #13 on: May 20, 2005, 06:42:49 pm »
gr8 work Jiten

But only one problem......
that RecordBot comes b4 MOTD
Because of that all that goes up..
Can it be done after MOTD

waiting reply,
« Last Edit: May 20, 2005, 06:44:14 pm by kash© »

Offline Dessamator

  • Scripter
  • Emperor
  • ******
  • Posts: 1 257
  • Karma: +13/-7
(No subject)
« Reply #14 on: May 20, 2005, 07:28:57 pm »
indeed, its simple to solve, jiten go go go , :),
btw it would be nice if PPK, could implement an API, that does that, :)
Ignorance is Bliss.

Offline jiten

  • Scripter
  • Forum Legend
  • ******
  • Posts: 1 585
  • Karma: +71/-5
(No subject)
« Reply #15 on: May 20, 2005, 07:47:57 pm »
Quote
Originally posted by kash©
gr8 work Jiten

But only one problem......
that RecordBot comes b4 MOTD
Because of that all that goes up..
Can it be done after MOTD

waiting reply,

Yes, it can be done. First post updated with that fix.

Cheers

Offline kash©

  • Double Ace
  • *
  • Posts: 101
  • Karma: +0/-1
(No subject)
« Reply #16 on: May 20, 2005, 08:32:28 pm »
thanx Jiten
working gr8
keep up good job

Offline jiten

  • Scripter
  • Forum Legend
  • ******
  • Posts: 1 585
  • Karma: +71/-5
(No subject)
« Reply #17 on: June 03, 2005, 11:25:18 am »
First post updated with Top Share and Sharer Record addition.

Cheers

chettedeboeuf

  • Guest
(No subject)
« Reply #18 on: June 03, 2005, 11:53:19 am »
I test this script now

Thank you jiten

Offline Optimus

  • Emperor
  • **
  • Posts: 1 485
  • Karma: +13/-1
(No subject)
« Reply #19 on: June 03, 2005, 12:22:04 pm »
Code: [Select]
if Record.Share == nil then Record.Share = 0 end This an others can be written as

Record.Share = Record.Share or 0

- Optimus

Offline jiten

  • Scripter
  • Forum Legend
  • ******
  • Posts: 1 585
  • Karma: +71/-5
(No subject)
« Reply #20 on: June 03, 2005, 12:41:41 pm »
Quote
Originally posted by Optimus
Code: [Select]
if Record.Share == nil then Record.Share = 0 end This an others can be written as

Record.Share = Record.Share or 0

- Optimus

Thanks for the tip, Optimus ;)
Going to start using that one.

Cheers

chettedeboeuf

  • Guest
(No subject)
« Reply #21 on: June 03, 2005, 01:15:02 pm »
----------------------------------------------------------------------------------------------------
   Record      Value      Date - Time
   ----------------------------------------------------------------------------------------------------
   Share      1.5 TB       06/03/05 12:45:39
   Users      40 user(s)
   Top Sharer   --MFZ--ChEtTeDeBoEuF™ (168.9 GB)
   ----------------------------------------------------------------------------------------------------

No date-time for top users ?

jiten, do you response at private message if ...

Offline jiten

  • Scripter
  • Forum Legend
  • ******
  • Posts: 1 585
  • Karma: +71/-5
(No subject)
« Reply #22 on: June 03, 2005, 05:39:04 pm »
Quote
Originally posted by chettedeboeuf
----------------------------------------------------------------------------------------------------
   Record      Value      Date - Time
   ----------------------------------------------------------------------------------------------------
   Share      1.5 TB       06/03/05 12:45:39
   Users      40 user(s)
   Top Sharer   --MFZ--ChEtTeDeBoEuF™ (168.9 GB)
   ----------------------------------------------------------------------------------------------------

No date-time for top users ?

jiten, do you response at private message if ...

First post updated with that request ;)

Cheers

Offline Optimus

  • Emperor
  • **
  • Posts: 1 485
  • Karma: +13/-1
(No subject)
« Reply #23 on: June 03, 2005, 08:06:01 pm »
yw  8)

chettedeboeuf

  • Guest
(No subject)
« Reply #24 on: June 04, 2005, 04:22:37 am »
Thank You Jiten

Offline jiten

  • Scripter
  • Forum Legend
  • ******
  • Posts: 1 585
  • Karma: +71/-5
(No subject)
« Reply #25 on: June 04, 2005, 09:23:40 am »
You're welcome :]

Offline TwîsTèd-dèvîl

  • Lord
  • ***
  • Posts: 438
  • Karma: +79/-2
    • EURO-OP
(No subject)
« Reply #26 on: June 04, 2005, 01:01:49 pm »
Can you add switch to allow reg/unreg bot please :D

Offline jiten

  • Scripter
  • Forum Legend
  • ******
  • Posts: 1 585
  • Karma: +71/-5
(No subject)
« Reply #27 on: June 04, 2005, 02:37:17 pm »
Quote
Originally posted by (uk)jay
Can you add switch to allow reg/unreg bot please :D

First post updated with that request.

Cheers m8

Offline TwîsTèd-dèvîl

  • Lord
  • ***
  • Posts: 438
  • Karma: +79/-2
    • EURO-OP
(No subject)
« Reply #28 on: June 04, 2005, 02:47:08 pm »
Cheers m8   :))

Offline Cosmos

  • Newbie
  • *
  • Posts: 9
  • Karma: +0/-0
(No subject)
« Reply #29 on: June 04, 2005, 10:19:26 pm »
im just testing this script.. and in a hub where nobody is sharing i get this error:

[16:18] Syntax C:\0.3.3.0.b17.08.nt.dbg\scripts\record.lua:303: attempt to concatenate field `maxSharer' (a nil value)

Offline jiten

  • Scripter
  • Forum Legend
  • ******
  • Posts: 1 585
  • Karma: +71/-5
(No subject)
« Reply #30 on: June 04, 2005, 10:51:39 pm »
Quote
Originally posted by Cosmos
im just testing this script.. and in a hub where nobody is sharing i get this error:

[16:18] Syntax C:\0.3.3.0.b17.08.nt.dbg\scripts\record.lua:303: attempt to concatenate field `maxSharer' (a nil value)

Thanks for the report. First post updated.

Cheers

chettedeboeuf

  • Guest
(No subject)
« Reply #31 on: June 05, 2005, 01:17:35 am »
Hi ,

----------------------------------------------------------------------------------------------------
   Record      Valeur      Date - Heure
   ----------------------------------------------------------------------------------------------------
   Share      2.3 TB         06/04/05 21:24:58
   Users      64 user(s)   06/04/05 21:24:58
   Top Sharer   [rug.nl]pinger (310.0 GB)
   ----------------------------------------------------------------------------------------------------

Est il possible de filtrer certains utilisateurs pour eviter de fausser les records ?

It is possible to filter certain users for eviter to distort the records?

i.e. : Top Sharer   [rug.nl]pinger (310.0 GB)
He doesn't appear either on share nor on the users nor on top sharer

Offline jiten

  • Scripter
  • Forum Legend
  • ******
  • Posts: 1 585
  • Karma: +71/-5
(No subject)
« Reply #32 on: June 05, 2005, 11:26:18 am »
Quote
Originally posted by chettedeboeuf
Hi ,

----------------------------------------------------------------------------------------------------
   Record      Valeur      Date - Heure
   ----------------------------------------------------------------------------------------------------
   Share      2.3 TB         06/04/05 21:24:58
   Users      64 user(s)   06/04/05 21:24:58
   Top Sharer   [rug.nl]pinger (310.0 GB)
   ----------------------------------------------------------------------------------------------------

Est il possible de filtrer certains utilisateurs pour eviter de fausser les records ?

It is possible to filter certain users for eviter to distort the records?

i.e. : Top Sharer   [rug.nl]pinger (310.0 GB)
He doesn't appear either on share nor on the users nor on top sharer

Yes, it's possible. I'm going to add that check to the script.

Best regards

Offline jiten

  • Scripter
  • Forum Legend
  • ******
  • Posts: 1 585
  • Karma: +71/-5
(No subject)
« Reply #33 on: June 05, 2005, 12:11:25 pm »
First post updated once again.

Cheers

chettedeboeuf

  • Guest
(No subject)
« Reply #34 on: June 05, 2005, 10:57:11 pm »
Wow
Thank you jiten

 

determinate determinate