PtokaX forum

Archive => Archived 5.1 boards => Request for scripts => Topic started by: TrIp-iN-SuN on 18 August, 2006, 16:08:00

Title: need help find script shoutstats To LUA 5.1
Post by: TrIp-iN-SuN on 18 August, 2006, 16:08:00
same one can to help me with script shoutstats to convert from lua 5.0 to lua 5.1 or make new one?
Title: Re: need help find script shoutstats To LUA 5.1
Post by: TiMeTrAVelleR on 18 August, 2006, 17:00:00

-- ShoutStats 1.21
--
-- by Mutor The Ugly
-- Requested By Bastya_Elvtars
--
-- ShoutCAST Status Grabber
-- Grabs the current stream info
-- Return to user or send to all
--
-- Bug fix by Mutor 10/8/04
-- Fixed double url...
--
-- Added Timer function 10/24/04
-- requested vy Psycho_Chihuahua

-- PXWSA (c) 2005-2006 by Morten Larsen (bluebear)
-- http://pxextension.piratez.dk/#pxwsa

-- Converted to LUA5 and made it based on the PXWSA lib by bastya_elvtars (2005-08-19)
-- Make a folder called libs inside your scripts folder and extract PXWSA there.
-- WARNING: it may crash your hub! Use at your own risk!

-------- 1.2
-- done a little cleanup by bastya_elvtars (2006-03-27)
-- made compatible with the new pxwsa by bastya_elvtars (2006-03-27)

-------- 1.21
-- made compatible with lua 5.1 by eMTee (2006-07-13)
-- made compatible with pxwsa for lua 5.1 by eMTee (2006-07-13)


--User Settings-------------------------------------------------------------------------------------
Bot =
  {
    Name="-LeViA-",
    Email="shoutcastbot@ptokax.exe",
    Desc="RadioStats bot",
IsOp=1, -- 0 or 1 accordingly
  }
Command1 = "+sr" --Get status now
Command2 = "+srall" --Toggle send to all on/off
Mins = 2 --Time between announces in minutes
TimerOn = 1 --Timer 0 - off, 1 - on (grr Psycho_Chihuahua)
ghostin = "http://stream01.pcextreme.nl/stream " --SHOUTcast D.N.A.S. Status Address
gport = 8035 --Port to connect to
gfile = "/index.html" --default file for web page
Send2Main = "yes" --Send results to all users? 'yes/no'
--End User Settings----------------------------------------------------------------------------------
--
-- Loading the library.
libinit = package.loadlib("libs/pxwsa_l51.dll", "_libinit")
assert(libinit,"Cannot load the WSA library!")
libinit()
chktbl={}

function Main()
  ghost = ghostin
  ghost = string.gsub(string.lower(ghost), "(http://)","")
  Msg="\r\n\t=-=<>=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=--=-=-=-=-==-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=--=<>=-=\r\n"
  Msg = Msg.."\t\tSHOUTcast D.N.A.S. Status For: \t[ "..ghost..":"..gport.." ]\r\n"
  Msg = Msg.."\t\t\t**** Current Stream Information ****\r\n"
  Msg = Msg.."\t=-=<>=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=--=-=-=-=-==-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=--=<>=-=\r\n"
  assert(WSA.Init()==nil,"Error initializing WSA lib.") -- Initializing the lib
  frmHub:RegBot(Bot.Name,Bot.IsOp,Bot.Desc,Bot.Email)
  --SetTimer(Mins*60000)
SetTimer(1000)
  Timed = ""
  StartTimer()
end

-- Meta-variables.
_M=0
_C=false
_HTML=""
--

function OnTimer()
if _C then GetStuff() end
if _M==Mins*60 then -- multitimer!
Timed = 1
GetNews()
_M=0
else
_M=_M+1
end
end

function SockError(err)
  if user then
    local dsp2
    dsp2 = "\r\n\t=-=<>=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=--=-=-=-=-=<>=-=\r\n"
    dsp2 = dsp2.."\t >Connect Status:\t  **Failed! - Unable To Connect\r\n"
    dsp2 = dsp2.."\t >Failure Cause:\t "..err.."\r\n"
    dsp2 = dsp2.."\t=-=<>=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=--=-=-=-=-=<>=-=\r\n"
    if Send2Main == "yes" then
      SendToAll(Bot.Name,dsp2.."\r\n")
    else
      user:SendData(Bot.Name,dsp2.."\r\n")
    end
  end
  Msg="\r\n\t=-=<>=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=--=-=-=-=-==-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=--=<>=-=\r\n"
  Msg = Msg.."\t\tSHOUTcast D.N.A.S. Status For: \t[ "..ghost..":"..gport.." ]\r\n"
  Msg = Msg.."\t\t\t**** Current Stream Information ****\r\n"
  Msg = Msg.."\t=-=<>=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=--=-=-=-=-==-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=--=<>=-=\r\n"
  WSA.Close(sock)
_C=false
end

GetStuff = function()
local error1, error2, code = WSA.Receive(sock)
  if not error1 then
_HTML=_HTML..code
elseif error1==0 then
    local x = string.gsub(_HTML, "^(.+)%s*<body","<body")
    x = string.gsub(x, "^(.+)>Current Stream Information","")
    x = string.gsub(x, "HTTP/1.0%s+200%s+OK.?content%-type:text/html","")
    x = string.gsub(x, "Average","Avg%.")
    x = string.gsub(x, "</table>(%s+)Written","")
    x = string.gsub(x, "Current Song%s.+(<%/td>.+)","")
    x = string.gsub(x, "<br>(.+)Written","Written")
    x = string.gsub(x, "Written%s.+","")
    x = string.gsub(x, "(aim.+A\">)","")
    x = string.gsub(x, "(<a%shref%=\")","")
    x = string.gsub(x, "\">%S+</a>","")
    x = string.gsub(x, "&nbsp;"," ")
    x = string.gsub(x, "&quot;","\"")
    x = string.gsub(x, "&raquo;","?")
    x = string.gsub(x, "&amp;","&")
    x = string.gsub(x, "&lt;","<")
    x = string.gsub(x, "&gt;",">")
    x = string.gsub(x, "%%20"," ")
    x = string.gsub(x, "%s%s+","")
    x = string.gsub(x, "&trade;","?")
    x = string.gsub(x, "&copy;","?")
    x = string.gsub(x, "&reg;","?")
    x = string.gsub(x, "&bull;","?")
    x = string.gsub(x, "&deg;","?")
    x = string.gsub(x, "&middot;","?")
    x = string.gsub(x, "<tr>","\r\n\t<tr>")
    x = string.gsub(x, "<td>","\t - \t")
    x = string.gsub(x, "<br>","\r\n")
    x = string.gsub(x, "<([^>]-)>","")
    Msg=Msg..x
if Timed == 1 then
      SendToAll(Bot.Name,Msg.."\r\n")
      WSA.Close(sock)
      Timed=0
    else
      if Send2Main == "yes" then
        SendToAll(Bot.Name,Msg.."\r\n")
        WSA.Close(sock)
      else
        user:SendData(Bot.Name,Msg.."\r\n")
      end
    end
_C=false
_HTML=""
Msg = "\r\n\t=-=<>=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=--=-=-=-=-==-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=--=<>=-=\r\n"
    Msg = Msg.."\t\tSHOUTcast D.N.A.S. Status For: \t[ "..ghost..":"..gport.." ]\r\n"
    Msg = Msg.."\t\t\t**** Current Stream Information ****\r\n"
    Msg = Msg.."\t=-=<>=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=--=-=-=-=-==-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=--=<>=-=\r\n"
  elseif error1~= 10035 then
      SockError(error2)
_HTML=""
  end
end

function GetNews(usr)
  user=usr
  _,_,sock=WSA.NewSocket(0)
  local err1,err2=WSA.Connect(sock,ghost,gport)
  if err1 then
    SockError(err2)
  else
WSA.MarkNonBlocking(sock)
_C=true
    local GETHTML = "GET "..gfile.." HTTP/1.1\r\nHost: "..ghost.."\r\nUser-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)\r\n"
    local err1, err2 = WSA.Send(sock,GETHTML..string.char(13,10))
if errorCode then
SockError(err2)
end
  end
end

function OnExit()
  WSA.Dispose() -- we drop the lib
end

function ChatArrival(usr, data)
  data = string.sub(data,1,string.len(data)-1)
  local  _,_,cmd = string.find(data,"^%b<>%s+(%S+)")--
  if (cmd == Command1) then
    GetNews(usr)
    usr:SendData(Bot.Name,"Getting info from server. Please wait.")
    return 1
  elseif (cmd == Command2) then
    if Send2Main == "no" then Send2Main = "yes"
      usr:SendData(Bot.Name,"Shoutcast status ' Send To All ' is now [ON]")
    elseif Send2Main == "yes" then Send2Main = "no"
      usr:SendData(Bot.Name,"Shoutcast status ' Send To All ' is now [OFF]")
      return 1
    end
  end
end

ToArrival=ChatArrival


there you go
Title: Re: need help find script shoutstats To LUA 5.1
Post by: bastya_elvtars on 20 August, 2006, 14:00:39
Post the code to my forum as well, please. Thanks in advance.
Title: Re: need help find script shoutstats To LUA 5.1
Post by: AL?MCi on 29 September, 2007, 01:37:11
Hi all,

I want to remove some lines in hub screen ( invisible for all ops and users )

For example:

   Listener Peak     -    10
   Avg. Listen Time     -    49m 29s

etc.

is it possible?

thx.