PtokaX forum

Archive => Archived 4.0 boards => Help with Lua 4 scripts => Topic started by: jsjen on 25 March, 2004, 12:37:19

Title: Help to fix WhoIs bot
Post by: jsjen on 25 March, 2004, 12:37:19
It didnt work so I played with it and tried to get the syntax errors out :S

I hope someone can get it to work for us

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


sBotName = "Whois"

function Main()
  --sBotName = "Whois"
  frmHub.RegisterBotName(sBotName)
end

function DataArival (curUser, sCurData)
  if curUser.bOperator and (Left(sCurData,1)=="<" or Left(sCurData,Len(sBotName)+6)=="$To: "+sBotName+" ") then
    s=LCase(Mid(CStr(sCurData),inStr(CStr(sCurData),">")+2))
    if InStr(s," ") then
      sCmd=Left(s,InStr(s," ")-1)
      sUser=Mid(s,InStr(s," ")+1)
    else
      sCmd=s
      sUser=curUser.sName
    end
    if sCmd=="whois" then
      if bIsIP(sUser) then
        curUser.PrivateMessage(CStr(sBotName),"Whois information about IP "+cStr(sUser)+cStr(sWhois(sUser)))
      else
        if colUsers.Online(CStr(sUser)) then
          curUser.PrivateMessage(cStr(sBotName),"Whois information about user "+cStr(sUser)+" ("+cStr(colUsers.ItemByName(CStr(sUser)).IP)+")"+cStr(sWhois(colUsers.ItemByName(CStr(sUser)).IP)))
        else
          curUser.PrivateMessage(cStr(sBotName),"User "+cStr(sUser)+" is not online.")
        end
      end
    end
  end
end

function bIsIP(sIP)
  bIsIP=False
  i=0
  for j = 1,Len(CStr(sIP)) do
    if (Asc(Mid(CStr(sIP),j,1))<48 or Asc(Mid(CStr(sIP),j,1))>57) and Asc(Mid(CStr(sIP),j,1))~=46 then
   i = 9
    end
    if Asc(Mid(CStr(sIP), j, 1)) == 46 then
   i = i + 1
    end
  end
  if i==3 then
   bIsIP=True
  end
end

function sWhois(sIP)
  oSrvHTTP = CreateObject("MSXML2.ServerXMLHTTP")
  oSrvHTTP.open("GET","http://www.ripe.net/perl/whois?searchtext="+sIP+"&alt_database=ALL", False)
  oSrvHTTP.Send()
  sRes = oSrvHTTP.responsetext
  oSrvHTTP = Nothing
  sRes=Mid(sRes,InStr(sRes,"
")+11)
  sRes=Left(sRes,InStrRev(sRes,"
")-2)
  sRes=Replace(sRes,chr(10),vbCRLF)
  sRes=Replace(sRes,"
",vbCRLF)
  sRes=Replace(sRes,"    "," ")
  sRes=Replace(sRes,"   "," ")
  sRes=Replace(sRes,"  "," ")
  sRes=Replace(sRes,": ",":"+vbTab+vbTab)
  sRes=Replace(sRes,"mnt-routes:"+vbTab,"mnt-routes:")
  sRes=Replace(sRes,"mnt-lower:"+vbTab,"mnt-lower:")
  sWhois=vbCRLF
  iZ=True
  for i=1,Len(sRes) do
    if Mid(sRes,i,1)=="<" then
     iZ=False
    end
    if iZ then
     sWhois=sWhois+Mid(sRes,i,1)
    end
    if Mid(sRes,i,1)==">" then
     iZ=True
    end
  end
end
------------------------------------
Title:
Post by: pHaTTy on 25 March, 2004, 13:10:28
looks more like a script from sdch, but if u post the version b4 u edited, i will fix the rest, im short on time.....
Title:
Post by: pHaTTy on 25 March, 2004, 13:17:01
in fact try this


sBotName = "Whois"

function Main()
sBotName = "Whois"
frmHub.RegisterBotName(sBotName)
end

function DataArival (curUser, sCurData)
if curUser.bOperator and (Left(sCurData,1)=="<" or Left(sCurData,Len(sBotName)+9)=="$To: "..sBotName) then
s=LCase(Mid(CStr(sCurData),inStr(CStr(sCurData),">")+2))
if InStr(s," ") then
sCmd=Left(s,InStr(s," ")-1)
sUser=Mid(s,InStr(s," ")+1)
else
sCmd=s
sUser=curUser.sName
end
if sCmd=="whois" then
if bIsIP(sUser) then
curUser.PrivateMessage(CStr(sBotName),"Whois information about IP "..cStr(sUser)..cStr(sWhois(sUser)))
else
if colUsers.Online(CStr(sUser)) then
curUser.PrivateMessage(cStr(sBotName),"Whois information about user "..cStr(sUser)..(cStr(colUsers.ItemByName(CStr(sUser)).IP))..cStr(sWhois(colUsers.ItemByName(CStr(sUser)).IP)))
else
curUser.PrivateMessage(cStr(sBotName),"User "..cStr(sUser).." is not online.")
end
end
end
end
end

function bIsIP(sIP)
bIsIP=False
i=0
for j = 1,Len(CStr(sIP)) do
if (Asc(Mid(CStr(sIP),j,1))<48 or Asc(Mid(CStr(sIP),j,1))>57) and Asc(Mid(CStr(sIP),j,1))~=46 then
i = 9
end
if Asc(Mid(CStr(sIP), j, 1)) == 46 then
i = i + 1
end
end
if i==3 then
bIsIP=True
end
end

function sWhois(sIP)
oSrvHTTP = CreateObject("MSXML2.ServerXMLHTTP")
oSrvHTTP.open("GET","http://www.ripe.net/perl/whois?searchtext="..sIP.."&alt_database=ALL", False)
oSrvHTTP.Send()
sRes = oSrvHTTP.responsetext
oSrvHTTP = Nothing
sRes=Mid(sRes,InStr(sRes,"
")+11) 
sRes=Left(sRes,InStrRev(sRes,"
")-2)
sRes=Replace(sRes,chr(10),vbCRLF)
sRes=Replace(sRes,"
",vbCRLF) 
sRes=Replace(sRes," "," ")
sRes=Replace(sRes," "," ")
sRes=Replace(sRes," "," ")
sRes=Replace(sRes,": ",":"..vbTab..vbTab)
sRes=Replace(sRes,"mnt-routes:"..vbTab,"mnt-routes:")
sRes=Replace(sRes,"mnt-lower:"..vbTab,"mnt-lower:")
sWhois=vbCRLF
iZ=True
for i=1,Len(sRes) do
if Mid(sRes,i,1)=="<" then
iZ=False
end
if iZ then
sWhois=sWhois+Mid(sRes,i,1)
end
if Mid(sRes,i,1)==">" then
iZ=True
end
end
end