Needing share and user recordt script
 

News:

29 December 2022 - PtokaX 0.5.3.0 (20th anniversary edition) released...
11 April 2017 - PtokaX 0.5.2.2 released...
8 April 2015 Anti child and anti pedo pr0n scripts are not allowed anymore on this board!
28 September 2015 - PtokaX 0.5.2.1 for Windows 10 IoT released...
3 September 2015 - PtokaX 0.5.2.1 released...
16 August 2015 - PtokaX 0.5.2.0 released...
1 August 2015 - Crowdfunding for ADC protocol support in PtokaX ended. Clearly nobody want ADC support...
30 June 2015 - PtokaX 0.5.1.0 released...
30 April 2015 Crowdfunding for ADC protocol support in PtokaX
26 April 2015 New support hub!
20 February 2015 - PtokaX 0.5.0.3 released...
13 April 2014 - PtokaX 0.5.0.2 released...
23 March 2014 - PtokaX testing version 0.5.0.1 build 454 is available.
04 March 2014 - PtokaX.org sites were temporary down because of DDOS attacks and issues with hosting service provider.

Main Menu

Needing share and user recordt script

Started by vadertje, 07 May, 2005, 09:21:44

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

vadertje

hi can some 1 help me i looking for a user share recordt script for lua5 and a joker script and a working birthday script not like 3.5 that not work :(

jiten

QuoteOriginally posted by vadertje
hi can some 1 help me i looking for a user share recordt script for lua5 and a joker script and a working birthday script not like 3.5 that not work :(
Regarding to the Birthday script, I tested it many times and it works. Maybe u're doing something wrong or didn't copy it well from the forum.
For the user/share record bot, I remember one that shows it on login (there may be others as I haven't searched). Don't know if it suits ur needs. Here it is.

Cheers

vadertje

can some 1 make this script in lua 5 ? thnx


--
-- [RecordBot] - v0.952
--
-- Simple bot which saves your hub's all-time share & user record
-- Written by bonki 2003
--
-- ABOUT:
--   It's first version was my first attempt of a script - written only to get in touch with the LUA language.
--   I know it's neither special nor very complex, I hope it's useful for someone, though. :)
--
--   If you downloaded this script as a packed archive there already exist a template
--   and a config file (in txt/), you can delete both if you don't need them.
--   Read the following if you want to know more about those files.
--
-- THANKS:
--   http://lua.bcs-solutions.de :)
--
-- USED FILES (don't forget to create the "scripts/txt" folder!!!):
--   Syntax:
--      options=value
--
--   o) txt/RecordBot.records.txt: File the bot saves the records to.
--                                 Don't create it yourself!
--
--      Options:
--        share = share record in bytes
--        users = user  record
--
--   o) txt/RecordBot.template.txt (optional): Template file where you can change the bot's messages.
--
--      Options:
--        *requestshare: used when user displays records - share record     (3)
--        *requestusers: used when user displays records - user  record     (2)
--        *newsharemain: main chat message               - new share record (1,3)
--        *newusersmain: main chat message               - new user  record (1,2)
--        *newsharepm:   PM chat message                 - new share record (1,3)
--        *newuserspm:   PM chat message                 - new user  record (1,2)
--
--      *Available variables/substitutions:
--        (1): [nick]  will be replaced with the user's nick
--        (2): [users] -||-                      new user record
--        (3): [bb]    -||-                      new share record (in B)
--             [mb.x]  -||-                      new share record (in MB, x digits after the decimal point)
--             [gb.x]  -||-                      new share record (in GB, x digits after the decimal point)
--             [tb.x]  -||-                      new share record (in TB, x digits after the decimal point)
--             [pb.x]  -||-                      new share record (in PB, x digits after the decimal point)
--
--      Example file:
--
--        requestshare=Unser Share Rekord ist : [tb.2]
--        requestusers=Unser User Rekord ist: [users]
--        newsharemain=[nick] hat gerade den allzeit tausch rekord auf: [tb.3]gebracht ;-)
--        newusersmain=Soeben wurde ein neuer rekord von: [users] Benutzern erreicht ;-)
--        newsharepm=Danke, [nick]. Du hast gerade den allzeit tausch rekord erh?ht!
--        newuserspm=Danke, [nick]. Du hast gerade den allzeit user record erh?ht!
--
--   o) txt/RecordBot.config.txt (optional): Config file
--
--      Options:
--        showmain: 0 enables the bot's main messages (the ones when a new record arises)
--                  1 disables the same
--        showpm:   same as above for the private messages
--
-- AVAILABLE COMMANDS:
--   !rb.help:                       Displays a help message.
--   !rb.show:                       Displays both records
--   !rb.showmain  : Enables/disables the bot's main messages when a new record arises
--   !rb.showpm    : Same as above with private messages
--   !rb.showlogin : Enables/disables the login report of both records
--                                   (messages looks exactly like as if requested by !rb.show)
--   !rb.reset:                      Sets both records back to 0
--
-- TODO:
--   Any suggestions? :)
--
-- BUGS:
--   It also counts bots.
--   Tell me!
--
-- CHANGELOG:
--   v0.952: Added:     Added a nice-looking tag to the bot showing both records
--           Optimized: Did some small code beautifications
--   v0.951: General:   Changed filenames, they will now always be Recordbot.*.* independent from the botname
--   v0.95:  Added:     Possibility to enable/disable the login report of both records
--           Optimized: Code partly rewritten/beautified/optimized, looks much better now :-)
--           Bugfix:    Removed bot's share because it was added to the total share
--                      DC++ displays which causes the displayed amount to be doubled...
--   v0.941: General:   Minor changes
--   v0.94:  Bugfix:    Fixed bot's share bug, now also works after records resetting
--           Added:     Possibility to enable/disable the bot's main/PM messages
--           General:   CHANGED FILE NAMES! (RecordBot.config.txt is now RecordBot.template.txt
--                      (sorry for the confusion, have a look at USED FILES for further details))
--   v0.93:  Optimized: Template file parsing code rewritten, have a look at USED FILES what has changed!
--   v0.921: Bugfix:    Fixed some minor bugs
--           Bugfix:    Fixed bot's share bug, now also works at startup
--   v0.92:  Bugfix:    Fixed some minor bugs
--           Added:     Bot's share = share record
--           Optimized: Template file is now optional
--           Added:     Improved template file support
--   v0.91:  General:   No info
--   v0.9:   General:   Initial release
--

sVer   = "0.952";
sName  = "White_Nation";
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 = "White_Nation",
          sBotSpeed = "Fast",
          sBotDescr = "[NL]FESTUNG EUROPA Kerkrade",
          sBotTag   = "<++ V:"..sVer..",P:NS,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();

vadertje

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

6Marilyn6Manson6

Use [ CODE] and [ /CODE] without space..... before and after script.. please

vadertje

hmmmm how do you mean i'm new here sorry :(

6Marilyn6Manson6

QuoteOriginally posted by vadertje
hmmmm how do you mean i'm new here sorry :(


[ CODE]script[ /CODE]

this write without space... and subject script with you're script

jiten

Check this thread for the Lua 5 version.

Cheers

SMF spam blocked by CleanTalk