ScriptUpdater
 

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

ScriptUpdater

Started by Madman, 16 April, 2006, 21:53:17

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Madman

-- ScriptUpdater
-- Made by Madman, 16.04.06

--[[--
	Very much based on WebBot 1.0 by Mutor
	
	Thanks to jiten and Hungarista for the help =)
	
	A script to use for updateing files in the script folder
	
	Using bluebears httpget-beta1 extension lib for PtokaX.
	Get the pre-released beta here:
	http://www.thewildplace.dk/downloads/betas/httpget-beta1.zip
--]]--

GetCfg = {
Interval = 500,
Bot = "ScriptUpdater",
Done = 0,
Count = 0,
Time = os.time(),
}


function Main()
	libinit = loadlib("luahttpget.dll", "_libinit")
	libinit()
end

function ChatArrival(curUser, data)
	local data = string.sub(data, 1, -2)
	local s,e,cmd = string.find(data, "%b<>%s+[%!%+%#%?](%S+)")
	if cmd and curUser.bOperator then
		if cmd == "updatescript" then
			s,e,Url,WriteFile = string.find(data, "%b<>%s+%S+%s+(%S+)%s+(%S+)")
			if Url and WriteFile then
				if string.find(Url, "http://") then
					AddDL(Url,WriteFile)
					SetTimer(GetCfg.Interval)
					StartTimer()
				else
					curUser:SendData(GetCfg.Bot, "Syntax: !updatescript <domain><file> <target> (i.e !updatescript http://www.mydomain.com/Myfile.txt FileOnHardDrive.txt)")
				end
			else
				curUser:SendData(GetCfg.Bot, "Syntax: !updatescript <domain><file> <target> (i.e !updatescript http://www.mydomain.com/Myfile.txt FileOnHardDrive.txt)")
			end
			return 1
		end
	end
end

function GetStats(uri)
	local Tab = {
	[0] = "Pending",
	[1] = "Downloading",
	[2] = "Download Complete",
	[3] = "Download Failed",
	}
	if uri then
		local r,s = HttpDlStats(uri)," = "..uri
		r = tonumber(r)
		if Tab[r] then
			s = Tab[r]..s
		else
			s = s.." is not in list!"
		end
		return s,r
	end
end

function OnTimer()
	if Url ~= "" and WriteFile ~= "" then
		local status,code = GetStats(Url)
		local file = WriteFile
		if code < 2 then
			if GetCfg.Count == 0 then
				SendToOps(GetCfg.Bot, status)
				GetCfg.Count = 1
			end
		end
		if code >= 2 then
			StopTimer()
			if code == 2 then
				local hub,ver = getHubVersion()
					local size,kb = Checkfile(file)
					kb = string.format ("%-5.2f Kb/s", kb / (os.time() - GetCfg.Time))
					local stat = "\r\n\r\n\t"..status.."\r\n"..
				"\tDownload Size:\t"..size..
				"\r\n\tDownload Time:\t"..
				(os.time() - GetCfg.Time).." seconds\r\n"..
				"\tTransfer Speed:\t"..kb.." \r\n"..
				"\tPtokaX Version:\t"..hub.." "..ver.."\r\n"..
				"\tPXLua Version:\t".._VERSION.."\r\n\r\n"
				SendToOps(GetCfg.Bot,stat)
			end
			if GetCfg.Done == 0 then
				GetCfg.Done = 1
			elseif GetCfg.Done == 1 then
				GetCfg.Done = 0
				Url,WriteFile = nil,nil
			end
		end
	end
end

function Checkfile(file)
	local f,e = io.open(file,"r")
	if f then
		local current = f:seek()
		local size = f:seek("end")
		local kb = string.format ("%-5.2f", size / 1024)
		kb = tonumber(kb)
		f:seek("set", current)
		f:close()
		if size > 1048576 then
			size = string.format ("%-5.2fMb", size / 1048576)
		elseif size > 1024 and size < 1048576 then
			size = string.format ("%-5.2f Kb", size / 1024)
		else
			size = string.format ("%-4d Bytes", size)
		end
		return size,kb
	else
		return nil
	end
end

function AddDL(Url,target)
	if Url and target then
		local res = HttpDlAdd(Url, target)
		if res then
			SendToOps(GetCfg.Bot, " Not added")
		else
			SendToOps(GetCfg.Bot, Url..", Has Been added to download list!")
			GetCfg.Time = os.time()
			GetCfg.Count = 0
		end
		SendToOps(GetCfg.Bot, GetStats(Url))
	end
end


Made so i could update a freinds hub with new versions of a script easier...
The script can be used to download any file from any site to the script folder...
We suffer in silence, we lurk in the shadows, we kill in the night
Site currently down, ETA of returning online is 2099 ;p

Thor

Nice work! ;) Maybe a frmHub:RestartScripts() would be nice after update.

Madman

Maybe...
But sometimes you dl more then 1 script...
So i thought it would be better to restart manually...
We suffer in silence, we lurk in the shadows, we kill in the night
Site currently down, ETA of returning online is 2099 ;p

SMF spam blocked by CleanTalk