Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local myURL = "promoted-goshawk-publicly.ngrok-free.app"
- local file = fs.open("apps/token", "r")
- local token = file.readAll()
- file.close()
- local ws = assert(http.websocket("wss://" .. myURL .. "?token=" .. token))
- function inspect()
- local below, result = turtle.inspectDown()
- if below then
- ws.send(textutils.serialiseJSON(result))
- end
- local up, result = turtle.inspectUp()
- if up then
- ws.send(textutils.serialiseJSON(result))
- end
- local front, result = turtle.inspect()
- if front then
- ws.send(textutils.serialiseJSON(result))
- end
- end
- function forward()
- turtle.forward()
- inspect()
- end
- function up()
- turtle.up()
- inspect()
- end
- function back()
- turtle.back()
- inspect()
- end
- function down()
- turtle.down()
- inspect()
- end
- function right()
- turtle.turnRight()
- inspect()
- end
- function left()
- turtle.turnLeft()
- inspect()
- end
- function fuel()
- local fuel = turtle.getFuelLevel()
- if fuel == 0 then
- turtle.refuel()
- end
- end
- function mine()
- local broken, why = turtle.dig('right')
- if broken == false then
- ws.send(textutils.serialise(why))
- end
- end
- function mineUp()
- local broken, why = turtle.digUp('right')
- if broken == false then
- ws.send(textutils.serialise(why))
- end
- end
- function mineDown()
- local broken, why = turtle.digDown('right')
- if broken == false then
- ws.send(textutils.serialise(why))
- end
- end
- function place()
- local placed, why = turtle.place('right')
- if placed == false then
- ws.send(textutils.serialise(why))
- end
- end
- function placeUp()
- local placed, why = turtle.placeUp('right')
- if placed == false then
- ws.send(textutils.serialise(why))
- end
- end
- function placeDown()
- local placed, why = turtle.placeDown('right')
- if placed == false then
- ws.send(textutils.serialise(why))
- end
- end
- while true do
- fuel()
- message = ws.receive()
- print("Received: " .. message)
- if message == 'back' then
- back()
- end
- if message == 'forward' then
- forward()
- end
- if message == 'up' then
- up()
- end
- if message == 'down' then
- down()
- end
- if message == 'left' then
- left()
- end
- if message == 'right' then
- right()
- end
- if message == 'mine' then
- mine()
- end
- if message == 'mineUp' then
- mineUp()
- end
- if message == 'mineDown' then
- mineDown()
- end
- if message == 'place' then
- place()
- end
- if message == 'placeUp' then
- placeUp()
- end
- if message == 'placeDown' then
- placeDown()
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement