Advertisement
hunter3216

loadAPIs.lua

Mar 31st, 2023
705
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.33 KB | None | 0 0
  1. -- pastebin 6x0B3PVu
  2. -- Script for loading APIs
  3. -- This script will be updated with new apis as I make new ones
  4. -- Another script will have to be called to get this from pastebin and run it
  5. local forceLoad = ...
  6.  
  7. local function getDeviceType()
  8.     if turtle then
  9.         return "turtle"
  10.     elseif pocket then
  11.         return "pocket"
  12.     elseif commands then
  13.         return "command_computer"
  14.     else
  15.         return "computer"
  16.     end
  17. end
  18. local dt = getDeviceType()
  19.  
  20. local APIs_all = {
  21.     ["storage.lua"] = "3MzNhUv4"
  22. }
  23.  
  24. local APIs_turtle = {
  25.     ["home.lua"] = "ad7iiybK",
  26.     ["egps"] = "9x7wXGBm",
  27.     ["robot.lua"] = "n26GUHfJ"
  28. }
  29.  
  30. local APIs_computer = {
  31.  
  32. }
  33.  
  34. local APIs_pocket = {
  35.  
  36. }
  37.  
  38. if forceLoad == "force"  or forceLoad == "f" then
  39.     shell.run("rm " .. "APIs/")
  40. end
  41.  
  42. APIs = APIs_all
  43. if dt == "turtle" then
  44.     print("Turtle detected")
  45.     for k, v in pairs(APIs_turtle) do APIs[k] = v end
  46. elseif dt == "pocket" then
  47.     print("Pocket computer detected")
  48.     for k, v in pairs(APIs_computer) do APIs[k] = v end
  49. elseif dt == "computer" then
  50.     print("Computer detected")
  51.     for k, v in pairs(APIs_pocket) do APIs[k] = v end
  52. end
  53.  
  54. for k,v in pairs(APIs) do
  55.  
  56.     local f = io.open("APIs/" .. k, "r")
  57.     if f == nil then
  58.         shell.run("wget " .. v .. " APIs/" .. k)
  59.     end
  60.     io.close(f)
  61. end
  62.  
  63. for k,v in pairs(APIs) do
  64.     pcall(function()
  65.         os.loadAPI("APIs/" .. k)
  66.     end)
  67. end
  68.  
  69. -- Any files to be included that aren't APIs
  70. local localFiles_all = {
  71.    
  72. }
  73.  
  74. local localFiles_turtle = {
  75.     ["home.lua"] = "https://raw.githubusercontent.com/hunterC90/minecraftLuaCode/main/CC/home.lua?token=GHSAT0AAAAAAB7V2JHMLJYH6MNXG5V6U764ZBE55YQ"
  76. }
  77.  
  78. local localFiles_computer = {
  79.  
  80. }
  81.  
  82. local localFiles_pocket = {
  83.  
  84. }
  85.  
  86. localFiles = localFiles_all
  87. if dt == "turtle" then
  88.     for k, v in pairs(localFiles_turtle) do localFiles[k] = v end
  89. elseif dt == "pocket" then
  90.     for k, v in pairs(localFiles_computer) do localFiles[k] = v end
  91. elseif dt == "computer" then
  92.     for k, v in pairs(localFiles_pocket) do localFiles[k] = v end
  93. end
  94.  
  95. for k,v in pairs(localFiles) do
  96.     if forceLoad == "force"  or forceLoad == "f" then
  97.         shell.run("rm " .. k)
  98.     end
  99.  
  100.     local f = io.open(k, "r")
  101.     if f == nil then
  102.         shell.run("wget " .. v .. " " .. k)
  103.     end
  104.     io.close(f)
  105. end
  106.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement