rtmc/keypadOS.lua

200 lines
6.3 KiB
Lua
Raw Permalink Normal View History

2024-08-18 00:34:13 +00:00
local __BUNDLER_FILES = {}
local __DEFAULT_IMPORT = require
local require = function(path)
2024-08-18 00:43:01 +00:00
if __BUNDLER_FILES[path] then
return __BUNDLER_FILES[path]()
2024-08-25 21:04:22 +00:00
elseif __BUNDLER_FILES[path .. ".lua"] then
return __BUNDLER_FILES[path .. ".lua"]()
else
return __DEFAULT_IMPORT(path)
2024-08-18 00:43:01 +00:00
end
2024-08-17 23:08:11 +00:00
end
2024-08-25 21:16:13 +00:00
local __UPDATE_HASH = "5e1c10aba96c3f9ded6aecb030f2774577c005af"
rawset(__BUNDLER_FILES, "updater.lua", function ()
2024-08-18 00:34:13 +00:00
local utils = require("utils.lua")
2024-08-18 11:37:59 +00:00
local config = require("config.lua")
2024-08-18 01:34:08 +00:00
local mod = {}
function mod.GetBasalt()
2024-08-18 00:34:13 +00:00
if fs.exists("basalt.lua") then
utils.MonPrint("Basalt found!")
else
utils.MonPrint("Downloading basalt...")
2024-08-21 02:19:45 +00:00
local basalt_code = http.get(config.basalt_url).readAll()
2024-08-18 00:34:13 +00:00
utils.MonPrint("Installing basalt...")
local file = fs.open("basalt.lua", "w")
if not file then
utils.MonPrint("failed to get basalt")
sleep(60)
os.reboot()
end
2024-08-18 00:36:52 +00:00
file.write(utils.Cast(basalt_code))
2024-08-18 00:34:13 +00:00
file.close()
utils.MonPrint("Rebooting...")
os.reboot()
end
2024-08-17 23:08:11 +00:00
end
2024-08-18 01:34:08 +00:00
return mod
2024-08-18 11:37:59 +00:00
end)
2024-08-18 01:13:38 +00:00
rawset(__BUNDLER_FILES, "config.lua", function ()
2024-08-18 11:37:59 +00:00
local config = {
correctPin = "42069",
2024-08-18 11:37:59 +00:00
release_url = "https://git.mcorangehq.xyz/xomf/keypadOS/raw/branch/main/keypadOS.lua",
basalt_url = "https://raw.githubusercontent.com/Pyroxenium/Basalt/master/docs/versions/latest.lua",
ntfy_url = "https://ntfy.sh/keypadOS_alerts",
2024-08-18 11:37:59 +00:00
config_path = "keypadOS.config.lua"
2024-08-18 00:34:13 +00:00
}
2024-08-18 11:37:59 +00:00
local DEFAULT_CONFIG = "return {\n" ..
" group=\"default\",\n" ..
"}\n"
function config.ReadConfig()
if not fs.exists(config.config_path) then
local f = fs.open(config.config_path, "w")
f.write(DEFAULT_CONFIG)
f.close();
end
local cfg = require(config.config_path)
return cfg
end
return config
end)
2024-08-18 01:13:38 +00:00
rawset(__BUNDLER_FILES, "ui.lua", function ()
2024-08-18 00:36:52 +00:00
local utils = require("utils.lua")
2024-08-18 00:34:13 +00:00
local basalt = require("basalt")
local config = require("config.lua")
local updater = require("updater.lua")
2024-08-18 00:36:52 +00:00
local monitor = utils.Cast(peripheral.find("monitor"))
local drive = utils.Cast(peripheral.find("drive"))
2024-08-18 01:34:08 +00:00
local mod = {}
2024-08-18 02:15:40 +00:00
local function resetEverything(ui)
sleep(2)
ui.pin = ""
ui.pinLabel:setText("")
redstone.setOutput("front", false)
ui.enterButton:setBackground(colors.blue)
end
2024-08-18 00:34:13 +00:00
local function unlockDoor(ui)
2024-08-17 23:08:11 +00:00
if drive.isDiskPresent() then
2024-08-18 00:34:13 +00:00
if drive.getDiskLabel() == config.correctPin then
ui.pin = config.correctPin
2024-08-17 23:08:11 +00:00
drive:ejectDisk()
end
end
2024-08-18 00:34:13 +00:00
if ui.pin == config.correctPin then
2024-08-25 20:47:51 +00:00
blibs.notifier.notify("5", "Unlocked door :3 love u");
2024-08-18 00:34:13 +00:00
ui.enterButton:setBackground(colors.green)
ui.pinLabel:setText("Welcome")
redstone.setOutput("front", true)
if drive.isDiskPresent() then
if drive.getDiskLabel() == nil then
drive.setDiskLabel(config.correctPin)
ui.pinLabel:setText("Crd set")
drive:ejectDisk()
end
end
else
ui.pinLabel:setText("Wrong")
ui.enterButton:setBackground(colors.red)
end
2024-08-18 02:09:44 +00:00
ui.main:addThread():start(function()
2024-08-18 02:15:40 +00:00
resetEverything(ui)
2024-08-18 02:09:44 +00:00
end)
2024-08-17 23:08:11 +00:00
end
2024-08-18 00:34:13 +00:00
local function addToPin(ui, i)
if #ui.pin >= 5 then
return
end
ui.pin = ui.pin .. tostring(i)
ui.pinLabel:setText(ui.pin)
end
2024-08-18 01:34:08 +00:00
function mod.InitUi()
2024-08-18 00:34:13 +00:00
local ui = {
2024-08-18 01:56:03 +00:00
pin = "",
2024-08-18 01:40:57 +00:00
main = basalt.addMonitor(),
2024-08-18 00:34:13 +00:00
}
ui.main:setMonitor(monitor)
ui.pinLabel = ui.main:addLabel()
:setText("")
:setFontSize(1)
ui.enterButton = ui.main:addButton()
:setText(">>>>")
:setBackground(colors.blue)
2024-08-18 03:24:30 +00:00
:setPosition(6,2)
2024-08-18 00:34:13 +00:00
:setSize(1.5,3.2)
:onClick(function()
unlockDoor(ui)
end)
local btnX = 1
2024-08-18 03:24:30 +00:00
local btnY = 2
ui.main:addButton()
:setPosition(1, 5)
:setText("0")
:setSize(6,1)
:onClick(function()
addToPin(ui, 0)
end)
2024-08-18 00:34:13 +00:00
for i = 1, 9 do
ui.main:addButton()
:setPosition(btnX, btnY)
:setText(tostring(i))
:setSize(2,1)
:onClick(function()
addToPin(ui, i)
end)
btnX = btnX + 2
if btnX >= 6 then
btnY = btnY + 1
btnX = 1
end
end
2024-08-18 01:50:23 +00:00
local status, err = pcall(function ()
2024-08-25 19:00:12 +00:00
parallel.waitForAll(basalt.autoUpdate)
2024-08-18 00:34:13 +00:00
end)
2024-08-18 02:02:09 +00:00
if not status and err ~= "Terminated" then
2024-08-25 21:16:13 +00:00
log.error("Error detected: " .. err)
blibs.notifier.notify("5", err); --exposed ntfy url no spam me pls
sleep(5)
utils.MonReset(0.5)
2024-08-18 00:34:13 +00:00
fs.delete("basalt.lua")
fs.delete("startup.lua")
fs.copy("backup.lua", "startup.lua")
2024-08-18 02:28:14 +00:00
os.reboot()
2024-08-18 00:34:13 +00:00
end
end
2024-08-18 01:34:08 +00:00
return mod
2024-08-18 11:37:59 +00:00
end)
2024-08-18 01:13:38 +00:00
rawset(__BUNDLER_FILES, "utils.lua", function ()
2024-08-18 01:34:08 +00:00
local utils = {}
function utils.Cast(object)
2024-08-18 00:39:01 +00:00
return object
end
2024-08-18 01:35:45 +00:00
local MONITOR = utils.Cast(peripheral.find("monitor"))
2024-08-18 00:34:13 +00:00
local MONITOR_Y = 1
2024-08-18 01:34:08 +00:00
function utils.MonPrint(text)
2024-08-18 00:34:13 +00:00
MONITOR.setCursorPos(1,MONITOR_Y)
MONITOR.write(text)
MONITOR_Y = MONITOR_Y + 1
end
2024-08-18 01:34:08 +00:00
function utils.MonReset(scale)
2024-08-18 00:34:13 +00:00
MONITOR.clear()
MONITOR.setTextScale(scale)
end
2024-08-18 01:34:08 +00:00
return utils;
2024-08-18 11:37:59 +00:00
end)
2024-08-18 01:13:38 +00:00
rawset(__BUNDLER_FILES, "main.lua", function ()
2024-08-18 00:34:13 +00:00
local utils = require("utils.lua")
local updater = require("updater.lua")
2024-08-25 20:47:51 +00:00
local mod = {}
KEYPADOS_VERSION = "4.0"
2024-08-25 20:47:51 +00:00
function mod.main(blibs)
2024-08-25 21:16:13 +00:00
_G.log = blibs.log;
2024-08-25 21:13:01 +00:00
_G.blibs = blibs;
2024-08-18 02:41:05 +00:00
utils.MonReset(0.5)
2024-08-18 01:36:42 +00:00
updater.GetBasalt()
2024-08-18 00:34:13 +00:00
utils.MonPrint("keypadOS v" .. KEYPADOS_VERSION)
2024-08-18 02:41:05 +00:00
utils.MonReset(1)
2024-08-18 01:45:34 +00:00
require("ui.lua").InitUi()
2024-08-17 23:08:11 +00:00
end
2024-08-25 20:47:51 +00:00
return mod;
2024-08-18 11:37:59 +00:00
end)
2024-08-25 20:58:57 +00:00
return require("main.lua")