Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local tArgs = { ... }
- if #tArgs < 2 then
- return
- end
- local function get(paste)
- local response = http.get("http://pastebin.com/raw.php?i="..textutils.urlEncode( paste ))
- if response then
- local sResponse = response.readAll()
- response.close()
- return sResponse
- else
- printError( "Failed." )
- end
- end
- local sCommand = tArgs[1]
- if sCommand == "put" then
- local sFile = tArgs[2]
- local sPath = shell.resolve( sFile )
- if not fs.exists( sPath ) or fs.isDir( sPath ) then
- print( "No such file" )
- return
- end
- local sName = fs.getName( sPath )
- local file = fs.open( sPath, "r" )
- local sText = file.readAll()
- file.close()
- local key = "0ec2eb25b6166c0c27a394ae118ad829"
- local response = http.post(
- "http://pastebin.com/api/api_post.php",
- "api_option=paste&"..
- "api_dev_key="..key.."&"..
- "api_paste_format=lua&"..
- "api_paste_name="..textutils.urlEncode(sName).."&"..
- "api_paste_code="..textutils.urlEncode(sText)
- )
- if response then
- local sResponse = response.readAll()
- response.close()
- local sCode = string.match( sResponse, "[^/]+$" )
- else
- print( "Failed." )
- end
- elseif sCommand == "get" then
- if #tArgs < 3 then
- printUsage()
- return
- end
- local sCode = tArgs[2]
- local sFile = tArgs[3]
- local sPath = shell.resolve( sFile )
- if fs.exists( sPath ) then
- return
- end
- local res = get(sCode)
- if res then
- local file = fs.open( sPath, "w" )
- file.write( res )
- file.close()
- end
- elseif sCommand == "run" then
- local sCode = tArgs[2]
- local res = get(sCode)
- if res then
- local func, err = loadstring(res)
- if not func then
- printError( err )
- return
- end
- setfenv(func, getfenv())
- local success, msg = pcall(func, unpack(tArgs, 3))
- if not success then
- printError( msg )
- end
- end
- else
- printUsage()
- return
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement