Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- args = login/login
- --pastebin functions
- function get_pastebin_id(file_path)
- local file = fs.open(file_path, "r")
- local id = file.readLine():match("--pastebin:([a-zA-Z0-9]*)")
- return id
- end
- function get_paste(id)
- local response = http.get("http://pastebin.com/raw/" .. textutils.urlEncode(id))
- if response then
- local content = response.readAll()
- response.close()
- return content
- else
- printError("Unable to get update. Are you online?")
- error()
- end
- end
- function get_updated_content(file_path)
- if get_pastebin_id(file_path) then --if pastebin
- return get_paste(get_pastebin_id(file_path)) --return updated paste
- else
- print("Unable to find pastebin id. Please do not edit the login file.")
- end
- end
- function update_file(file_path)
- local content = get_updated_content(file_path)
- if content then
- local backup_path = file_path .. ".outdated"
- if fs.exists(backup_path) then
- print("Backup / Older file exists.")
- print("Would you like to overwrite it?")
- write("[Y/N] ")
- local answer = read()
- if answer == "y" or answer == "Y" or answer == "" then
- print("overwriting")
- fs.delete(backup_path)
- fs.move(file_path, file_path .. ".backup")
- else
- print("Cancelled.")
- error()
- end
- else
- fs.move(file_path, file_path .. ".outdated")
- end
- local file = fs.open(file_path, "w")
- file.write(content)
- file.close()
- else
- return
- end
- end
- if args[1] then
- if fs.exists(shell.resolve(args[1])) then
- update_file(shell.resolve(args[1]))
- else
- printError("Where's your login/login file?")
- error()
- end
- else
- print("This is the dumbest error in the world and this should never ever happen. Contact me immediately if it does.")
- error()
- end
Advertisement
Add Comment
Please, Sign In to add comment