Advertisement
goldfiction

market_mc

Mar 11th, 2022
919
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. --Market by: TurtleScripts.com
  2. --This is a modified version of the PasteBin script to work directly with TurtleScript project files.
  3. local tArgs = { ... }
  4.  
  5. local function printUsage()
  6.   term.clear()
  7.   term.setCursorPos(1,1)
  8.     print( "TurtleMarket v1.0 BETA [#gjdgyl]" )
  9.     print( "-------------------------------------------------" )
  10.     print( "by: TurtleScripts.com (update file_key: #gjdgz7)" )
  11.     print( " " )
  12.     print( "Usages:" )
  13.     print( " ==UPLOAD==" )
  14.     print( "  market put (file_key) (filename) (write_pin)" )
  15.     print( "  [pin req'd]" )
  16.     print( " ==DOWNLOAD==" )
  17.     print( "  market get (file_key) (filename) (read_pin) [y]" )
  18.     print( "  [pin req'd for private/drafts]" )
  19.     print( " " )
  20. end
  21.  
  22. local function putFile(sCode, sFile, sPin, sOverride)
  23.     local sPath = shell.resolve( sFile )
  24.     if not fs.exists( sPath ) or fs.isDir( sPath ) then
  25.             print( "No such file" )
  26.             return
  27.     end
  28.     local sName = fs.getName( sPath )
  29.     local file = fs.open( sPath, "r" )
  30.     local sText = file.readAll()
  31.     file.close()
  32.     write( "Connecting to TurtleScripts.com... " )
  33.     local response = http.post("http://api.turtlescripts.com/putFileRaw/"..textutils.urlEncode( sCode ),"pin="..sPin.."&".."data="..textutils.urlEncode(sText))
  34.     if response then
  35.         print( "Success." )
  36.         local sResponse = response.readAll()
  37.         response.close()
  38.         print( " " )
  39.         print( "Local: "..sFile )
  40.         print( "Remote: #"..sCode )
  41.         print( "[==========================================] 100%" )
  42.         print(string.len(sText).." bytes")
  43.         print( " " )
  44.         print( "Upload Complete." )
  45.     else
  46.         print( "Failed." )
  47.         print( " " )
  48.         print( "ERROR: The file key is bad or project pin is wrong." )
  49.     end
  50. end
  51. local function getFile(sCode, sFile, sPin, sOverride)
  52.     local sPath = shell.resolve( sFile )
  53.     if sCode == "" then
  54.         print( "You must specify a File Key from TurtleScripts.com!" )
  55.         return
  56.     end
  57.     if sFile == "" then
  58.         print( "You must specify a Filename to write to!" )
  59.         return
  60.     end
  61.     if fs.exists( sPath ) then
  62.         print( "File already exists" )
  63.         if sOverride == "" and (sPin ~= "y" or sOverride ~= "") then
  64.             return
  65.         end
  66.     end
  67.     write( "Connecting to TurtleScripts.com... " )
  68.     local response = http.post("http://api.turtlescripts.com/getFileRaw/"..textutils.urlEncode( sCode ),"pin="..sPin)
  69.     if response then
  70.         print( "Success." )
  71.         local sResponse = response.readAll()
  72.         response.close()
  73.         local file = fs.open( sPath, "w" )
  74.         file.write( sResponse )
  75.         file.close()
  76.         print( " " )
  77.         print( "Remote: #"..sCode )
  78.         print( "Local: "..sFile )
  79.         print( "[==========================================] 100%" )
  80.         print(string.len(sResponse).." bytes")
  81.         print( " " )
  82.         print( "Downloaded Complete." )
  83.     else
  84.         print( "Failed." )
  85.         print( " " )
  86.         print( "ERROR: The file key is bad or project is private (in which case, did you specify your project pin??)." )
  87.     end
  88. end
  89.  
  90.     local gui_mode = false
  91.     if #tArgs < 3 then
  92.         printUsage()
  93.         return
  94.     end
  95.     local sCommand = tArgs[1]
  96.     local sCode = tArgs[2] or ""
  97.     local sFile = tArgs[3] or ""
  98.     local sPin  = tArgs[4] or ""
  99.     if sCommand == "put" then
  100.         putFile(sCode, sFile, sPin)
  101.     elseif sCommand == "get" then
  102.         local sOverride  = tArgs[5] or ""  
  103.         getFile(sCode, sFile, sPin, sOverride)
  104.     else
  105.         printUsage()
  106.         return
  107.     end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement