Sir_Mr_Bman

PastebinAPI for ComputerCraft

May 24th, 2014
192
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.77 KB | None | 0 0
  1. -- Pastebin API
  2. -- Created by Sir_Mr_Bman
  3. -- Copyright (c) 2014
  4. -- Feel free to redistribute this program as part of your own programs (if you give me credit)
  5.  
  6. -- Light-Docs:
  7. --      RETURN CODES (downloader):
  8. --      11: HTTP API is not enabled
  9. --      12: Savefile exists
  10. --      13: Could not connect. Is pastebin down?
  11. --      2: Download complete!
  12.  
  13. function downloader(paste, savefile)
  14.  
  15.     if not http then
  16.         return 11
  17.     end
  18.     if fs.exists(textutils.urlEncode(savefile)) then
  19.         return 12
  20.     end
  21.  
  22.     local pastebin = http.get("http://www.pastebin.com/raw.php?i="..textutils.urlEncode(paste))
  23.     if pastebin then
  24.         local saveTo = pastebin.readAll()
  25.         pastebin.close()
  26.         local file = fs.open(savefile, "w")
  27.         file.write(saveTo)
  28.         file.close()
  29.         return 2
  30.     else
  31.         return 13
  32.     end
  33. end
Advertisement
Add Comment
Please, Sign In to add comment