Advertisement
Loneranger419

fetchPaste

Feb 1st, 2025
22
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ------------------------------------------------------------
  2. -- fetch (Computer Craft)
  3. -- This program fetches pastebins based on an internal table
  4. -- To use run: fetch programname
  5. ------------------------------------------------------------
  6.  
  7. -- Table of <program name, pastebin string> pairs
  8. local progTable = {
  9.     {"quarry",     "HKvSqARi"},
  10.     {"stripmine",  "7Q3kjTQB"}
  11. }
  12.  
  13. function main()
  14.     -- Get the target
  15.     if (arg[1] == nil) then
  16.         print("Specify a program")
  17.         return
  18.     end
  19.    
  20.     -- Check if the target exists in the table
  21.     target = nil
  22.     for i = 1, #progTable do
  23.         if (arg[1] == progTable[i][1]) then
  24.             target = progTable[i][2]
  25.         end    
  26.     end
  27.    
  28.     if (target == nil) then
  29.         print("Target not found.")
  30.         return
  31.     end
  32.    
  33.     -- the program was found
  34.     name = arg[1] .. ".lua"
  35.     -- remove the current version
  36.     res1 = shell.run("rm", name)
  37.     -- get the new version
  38.     res2 = shell.run("pastebin", "get", target, name)
  39.    
  40.     if (res1 and res2) then
  41.         print("Fetched " .. name)    
  42.     else
  43.         print("Fetch failed")
  44.     end    
  45. end
  46.  
  47. main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement