Advertisement
1lann

sniptget

Jun 24th, 2013
145
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.01 KB | None | 0 0
  1. local function get(url, noCancel)
  2.     http.request(url)
  3.     while true do
  4.         local e, rUrl, rmsg = os.pullEvent()
  5.         if (e == "http_success") and (rUrl == url) then
  6.             if rmsg then
  7.                 local data = rmsg.readAll()
  8.                 rmsg.close()
  9.                 if (data ~= "") and data then
  10.                     return "success", data
  11.                 else
  12.                     http.request(url)
  13.                 end
  14.             else
  15.                 http.request(url)
  16.             end
  17.         elseif (e == "http_failure") and (rUrl == url) then
  18.             return "failure"
  19.         elseif (e == "chat_command") and ((trimText(rUrl:lower()) == "cancel") or (trimText(rUrl:lower()) == "home")) and not(noCancel) then
  20.             return "cancel"
  21.         end
  22.     end
  23. end
  24.  
  25. local tArgs = {...}
  26.  
  27. if not tArgs[1] then
  28.     print("Snipt hash ID required!")
  29. elseif not tArgs[2] then
  30.     print("Snipt save location required!")
  31. else
  32.     print("Retrieving Snipt...")
  33.     local resp, data = get("https://snipt.net/raw/"..tArgs[1].."/", true)
  34.  
  35.     if resp ~= "success" then
  36.         print("Failed!")
  37.     else
  38.         local f=io.open(tArgs[2],"w")
  39.         f:write(data)
  40.         f:close()
  41.         print("Snipt saved!")
  42.     end
  43. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement