PtokaX forum

Archive => Archived 5.0 boards => Help with scripts => Topic started by: TiGa on 28 April, 2005, 03:47:09

Title: Simple script conversion!
Post by: TiGa on 28 April, 2005, 03:47:09
could someone plz convert this simple script to lua 5  for me!!
thank you!

-- FreshStuff v.3.0
-- original idea/script by chilla
-- completely rewriten by plop


-- Name the commands to what U like
-- This command adds stuff, syntax : +addalbum THESTUFF2ADD
cmd1 = "!addalbum"

-- This command shows the stuff, syntax : +albums
cmd2 = "!albums"

-- This command deletes an entry, syntax : +delalbum THESTUFF2DELETE
cmd3 = "!delalbum"

-- This command shows the latest stuff, syntax : +newalbums
cmd4 = "!newalbums"

-- This command reloads the txt file. syntax : +reloadalbums
-- (this command is needed if you manualy edit the text file)
cmd5 = "!reloadalbums"

-- Show latest stuff on entry 1=yes, 0=no
ShowOnEntry = 1

-- Max stuff shown on newalbums/entry
MaxNew = 100

-- The file storing the stuff
file = "txt/AlbumsAll.txt"

-- Name of the bot
Bot = "[BoT]PunjabiVibez.com"

--------------------- don't change anything below here
AllStuff = {}
NewestStuff = {}

function Main()
   frmHub:RegBot(Bot)
   Reload()
end

function NewUserConnected(user)
   if ShowOnEntry == 0 then
      user:SendPM(Bot, MsgNew.."|")
   end
end

function OpConnected(user)
   if ShowOnEntry == 0 then
      user:SendPM(Bot, MsgNew.."|")
   end
end

function DataArrival(user,data)
   if (strsub(data, 1, 1) == "<") then
      data = strsub(data,1,strlen(data)-1)
      s,e,cmd,tune = strfind(data, "%b<>%s+(%S+)%s*(.*)")
      if cmd == cmd2 then
         user:SendPM(Bot, MsgAll.."|")
         return 1
      elseif cmd == cmd4 then
         user:SendPM(Bot, MsgNew.."|")
         return 1
      elseif user.bOperator then
         if cmd == cmd3 then
            if tune ~= "" then
               DelStuff(user, tune)
            else
               user:SendData(Bot, "yea right, like i know what i got 2 delete when you don't tell me!|")
            end
            return 1
         elseif cmd == cmd1 then
            if tune ~= "" then
               AddStuff(user, tune)
            else
               user:SendData(Bot, "yea right, like i know what you got 2 add when you don't tell me!|")
            end
            return 1
         elseif cmd == cmd5 then
            Reload()
            user:SendData(Bot, "Albums reloaded!|")
            return 1
         end
      end
   end
end

function OpenStuff()
   AllStuff = nil
   NewestStuff = nil
   AllStuff = {}
   NewestStuff = {}
   Count = 0
   Count2 = 0
   readfrom(file)
   while 1 do
      local line = read()
      if ( line == nil ) then
         break
      else
         Count = Count +1
         AllStuff[Count]=line
      end
   end
   readfrom()
   if Count > MaxNew then
      local temp = Count - MaxNew + 1
      for i=temp, Count do
         Count2 = Count2 + 1
         NewestStuff[Count2]=AllStuff[i]
      end
   else
      for i=1, Count do
         Count2 = Count2 + 1
         NewestStuff[Count2]=AllStuff[i]
      end
   end
end

function SaveStuff()
   writeto(file)
   for i=1,Count do
      if AllStuff[i] then
         write(AllStuff[i].."\n")
      end
   end
   writeto()
end

function ShowAlbums(table)
   Msg = "\r\n"
   if table == NewestStuff then
      if Count2 == 0 then
         MsgNew = "\r\n\r\n".." - <-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-> \r\nNo albums on the list yet\r\n - <-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-> \r\n\r\n"
      else
         for i=1, Count2 do
            Msg = Msg..NewestStuff[i].."\r\n"
         end
         MsgNew = "\r\n\r\n".." - <-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-> \r\n"..Msg.."\r\n - <-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-> \r\n\r\n"
      end
   else
      if Count == 0 then
         MsgAll = "\r\n\r\r\n".." - <-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-> \r\nNo albums on the list yet\r\n - <-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-> \r\n\r\n"
      else
         for i=1, Count do
            Msg = Msg..AllStuff[i].."\r\n"
         end
         MsgAll = "\r\n\r\r\n".." - <-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-> \r\n"..Msg.."\r\n - <-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-> \r\n\r\n"
      end
   end
end

function AddStuff(user, what)
   Count = Count + 1
   AllStuff[Count]=what
   user:SendData(Bot, what.." is added to the Albums|")
   SaveStuff()
   Reload()
end

function DelStuff(user, what)
   Okie = nil
   for a,b in AllStuff do
      if b == what then
         AllStuff[a]=nil
         user:SendData(Bot, what.." is removed from the Albums|")
         Okie = 1
         break
      end
   end
   if Okie then
      SaveStuff()
      Reload()
   else
      user:SendData(Bot, what.." wasn't found in the Albums|")
   end
end

function Reload()
   OpenStuff()
   ShowAlbums(NewestStuff)
   ShowAlbums(AllStuff)
end
Title:
Post by: jiten on 28 April, 2005, 09:42:10
Check this (http://board.univ-angers.fr/thread.php?threadid=3885&boardid=26&styleid=1&sid=2fe016a4dde9870a9b4029df950b8124) and this (http://board.univ-angers.fr/thread.php?threadid=3893&boardid=26&styleid=1&sid=2fe016a4dde9870a9b4029df950b8124) threads.

Cheers