PtokaX forum

Archive => Archived 4.0 boards => Request for Lua 4 scripts => Topic started by: Skyhawk on 21 September, 2004, 12:31:33

Title: Need *WORKING* Record Bot
Post by: Skyhawk on 21 September, 2004, 12:31:33
Well on first view bonki's bot is great but when i looked closer it... well it just doesn't work ;(

Info:

I'm running PtokaX DC Hub 0.3.3.0 build 15.25 [debug]

The errors i found so far:

1. bot doesn't display the help screen right (scrambled in mainchat)
2. bot counts wrong (share/user records are not immediatelly updated but only when the next user enters the hub. Eg. i see the share/user amount in my DC client, but the bots tells me that the record is at a value that i saw before the current user entered)
3. botinfo etc does not work (it displayes an empty user AND an op with the same name eg. RecordBot. the Op has no tag infostring etc but the recordbot user has)



Please help!

Title:
Post by: Psycho_Chihuahua on 21 September, 2004, 12:40:23
Well this one does fine for me

sVer   = "KryFinal";
sName  = "RecordBot";
sAbout = "Logs and displays a hub's all time share and user record.";

sRecordFile   = "txt/RecordBot.records.txt";
sConfigFile   = "txt/RecordBot.config.txt";
sTemplateFile = "txt/RecordBot.template.txt";

sShowMain    = "1";
sShowPM      = "1";
sShowOnLogin = "1";

iShareCurrent = nil;
iUserCurrent  = nil;
iUserAllTime  = 0;
iShareAllTime = 0;

sNewShareResponse         = nil;
sNewUsersResponse         = nil;
sNewSharePMResponse       = nil;
sNewUsersPMResponse       = nil;
sShowRecordsShareResponse = nil;
sShowRecordsUsersResponse = nil;

sCrLf = "\r\n";

function Main()
  bot = { sBotName  = sName,
          sBotVer   = sVer,
          sBotEmail = "bonki@no-spam.net",
          sBotSpeed = "Sol",
          sBotDescr = "RecordBot v"..sVer.." written by bonki 2003",
          sBotTag   = "<++ V:"..sVer..",P:bonki,S:[gb.0],U:[users]>",
          iBotShare = 0 };

  ReadConfig();
  ReadRecords();

  UpdateBotInfo();

  PrepareCommands();

  frmHub:RegBot(bot.sBotName);
end

function PrepareCommands()
  sOpHelpOutput = sCrLf..sCrLf..bot.sBotDescr..
                         sCrLf..sAbout..
                  sCrLf..sCrLf.."OP Commands:"..sCrLf..sCrLf;

  sHelpOutput   = sCrLf.."Commands:"..sCrLf..sCrLf;

  tCommands = {
                [ "!rb.help" ]      = { CmdShowHelp,       0, "\t\t\tDisplays this help message."                      },
                [ "!rb.show" ]      = { CmdShowRecords,    0, "\t\t\tShows this hub's all time share and user record." },
                [ "!rb.showmain" ]  = { CmdSetShowMain,    1, "\tmain message."                        },
                [ "!rb.showpm" ]    = { CmdSetShowPM,      1, "\tprivate message."                     },
                [ "!rb.showlogin" ] = { CmdSetShowOnLogin, 1, "\treport on login."                     },
                [ "!rb.reset" ]     = { CmdResetRecords,   1, "\t\t\tResets all records."                              },
              };

  for sCmd, tCmd in tCommands do
    if(tCmd[2] == 1) then
      sOpHelpOutput = sOpHelpOutput..sCmd.."\t "..tCmd[3]..sCrLf;
    else
      sHelpOutput   = sHelpOutput..sCmd.."\t "..tCmd[3]..sCrLf;
    end
  end
end

function CmdShowHelp(curUser)
  curUser:SendData(bot.sBotName, sOpHelpOutput..sHelpOutput);
end

function CmdShowRecords(curUser)
  ReadTemplate(curUser);
  curUser:SendData(bot.sBotName, sShowRecordsShareResponse);
  curUser:SendData(bot.sBotName, sShowRecordsUsersResponse);
end

function CmdSetShowMain(curUser, args)
  if (args == "enable") then
    sShowMain = "1";
    WriteConfig();
    curUser:SendData(bot.sBotName, "Enabled!");
  elseif (args == "disable") then
    sShowMain = "0";
    WriteConfig();
    curUser:SendData(bot.sBotName, "Disabled!");
  else
    curUser:SendData(bot.sBotName, "Syntax error!");
  end
end

function CmdSetShowPM(curUser, args)
  if (args == "enable") then
    sShowPM = "1";
    WriteConfig();
    curUser:SendData(bot.sBotName, "Enabled!");
  elseif (args == "disable") then
    sShowPM = "0";
    WriteConfig();
    curUser:SendData(bot.sBotName, "Disabled!");
  else
    curUser:SendData(bot.sBotName, "Syntax error!");
  end
end

function CmdSetShowOnLogin(curUser, args)
  if (args == "enable") then
    sShowOnLogin = "1";
    WriteConfig();
    curUser:SendData(bot.sBotName, "Enabled!");
  elseif (args == "disable") then
    sShowOnLogin = "0";
    WriteConfig();
    curUser:SendData(bot.sBotName, "Disabled!");
  else
    curUser:SendData(bot.sBotName, "Syntax error!");
  end
end

function CmdResetRecords(curUser)
  iShareAllTime = 0;
  iUserAllTime  = 0;
  WriteNewRecord(iShareAllTime, iUserAllTime);
  SendToAll(bot.sBotName, "Hub records reset!");
end

function DataArrival(curUser, sData)
  local _, _, cmd, args = strfind(sData, "%b<>%s+(%S+)%s*([^%|]*)%|$");

  if(cmd == nil) then
    return 0; end

  cmd = strlower(cmd);
  if (tCommands[cmd]) then
    curUser:SendData(sData);
    if (tCommands[cmd][2] == 0 or curUser.bOperator) then
      tCommands[cmd][1](curUser, strlower(args));
    else
      curUser:SendData(bot.sBotName, "You do not have sufficient rights to run that command!");
    end
    return 1;
  end

  return 0;
end

function CheckForRecords(curUser)
  iShareCurrent = frmHub:GetCurrentShareAmount();
  iUserCurrent  = frmHub:GetUsersCount();

  if (iShareCurrent > iShareAllTime) then
    iShareAllTime = iShareCurrent;
    WriteNewRecord(iShareAllTime, iUserCurrent);
    ReadTemplate(curUser);

    UpdateBotInfo();
    SendBotInfo();

    if (sShowPM == "1") then
      SendPmToNick(curUser.sName, bot.sBotName, sNewSharePMResponse); end;
    if (sShowMain == "1") then
      SendToAll(bot.sBotName, sNewShareResponse); end;
  end

  if (iUserCurrent > iUserAllTime) then
    iUserAllTime = iUserCurrent;
    WriteNewRecord(iShareCurrent, iUserAllTime);
    ReadTemplate(curUser);

    UpdateBotInfo();
    SendBotInfo();

    if (sShowPM == "1") then
      SendPmToNick(curUser.sName, sNewUsersPMResponse); end;
    if (sShowMain == "1") then
      SendToAll(bot.sBotName, sNewUsersResponse); end;
  end
end

function NewUserConnected(curUser)
  SendBotInfo(curUser);

  CheckForRecords(curUser);

  if (sShowOnLogin == "1") then
    CmdShowRecords(curUser); end;
end

function OpConnected(curUser)
  SendBotInfo(curUser);

  CheckForRecords(curUser);

  if (sShowOnLogin == "1") then
    CmdShowRecords(curUser); end;
end

function FormatSize(sString, iVal)
  assert(type(sString) == "string", "FormatSize(): bad argument #1 (string expected)");
  assert(type(iVal)    == "number", "FormatSize(): bad argument #2 (numerical value expected)");

  local _, _, sFormat = strfind(sString, "%[[mgtp]b(%.%d+)%]");

  if (sFormat) then
    sFormat = "%"..sFormat.."f";
    sString = gsub(sString, "%[mb.*%]", format(sFormat, toMB(iVal)).." MB");
    sString = gsub(sString, "%[gb.*%]", format(sFormat, toGB(iVal)).." GB");
    sString = gsub(sString, "%[tb.*%]", format(sFormat, toTB(iVal)).." TB");
    sString = gsub(sString, "%[pb.*%]", format(sFormat, toPB(iVal)).." PB");
  else
    sString = gsub(sString, "%[bb%]",   iVal.." B");
  end

  return sString;
end

function WriteConfig()
  local flConfigFile = openfile(sConfigFile, "w+");

  if (flConfigFile) then
    write(flConfigFile, "showmain="..sShowMain.."\r\n");
    write(flConfigFile, "showpm="..sShowPM.."\r\n");
    write(flConfigFile, "showonlogin="..sShowOnLogin);

    closefile(flConfigFile);
  end
end

function ReadConfig()
  local flConfigFile = openfile(sConfigFile, "r");

  if (flConfigFile) then
    local line = read(flConfigFile);
    while(line) do
      if     (strfind(line, "^showmain=[01]$")) then    _, _, sShowMain    = strfind(line, "^showmain=([01])$");
      elseif (strfind(line, "^showpm=[01]$")) then      _, _, sShowPM      = strfind(line, "^showpm=([01])$");
      elseif (strfind(line, "^showonlogin=[01]$")) then _, _, sShowOnLogin = strfind(line, "^showonlogin=([01])$");
      end

      line = read(flConfigFile);
    end
    closefile(flConfigFile);
  end
end

function ReadTemplate(curUser)
  local flTemplateFile = openfile(sTemplateFile, "r");

  if (flTemplateFile) then
    local sShareFormat = nil;

    local line = read(flTemplateFile);
    while(line) do
      if (strfind(line, "^requestshare=.*$")) then
        _, _, sShowRecordsShareResponse = strfind(line, "^requestshare=(.*)$");
              sShowRecordsShareResponse = FormatSize(sShowRecordsShareResponse, iShareAllTime);

      elseif (strfind(line, "^requestusers=.*$")) then
        _, _, sShowRecordsUsersResponse = strfind(line, "^requestusers=(.*)$");
              sShowRecordsUsersResponse = gsub(sShowRecordsUsersResponse, "%[users%]", tostring(iUserAllTime));

      elseif (strfind(line, "^newsharemain=.*$")) then
        _, _, sNewShareResponse = strfind(line, "^newsharemain=(.*)$");
              sNewShareResponse   = gsub(sNewShareResponse, "%[nick%]", curUser.sName);
              sNewShareResponse   = FormatSize(sNewShareResponse, iShareAllTime);

      elseif (strfind(line, "^newusersmain=.*$")) then
        _, _, sNewUsersResponse = strfind(line, "^newusersmain=(.*)$");
              sNewUsersResponse   = gsub(sNewUsersResponse, "%[nick%]", curUser.sName);
              sNewUsersResponse   = gsub(sNewUsersResponse, "%[users%]", tostring(iUserAllTime));

      elseif (strfind(line, "^newsharepm=.*$")) then
        _, _, sNewSharePMResponse = strfind(line, "^newsharepm=(.*)$");
              sNewSharePMResponse = gsub(sNewSharePMResponse, "%[nick%]", curUser.sName);
              sNewSharePMResponse = FormatSize(sNewSharePMResponse, iShareAllTime);

      elseif (strfind(line, "^newuserspm=.*$")) then
        _, _, sNewUsersPMResponse = strfind(line, "^newuserspm=(.*)$");
              sNewUsersPMResponse = gsub(sNewUsersPMResponse, "%[nick%]", curUser.sName);
              sNewUsersPMResponse = gsub(sNewUsersPMResponse, "%[users%]", tostring(iUserAllTime));
      end

      line = read(flTemplateFile);
    end

    closefile(flTemplateFile);
  end

  if (not sShowRecordsShareResponse) then sShowRecordsShareResponse = "Share record: "..format("%.3f", toTB(iShareAllTime)).." TB"; end;
  if (not sShowRecordsUsersResponse) then sShowRecordsUsersResponse = "User record: "..iUserAllTime.." users"; end;
  if (not sNewShareResponse)         then sNewShareResponse         = curUser.sName.." has just raised the all-time share record to: "..format("%.3f", toTB(iShareAllTime)).." TB :)"; end;
  if (not sNewUsersResponse)         then sNewUsersResponse         = curUser.sName.." has just raised the all-time user record to: "..iUserAllTime.." users :)"; end;
  if (not sNewSharePMResponse)       then sNewSharePMResponse       = "Thanks, buddie. You've just raised the all-time share record!"; end;
  if (not sNewUsersPMResponse)       then sNewUsersPMResponse       = "Thanks, buddie. You've just raised the all-time user record!"; end;
end

function ReadRecords()
  local flRecordFile = openfile(sRecordFile, "r");

  if (flRecordFile) then
    _, _, iShareAllTime = strfind(read(flRecordFile), "^share=(%d+)$"); iShareAllTime = tonumber(iShareAllTime);
    _, _, iUserAllTime  = strfind(read(flRecordFile), "^users=(%d+)$"); iUserAllTime  = tonumber(iUserAllTime);

    closefile(flRecordFile);
  else
    iShareAllTime = 0;
    iUserAllTime  = 0;
  end
end

function WriteNewRecord(shareRecord, userRecord)
  local flRecordFile = openfile(sRecordFile, "w+");

  if (flRecordFile) then
    write(flRecordFile, "share="..shareRecord.."\r\n");
    write(flRecordFile, "users="..userRecord);

    closefile(flRecordFile);
  end
end

function UpdateBotInfo()
  local sBotTag = gsub(bot.sBotTag, "%[users%]", iUserAllTime);
  sBotTag = FormatSize(sBotTag, iShareAllTime);
  sBotTag = gsub(sBotTag, " (.B,)", "%1");
  sBotInfo = "$MyINFO $ALL "..bot.sBotName.." "..bot.sBotDescr..sBotTag.."$ $"..bot.sBotSpeed..strchar(1).."$"..bot.sBotEmail.."$"..bot.iBotShare.."$" ;
end

function SendBotInfo(curUser)
  if (curUser) then
    curUser:SendData(sBotInfo);
  else
    SendToAll(sBotInfo);
  end
end

function toMB(bytes)
  return (bytes / 1024 / 1024);
end

function toGB(bytes)
  return (bytes / 1024 / 1024 / 1024);
end

function toTB(bytes)
  return (bytes / 1024 / 1024 / 1024 / 1024);
end

function toPB(bytes)
  return (bytes / 1024 / 1024 / 1024 / 1024 / 1024);
end
Title:
Post by: Skyhawk on 21 September, 2004, 13:13:58
Well i tried that one before it doesn't work see above
Title:
Post by: Skyhawk on 21 September, 2004, 13:18:51
well the error with those two bots in the list came from a space in the botname but...  it still doesn't work

[13:17:19] [OP]www.••Cybercop••.nl has just raised the all-time share record to: 0.000 TB :)
[13:17:19] [OP]www.••Cybercop••.nl has just raised the all-time user record to: 1 users :)
[13:17:19] Hallo Reg-User //www.•••Jamann•••.de. Willkommen in SuSas WeltWeiteWebsauger.
[13:17:19] [OP]www.••Cybercop••.nl has just raised the all-time share record to: 0.000 TB :)
[13:17:19] [OP]www.••Cybercop••.nl has just raised the all-time user record to: 1 users :)
[13:17:19] Hallo Reg-User //www.•••Nogelle•••.de. Willkommen in SuSas WeltWeiteWebsauger.
[13:17:20] [OP]www.••Cybercop••.nl has just raised the all-time share record to: 0.000 TB :)
[13:17:20] [OP]www.••Cybercop••.nl has just raised the all-time user record to: 1 users :)
[13:17:20] Hallo Reg-User //www.•••dealer•••.de. Willkommen in SuSas WeltWeiteWebsauger.
[13:17:21] *** MyINFO Spam detected!! from user: WWW-Record-Bot
[13:17:21] [OP]www.••Cybercop••.nl has just raised the all-time share record to: 0.000 TB :)
[13:17:21] [OP]www.••Cybercop••.nl has just raised the all-time user record to: 1 users :)
[13:17:21] Der Operator [OP]www.•••Moinsen•••.de betritt SuSas WeltWeiteWebsauger.
[13:17:25] [OP]www.••Cybercop••.nl has just raised the all-time share record to: 0.000 TB :)
[13:17:25] [OP]www.••Cybercop••.nl has just raised the all-time user record to: 1 users :)
[13:17:25] Der Operator [OP]www.••••SpyKid••••.de betritt SuSas WeltWeiteWebsauger.
[13:17:26] [OP]www.••Cybercop••.nl has just raised the all-time user record to: 1 users :)
[13:17:26] Hallo Reg-User //www.•••H@MM€?•••.de. Willkommen in SuSas WeltWeiteWebsauger.
[13:17:26] [OP]www.••Cybercop••.nl has just raised the all-time user record to: 1 users :)
[13:17:27] [OP]www.••Cybercop••.nl has just raised the all-time share record to: 0.000 TB :)
[13:17:27] [OP]www.••Cybercop••.nl has just raised the all-time user record to: 1 users :)
[13:17:27] Hallo Reg-User //www.•••?ainIVIake?•••.de. Willkommen in SuSas WeltWeiteWebsauger.
[13:17:29] [OP]www.••Cybercop••.nl has just raised the all-time share record to: 0.000 TB :)
[13:17:29] [OP]www.••Cybercop••.nl has just raised the all-time user record to: 1 users :)
[13:17:29] Hallo Reg-User //www.•••dj_Xthydr.23dre5•••.de. Willkommen in SuSas WeltWeiteWebsauger.
[13:17:34] [OP]www.••Cybercop••.nl has just raised the all-time share record to: 0.000 TB :)
[13:17:34] [OP]www.••Cybercop••.nl has just raised the all-time user record to: 1 users :)
[13:17:35] [OP]www.••Cybercop••.nl has just raised the all-time share record to: 0.000 TB :)
[13:17:35] [OP]www.••Cybercop••.nl has just raised the all-time user record to: 1 users :)
[13:17:35] Hallo Reg-User //www.•••error404•••.de. Willkommen in SuSas WeltWeiteWebsauger.
[13:17:37] [OP]www.••Cybercop••.nl has just raised the all-time share record to: 0.000 TB :)
[13:17:37] [OP]www.••Cybercop••.nl has just raised the all-time user record to: 1 users :)
Title:
Post by: Skyhawk on 21 September, 2004, 13:21:56
sorry for this ... those weird looking ••  are actually bullets  dots in the nicknames

