Advertisement
domian844

[OpenComputers] GT Miner Telegram

Jan 17th, 2021
1,458
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.71 KB | None | 0 0
  1. comp = require("component")
  2. miner = comp.gt_machine
  3. screen = require("term")
  4. GPU1 = comp.gpu
  5. computer = require("computer")
  6. event = require("event")
  7.  
  8. screenWidth = 160
  9. screenHeight = 40
  10. errorColor = 0xCC0000
  11. idleColor = 0xc0cc00
  12. goodColor = 0x00cc0e
  13. local state = "off"
  14.  
  15. local internet = comp.internet
  16.  
  17. Telegram = {
  18.     "", ""
  19. }
  20.  
  21. function SendTelega(Text)
  22.     local url ="https://api.telegram.org/bot"..Telegram[1].."/sendMessage?chat_id="..Telegram[2].."&text="..Text
  23.     internet.request(url)
  24. end
  25.  
  26. function write(x, y, text, color)
  27.     color = color
  28.     screen.setCursor(x, y)
  29.     oldColor = GPU1.setForeground(color)
  30.     screen.write(text)
  31.     GPU1.setForeground(oldColor)
  32. end
  33.  
  34. function box(x, y, w, h, color)
  35.     local oldColor = GPU1.setBackground(color)
  36.     GPU1.fill(x, y, w, h, " ")
  37.     GPU1.setBackground(oldColor)
  38. end
  39.  
  40. function MachineGT(step)
  41.     x = 0
  42.     y = 0
  43.     maintenanceIndex = 0
  44.     uses = 0
  45.     for i = 1, #miner.getSensorInformation() do
  46.         if string.match(miner.getSensorInformation()[i], "Problems") then
  47.             maintenanceIndex = i
  48.         end
  49.     end
  50.     for i = 1, #miner.getSensorInformation() do
  51.         if string.match(miner.getSensorInformation()[i], "Probably") then
  52.             uses = i
  53.         end
  54.     end
  55.  
  56.     if (miner.isMachineActive()) then
  57.         write(x + 1, y + 2, "                             ", goodColor)
  58.         write(x + 1, y + 2, "Miner Worked!", goodColor)
  59.         if step % 1800 == 0 then
  60.             SendTelega("Miner worked: ".. step/60 .. "min")
  61.         end
  62.     end
  63.  
  64.     if (maintenanceIndex == 0 or string.match(miner.getSensorInformation()[maintenanceIndex], "c0")) and miner.isWorkAllowed() then
  65.     else
  66.         if (miner.isWorkAllowed()) then
  67.             write(x + 1, y + 2, "                             ", errorColor)
  68.             write(x + 1, y + 2, "Needs maintenance!", errorColor)
  69.             if step % 60 == 0 then
  70.                 SendTelega("Needs maintenance!")
  71.             end
  72.         else
  73.             write(x + 1, y + 2, "                             ", errorColor)
  74.             write(x + 1, y + 2, "Miner disabled!", idleColor)
  75.             if step % 60 == 0 then
  76.                 SendTelega("Miner Not Worked")
  77.             end
  78.         end
  79.     end
  80. end
  81.  
  82. screen.clear()
  83. step = 1
  84. i = 1
  85.  
  86. while (true) do
  87.     GPU1.setResolution(20, 5)
  88.     step = step + 1
  89.     MachineGT(step)
  90.     write(1, 3, "[ "..(step).." sec ]", idleColor)
  91.     if step % 60 == 0 then
  92.         write(1, 4, "[ "..(i).." min ]", idleColor)
  93.         i = i + 1
  94.     end
  95.     -- Выключить программу ctrl+c
  96.     os.sleep(1)
  97.     if event.pull(.5, "interrupted") then
  98.         screen.clear()
  99.         break
  100.     end
  101. end
  102.  
  103.  
  104.  
  105.  
  106.  
  107.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement