Author Topic: convert swebot to new api2  (Read 2451 times)

0 Members and 1 Guest are viewing this topic.

Offline Mr.T

  • Member
  • ***
  • Posts: 48
  • Karma: +7/-2
convert swebot to new api2
« on: 02 September, 2008, 15:17:07 »
Code: [Select]
-- SweBot  v0.8
-- LUA 5.1
-- Made by Herman   20061030


-- This is a script for getting release news from different sites and convert it to a viewable format for ptokax hubs.

-- I get som help from   PxWSA lib's example script by jiten (3/10/2006)

-- OBS!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
-----------------------------------------------------------------------------------------------
-- You need PxWSA lib to make it work. available here: http://libs.ptokax.ath.cx/#pxwsa   --
-- wsat.lua and wsat-L51-0.1.1.1.lua    is only demofile so delete it.                    --
-- Place pxwsa.dll or pxwsa_l51.dll in script folder                                      --
-----------------------------------------------------------------------------------------------
-- OBS!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!




sBot = frmHub:GetHubBotName ()   -- Default Bot Name or -- sBot = frmHub:GetHubBotName()
updateTime = 30                 -- Update in minutes.    min value is 10

cmd_swenews = "swenews"           -- command to view the different release site files. you can use + , ! , # and ?  to trigger
cmd_swecheck = "swecheck"
cmd_undertexter_film = "undertexter_film"
cmd_undertexter_serie = "undertexter_serie"

showErr = 0                       -- Show if connection to the site fails. ( 1 = yes )
useRightclickmenu = 1          -- If you will use rightclick menu ( 1 = yes )
sMenu = "??Queen??"           -- Rightclick menu name.  use "" to place the commands in the "root"





------------------------------------------------------------------
----- DO NOT CHANGE ANYTHING BELOW THIS IF YOU DONT KNOW WHY------
------------------------------------------------------------------

if updateTime < 10 then updateTime = 10  end

SiteCfg = {

Tid = {1, math.ceil(tonumber(updateTime)/2) , math.ceil(tonumber(updateTime)), math.ceil((tonumber(updateTime)*3)/2), math.ceil(tonumber(updateTime)*2)},  

RawFile_swenews = "txt/raw_swenews",
Swenews_ConvertedFile = "txt/swenews.txt",
Swenews_Url = "swenews.info",
Swenews_File = "/bot.php",

RawFile_swecheck = "txt/raw_swecheck",
Swecheck_ConvertedFile = "txt/swecheck.txt",
Swecheck_Url = "rss.swecheck.net",
Swecheck_File = "/?s=all",

RawFile_undertexter_film = "txt/raw_undertexter_film",
Undertexter_film_ConvertedFile = "txt/undertexter_film.txt",
Undertexter_film_Url = "www.zowat.se",
Undertexter_film_File = "/dev/ut_rss/ut_rss_film.asp",

RawFile_undertexter_serier = "txt/raw_undertexter_serier",
Undertexter_serier_ConvertedFile = "txt/undertexter_serier.txt",
Undertexter_serier_Url = "www.zowat.se",
Undertexter_serier_File = "/dev/ut_rss/ut_rss_serier.asp",


}

Settings = {
sProt = 0,       -- 0 for TCP, 1 for UDP (mostly it's TCP)
sPort = 80,       -- WSA lib default port
Interval = 1000,           -- var 60000, -- 60 sek
}


-- Init WSA lib
if _VERSION == "Lua 5.1" then
libinit = package.loadlib("pxwsa_l51.dll", "_libinit")
else
libinit = loadlib("pxwsa.dll", "_libinit")
  end
  libinit()
  
  -- Init sockets
WSA.Init()


  sCovertedFile = ""
  fData = ""
  update = 0



Main = function()

frmHub:RegBot(sBot)
SetTimer(Settings.Interval)
StartTimer()
if sMenu ~= "" then sMenu = sMenu.."\\" end


end

NewUserConnected = function(user)
if user.bUserCommand and useRightclickmenu == 1 then
user:SendData("$UserCommand 1 3 "..sMenu.."Nyheter fr?n swenews$<%[mynick]> +"..cmd_swenews.."&#124;|")
user:SendData("$UserCommand 1 3 "..sMenu.."Nyheter fr?n swecheck$<%[mynick]> +"..cmd_swecheck.."&#124;|")
user:SendData("$UserCommand 1 3 "..sMenu.."Nyheter fr?n undertexter Filmer$<%[mynick]> +"..cmd_undertexter_film.."&#124;|")
user:SendData("$UserCommand 1 3 "..sMenu.."Nyheter fr?n undertexter Serier$<%[mynick]> +"..cmd_undertexter_serie.."&#124;|")
end
end

OpConnected=NewUserConnected

ChatArrival = function(curUser, data)
local data = string.sub(data, 1, -2)
local s,e,cmd = string.find(data, "%b<>%s+[%!%+%#%?](%S+)")
if cmd then
if cmd == cmd_swenews then
ShowText(curUser, SiteCfg.Swenews_ConvertedFile)
return 1
elseif cmd == cmd_swecheck then
ShowText(curUser, SiteCfg.Swecheck_ConvertedFile)
return 1
elseif cmd == cmd_undertexter_film then
ShowText(curUser, SiteCfg.Undertexter_film_ConvertedFile)
return 1
elseif cmd == cmd_undertexter_serie then
ShowText(curUser, SiteCfg.Undertexter_serier_ConvertedFile)
return 1
end
end
end


OnTimer = function()
update = update + 1
if update == (30*SiteCfg.Tid[1]) then ConnectToHost(SiteCfg.Swenews_Url,SiteCfg.Swenews_File,SiteCfg.Swenews_ConvertedFile)
elseif update == (30*SiteCfg.Tid[2]) then ConnectToHost(SiteCfg.Swecheck_Url,SiteCfg.Swecheck_File,SiteCfg.Swecheck_ConvertedFile)
elseif update == (30*SiteCfg.Tid[3]) then ConnectToHost(SiteCfg.Undertexter_film_Url,SiteCfg.Undertexter_film_File,SiteCfg.Undertexter_film_ConvertedFile)
elseif update == (30*SiteCfg.Tid[4]) then ConnectToHost(SiteCfg.Undertexter_serier_Url,SiteCfg.Undertexter_serier_File,SiteCfg.Undertexter_serier_ConvertedFile)
end

if update > (30*SiteCfg.Tid[5]) then
update = 0
end

 Updater()
end


Updater = function()
if bConnected then

local errorCode, errorStr, sData, bytesRead = WSA.Receive(sock)               -- Wait for the request response
if errorCode then

if errorCode == 0 then                  -- Connection gracefully closed

WSA.Close(sock)                       -- Close existing socket
bConnected = false                    -- Mark as connected


if sCovertedFile == SiteCfg.Swenews_ConvertedFile then fData = ConvertText_Swenews(fData)
elseif sCovertedFile == SiteCfg.Swecheck_ConvertedFile then fData = ConvertText_Swecheck(fData)
elseif sCovertedFile == SiteCfg.Undertexter_film_ConvertedFile then fData = ConvertText_Undertexter(fData)
elseif sCovertedFile == SiteCfg.Undertexter_serier_ConvertedFile then fData = ConvertText_Undertexter(fData)
end

if fData ~= "" then
local f2 = io.open(sCovertedFile,"w+")
f2:write(fData)
f2:flush ()
f2:close()
end
fData = ""                            -- Empty receive buffer

elseif (errorCode == 10035) then        -- Non-critical error
else                                    -- Receive failed

WSA.Close(sock)                       -- Close existing socket
bConnected = false                    -- Mark as not connected
fData = ""                            -- Empty receive buffer

end
else

fData = fData..sData                    -- Merge to received buffer
end
end
end

ConnectToHost = function(Url, sFile, CovertedFile)

if not bConnected then                                                                 -- If not connected to any socket
s,e,sock = WSA.NewSocket(Settings.sProt)                                               -- Create a socket according to what we have above
local errorCode, errorStr = WSA.Connect(sock,Url,Settings.sPort)                       -- Try connection to host
if errorCode then                                                                      -- Connection failed

if showErr == 1 then SendToOps(sBot,"*** Error: Connection to "..Url.." failed!") end-- Connection Report
bConnected = false                                                                   -- Mark as not connected
else
--SendToOps(sBot,"*** Connected")

bConnected = true                                                                    -- Mark as connected
local sError, Str = WSA.MarkNonBlocking(sock)                                     -- Mark non-blocking socket

if sError then                                                                       -- Error

if showErr == 1 then SendToOps(sBot,"*** Error: Could not mark non-blocking socket.") end  -- Socket Error Marking Report
else
--SendToOps(sBot,"*** Socket Marked")
-- Send Request
local wCmd = "GET "..sFile.." HTTP/1.0\r\nHost: "..Url.."\r\nUser-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)\r\n"..string.char(13,10)
local _ErrorCode, _ErrorStr, bytesSent = WSA.Send(sock,wCmd)                       -- Send the request

if _ErrorCode then                                                                 -- Connection failed
bConnected = false                                                               -- Mark as not connected
if showErr == 1 then SendToOps(sBot,"*** Error: Connection Failed - ".._ErrorStr) end -- Report Error
WSA.Close(sock)                                                                  -- Close existing socket
else
sCovertedFile = CovertedFile                                                     -- Set file to write
--SendToOps(sBot,"*** Request to "..Url.." sent!")                               -- Connection Report
end
end
end
end
end


ShowText = function(user,File)
local Text
local f = io.open(File,"r")
if f ~= nil then
Text = f:read("*a")
end
user:SendPM(sBot, Text)
end


ConvertText_Swenews = function(sData)

local xRow ="\r\n"
local swenewslist = ""

if sData ~= nil then
swenewslist = "\r\n\r\nSenaste releaserna fr?n Swenews ( http://swenews.info )\r\n\r\nUppdaterad: "..os.date("%c").."\r\n"

for w in string.gmatch(sData, "(%d+%-%d+%-%d+%s%a+%-*%a*%s%S+)%?") do
   swenewslist = swenewslist..xRow..w
 end
 
 swenewslist = swenewslist
end

swenewslist = swenewslist.."\r\n\r\n(Konverterad av Herman)\r\n\r\n"
return swenewslist
end


ConvertText_Swecheck = function(sData)

local xRow ="\r\n"
local swechecklist = ""

if sData ~= nil then
swechecklist = "\r\n\r\nSenaste releaserna fr?n Swecheck ( http://www.swecheck.net )\r\n\r\nUppdaterad: "..os.date("%c").."\r\n\r\n"

 for w, k, l, m in string.gmatch(sData, "%b<>.%c<title>(%d+%-%d+%-%d+)%s%-%s(%S+)%C*%c%s*<link>(%S+)</link>%s+%S+%s+%S+%s+(%S+)<br") do
   swechecklist = swechecklist..xRow..l.." \t"..w.."\t"..k.."\t"..m
   end
  
  swechecklist = swechecklist
end

swechecklist = swechecklist.."\r\n\r\n(Konverterad av Herman)\r\n\r\n"

return swechecklist
end


ConvertText_Undertexter = function(sData)

local xRow ="\r\n"
local undertextlist = ""

if sData ~= nil then
undertextlist = "\r\n\r\nSenaste releaserna fr?n Undertexter ( http://www.undertexter.se )\r\n\r\nUppdaterad: "..os.date("%c").."\r\n\r\n"

 for w, k, h in string.gmatch(sData, "<item>%s+<title>(%d+%-%d+%-%d+)%C*%s(%C*)%s+<link>(%S+)</link>") do
  k = string.gsub(k,"</title>","")
   undertextlist = undertextlist..xRow..h.."   \t"..w.."\t"..k
  end
 
undertextlist = undertextlist
end
undertextlist = undertextlist.."\r\n\r\n(Konverterad av Herman)\r\n\r\n"
return undertextlist
end

ToArrival = ChatArrival


Can somebody help me convert this to new api2 ;)

PtokaX forum

convert swebot to new api2
« on: 02 September, 2008, 15:17:07 »

Offline Mr.T

  • Member
  • ***
  • Posts: 48
  • Karma: +7/-2
Re: convert swebot to new api2
« Reply #1 on: 09 September, 2008, 19:56:49 »
isnt there nobody how can covert this script please :)

Offline BrotherBear

  • Triple Ace
  • **
  • Posts: 165
  • Karma: +20/-1
Re: convert swebot to new api2
« Reply #2 on: 27 September, 2008, 09:33:16 »
Hi!

Would like to have this converted to, Please :)
Regards,

BrotherBear

PtokaX forum

Re: convert swebot to new api2
« Reply #2 on: 27 September, 2008, 09:33:16 »