can anyone convert this script to lua 5 for me please?
 

can anyone convert this script to lua 5 for me please?

Started by FrAcTi0n, 22 March, 2005, 08:53:45

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

FrAcTi0n

hello, can anyone convert this f*** good scipt to lua 5?

part 1
--------------------------------------------------------------------------------------------------------------------------
-- Database Bot v 0.8
-- for ptokax 3.2.6
-- by toen
-- 2k4
-------------------
-- Settings    --
-------------------

Bot = "---=ReleaseS=---"

-- 0=disabled,1=guests,2=regged,3=vips,4=ops,5=mods,6=admins
VSHOWFAV = 2
VSHOWFRESH = 2
VSHOWBIGGUP = 2
VSHOWHELP = 2
VADDDATA = 2
VDELDATA =3
VSEARCHDATA = 2

maxl = 100  -- max lines saved in the fresh lists

cmd1 = "fresh"
cmd2 = "fav"
cmd3 = "biggup"
cmd4 = "add"
cmd5 = "del"
cmd6 = "rls"
cmd7 = "rls"
cmd8 = "search"

cmdvisible = 1   -- 0=on,1=off

favdir = "Database/fav/"
freshdir = "Database/fresh/"
biggupdir = "Database/biggup/"
helpdir = "Database/help/"
triggerdir = "Database/triggers/"

syntaxerr = "Wrong synthax. Type +rls for further assistance. |"
rightserr = "You do not have sufficient rights to run that command! remember nick is CASE SENSITIVE, type +showregs in the main chat to find out if your nick is correct.)|"
disabled = "That command is disabled. |"


triggers={}    --initialisation

-------------------
-- Main function --
-------------------

function Main ()
   frmHub:RegBot(Bot)
   TextLoad(triggerdir.."triggers.dat",triggers)
end

function NewUserConnected(user)
   user:SendData(Bot, "=-- ATTENTION RIGHT CLICK MENU ENABLED, right click hub tab or write +cmd for your commands.")
   UserCmds(user)
end

function OpConnected(user)
   NewUserConnected(user)
end

function UserCmds(user)
user:SendData("$UserCommand 0 1 ||")
user:SendData("$UserCommand 1 1 [ReleaseS]\\Show\\Current month$<%[mynick]> !fresh||")
user:SendData("$UserCommand 1 1 [ReleaseS]\\Show\\Singles/ EPs$<%[mynick]> !fresh s||")
user:SendData("$UserCommand 1 1 [ReleaseS]\\Show\\Albums/ Compilations$<%[mynick]> !fresh a||")
user:SendData("$UserCommand 1 1 [ReleaseS]\\Show\\mixes$<%[mynick]> !fresh m||")
user:SendData("$UserCommand 1 1 [ReleaseS]\\Show\\users production$<%[mynick]> !fresh u||")
user:SendData("$UserCommand 1 1 [ReleaseS]\\Show\\Web links$<%[mynick]> !fresh w||")
user:SendData("$UserCommand 1 1 [ReleaseS]\\Search:$<%[mynick]> !search %[line: String]||")
user:SendData("$UserCommand 1 1 [ReleaseS]\\Add\\Single / EP:$<%[mynick]> !add fresh s %[line:Entry]||")
user:SendData("$UserCommand 1 1 [ReleaseS]\\Add\\Album / Compilation:$<%[mynick]> !add fresh a %[line:Entry]||")
user:SendData("$UserCommand 1 1 [ReleaseS]\\Add\\Mix:$<%[mynick]> !add fresh m %[line:Entry]||")
user:SendData("$UserCommand 1 1 [ReleaseS]\\Add\\JUNGLiST users production and mixes:$<%[mynick]> !add fresh u %[line:Entry]||")
user:SendData("$UserCommand 1 1 [ReleaseS]\\Add\\Weblink:$<%[mynick]> !add fresh w %[line:Entry]||")
user:SendData("$UserCommand 1 1 [ReleaseS]\\Delete\\Single / EP:$<%[mynick]> !del fresh s %[line:Entry]||")
user:SendData("$UserCommand 1 1 [ReleaseS]\\Delete\\Album / Compilation / EP:$<%[mynick]> !del fresh a %[line:Entry]||")
user:SendData("$UserCommand 1 1 [ReleaseS]\\Delete\\Mix:$<%[mynick]> !del fresh m %[line:Entry]||")
user:SendData("$UserCommand 1 1 [ReleaseS]\\Delete\\JUNGLiST users production and mixes:$<%[mynick]> !del fresh u %[line:Entry]||")
user:SendData("$UserCommand 1 1 [ReleaseS]\\Delete\\Weblink:$<%[mynick]> !del fresh w %[line:Entry]||")
user:SendData("$UserCommand 0 2 ||")
user:SendData("$UserCommand 1 2 [ReleaseS]\\User Favorites\\User Favs$<%[mynick]> !fav %[nick]||")
user:SendData("$UserCommand 1 1 [ReleaseS]\\User Favorites\\Add:$<%[mynick]> !add fav %[line:Entry]||")
user:SendData("$UserCommand 1 1 [ReleaseS]\\User Favorites\\Del:$<%[mynick]> !del fav %[line:Entry]||")
user:SendData("$UserCommand 1 1 [ReleaseS]\\User Favorites\\Show users that have some fav added:$<%[mynick]> !fav||")
user:SendData("$UserCommand 1 1 [ReleaseS]\\Help$<%[mynick]> !rls||")
end


