pepeknamornik

Stahovani_P7

Feb 28th, 2021 (edited)
705
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. verze = "21.0228.R1"
  2. local tArgs = { ... }
  3. if #tArgs < 2 then
  4.     printUsage()
  5.     return
  6. end
  7.  
  8. if not http then
  9.     return
  10. end
  11.  
  12. local function extractId(paste)
  13.     local patterns = {
  14.         "^([%a%d]+)$",
  15.         "^https?://pastebin.com/([%a%d]+)$",
  16.         "^pastebin.com/([%a%d]+)$",
  17.         "^https?://pastebin.com/raw/([%a%d]+)$",
  18.         "^pastebin.com/raw/([%a%d]+)$",
  19.     }
  20.  
  21.     for i = 1, #patterns do
  22.         local code = paste:match(patterns[i])
  23.         if code then return code end
  24.     end
  25.  
  26.     return nil
  27. end
  28.  
  29. local function get(url)
  30.     local paste = extractId(url)
  31.     if not paste then
  32.         io.stderr:write("Invalid pastebin code.\n")
  33.         io.write("The code is the ID at the end of the pastebin.com URL.\n")
  34.         return
  35.     end
  36.  
  37.     local cacheBuster = ("%x"):format(math.random(0, 2 ^ 30))
  38.     local response, err = http.get(
  39.         "https://pastebin.com/raw/" .. textutils.urlEncode(paste) .. "?cb=" .. cacheBuster
  40.     )
  41.  
  42.     if response then
  43.         -- If spam protection is activated, we get redirected to /paste with Content-Type: text/html
  44.         local headers = response.getResponseHeaders()
  45.         if not headers["Content-Type"] or not headers["Content-Type"]:find("^text/plain") then
  46.             io.stderr:write("Failed.\n")
  47.             return
  48.         end
  49.  
  50.         local sResponse = response.readAll()
  51.         response.close()
  52.         return sResponse
  53.     else
  54.         io.stderr:write("Failed.\n")
  55.     end
  56. end
  57.  
  58. local sCommand = tArgs[1]
  59. if sCommand == "get" then
  60.  
  61.     local sCode = tArgs[2]
  62.     local sFile = tArgs[3]
  63.     local sPath = shell.resolve(sFile)
  64.     if fs.exists(sPath) then
  65.         return
  66.     end
  67.  
  68.     local res = get(sCode)
  69.     if res then
  70.         local file = fs.open(sPath, "w")
  71.         file.write(res)
  72.         file.close()
  73.     end
  74. elseif sCommand == "run" then
  75.     local sCode = tArgs[2]
  76.  
  77.     local res = get(sCode)
  78.     if res then
  79.         local func, err = load(res, sCode, "t", _ENV)
  80.         if not func then
  81.             return
  82.         end
  83.         local success, msg = pcall(func, select(3, ...))
  84.     end
  85. else
  86.     printUsage()
  87.     return
  88. end
  89.  
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×