View difference between Paste ID: ndySpYZm and 9YZLyYAD
SHOW: | | - or go back to the newest paste.
1-
--pastebin:9YZLyYAD
1+
args = login/login
2
3-
args = {...}
3+
4
function get_pastebin_id(file_path)
5
  local file = fs.open(file_path, "r")
6
  local id = file.readLine():match("--pastebin:([a-zA-Z0-9]*)")
7
  
8
  return id
9
end
10
11
function get_paste(id)
12
13
  local response = http.get("http://pastebin.com/raw/" .. textutils.urlEncode(id))
14
        
15
  if response then
16
    local content = response.readAll()
17
    response.close()
18
    return content
19
  else
20
    printError("Unable to get update. Are you online?")
21
    error()
22-
    printError("Failed to get paste.")
22+
23
end
24
25
function get_updated_content(file_path)
26
  if get_pastebin_id(file_path) then --if pastebin
27-
--github functions
27+
28-
function get_github_url(file_path)
28+
29
    print("Unable to find pastebin id. Please do not edit the login file.")
30-
  local id = file.readLine():match("--github:([^\ ]*)") --everything that is not a space
30+
31
end
32
33-
  if id and id:sub(1,1) == "/" then
33+
34-
    return id:sub(2,-1)
34+
35
  
36
  if content then
37
    local backup_path = file_path .. ".outdated"
38
  
39
    if fs.exists(backup_path) then
40-
function get_gihub_file(url)
40+
      print("Backup / Older file exists.")
41-
  local response = http.get("https://raw.githubusercontent.com/" .. textutils.urlEncode(url))
41+
42
      write("[Y/N] ")
43
      local answer = read()
44
      
45
      if answer == "y" or answer == "Y" or answer == "" then
46
        print("overwriting")
47
        fs.delete(backup_path)
48-
    printError("Failed to get github file.")
48+
49
      else
50
        print("Cancelled.")
51
        error()
52
      end
53-
--generic functions
53+
54-
function get_generic_url(file_path)
54+
      fs.move(file_path, file_path .. ".outdated")
55
    end
56-
  local id = file.readLine():match("--generic:([^\ ]*)") --everything that is not a space
56+
57
    file.write(content)
58
    file.close()
59
  else
60
    return
61-
function get_generic_file(url)
61+
62-
  if url:sub(1,8) == "https://" then
62+
63-
    local response = http.get("https://" .. textutils.urlEncode(url:sub(9, -1)))
63+
64-
  elseif url:sub(1,7) == "http://" then
64+
65-
    local response = http.get("http://" .. textutils.urlEncode(url:sub(8, -1)))
65+
66
    update_file(shell.resolve(args[1]))
67-
    print("missing http or https, please specify protocol when using generic.")
67+
68
    printError("Where's your login/login file?")
69
    error()
70
  end
71
else
72
  print("This is the dumbest error in the world and this should never ever happen. Contact me immediately if it does.")
73
  error()
74
end