------------------
-- Data Arrival --
------------------

function DataArrival(user,data)
   
   whoTo,cmd,arg,arg2,arg3=nil,nil,nil,nil,nil

   returndata = 0


-- get args from main chat   
   if (strsub(data,1,1)=="<") then
   
   data=strsub(data,1,strlen(data)-1)
   
   s,e,cmd = strfind(data,"%b<>%s+(%S+)")
   s,e,arg = strfind(data,"%b<>%s+%S+%s+(.*)")
   if arg ~= nil then
      s,e,arg2 = strfind(data,"%b<>%s+%S+%s+%S+%s+(.*)")
      if arg2 ~= nil then
         s,e,arg,arg2 = strfind(data,"%b<>%s+%S+%s+(%S+)%s+(.*)")
         s,e,arg3 = strfind(data,"%b<>%s+%S+%s+%S+%s+%S+%s+(.*)")
         if arg3 ~= nil then
            s,e,arg,arg2,arg3 = strfind(data,"%b<>%s+%S+%s+(%S+)%s+(%S+)%s+(.*)")
         end   
      end
   end
   end

-- get args from pm
   if(strsub(data, 1, 4) == "$To:") then
      data=strsub(data,1,strlen(data)-1)
      s,e,whoTo = strfind(data,"$To:%s+(%S+)")
      if (whoTo == Bot) then
         s,e,cmd = strfind(data,"$To:%s+%S+%s+From:%s+%S+%s+$%b<>%s+(%S+)")
         s,e,arg = strfind(data,"$To:%s+%S+%s+From:%s+%S+%s+$%b<>%s+%S+%s+(.*)")
         if arg ~= nil then
            s,e,arg2 = strfind(data,"$To:%s+%S+%s+From:%s+%S+%s+$%b<>%s+%S+%s+%S+%s+(.*)")
            if arg2 ~= nil then
               s,e,arg,arg2 = strfind(data,"$To:%s+%S+%s+From:%s+%S+%s+$%b<>%s+%S+%s+(%S+)%s+(.*)")
               s,e,arg3 = strfind(data,"$To:%s+%S+%s+From:%s+%S+%s+$%b<>%s+%S+%s+%S+%s+%S+%s+(.*)")
               if arg3 ~= nil then
                  s,e,arg,arg2,arg3 = strfind(data,"$To:%s+%S+%s+From:%s+%S+%s+$%b<>%s+%S+%s+(%S+)%s+(%S+)%s+(.*)")
               end
            end
         end
      end
   end
   
   user:SendData(bot, cmd)
   user:SendData(bot, arg)
   user:SendData(bot, arg2)
   user:SendData(bot, arg3)   

-- Script Commands --
   

   if (cmd=="!"..cmd1 or cmd=="+"..cmd1) then
      ShowFresh(user,arg)
      returndata = cmdvisible
   
   elseif (cmd=="!"..cmd2 or cmd=="+"..cmd2) then
      ShowFav(user,arg)
      returndata = cmdvisible

   elseif (cmd=="!"..cmd3 or cmd=="+"..cmd3) then
      ShowBiggup(user)
      returndata = cmdvisible
      
   elseif (cmd=="!"..cmd6 or cmd=="+"..cmd6 or cmd=="?"..cmd6 or cmd=="!"..cmd7) then
      ShowHelp(user)
      returndata = cmdvisible
      
   elseif (cmd=="!"..cmd4 or cmd=="+"..cmd4) then
      AddData(user,arg,arg2,arg3)
      returndata = cmdvisible

   elseif (cmd=="!"..cmd5 or cmd=="+"..cmd5) then
      DelData(user,arg,arg2,arg3)
      returndata = cmdvisible
   
   elseif (cmd=="!"..cmd8 or cmd=="+"..cmd8) then
      SearchData(user,arg, freshdir.."singles.txt","    SINGLEs/EPs   ")
      SearchData(user,arg, freshdir.."albums.txt","    ALBUMs/LPs    ")
      SearchData(user,arg, freshdir.."mixes.txt","         MIXes           ")
      SearchData(user,arg, freshdir.."users.txt","JUNGLiST USERs")
      SearchData(user,arg, freshdir.."weblinks.txt","      WEBLINKs      ")
      returndata = cmdvisible

   else for x=1,getn(triggers) do  
      if cmd=="!"..triggers[x] then
         SendToAll(Bot,"\r\n"..fileshow(nil,triggerdir.."/"..triggers[x]..".txt"))
      end
        end   
   end
   
   return returndata
end



--------------------------------------
-- Search Data              --
--------------------------------------
function SearchData(user,arg, file, caption)
   if VSEARCHDATA ~= 0 then
      if VSEARCHDATA <= CheckUserLevel(user) then
         if arg=="" then                           --check for right parameters
            user:SendPM(Bot, syntaxerr)                        
            return
         else   local ha=readfrom(file)
            local tmp = "\r\n=------------------------------------------------------------------------------------ "..caption.." --------------------------------------------------------------------------------------="
            if ha then
               while 1 do
                  local line = read(ha, "*l")
                  if line and (line~="") then
                     if strfind(strlower(line), strlower(arg),1,1) then
                        tmp = tmp.."\r\n"..line
                     end
                  else
                     break
                  end
               end
               user:SendPM(Bot,tmp)
            end
         end
      else
         user:SendPM(Bot,rightserr)
      end
   else   user:SendPM(Bot, disabled)
   end
end
--------------------------------------
-- Show Data functions           --
--------------------------------------

-- Show Favorites functions        --


function ShowFav(user,arg)
   if VSHOWFAV ~= 0 then
      if VSHOWFAV <= CheckUserLevel(user) then
         ShowFavUser(user,arg)
      else
         user:SendPM(Bot,rightserr)
      end
   else   user:SendPM(Bot, disabled)
   end
end

function ShowFavUser (user, arg)
   local file=favdir
   if arg then
      if arg~="" and arg~="all" then
         file=file..arg..".txt"
      else
         ShowFavAll(user)
         return
      end
   else
      ShowFavAll(user)
      return
   end

   local str="\r\n"
   str=str.."\r\n=------------------------------------------------------------------------------------ "..arg.." --------------------------------------------------------------------------------------="
   str=str..fileshow(nil,favdir..arg..".txt").."\r\n"

      if user then
         user:SendPM(Bot, str.."|")
         return
      else
         return str
      end

end

function ShowFavAll(user)
   file=favdir.."!nick_index.dat"
   local ha=readfrom(file)
   local str=""
   if ha then
      while ha do
         local line = read(ha, "*l")
         if line then
            user:SendPM(Bot, line.."|")
            -- str=str..ShowFavUser(nil, line)
         else
            break
         end
      end
      closefile(ha)
      user:SendPM(Bot, str.."|")
   end
end


-- Show Fresh function           --

function ShowFresh(user,arg)
   if VSHOWFRESH ~= 0 then
      if VSHOWFRESH <= CheckUserLevel(user) then
            if (arg ~= nil) then
               if    arg == "s" then
                  str = "=------------------------------------------------------------------------------------ SINGLEs/EPs --------------------------------------------------------------------------------------=\r\n\r\n"
                  user:SendPM(Bot,str..fileshow(nil, freshdir.."singles.txt"))
               elseif   arg == "a" then
                  str = "=------------------------------------------------------------------------------------ ALBUMs/LPs ---------------------------------------------------------------------------------------=\r\n\r\n"
                  user:SendPM(Bot,str..fileshow(nil, freshdir.. "albums.txt"))
               elseif   arg == "m" then
                  str = "=---------------------------------------------------------------------------------------- MIXes ------------------------------------------------------------------------------------------------=\r\n\r\n"
                  user:SendPM(Bot,str..fileshow(nil, freshdir.."mixes.txt"))
               elseif  arg == "u" then
                  str = "=------------------------------------------------------------------------ JUNGLiST users production ------------------------------------------------------------------------------=\r\n\r\n"
                  user:SendPM(Bot,str..fileshow(nil, freshdir.."users.txt"))
               elseif  arg == "w" then
                  str = "=------------------------------------------------------------------------------------ WEBLINKs --------------------------------------------------------------------------------------------=\r\n\r\n"
                  user:SendPM(Bot,str..fileshow(nil, freshdir.."weblinks.txt"))
               end

            else      arg = date("%B-%Y")
                  user:SendPM(Bot,"Search: "..arg)
                  SearchData(user,arg, freshdir.."singles.txt","    SINGLEs/EPs   ")
                  SearchData(user,arg, freshdir.."albums.txt","    ALBUMs/LPs    ")
                  SearchData(user,arg, freshdir.."mixes.txt","         MIXes           ")
                  SearchData(user,arg, freshdir.."users.txt","JUNGLiST USERs")
                  SearchData(user,arg, freshdir.."weblinks.txt","      WEBLINKs      ")
               
            end
      else
         user:SendPM(Bot,rightserr)
      end
   else   user:SendPM(Bot, disabled)
   end
end


-- Show Biggup function           --

function ShowBiggup(user)
   if VSHOWBIGGUP ~= 0 then
      if VSHOWBIGGUP <= CheckUserLevel(user) then
         str = "=------------------------------------------------------------------------------------ BIGGUPs --------------------------------------------------------------------------------------=\r\n\r\n"
         user:SendPM(Bot,str..fileshow(nil,biggupdir.."biggups.txt"))
         
      else
         user:SendPM(Bot,rightserr)
      end
   else   user:SendPM(Bot, disabled)
   end
end

function ShowHelp(user)
   if VSHOWHELP ~= 0 then
      if VSHOWHELP <= CheckUserLevel(user) then
         str = "\r\n\r\n"
         user:SendPM(Bot,str..fileshow(nil,helpdir.."dbhelp.txt")..fileshow(nil,triggerdir.."/triggers.txt"))
         
      
      end
   end
end

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

FrAcTi0n

part 2
------------------------------------------------------------------------------

--------------------------------------
-- Add Data functions           --
--------------------------------------

