Help me please with Announcebot
 

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

Help me please with Announcebot

Started by Helper, 11 March, 2005, 12:27:11

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Helper

profileNr = { }

count = {
  chat = 0,
  connected = 0,
  startdate = date(),
}


--// This function is fired at the serving start

function Main()
  setlocale("swe")
  if BotName == nil then
    layout = "*** "
  else
    layout = "<"..BotName.."> "
  end

  SetTimer(MessageDelay*60000)
  if UseTimer == 1 then
    StartTimer()
  end
end

--// This function is fired when a new data arrives

function DataArrival(curUser, sData)
  if strsub(sData, 1, 1) == "<" then
    count.chat = count.chat + 1
  end
end

--// This function is fired when a new user finishes the login

function NewUserConnected(curUser)
  getmessages(curUser, "in")
end


--// This function is fired when an operator enters the hub

function OpConnected(curUser)
  getmessages(curUser, "in")
end


--// This function is fired when an user disconnects

function UserDisconnected(curUser)
  getmessages(curUser, "out")
end


--// This function is fired when an operator disconnects

function OpDisconnected(curUser)
  getmessages(curUser, "out")
end

function OnTimer()
  if timetag == nil then
    timetag = 0
    count.chat = MinChat
    count.connected = MinUserConnect
  end

  timetag = timetag + 1

  if timetag == 1 then
    if MinChat > 0 then
      reset = 0
      if count.chat < MinChat then
        timetag = 0
        local reset = 0
      else
        count.chat = 0
        count.connected = 0
        local reset = 1
      end
    end
    if MinUserConnect > 0 and reset == 0 then
      if count.connected < MinUserConnect then
        timetag = 0
      else
        count.chat = 0
        count.connected = 0
      end
    end
  end
  if tmessages[timetag] then
    message = tmessages[timetag]
    if strsub(message, 1, 5)=="file:" then
      local filename = strsub(message, 6, strlen(message))
      readfrom(filename)
        local message = ""
        while 1 do
          local line = read()
          if line == nil then break
          else
            message = message..line.."\r\n"
          end
        end
      announce(BotName, message)
      readfrom()
    else
      announce(BotName, message)
    end
  else
    timetag = 0
  end
end

--// Help functions ----------------------------------------------------

function announce(user, string)
  local arrTmp = substitute(user, string)
  SendToAll(layout..arrTmp)
end

function pm(user, string)
  local arrTmp = substitute(user, string)
  if privatemode == "pm" then
    user:SendPM(BotName, arrTmp)
  elseif privatemode == "main" then
    user:SendData(layout..arrTmp)
  end
end

function substitute(user, string)
  local arrTmp = gsub(string, "%[usercount%]", frmHub:GetUsersCount())
  arrTmp = gsub(arrTmp, "%[maxusers%]",        frmHub:GetMaxUsers())
  arrTmp = FormatSize(arrTmp, "totalshare",    frmHub:GetCurrentShareAmount());
  arrTmp = gsub(arrTmp, "%[minshare%]",        frmHub:GetMinShare()/1024)
  arrTmp = gsub(arrTmp, "%[hubname%]",         frmHub:GetHubName())
  arrTmp = gsub(arrTmp, "%[hubowner%]",        HubOwner)
  arrTmp = gsub(arrTmp, "%[crlf%]",            "\r\n")

  if type(user) == "table" then
    local myinfo = user.sMyInfoString
    local _, _, desc, speed, email, sharesize = strfind(myinfo, "$ALL %S+ (.*)%$ %$(.+)%$(.*)%$(%d+)%$");

    if (desc and strfind(desc, "(.+)%b<>")) then
      desc = gsub(desc, "(.+)%b<>", "%1");
    else
      desc = "none";
    end

    if (speed     == nil or strlen(speed) == 0) then speed     = "none"  end;
    if (email     == nil or strlen(email) == 0) then email     = "none"; end;
    if (sharesize == nil)                       then sharesize = 0;      end;

    arrTmp = gsub(arrTmp, "%[user%]",        user.sName)
    arrTmp = gsub(arrTmp, "%[userdesc%]",    desc)
    arrTmp = gsub(arrTmp, "%[userspeed%]",   strsub(speed, 1, strlen(speed)-1))
    arrTmp = gsub(arrTmp, "%[useremail%]",   email)
    arrTmp = FormatSize(arrTmp, "usershare", tonumber(sharesize));
    arrTmp = gsub(arrTmp, "%[userip%]",      user.sIP)
  end
  return arrTmp
end

function getmessages(user, io)
  local userprofile = GetProfileName(user.iProfile)
  if user.iProfile == -1 then
    userprofile = "unreg$"
  end
  if userprofile == nil then userprofile = "qwertyuiopasdfghjkl" end
  if io == "in" then
    if iprofiles["$"..user.sName] then
      if iprofiles["$"..user.sName] ~= "@" then
        announce(user, iprofiles["$"..user.sName])
        count.chat = count.chat + 1
      else
        count.connected = count.connected + 1
      end
    elseif iprofiles[userprofile] then
      announce(user, iprofiles[userprofile])
      count.chat = count.chat + 1
    else
      count.connected = count.connected + 1
    end
    if iprofiles["$pm$"..user.sName] then
      pm(user, iprofiles["$pm$"..user.sName])
    end
    if iprofiles["!"..userprofile] then
      pm(user, iprofiles["!"..userprofile])
    end
  else
    if oprofiles["$"..user.sName] then
      if oprofiles["$"..user.sName] ~= "@" then
        announce(user, oprofiles["$"..user.sName])
        count.chat = count.chat + 1
      end
    elseif oprofiles[userprofile] then
      announce(user, oprofiles[userprofile])
      count.chat = count.chat + 1
    end
  end
end

function FormatSize(sString, sTag, 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, "%["..sTag.."%.[mgtp]b(%.%d+)%]");

  if (sFormat) then
    sFormat = "%"..sFormat.."f";

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

  return sString;
end -- bonki

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
1 dag niet gelachen is 1 dag niet geleefd.

RoboCop? 10.01a Made by Optimus?

SMF spam blocked by CleanTalk