but you can see that:

1. the user record counter stays at 1
2. the share record stays at 0.000
Title:
Post by: Psycho_Chihuahua on 21 September, 2004, 15:34:19
QuoteOriginally posted by Skyhawk
sorry for this ... those weird looking ••  are actually bullets  dots in the nicknames

but you can see that:

1. the user record counter stays at 1
2. the share record stays at 0.000


well look at this, im using that script in my hub and this is the result:
!rb.show
Unser Share rekord ist: 2.27 TB
Unser Mitglieder rekord ist: 36
Title:
Post by: Skyhawk on 21 September, 2004, 17:18:07
welche version von Ptokax benutzt du ?

which version of ptokax are you using?
Title:
Post by: Psycho_Chihuahua on 21 September, 2004, 18:14:05
QuoteOriginally posted by Skyhawk
welche version von Ptokax benutzt du ?

which version of ptokax are you using?

Der verwendet PtokaX DC Hub 0.3.2.6 TestDrive 3

That paticular one is running PtokaX DC Hub 0.3.2.6 TestDrive 3

Here some more examples from today
bbst hat soeben den Hub User Rekord erh?ht auf: 41 users :)
[TMC]?Sonu_xin hat soeben den Hub User Rekord erh?ht auf: 42 users :)
jas hat soeben den Hub User Rekord erh?ht auf: 43 users :)
Tremors hat soeben den Hub User Rekord erh?ht auf: 44 users :)
fastbuing hat soeben den Hub User Rekord erh?ht auf: 45 users :)
Matti hat soeben den Hub User Rekord erh?ht auf: 47 users :)
[rug.nl]pinger hat soeben den Hub User Rekord erh?ht auf: 48 users :)
Jasu hat soeben den Hub Share Rekord erh?ht auf: 2.451 TB :)
Jasu hat soeben den Hub User Rekord erh?ht auf: 49 users :)
Title:
Post by: Skyhawk on 22 September, 2004, 15:50:08
Well i am giving up...  :(

I tried 2 different versions of Ptokax (0.330.b15.25.dbg and PtokaX-0.326.TestDrive4.99), RecordBot 0.95 and 0.952 and i changed my nick (i lost those bullets)...

Thsi script simply doesn't work for me. Since the change of the nicks didn't make ANY difference i am pretty sure it is a PtokaX version issue. Maybe because those older version don't have the new profiles.

In any case...

I need a working Record Bot for Ptokax 0.330.b15.25.dbg and/or PtokaX-0.326.TestDrive4.99

It's URGENT !

Many, many thanks in advance!
Title:
Post by: Psycho_Chihuahua on 22 September, 2004, 16:02:23
hmmm funny but.......


!rb.help


RecordBot vKryFinal written by bonki 2003
Logs and displays a hub's all time share and user record.

OP Commands:

!rb.showmain main message.
!rb.reset Resets all records.
!rb.showpm private message.
!rb.showlogin report on login.

Commands:

!rb.show Shows this hub's all time share and user record.
!rb.help Displays this help message.

!rb.show
Unser Share Record ist: 1699.43 GB
Unser User Record ist: 18

Tested on PtokaX 0.330 Build 1525 [debug]

Not showing correct Format - I.e showing munched in Main - could be, i use Tahoma 9pt in my Hub

Try this ---> RecordBot-German (http://helvetia.ath.cx/downloads/ptokax/RecordBot.zip)
Title:
Post by: Caduceus on 22 December, 2004, 14:04:55
Hi! I need some advice for a prob with recordbot.
I'm using the same script as Psycho_Chihuahua stated above.
Seems to be working just fine, except for one anoying thing: every time i restart the script the sharerecord gets reset, although the userrecord keeps the same...

How is it possible to prevent this? Is there a change in the script possible to overcome this problem?

Grtz.

(btw: using ptokax ver. 0.3.3.0 15.25)