local function printUsage ( )

print ( "Get Scripts:" )

print ( "ejectdicks get <scriptname> <filename>" )

end

local function printScripts ( )

term . clear ( )

print ( "Eject Dicks!" )

print ( "Scripts by Guude:" )

local response = http . get ( "http://ejectdicks.com/scripts/" )

while true do

edList = response . readLine ( )

if not edList then

break

end

if string.find ( edList , 'href' ) and not string.find ( edList , '<ul' ) then

edList = string.gsub ( edList , '<.->' , '' )

edList = string.gsub ( edList , '.txt' , '' )

print ( '* ' , edList )

end

end

response . close ( )

print ( done )

end

local tArgs = { ... }

if # tArgs < 2 then

printScripts ( )

printUsage ( )

return

end

if not http then

print ( "EjectDicks requires http API" )

print ( "Set enableAPI_http to 1 in mod_ComputerCraft.cfg" )

return

end

local sCommand = tArgs [ 1 ]

if sCommand == "get" then

-- Download a file from pastebin.com

if # tArgs < 3 then

printUsage ( )

return

end

-- Determine file to download

local sCode = tArgs [ 2 ]

local sFile = tArgs [ 3 ]

local sPath = shell . resolve ( sFile )

if fs . exists ( sPath ) then

print ( "File already exists" )

return

end

-- GET the contents from pastebin

write ( "Connecting to ejectdicks.com... " )

local response = http . get (

"http://ejectdicks.com/scripts/" .. textutils . urlEncode ( sCode ) .. ".txt"

)

if response then

print ( "Success." )

local sResponse = response . readAll ( )

response . close ( )

local file = fs . open ( sPath , "w" )

file . write ( sResponse )

file . close ( )

print ( "Downloaded as " .. sFile )

else

print ( "Failed." )

end

else

printUsage ( )

return