Advertisement
SimplyAzgoth

Updater v1.1.0

Nov 24th, 2022 (edited)
474
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.28 KB | None | 0 0
  1. --[[
  2.     Updater v1.0.0 by SimplyAzgoth
  3.  
  4.     Disclaimer: I am not the best coder.
  5.  
  6.     Script allows for CC:Tweaked computer's code to easily be updated from a local server.
  7.     Requires you to enable local http servers in your CC:Tweaked configs. See https://tweaked.cc/guide/local_ips.html for help.
  8.  
  9.     Server should give a json list of json objects that contain the cc:tweaked filepath and the code you want to put.
  10.     example below:
  11.     [
  12.         {
  13.             "filePath": "tester.lua",
  14.             "code": "print('Hello World!')"
  15.         },
  16.         {
  17.             "filePath": "tester2.lua",
  18.             "code": "print('Hello')\nprint('World!')"
  19.         }
  20.     ]
  21. --]]
  22.  
  23.  
  24. local URL = "http://127.0.0.1:5000/update"
  25. local response = http.get(URL)
  26.  
  27. if response.getResponseCode() == 200 then
  28.     print("Successfully requested from: " .. URL)
  29.  
  30.     local json_list = textutils.unserialiseJSON(response.readAll())
  31.  
  32.     for _, json_obj in ipairs(json_list) do
  33.         local file = fs.open(json_obj["filePath"], "w")
  34.         file.write(json_obj["code"])
  35.         file.close()
  36.         print("Successfully written code to: " .. json_obj["filePath"])
  37.     end
  38.  
  39.     print("Finished updating")
  40. else
  41.     print("GET request errored with code: " .. response.getResponseCode())
  42. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement