Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- K_VERSION = 0.093
- function _print(message)
- wrap = function(str) return "| " .. str .. string.rep(" ", 35 - string.len(str)) .. " |" end
- split = function() print(string.rep("- ", 20)) end
- _read = function() print("»", message, "«") return read() end
- write = function() print(wrap(message)) end
- sub = function() print(wrap(" » " .. message)) end
- raw = function() print(message) end
- return { split = split, write = write, read = _read, sub = sub, raw = raw }
- end
- function message()
- function printTitle()
- _print(" Diggy Turtle v" .. getVersion(getRemoteData("Pu8jbGue")) .. " by omr").raw()
- _print().split()
- end
- function info()
- printTitle()
- _print("Features:").write()
- _print("Auto-update").sub()
- _print("Auto-resume").sub()
- _print("Usage:").write()
- _print("Start position: Bottom Right").sub()
- _print("Chest position: Above turtle").sub()
- _print("Fuel slot: Last").sub()
- _print("Run: " .. fs.getName(shell.getRunningProgram()) .. " <Length> <Width> <Height>").sub()
- _print().split()
- end
- function status(params)
- resetScreen()
- printTitle()
- _print("Details:").write()
- _print("Size (x:y:z): " .. params[1] .. ":" .. params[2] .. ":" .. params[3]).sub()
- _print("Fuel: " .. turtle.getFuelLevel()).sub()
- _print().split()
- if (params[4]) then
- _print("Resuming...").raw()
- end
- end
- return { info = info, status = status }
- end
- function resetScreen()
- term.clear()
- term.setCursorPos(1, 1)
- end
- function getRemoteData(id)
- if (not http) then return end
- local httpResponce = http.get("http://pastebin.com/raw.php?i=" .. id)
- local data = httpResponce.readAll()
- httpResponce.close()
- return data
- end
- function getLocalData(name)
- local file = fs.open(name, "r")
- local data = file.readAll()
- file.close()
- return data
- end
- function getVersion(data)
- local _, versionIndex = string.find(data, 'K_VERSION *= *')
- if (versionIndex) then return tonumber(string.match(data, '%d+[%.?%d*]*', versionIndex + 1))
- else return 0 end
- end
- function loadLib(id, name, isAPI)
- if (not fs.exists(name)) then
- shell.run("pastebin get " .. id .. " " .. name)
- assert(fs.exists(name), "Connection issue, try again later")
- end
- if (isAPI) then
- os.loadAPI(name)
- else
- local remoteVersion = getVersion(getRemoteData(id))
- local localVersion = getVersion(getLocalData(name))
- if (localVersion < remoteVersion) then
- shell.run("rm " .. name)
- shell.run("pastebin get " .. id .. " " .. name)
- os.reboot()
- --shell.run(shell.getRunningProgram())
- end
- end
- end
- function saveParams(table)
- local file = fs.open("resumeParams", "w")
- file.write(textutils.serialize(table))
- file.close()
- return true
- end
- function loadParams()
- if (fs.exists("resumeParams")) then
- local file = fs.open("resumeParams", "r")
- local data = file.readAll()
- file.close()
- local params = textutils.unserialize(data)
- table.insert(params, "true")
- return params
- else
- local params
- if (#args ~= 3) then
- local z = tonumber(_print("Enter length").read())
- assert(type(z) == "number" and z > 0, "Value must be a number and greater than 0")
- local x = tonumber(_print("Enter width").read())
- assert(type(x) == "number" and x > 0, "Value must be a number and greater than 0")
- local y = tonumber(_print("Enter height").read())
- assert(type(y) == "number" and y > 0, "Value must be a number and greater than 0")
- params = {x, y, z}
- else
- params = args
- end
- saveParams(params)
- return params;
- end
- end
- function run()
- message().info()
- local params = loadParams()
- message().status(params)
- if (shell.run("diggyturtle", unpack(params))) then
- _print("Mining finished!").raw()
- fs.delete("resumeParams")
- fs.delete("/.lama/")
- else
- _print("Mining aborted!").raw()
- end
- end
- function main()
- resetScreen()
- loadLib("qDaGHBU3", "lama", true)
- loadLib("Pu8jbGue", "diggyturtle")
- loadLib("85G2W3Hz", shell.getRunningProgram())
- run()
- end
- args = { ... }
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement