Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- least time to shut down at
- local STOPAT = "05:00"
- -- ammount of minutes before shutdown should happen
- -- to ensure shut down will not be skipped in loop
- -- cycles
- local MARGIN = 10
- -- check every x loop cycles
- local CHECKEVERY = 20
- -- An API which returns the current time on GET
- -- request in the default strftime format:
- -- '%A, %d-%h-%G %T %Z'
- local TIMEAPI = "https://api.zekro.de/time"
- -- The POST webhook to send coordinate data to
- local POSITION_WEBHOOK = "https://maker.ifttt.com/trigger/framer_moved/with/key/EXAMPLEKEYUSEYOUROWNHERE"
- -- The name to be used for the webhook to
- -- identify this computer
- local POSITION_NAME = os.getComputerLabel() or "default"
- -- The direction vector where the framer is headed
- -- to to calculate current position after move
- local POSITION_MOVE_VEC = vector.new(-1, 0, 0)
- -- The file to save the current position to
- local POSITION_FILE = "curr.pos"
- ---------------------------------------------
- local function parseTime(s)
- time = s:match('%d%d:%d%d')
- h = tonumber(time:sub(1, 2))
- m = tonumber(time:sub(4, 5))
- return h, m
- end
- local function getTime()
- res = http.get(TIMEAPI)
- if not res then
- sleep(0.5)
- return getTime()
- end
- time = res.readLine()
- return parseTime(time)
- end
- local function checkExit(h, m)
- ch, cm = getTime()
- return ch == h and cm >= m-MARGIN and cm <= m
- end
- local function writePositionToFile(vec)
- f = fs.open(POSITION_FILE, "w")
- f.writeLine(vec.x)
- f.writeLine(vec.y)
- f.writeLine(vec.z)
- f.close()
- end
- local function readPositionFromFile()
- f = fs.open(POSITION_FILE, "r")
- vec = vector.new(0, 0, 0)
- if f then
- vec.x = f.readLine()
- vec.y = f.readLine()
- vec.z = f.readLine()
- f.close()
- end
- return vec
- end
- local function postPosition(name, x, z)
- if not POSITION_WEBHOOK then return end
- http.post(
- string.format(
- "%s?value1=%s&value2=%d&value3=%d",
- POSITION_WEBHOOK,
- name, x, z
- )
- )
- end
- local function pulse(side)
- redstone.setOutput(side, true)
- sleep(0.5)
- redstone.setOutput(side, false)
- sleep(0.5)
- end
- local function moveFrame()
- pulse("bottom")
- sleep(0.2)
- pulse("bottom")
- sleep(0.2)
- end
- local function dig()
- pulse("right")
- sleep(3)
- while redstone.getInput("left") == true do
- print("Waiting")
- event = os.pullEvent("redstone")
- sleep(0.2)
- end
- end
- local hstop, mstop = parseTime(STOPAT)
- local currpos = readPositionFromFile()
- local count = 0
- print("Ready")
- while true do
- sleep(0.2)
- if redstone.getInput("back") == true then
- print("Performing")
- dig()
- moveFrame()
- currpos = currpos + POSITION_MOVE_VEC
- print("Pos: ", currpos)
- writePositionToFile(currpos)
- count = count + 1
- if count >= CHECKEVERY then
- postPosition(POSITION_NAME, currpos.x, currpos.z)
- if checkExit(hstop, mstop) then
- print("Scheduled Stop")
- return
- end
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement