Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local function printUsage()
- print( "Usages:" )
- print( "mydown pb <code> <filename>" )
- print( "mydown tyc <code> <filename>" )
- end
- local tArgs = { ... }
- if #tArgs < 2 then
- printUsage()
- return
- end
- if not http then
- print( "MyDown requires http API" )
- print( "Set enableAPI_http to 1 in mod_ComputerCraft.cfg" )
- return
- end
- local sCommand = tArgs[1]
- if sCommand == "tyc" then
- -- Download a file from tycoonier.co.uk
- 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 tycoonier.co.uk... " )
- local response = http.get(
- "http://tycoonier.co.uk/dl/upload/"..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
- elseif sCommand == "tyc73" then
- -- Download a file from tycoonier.co.uk/dl
- 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 tycoonier.co.uk... " )
- local response = http.get(
- "http://tycoonier.co.uk/dl/"..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
- elseif sCommand == "pb" 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 pastebin.com... " )
- local response = http.get(
- "http://pastebin.com/raw.php?i="..textutils.urlEncode( sCode )
- )
- 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
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement