Can somebody convert this script to Lua 5 please..?
I couldn't have it running, cause it's probably Lua 4, so i didn't have the chance to check if it's working..
Thnx in advance ;)
-- IMDBBOT By [NL]Pur and GoldMember
-- last updated: 8 juni 2003
MainBotName = "[bot]Security" -- Rename to match your Main hub bot
BotName = "[bot]iMDb"
TimeSpanInMinutes = 30
-- Commands --
cmd1 = "?search" -- <searchstring multiple words>
cmd2 = "?topmovies" -- no arguments
cmd4 = "?restrict" -- arguments <tv> <movie> <both>
cmd5 = "?settings" -- no arguments
cmd6 = "?sort" -- arguments <smart> - best search matches first
-- <alpha> - alphabetically
-- <chrono> - chronologically
cmd7 = "?type" -- arguments <regexp> - Regular expression
-- <fuzzy> - fuzzy search
-- <word> - word(s)
cmd8 = "?fromyear" -- argument search from which year
cmd9 = "?toyear" -- argument search to which year
cmda = "?help"
-- Default Settings --
RegisterBot = "PM" -- PM = Results in PM , MainChat = Results in Main Chat
usetimer = "0" -- 1 = Updates of Top15 with use of the timer , 0 = Updates when command ?topmovies is used
searchfor = '&tv=only'
sorts = '&sort=smart'
type = '&type=substring'
fromyear = '&from_year1890'
toyear = '&to_year2010'
function Main()
if (RegisterBot=="PM") then
frmHub:RegBot(BotName)
else
frmHub:UnregBot(BotName)
end
SendPmToOps(MainBotName,date("iMDb Activated [%d %B %Y l %X] ("..RegisterBot.." Mode)"))
SetTimer(TimeSpanInMinutes*60000)
StartTimer()
end
function OnTimer()
if (usetimer=="1") then
getNews1()
end
end
function Get1Arg(data)
s,e,cmd,arg = strfind( data, "%b<>%s+(%S+)%s+(.+)" )
return arg
end
function wr(target,text)
target:SendPM(BotName,text)
end
function DataArrival(curUser,data)
if (strsub(data, 1, 1) == "<") then
data = strsub(data,1,strlen(data)-1)
if (strfind(strlower(data), strlower(cmd1))) then
arg = Get1Arg(data)
if (arg==nil) then
else
sp = strchar(32)
arg = gsub(arg, sp, '+')
findNews(curUser,arg..sorts..type..searchfor..fromyear..toyear)
end
end
if (strfind(strlower(data), strlower(cmd2))) then
if (usetimer=="0") then
getNews1()
end
headpm(curUser)
readfile(curUser,"top15.txt")
end
if (strfind(strlower(data), strlower(cmda))) then
readfile(curUser,"helpimdb.txt")
end
if (getcmd(data,cmd4)==1) and (curUser.bOperator) then
if (arg=='movie') then searchfor='&tv=off' end
if (arg=='both') then searchfor='&tv=both' end
if (arg=='tv') then searchfor='&tv=only' end
end
if (getcmd(data,cmd6)==1) and (curUser.bOperator)then
if (arg=='smart') then sorts='&sort=smart' end
if (arg=='alpha') then sorts='&sort=alpha' end
if (arg=='chrono') then sorts='&sort=chrono' end
end
if (getcmd(data,cmd7)==1) and (curUser.bOperator) then
if (arg=='regexp') then type='&type=regexp' end
if (arg=='fuzzy') then type='&type=fuzzy' end
if (arg=='word') then type='&type=substring' end
end
if (getcmd(data,cmd8)==1) and (curUser.bOperator) then
toyear = "&from_year"..arg
end
if (getcmd(data,cmd9)==1) and (curUser.bOperator) then
toyear = "&to_year"..arg
end
if (strfind(strlower(data), strlower(cmd5))) then sett(curUser) end
end
end
function getcmd(data,md)
getmd=0
if (strfind(strlower(data), strlower(md))) then
arg = Get1Arg(data)
if (arg==nil) then
else
getmd=1
return getmd
end
end
end
function sett(target)
readfile(target,"settings.txt")
if (searchfor=='&tv=off') then
res = " Movie"
elseif (searchfor=='&tv=both') then
res = " Both"
elseif (searchfor=='&tv=only') then
res = " Tv"
end
wr(target,"Restrict is set for: "..res)
if (sorts=='&sort=smart') then
sort = " Best search matches first"
elseif (sorts=='&sort=alpha') then
sort = " Alphabetically"
elseif (sorts=='&sort=chrono') then
sort = " Chronologically"
end
wr(target,"Sort method is set for: "..sort)
if (type=='&type=regexp') then
typed = " Regular expression"
elseif (type=='&type=fuzzy') then
typed = " Fuzzy search"
elseif (type=='&type=substring') then
typed = " Word(s)"
end
wr(target,"Type of search is: "..typed)
fyear = gsub(fromyear, '&from_year','')
tyear = gsub(toyear, '&to_year','')
wr(target, "Bot searches from the year: "..fyear.." until "..tyear)
wr(target,'')
wr(target,"――――――――――――――――――――――――――――――――――――――――――――――――――――――――")
end
send = " HTTP/1.1"..strchar(13, 10).."Host: us.imdb.com"..strchar(13, 10).."Connection: Close"..strchar(13, 10)..
"User-Agent: Mozilla/4.0 (blah blah blah whatever blah)"..strchar(13, 10)..strchar(13, 10)
function findNews(target,find)
wr(target,"_____________")
wr(target," Find something!")
wr(target,"―――――――――――――")
wr(target,"Results for: "..find)
wr(target,"――――――――――――――――――――――――――――――――――――――――――――――――――――――――")
file = ""..find..".txt"
if (openfile("imdb/"..file,"r")==nil) then
local line
local socket, err = connect("www.us.imdb.com",80)
writedonce=0
tob=nil
if not err then
socket:timeout(2)
err = socket:send("GET http://us.imdb.com/Tfuzzy?type=fuzzy&...rono&title="..find..send)
if not err then
writeto("imdb/"..find..".txt")
while not(line == "</HTML>") do
line, err = socket:receive("*l")
if err then break end
s,e = strfind(line,"<OL><LI><A HREF=")
if (s~=nil) then tob = strip(line,34) end
s,e = strfind(line,"<LI><A HREF=")
if (s~=nil) then tob = strip(line,30) end
if (tob~=nil) then
writedonce=1
write(" "..tob..strchar(13)..strchar(10))
tob=nil
end
end
writeto()
end
end
socket:close()
end
if (writedonce==1 or openfile("imdb/"..file,"r")~=nil) then
--if (checkfile(file) == 1) then
readfile(target,file)
readfile(target,"endresult.txt")
--end
end
end
function strip(tob,num)
tob = strsub(tob,num)
tob = gsub(tob, '</A>','')
tob = gsub(tob, '<I>','')
tob = gsub(tob, '<BR>','')
tob = gsub(tob, '</I>','')
tob = gsub(tob, '</LI>','')
tob = gsub(tob, '<SMALL>','')
tob = gsub(tob, '</SMALL>','')
tob = gsub(tob, '&#[i];','')
tob = gsub(tob, '<B>','')
tob = gsub(tob, '</B>','')
tob = gsub(tob, '</TD>','')
tob = gsub(tob, '</B></TD>','')
tob = gsub(tob, '</A></TD>','')
for i = 160, 255 do
n=stripchar(i)
tob = gsub(tob, n,'')
end
return tob
end
function stripchar(num)
n = '&#'..num..';'
return n
end
function headpm(target)
wr(target,"_________________")
wr(target,"IMDb Top 15 Movies!")
wr(target,"―――――――――――――――――")
wr(target,"Rank was Title (YEAR)")
wr(target,"――――――――――――――――――――――――――――――――――――――――――――――――――――――――")
end
function getNews1()
local line
local socket, err = connect("www.us.imdb.com",80)
if not err then
socket:timeout(2)
err = socket:send("GET http://www.us.imdb.com/Charts/top-titles-week.html"..send)
if not err then
writeto("imdb/top15.txt")
while not(line == "</HTML>") do
line, err = socket:receive("*l")
s,e = strfind(line,"ALIGN=CENTER><B>")
if (s~=nil) then tob = strip(line,33)end
o,p = strfind(line,"ALIGN=CENTER>")
if (o~=nil) then toc = strip(line,30)end
c,v = strfind(line,"/Title?")
if (c~=nil) then
url = strsub(line,c,c+13)
top = strip(line,38)
if strfind(top,'?">') then
top = strip(line,41)
else
top = strip(line,48)
end
end
if (tob~=nil) and (toc~=nil) and (top~=nil) then
url = "http://www.us.imdb.com"..url
write(" "..tob.." "..toc.." [ "..url.." ] "..top..strchar(13)..strchar(10))
tob=nil
toc=nil
top=nil
end
end
writeto()
end
end
socket:close()
end
function checkfile(file)
readfrom ("imdb/"..file)
n=1
while 1 do
local line = read()
e,g = strfind(line,"rating")
if (e ~= nil) then
n = 1
else
n = 0
break
end
return n
end
readfrom()
end
function readfile(target,file)
readfrom("imdb/"..file)
while 1 do
local line = read()
if (line ~= nil) then
wr(target,line)
else
break
end
end
readfrom()
end
Finally i managed to convert it myself :) , but despite the fact that i've got no errors in PtokaX's script editor, none of the commands work.. Any1 has an idea..?
Quote from: ReNeGaDe on 27 October, 2006, 07:57:45
none of the commands work
What i saw is that your script needs a socket library to work.
Check PxExtensions site (http://pxextension.piratez.dk/) for more info and the The PxWiki (http://ptxwiki.psycho-chihuahua.net/doku.php). There are scripts using the socket lib too. Check them out.
well i have stone's Hacked.PXLuaSockets.Lua5.0.3, if you mean that, but it's still not working..
Quote from: ReNeGaDe on 27 October, 2006, 10:53:54
if you mean that, but it's still not working..
Yes, it was that. Post your script.
Here is the imdb script, converted to lua 5:
-- IMDBBOT By [NL]Pur and GoldMember
-- last upos.dated: 8 juni 2003
MainBotName = "#[-C??b??uS?-]" -- Rename to match your Main hub bot
BotName = "iMDb"
TimeSpanInMinutes = 30
-- Commands --
cmd1 = "?search" -- <searchstring multiple words>
cmd2 = "?topmovies" -- no arguments
cmd4 = "?restrict" -- arguments <tv> <movie> <both>
cmd5 = "?settings" -- no arguments
cmd6 = "?table.sort" -- arguments <smart> - best search matches first
-- <alpha> - alphabetically
-- <chrono> - chronomath.logically
cmd7 = "?type" -- arguments <regmath.exp> - Regular math.expression
-- <fuzzy> - fuzzy search
-- <word> - word(s)
cmd8 = "?fromyear" -- argument search from which year
cmd9 = "?toyear" -- argument search to which year
cmda = "?help"
-- Default Settings --
RegisterBot = "PM" -- PM = Results in PM , MainChat = Results in Main Chat
usetimer = "0" -- 1 = Upos.dates of Top15 with use of the timer , 0 = Upos.dates when command ?topmovies is used
searchfor = '&tv=only'
table.sorts = '&table.sort=smart'
type = '&type=substring'
fromyear = '&from_year1890'
toyear = '&to_year2010'
function Main()
if (RegisterBot=="PM") then
frmHub:RegBot(BotName)
else
frmHub:UnregBot(BotName)
end
SendPmToOps(MainBotName,os.date("iMDb Activated [%d %B %Y l %X] ("..RegisterBot.." Mode)"))
SetTimer(TimeSpanInMinutes*60000)
StartTimer()
end
function OnTimer()
if (usetimer=="1") then
getNews1()
end
end
function Get1Arg(data)
s,e,cmd,arg = string.find( data, "%b<>%s+(%S+)%s+(.+)" )
return arg
end
function wr(target,text)
target:SendPM(BotName,text)
end
function DataArrival(curUser,data)
if (string.sub(data, 1, 1) == "<") then
data = string.sub(data,1,string.len(data)-1)
if (string.find(string.lower(data), string.lower(cmd1))) then
arg = Get1Arg(data)
if (arg==nil) then
else
sp = string.char(32)
arg = string.gsub(arg, sp, '+')
findNews(curUser,arg..table.sorts..type..searchfor..fromyear..toyear)
end
end
if (string.find(string.lower(data), string.lower(cmd2))) then
if (usetimer=="0") then
getNews1()
end
headpm(curUser)
readfile(curUser,"top15.txt")
end
if (string.find(string.lower(data), string.lower(cmda))) then
readfile(curUser,"helmath.pimdb.txt")
end
if (getcmd(data,cmd4)==1) and (curUser.bOperator) then
if (arg=='movie') then searchfor='&tv=off' end
if (arg=='both') then searchfor='&tv=both' end
if (arg=='tv') then searchfor='&tv=only' end
end
if (getcmd(data,cmd6)==1) and (curUser.bOperator)then
if (arg=='smart') then table.sorts='&table.sort=smart' end
if (arg=='alpha') then table.sorts='&table.sort=alpha' end
if (arg=='chrono') then table.sorts='&table.sort=chrono' end
end
if (getcmd(data,cmd7)==1) and (curUser.bOperator) then
if (arg=='regmath.exp') then type='&type=regmath.exp' end
if (arg=='fuzzy') then type='&type=fuzzy' end
if (arg=='word') then type='&type=substring' end
end
if (getcmd(data,cmd8)==1) and (curUser.bOperator) then
toyear = "&from_year"..arg
end
if (getcmd(data,cmd9)==1) and (curUser.bOperator) then
toyear = "&to_year"..arg
end
if (string.find(string.lower(data), string.lower(cmd5))) then sett(curUser) end
end
end
function getcmd(data,md)
getmd=0
if (string.find(string.lower(data), string.lower(md))) then
arg = Get1Arg(data)
if (arg==nil) then
else
getmd=1
return getmd
end
end
end
function sett(target)
readfile(target,"settings.txt")
if (searchfor=='&tv=off') then
res = " Movie"
elseif (searchfor=='&tv=both') then
res = " Both"
elseif (searchfor=='&tv=only') then
res = " Tv"
end
wr(target,"Restrict is set for: "..res)
if (table.sorts=='&table.sort=smart') then
table.sort = " Best search matches first"
elseif (table.sorts=='&table.sort=alpha') then
table.sort = " Alphabetically"
elseif (table.sorts=='&table.sort=chrono') then
table.sort = " Chronomath.logically"
end
wr(target,"Sort method is set for: "..table.sort)
if (type=='&type=regmath.exp') then
typed = " Regular math.expression"
elseif (type=='&type=fuzzy') then
typed = " Fuzzy search"
elseif (type=='&type=substring') then
typed = " Word(s)"
end
wr(target,"Type of search is: "..typed)
fyear = string.gsub(fromyear, '&from_year','')
tyear = string.gsub(toyear, '&to_year','')
wr(target, "Bot searches from the year: "..fyear.." until "..tyear)
wr(target,'')
wr(target,"――――――――――――――――――――――――――――――――――――――――――――――――――――――――")
end
send = " HTTP/1.1"..string.char(13, 10).."Host: us.imdb.com"..string.char(13, 10).."Connection: Close"..string.char(13, 10)..
"User-Agent: Mozilla/4.0 (blah blah blah whatever blah)"..string.char(13, 10)..string.char(13, 10)
function findNews(target,find)
wr(target,"_____________")
wr(target," Find something!")
wr(target,"―――――――――――――")
wr(target,"Results for: "..find)
wr(target,"――――――――――――――――――――――――――――――――――――――――――――――――――――――――")
file = ""..find..".txt"
if (openfile("imdb/"..file,"r")==nil) then
local line
local socket, err = connect("www.us.imdb.com",80)
writedonce=0
tob=nil
if not err then
socket:timeout(2)
err = socket:send("GET http://us.imdb.com/Tfuzzy?type=fuzzy&...rono&title="..find..send)
if not err then
writeto("imdb/"..find..".txt")
while not(line == "</HTML>") do
line, err = socket:receive("*l")
if err then break end
s,e = string.find(line,"<OL><LI><A HREF=")
if (s~=nil) then tob = strip(line,34) end
s,e = string.find(line,"<LI><A HREF=")
if (s~=nil) then tob = strip(line,30) end
if (tob~=nil) then
writedonce=1
write(" "..tob..string.char(13)..string.char(10))
tob=nil
end
end
writeto()
end
end
socket:close()
end
if (writedonce==1 or openfile("imdb/"..file,"r")~=nil) then
--if (checkfile(file) == 1) then
readfile(target,file)
readfile(target,"endresult.txt")
--end
end
end
function strip(tob,num)
tob = string.sub(tob,num)
tob = string.gsub(tob, '</A>','')
tob = string.gsub(tob, '<I>','')
tob = string.gsub(tob, '<BR>','')
tob = string.gsub(tob, '</I>','')
tob = string.gsub(tob, '</LI>','')
tob = string.gsub(tob, '<SMALL>','')
tob = string.gsub(tob, '</SMALL>','')
tob = string.gsub(tob, '&#[i];','')
tob = string.gsub(tob, '<B>','')
tob = string.gsub(tob, '</B>','')
tob = string.gsub(tob, '</TD>','')
tob = string.gsub(tob, '</B></TD>','')
tob = string.gsub(tob, '</A></TD>','')
for i = 160, 255 do
n=stripchar(i)
tob = string.gsub(tob, n,'')
end
return tob
end
function stripchar(num)
n = '&#'..num..';'
return n
end
function headpm(target)
wr(target,"_________________")
wr(target,"IMDb Top 15 Movies!")
wr(target,"―――――――――――――――――")
wr(target,"Rank was Title (YEAR)")
wr(target,"――――――――――――――――――――――――――――――――――――――――――――――――――――――――")
end
function getNews1()
local line
local socket, err = connect("www.us.imdb.com",80)
if not err then
socket:timeout(2)
err = socket:send("GET http://www.us.imdb.com/Charts/top-titles-week.html"..send)
if not err then
writeto("imdb/top15.txt")
while not(line == "</HTML>") do
line, err = socket:receive("*l")
s,e = string.find(line,"ALIGN=CENTER><B>")
if (s~=nil) then tob = strip(line,33)end
o,p = string.find(line,"ALIGN=CENTER>")
if (o~=nil) then toc = strip(line,30)end
c,v = string.find(line,"/Title?")
if (c~=nil) then
url = string.sub(line,c,c+13)
top = strip(line,38)
if string.find(top,'?">') then
top = strip(line,41)
else
top = strip(line,48)
end
end
if (tob~=nil) and (toc~=nil) and (top~=nil) then
url = "http://www.us.imdb.com"..url
write(" "..tob.." "..toc.." [ "..url.." ] "..top..string.char(13)..string.char(10))
tob=nil
toc=nil
top=nil
end
end
writeto()
end
end
socket:close()
end
function checkfile(file)
readfrom ("imdb/"..file)
n=1
while 1 do
local line = read()
e,g = string.find(line,"rating")
if (e ~= nil) then
n = 1
else
n = 0
break
end
return n
end
readfrom()
end
function readfile(target,file)
readfrom("imdb/"..file)
while 1 do
local line = read()
if (line ~= nil) then
wr(target,line)
else
break
end
end
readfrom()
end
It's still LUA4. Check the function names - in LUA5 there is no DataArrival, it has been separated to each arrivals.
It would be very nice of you, if could help me fully converting this script.