function AddData(user,arg,arg2,arg3)
   lvl = CheckUserLevel(user)
   if VADDDATA ~= 0 then
      if VADDDATA <= lvl then
            if    arg == "fresh" then
               if    arg2 == "s" then file=freshdir.."singles.txt"
                         fileweb=freshdir.."singles_web.txt"
               elseif   arg2 == "a" then file=freshdir.."albums.txt"
                         fileweb=freshdir.."albums_web.txt"
               elseif  arg2 == "m" then file=freshdir.."mixes.txt"
                         fileweb=freshdir.."mixes_web.txt"
               elseif   arg2 == "u" then file=freshdir.."users.txt"
                         fileweb=freshdir.."users_web.txt"
               elseif   arg2 == "w" then file=freshdir.."weblinks.txt"
                         fileweb=freshdir.."weblinks_web.txt"
               else   user:SendPM(Bot, syntaxerr)
               end
               AddFresh(user,file,fileweb,arg3)
            
            elseif   arg == "fav" then
                  if   arg3 == nil then
                     AddFav(user,arg2)
                  else   AddFav(user,arg2.." "..arg3)
                  end   
            elseif arg == "biggup" then
                  if   arg3 == nil then
                     AddBiggup(user,arg2)
                  else   AddBiggup(user,arg2.." "..arg3)
                  end
            else   user:SendPM(Bot, syntaxerr)
            end
         
      else      user:SendPM(Bot,rightserr)
      end
   else   user:SendPM(Bot, disabled)
   end
end

-- Add Biggup function           --

function AddBiggup (user, entry)
   if entry=="" then                           --check for right parameters
      user:SendPM(Bot, syntaxerr)                        
      return
   else   local file=biggupdir.."biggups.txt"               --writing block
      local fh=appendto(file)
      write(fh, date("%d-%B-%Y").." * "..user.sName.." * "..entry.."\n")
      closefile(fh)
      user:SendPM(Bot, "***ADDED***")
   end
end


-- Add Fav function           --

function AddFav (user, entry)
   if entry=="" then                           --check for right parameters
      user:SendPM(Bot, syntaxerr)                        
      return
   else   local file=favdir..user.sName..".txt"
      local ha=readfrom(file)
      
      if ha then                           --DUPES CHECK
         while ha do
         local line = read(ha, "*l")
         if line then
            x, y, dat, entryR = strfind(line, "(.+)*(.+)")
            if " "..entry==entryR then
               user:SendPM(Bot, user.sName..", you already added this favorite: ["..entry.. "] at "..dat)
               return
            end
         else
            break
         end
         end
         closefile(ha)
      else    local fhn=appendto(favdir.."!nick_index.dat")         --else adds user to INDEX file
         write(fhn, user.sName.."\n")
         closefile(fhn)
      end
   
   
      local fh=appendto(file)                        --writing block
      write(fh, date("%d-%B-%Y").." * "..entry.."\n")
      closefile(fh)
      user:SendPM(Bot, "***ADDED***")
   end
end

-- Add Fresh function           --
      
function AddFresh (user, file, fileweb, entry)
   if entry=="" then                           --check for right parameters
      user:SendPM(Bot, syntaxerr)                        
      return
   else   
   --dup check routine
   local dups=nil
   local coord=nil
   local fileend=nil       --needed to update file in middle
   local ha=readfrom(file)
   if ha then
      while 1 do
         local line = read(ha, "*l")
         if line then
            x, y, dateR, entryR = strfind(line, "(.*)*(.*)")         
            if x then
               if entryR==" "..entry then
                  dups=1
               end --if for alone/duplicate nick

            
            end --if for line format
         else
         break
         end --if for new readline
      end --while for readfile
      closefile(ha)
   end --//dup check


   --writing block
   if dups then
      user:SendPM(Bot, "*** ALREADY ADDED - DATE: "..dateR.." ***")
   else
      local fh=appendto(file)
      write(fh, date("%d-%B-%Y").." * "..entry.."\n")
      closefile(fh)
      user:SendPM(Bot, "***ADDED***")
      SendToAll("=----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------=")
      SendToAll("NEW RELEASE ADDED: \t"..entry)
      SendToAll("=------------------------------------------------------------------------------------------------ use right click on hub tab to see more commands ---=")
      filecut(file,maxl)
      
   end
   end
end

