FoxWorn3365

MERDOR - ARC [1]

Jun 10th, 2021 (edited)
162
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. -- MERDOR (FIH) & ARC (CFG)
  2. -- Variabili di MERDOR
  3. pc1 = ""
  4. rednetPos = "top"
  5.  
  6. -- MERDOR di [[1]]
  7.  
  8. rednet.open("top")
  9.  
  10. --Inizializzo le funzioni
  11. function getAPI(API, computer)
  12.     risposta = http.get("https://arc.rgbcraft.com/api/get/switch?token="..token.."&computer="..computer)
  13.     if risposta ~= nil and ris ~= "" then
  14.         a = http.get("https://arc.rgbcraft.com/api/get/switch?token="..token.."&computer="..computer).readAll()
  15.         b = textutils.unserialize(a)
  16.     end
  17.     return b
  18. end
  19.  
  20. function header(text)
  21.     term.setCursorPos(18, 1)
  22.     print(text)
  23. end
  24.  
  25. function interfacciaNonConfigurata()
  26.     term.clear()
  27.     header("MERDOR - Installazione")
  28.     print("\n\nInserisci il token di Arc")
  29.     local tokenArc = read()
  30.     print("\nPerfetto! Ora inserisci il numero del Computer di Arc!")
  31.     print("RICORDA che Computer1 su arc e' 0 e Computer2 e' 1")
  32.     local pcArc = read()
  33.    
  34.     -- Sistemo tutto nel file di configurazione
  35.     file = fs.open(".settings", "w")
  36.     file.writeLine("token = '"..tokenArc.."'")
  37.     file.writeLine("computer = "..pcArc)
  38.     file.close()
  39.     -- Restarto il programma
  40.     shell.run("startup")
  41. end
  42.  
  43. function interfacciaUtente()
  44.     term.clear()
  45.     header("MERDOR & ARC")
  46.     print("\n\nMERDOR e Arc stanno lavorando correttamente su questo computer")
  47.     print("\nPer fermare il programma fai CTRL + T per 5 secondi")
  48. end
  49.  
  50. function apiElaborateToken(pc1, api, computer, repe)
  51.     local api = getAPI(api, computer)
  52.     me1 = api.left
  53.    
  54.     if me1 == 1  and repe ~= 1 then
  55.         -- Merdor1
  56.         rednet.send(pc1, "ON")
  57.         print("MERDOR 1 [ OFF -> ON ]")
  58.     end
  59.     elseif me1 == 0 then
  60.         rednet.send(pc1, "OFF")
  61.         print("MERDOR 1 [ ON -> OFF ]")
  62.     end
  63. end
  64.  
  65.      
  66. -- Inizio il programma
  67. term.clear()
  68. if fs.exists(".settings") == false then
  69.     interfacciaNonConfigurata()
  70. else
  71.     shell.run(".settings")
  72.     interfacciaUtente()
  73.     while true do
  74.             local repe = apiElaborateToken(pc1, token, computer, repe)
  75.             sleep(0.5)
  76.     end
  77. end
  78.    
  79.  
  80.  
  81.  
  82.  
  83.  
  84.  
Add Comment
Please, Sign In to add comment