Simple script conversion!
 

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

Simple script conversion!

Started by TiGa, 28 April, 2005, 03:47:09

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

TiGa

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
I\'m sicker than sperm cells with syphillis germs,
and I\'m hotter than my shit is, when I piss and it burns

jiten

#1
Check this and this threads.

Cheers

SMF spam blocked by CleanTalk