--------------------------------------
-- Del Data functions           --
--------------------------------------

function DelData(user,arg,arg2,arg3)
   lvl = CheckUserLevel(user)
   if VDELDATA ~= 0 then
      if VDELDATA <= lvl then
            if    arg == "fresh" then
               if    arg2 == "s" then DoDelData(user,freshdir.."singles.txt",arg3)
               elseif   arg2 == "a" then DoDelData(user,freshdir.."albums.txt",arg3)
               elseif  arg2 == "m" then DoDelData(user,freshdir.."mixes.txt",arg3)
               elseif   arg2 == "l" then DoDelData(user,freshdir.."users.txt",arg3)
               elseif   arg2 == "w" then DoDelData(user,freshdir.."weblinks.txt",arg3)
               else   user:SendPM(Bot, syntaxerr)
               end
            else   if   arg == "fav" then
                  if   arg3 == nil then
                     DoDelData(user,favdir..user.sName..".txt",arg2)
                  else   DoDelData(user,favdir..user.sName..".txt",arg2.." "..arg3)
                  end   
               elseif   (arg == "biggup") and (lvl >= 3) then
                  if   arg3 == nil then
                     DoDelData(user,biggupdir.."biggups.txt",arg2)
                  else   DoDelData(user,biggupdir.."biggups.txt",arg2.." "..arg3)
                  end
               else   user:SendPM(Bot, syntaxerr)
               end
            end
      else      user:SendPM(Bot, rightserr)
      end
   else   user:SendPM(Bot, disabled)   
   end
end
            

function DoDelData(user, file, entry)
   local array={}
   array[0]=""
   local x=0

   readfrom(file)
   repeat    x=x+1
      array[x]=read()
   until (array[x]==nil)
   readfrom()
   
   remove(file)
      
   for x=0,getn(array) do
      
    local y, z, entryR = strfind(array[x], "*(.*)")
      if y then
         if entryR~=" "..entry then
            appendto(file)
            write(array[x].."\n")
            writeto()

         else   user:SendPM(Bot, "***DELETED***")
         end
      end
   end
end




--------------------------------------
-- Helper functions           --
--------------------------------------
function CheckUserLevel(user)
name,pass,lev=nil,nil,nil
local temp,r={},0
TextLoad("../RegisteredUsers.dat",temp)
   for x=1,getn(temp) do s,e,name,pass,lev=strfind(temp[x],"(.-)\124(.-)\124(.+)")
      if (user.sName==name) then
         r=r+1
         break
      end
   end

   if (r==0) then
      return 1   --guest
   else
      
         if lev == "0" then return 7      --hubowner
         elseif lev == "6" then return 6      --admin
         elseif lev == "5" then return 5      --mod
         elseif lev == "1" then return 4      --op
         elseif lev == "2" then return 3      --vip
         elseif lev == "3" then return 2      --reg
         else   return 1
         end
         
   
   end
   
end

--------- Text Loaded ---------

function TextLoad(file,array,text) array[0]="" local x=0
   readfrom(file)
   repeat    if (text) then
         text=text..array[x].."\r\n"
      end
      x=x+1
      array[x]=read()
   until (array[x]==nil)
   readfrom()
   return text
end

function fileshow(user,filename)
         local tmp =""
         readfrom(filename)
         while 1 do
            local line = read()
            if (line == nil) then
               break
            else
               tmp = tmp..line.."\r\n"
            end
         end
         readfrom()
         if user then
            user:SendPM(Bot,tmp.."|")
         else
            return tmp
         end
         
         
end

function filecut(file, MaxT)
   array={}
   array[0]=""
   local x=0
   readfrom(file)
   repeat    x=x+1
      array[x]=read()
   until (array[x]==nil)
   readfrom()
   if x > MaxT then
   remove(file)
   for x=(getn(array)-MaxT),getn(array) do
      appendto(file)
      write(array[x].."\n")
      writeto()
   end
   end
end
--------------------------------------------------------------------------
thanks very much.)

SMF spam blocked by CleanTalk