SHOW:
|
|
- or go back to the newest paste.
| 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 | - | function readWS() |
| 13 | + | local msg = "" |
| 14 | ||
| 15 | - | print(ws.receive()) |
| 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 send(msg) |
| 19 | + | function broadcast() |
| 20 | - | local ok = pcall(ws.send, msg) |
| 20 | + | |
| 21 | local ok = pcall(ws.send, template:format(msg)) | |
| 22 | - | if not ok then |
| 22 | + | |
| 23 | - | print "Disconnected" |
| 23 | + | if not ok then |
| 24 | - | connect() |
| 24 | + | print "Disconnected" |
| 25 | - | send(msg) |
| 25 | + | connect() |
| 26 | sleep(0.5) | |
| 27 | broadcast() | |
| 28 | end | |
| 29 | - | function writeWS() |
| 29 | + | |
| 30 | sleep(1) | |
| 31 | end | |
| 32 | end | |
| 33 | ||
| 34 | function set_text() | |
| 35 | - | send(input) |
| 35 | + | |
| 36 | while true do | |
| 37 | write "|> " | |
| 38 | local input = read(nil, hist) | |
| 39 | - | parallel.waitForAll(writeWS, readWS) |
| 39 | + | |
| 40 | msg = input | |
| 41 | end | |
| 42 | end | |
| 43 | ||
| 44 | parallel.waitForAll(set_text, broadcast) |