Advertisement
osmarks

Govos Street Sign

Mar 3rd, 2019
188
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. local key = settings.get "govos.key"
  2. if not key then error "GovOS RDS key not found." end
  3. local ws, err = http.websocket("wss://osmarks.tk/wsthing/GovOS/admin", {
  4.     authorization = "Key " .. key
  5. })
  6.  
  7. if err then
  8.     error(err)
  9. else
  10.     print "Connected"
  11. end
  12.  
  13. local msg = ""
  14.  
  15. local template = [[
  16. peripheral.find("monitor", function(_, o) o.setCursorPos(1, 1); o.setBackgroundColor(colors.green); o.clearLine(); o.setTextColor(colors.white); o.clearLine(); o.write(%q) end)
  17. ]]
  18.  
  19. function broadcast()
  20.     while true do
  21.         local ok = pcall(ws.send, template:format(msg))
  22.  
  23.         if not ok then
  24.             print "Disconnected"
  25.             connect()
  26.             sleep(0.5)
  27.             broadcast()
  28.         end
  29.        
  30.         sleep(1)
  31.     end
  32. end
  33.  
  34. function set_text()
  35.     local hist = {}
  36.     while true do
  37.         write "|> "
  38.         local input = read(nil, hist)
  39.         table.insert(hist, input)
  40.         msg = input
  41.     end
  42. end
  43.  
  44. parallel.waitForAll(set_text, broadcast)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement