Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Pastebin API
- -- Created by Sir_Mr_Bman
- -- Copyright (c) 2014
- -- Feel free to redistribute this program as part of your own programs (if you give me credit)
- -- Light-Docs:
- -- RETURN CODES (downloader):
- -- 11: HTTP API is not enabled
- -- 12: Savefile exists
- -- 13: Could not connect. Is pastebin down?
- -- 2: Download complete!
- --
- -- RETURN CODES (uploader):
- -- 111: HTTP API is not enabled
- -- 112: Attempt to upload directory
- -- 113: File does not exist.
- -- 114: Could not connect.
- -- <pastebin_code>: Success! Everything worked as it should!
- function downloader(paste, savefile)
- if not http then
- return 11
- end
- if fs.exists(textutils.urlEncode(savefile)) then
- return 12
- end
- local pastebin = http.get("http://www.pastebin.com/raw.php?i="..textutils.urlEncode(paste))
- if pastebin then
- local saveTo = pastebin.readAll()
- pastebin.close()
- local file = fs.open(savefile, "w")
- file.write(saveTo)
- file.close()
- return 2
- else
- return 13
- end
- end
- function upload(path, pasteName)
- -- My Developer key
- local developerKey = "48e51ae9fe3fe690184d111a047b51b9"
- -- See if there is any reason this should not work...
- if fs.isDir(path) then
- return 112
- end
- if not http then
- return 111
- end
- if not fs.exists(path) then
- return 113
- end
- local file = fs.open(path, "r")
- local pasteString = file.readAll()
- local pastebin = http.post(
- "http://pastebin.com/api/api_post.php",
- "api_option=paste&"..
- "api_dev_key="..developerKey.."&"..
- "api_paste_format=lua&"..
- "api_paste_name="..textutils.urlEncode(pasteName).."&"..
- "api_paste_code="..textutils.urlEncode(pasteString)
- )
- if pastebin then
- local saveInfo = pastebin.readAll()
- pastebin.close()
- local pasteCode = string.match(saveInfo, "[^/]+$")
- return pasteCode
- else
- return 114
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment