Advertisement
Guest User

reactor_monitor

a guest
Apr 6th, 2020
391
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.26 KB | None | 0 0
  1. local monitor = peripheral.find("monitor")
  2. local reactor = peripheral.find("BigReactors-Reactor")
  3.  
  4. local rodSize = 4
  5.  
  6. function clear()
  7.     term.clear()
  8.     term.setBackgroundColor(colors.black)
  9.     term.setCursorPos(1,1)
  10. end
  11.  
  12. function drawRods(sx, sy)
  13.  
  14.     local controlRods = reactor.getNumberOfControlRods()
  15.  
  16.     for i=1,controlRods do
  17.         term.setCursorPos(1,1)
  18.         local percent = reactor.getControlRodLevel(i-1)/100.0
  19.        
  20.         local h = math.floor(percent*rodSize)
  21.        
  22.         if percent == 1 then
  23.             h = rodSize-1
  24.         end
  25.        
  26.         local left = (rodSize-h)-1
  27.         local x = sx+i*2
  28.         local y = sy
  29.        
  30.         if i > 10 then
  31.             y = y + rodSize+1
  32.             x = sx + (i-10)*2
  33.         end
  34.        
  35.         --write(tostring(i)..' '..tostring(h))
  36.         --x,y,width,height
  37.         paintutils.drawFilledBox(x, y, x, y+h, colours.green)
  38.        
  39.         if percent < 1 then
  40.           paintutils.drawFilledBox(x, y+h, x, (y+h)+left, colours.red)
  41.         end
  42.     end
  43.  
  44.     term.setBackgroundColor(colours.black)
  45. end
  46.  
  47. function drawHeader()
  48.     local activeText = "Active"
  49.    
  50.     if not reactor.getActive() then
  51.         activeText = "Disabled"
  52.     end
  53.    
  54.     write("Reactor "..activeText.."\n")
  55. end
  56.  
  57. function discordNotify(botName, message)
  58.     local postDataTable = {
  59.         username = botName,
  60.         content = message
  61.     }
  62.     local postData = textutils.serializeJSON( postDataTable )
  63.     local headers = {
  64.         ["Content-Type"] = "application/json"
  65.     }
  66.  
  67.  write(postData)
  68.     -- Make a HTTP request
  69.     local request,err = http.post("https://discordapp.com/api/webhooks/696901545643606046/Ki7Un8TIliV9qpMNtOaWdevL_z1YcRYw-kpZsVo18TvueOqI3UesNowY2b5ZlZhYq4Zj", postData, headers)
  70.    
  71.  if not request then error(err) end
  72.  
  73.  request.close()
  74. end
  75.  
  76. term.redirect(monitor)
  77. monitor.setTextScale(0.5)
  78.  
  79. local updates = 0
  80. local screenUpdateEvery = 10
  81.  
  82. while true do
  83.     --if updates >= screenUpdateEvery then
  84.     --  clear()
  85.     --  drawHeader()
  86.     --  drawRods(1, 4)
  87.        
  88.     --  updates = 0
  89.     --end
  90.    
  91.  clear()
  92.     local time = textutils.formatTime(os.time("local"), true)
  93.     write(time)
  94.    
  95.  if time == "17:00" or time == "10:00" then
  96.      discordNotify("Reactor", "Test")    
  97.  end
  98.    
  99.  sleep(10)
  100.     --updates = updates + 1
  101. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement