PtokaX forum

Archive => Archived 5.0 boards => Request for scripts => Topic started by: GodLike on 24 July, 2005, 07:53:47

Title: need to transform in lua 5
Post by: GodLike on 24 July, 2005, 07:53:47
--
--  ShadowsBot v. 0.01
--     by [XP]Narc0tiq
--  Copyright ? 2004 [XP]Narc0tiq
--
--  Description:
--    Implements the !hideme and !showme commands. Will hide the
--  user from the userlist when !hideme is used, and all chat
--  messages from the user will be stated by the 'bot. Will show
--  the user when !showme is used.
--
--  Known bugs:
--    1. If scripts are restarted while users are hidden, some unusual phenomena may
--  be encountered, such as high lag for those users, usually fixed by reconnecting.
--    2. When hidden users reconnect they will also experience this high lag, this
--  leads me to think $MyINFO is very important for some reason... :-)
--
--  Fixes (which i am too lazy to do right now):
--    #2 might be fixed by unhiding the user when UserDisconnected is received...
--

botName = "Xpower"
botNick = "Xpower"
botVer = "0.01"
botEmail = ""
botSpeed = "Sol"
botDescr = ""

botInfo = "$MyINFO $ALL "..botNick.." "..botDescr.."$ $"..botSpeed..strchar(1).."$"..botEmail.."$0$"

botVisible = 1 -- set to nil to hide the bot from the userlist

--
-- That's all the configuration
--

hiddenUsers = {}

function NewUserConnected(curUser)
   curUser:SendData(botInfo);
   for a,b in hiddenUsers do
      curUser:SendData("$Quit "..a.."|")
   end
   if(curUser.bOperator) then
      curUser:SendData(botNick,"Currently Hidden users:")
      for a,b in hiddenUsers do
         curUser:SendData(botNick,"\t"..a);
      end
   end
end

OpConnected=NewUserConnected

function DataArrival(curUser, data)
   if(strsub(data, 1, 1) == "<") then
      cmd = GetCommand(data)
      if cmd == "!copyright" then
         SendToAll(botNick,"Copyright ? 2004-2005 All Rights Reserved By "GodLike".");
      elseif cmd == "!hideme" then
         HideUser(curUser)
         return 1;
      elseif cmd == "!showme" then
         ShowUser(curUser)
         return 1;
      elseif cmd == "!flashlight" then
         Flashlight(curUser);
         return 1;
      else
         return UserSays(curUser,data)
      end
   else
      return ProcessData(curUser,data)
   end
end

function ProcessData(curUser,data)
   if(strsub(data, 1, 7) == "$MyINFO") then
      if(isHidden(curUser.sName)) then
         return 1;
      end
   end
end

function GetCommand(data)
   data=strsub(data,1,strlen(data)-1) -- strip CR/LF off the end
   s,e,cmd = strfind(data,"%b<>%s+(%S+)")

   return cmd
end

function HideUser(who)
   if(hiddenUsers[who.sName]) then
      who:SendData(botNick,"Esti deja in umbre !")
   else
      if(who.bOperator) then
         hiddenUsers[who.sName] = 2
      else
         hiddenUsers[who.sName] = 1
      end
      
      SendToAll(botNick,who.sName.." a intrat in umbre !");
      SendToAll("$Quit "..who.sName.."|");
   end
end

function isHidden(who)
   if(hiddenUsers[who]) then
      return 1
   end
   return nil
end

function ShowUser(who)
   if(hiddenUsers[who.sName]) then
      SendToAll(botNick,who.sName.." urgenta de la umbre !");
      SendToAll("$Hello "..who.sName.."|");
      if(hiddenUsers[who.sName]==2) then
         SendToAll("$OpList "..who.sName.."$$|");
      end
      hiddenUsers[who.sName] = nil
   else
      who:SendData(botNick,"Esti deja inafara umbrei !")
   end
end

function UserDisconnected(curUser)
  hiddenUsers[curUser.sName] = nil
end

function OpDisconnected(curUser)
  hiddenUsers[curUser.sName] = nil
end

function UserSays(curUser,data)
   if(isHidden(curUser.sName)) then
      data = strsub(data,strlen(curUser.sName)+4)
      SendToAll(botNick,"*** "..curUser.sName.." whispers: "..data);
      return 1
   end
end

function Flashlight(curUser)
   if(curUser.bOperator) then
      SendToAll(botNick,curUser.sName.." a deschis un flash si a mers mai departe de umbra .");
      tableLength = 0
      for a,b in hiddenUsers do
         tableLength = tableLength + 1
      end
      if(tableLength == 0) then
         SendToAll(botNick,"Nu este nimeni in umbre .")
      else
         SendToAll(botNick,"El(ea) a vazut userul ducanduse acolo ...:")         
         for a,b in hiddenUsers do
            SendToAll(botNick,"\t"..a)
         end
      end
   else
      curUser:SendData(botNick,"Doar OP au flashuri !");
   end
end

function OnTimer()
   for a,b in hiddenUsers do
      SendToAll("$Quit "..a.."|")
   end
end

function Main()
   if(botVisible) then
      frmHub:RegBot(botNick)
   end
   SetTimer(100)
   StartTimer()
end

------------------------------------------------------------------------
=================AND====================
------------------------------------------------------------------------

--
--
--
--
--
--
--
--

botName = "Xpower"
botNick = "Xpower"
botVer = "0.01"
botEmail = ""
botSpeed = "SoL"
botDescr = ""

botInfo = "$MyINFO $ALL "..botNick.." "..botDescr.."$ $"..botSpeed..strchar(1).."$"..botEmail.."$0$"

botVisible = nil -- set to nil to hide the bot from the userlist

loginNick="\tNick-ul:"
loginIP="\tIP-ul:"
loginProfile="\tProfilul:"

--
-- No more configuration from this point forward!
--

function DataArrival(curUser, data)
   if(strsub(data, 1, 1) == "<") then
      cmd = GetCommand(data)
      if cmd == "!facut" then
         SendToAll(botNick,"Copyright ? 2004-2005 All Rights Reserved By "GodLike".");
      end
   end
end

function Main()
   if(botVisible) then
      frmHub:RegBot(botNick)
   end
end

function GetCommand(data)
   data=strsub(data,1,strlen(data)-1) -- strip CR/LF off the end
   s,e,cmd = strfind(data,"%b<>%s+(%S+)")

   return cmd
end

function NewUserConnected(curUser)
   if botVisible then
      curUser:SendData(botInfo)
   end
   
   curUser:SendData(botNick,loginNick.." "..curUser.sName);
   curUser:SendData(botNick,loginIP.." "..curUser.sIP);
   sProfile = "";
   if(curUser.iProfile==-1) then
      sProfile = "Guest";
   elseif(curUser.iProfile==1) then
      sProfile = "Master";
   elseif(curUser.iProfile==1) then
      sProfile = "Operator";
   elseif(curUser.iProfile==2) then
      sProfile = "VIP";
   elseif(curUser.iProfile==3) then
      sProfile = "Registered User";
   elseif(curUser.iProfile==4) then
      sProfile = "Moderator";
   elseif(curUser.iProfile==5) then
      sProfile = "NetFounder";
   else
      sProfile = "Master";
   end

   curUser:SendData(botNick,loginProfile.." "..sProfile.." ("..curUser.iProfile..")");
end

OpConnected = NewUserConnected