Compare commits
No commits in common. "a2546cb9ba2fa5e84d30d38212faee4f898f793a" and "bacd5ac1aa63ad2e7cc5d7ba49cc31cad16ba5ef" have entirely different histories.
a2546cb9ba
...
bacd5ac1aa
3033
basalt.lua
Normal file
3033
basalt.lua
Normal file
File diff suppressed because one or more lines are too long
75
keypadOS.lua
75
keypadOS.lua
|
@ -7,21 +7,24 @@ local require = function(path)
|
|||
return __DEFAULT_IMPORT(path)
|
||||
end
|
||||
end
|
||||
local KEYPADOS_UPDATE_HASH = "ThZGemtZHshNpaflGvUHcJoZ"rawset(__BUNDLER_FILES, "updater.lua", function ()
|
||||
local KEYPADOS_UPDATE_HASH = "sxJGuLGHFrttJcPZAxUKxhPw"
|
||||
rawset(__BUNDLER_FILES, "updater.lua", function ()
|
||||
local utils = require("utils.lua")
|
||||
local config = require("config.lua")
|
||||
local LAST_USED = os.time()
|
||||
local mod = {}
|
||||
local function checkForUpdate()
|
||||
local current_time = os.time()
|
||||
local difference = math.abs(current_time - LAST_USED)
|
||||
if difference > .5 then
|
||||
print("INFO: Updating! (diff: " .. tostring(difference) .. ")")
|
||||
local update_code_request = http.get(config.release_url .. "?x=" .. tostring(math.random(11111111, 99999999))) -- I HATE CACHE REEEEEEEEEEEEEEEEE
|
||||
print("Checking for update... difference: " .. tostring(difference))
|
||||
--its been considerable time since the keypad was interacted with
|
||||
--therefore it's time to force an update down the users throat (microsoft moment)
|
||||
if difference > 10 then
|
||||
local update_code_request = http.get("https://git.mcorangehq.xyz/xomf/keypadOS/raw/branch/main/keypadOS.lua?x=" .. tostring(math.random(11111111, 99999999))) -- I HATE CACHE REEEEEEEEEEEEEEEEE
|
||||
if update_code_request then
|
||||
local update_code_text = update_code_request.readAll()
|
||||
if update_code_text then
|
||||
if string.find(update_code_text, "^local __BUNDLER_FILES = {}") then
|
||||
-- Make backup
|
||||
if fs.exists("backup.lua") then
|
||||
fs.delete("backup.lua")
|
||||
end
|
||||
|
@ -58,7 +61,7 @@ local KEYPADOS_UPDATE_HASH = "ThZGemtZHshNpaflGvUHcJoZ"rawset(__BUNDLER_FILES, "
|
|||
utils.MonPrint("Basalt found!")
|
||||
else
|
||||
utils.MonPrint("Downloading basalt...")
|
||||
local basalt_code = http.get(config.release_url).readAll()
|
||||
local basalt_code = http.get("https://raw.githubusercontent.com/Pyroxenium/Basalt/master/docs/versions/latest.lua").readAll()
|
||||
utils.MonPrint("Installing basalt...")
|
||||
local file = fs.open("basalt.lua", "w")
|
||||
if not file then
|
||||
|
@ -73,36 +76,35 @@ local KEYPADOS_UPDATE_HASH = "ThZGemtZHshNpaflGvUHcJoZ"rawset(__BUNDLER_FILES, "
|
|||
end
|
||||
end
|
||||
return mod
|
||||
end)
|
||||
|
||||
end) -- FILE END: updater.lua --
|
||||
|
||||
rawset(__BUNDLER_FILES, "config.lua", function ()
|
||||
local config = {
|
||||
correctPin = "42169",
|
||||
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",
|
||||
config_path = "keypadOS.config.lua"
|
||||
return {
|
||||
correctPin = "42069"
|
||||
}
|
||||
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)
|
||||
|
||||
end) -- FILE END: config.lua --
|
||||
|
||||
rawset(__BUNDLER_FILES, "ui.lua", function ()
|
||||
local utils = require("utils.lua")
|
||||
local basalt = require("basalt")
|
||||
local config = require("config.lua")
|
||||
local updater = require("updater.lua")
|
||||
--- @type Monitor
|
||||
local monitor = utils.Cast(peripheral.find("monitor"))
|
||||
--- @type drive
|
||||
local drive = utils.Cast(peripheral.find("drive"))
|
||||
local mod = {}
|
||||
--- @class Ui
|
||||
--- @field pin string
|
||||
--- @field main any
|
||||
--- @field pinLabel any
|
||||
--- @field enterButton any
|
||||
--- @field resetEverything function
|
||||
--- @field unlockDoor function
|
||||
--- @field addToPin function
|
||||
--- @param ui Ui
|
||||
local function resetEverything(ui)
|
||||
sleep(2)
|
||||
ui.pin = ""
|
||||
|
@ -110,6 +112,7 @@ rawset(__BUNDLER_FILES, "ui.lua", function ()
|
|||
redstone.setOutput("front", false)
|
||||
ui.enterButton:setBackground(colors.blue)
|
||||
end
|
||||
--- @param ui Ui
|
||||
local function unlockDoor(ui)
|
||||
if drive.isDiskPresent() then
|
||||
if drive.getDiskLabel() == config.correctPin then
|
||||
|
@ -137,6 +140,7 @@ rawset(__BUNDLER_FILES, "ui.lua", function ()
|
|||
resetEverything(ui)
|
||||
end)
|
||||
end
|
||||
--- @param ui Ui
|
||||
local function addToPin(ui, i)
|
||||
if #ui.pin >= 5 then
|
||||
return
|
||||
|
@ -199,12 +203,19 @@ rawset(__BUNDLER_FILES, "ui.lua", function ()
|
|||
end
|
||||
end
|
||||
return mod
|
||||
end)
|
||||
|
||||
end) -- FILE END: ui.lua --
|
||||
|
||||
rawset(__BUNDLER_FILES, "utils.lua", function ()
|
||||
local utils = {}
|
||||
-- Type coersion for lsp
|
||||
---@generic T
|
||||
---@param object any
|
||||
---@return T
|
||||
function utils.Cast(object)
|
||||
return object
|
||||
end
|
||||
--- @type Monitor
|
||||
local MONITOR = utils.Cast(peripheral.find("monitor"))
|
||||
local MONITOR_Y = 1
|
||||
function utils.MonPrint(text)
|
||||
|
@ -217,8 +228,12 @@ rawset(__BUNDLER_FILES, "utils.lua", function ()
|
|||
MONITOR.setTextScale(scale)
|
||||
end
|
||||
return utils;
|
||||
end)
|
||||
|
||||
end) -- FILE END: utils.lua --
|
||||
|
||||
rawset(__BUNDLER_FILES, "main.lua", function ()
|
||||
-- keycardOS "bootloader", has no access to basalt
|
||||
-- intended for checking for updates, and automatically updating basalt if it is missing
|
||||
local utils = require("utils.lua")
|
||||
local updater = require("updater.lua")
|
||||
local main = {}
|
||||
|
@ -231,5 +246,7 @@ rawset(__BUNDLER_FILES, "main.lua", function ()
|
|||
require("ui.lua").InitUi()
|
||||
end
|
||||
return main
|
||||
end)
|
||||
|
||||
end) -- FILE END: main.lua --
|
||||
|
||||
require("main.lua").Main()
|
||||
|
|
|
@ -1,28 +1,3 @@
|
|||
local config = {
|
||||
correctPin = "42169",
|
||||
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",
|
||||
config_path = "keypadOS.config.lua"
|
||||
return {
|
||||
correctPin = "42069"
|
||||
}
|
||||
|
||||
local DEFAULT_CONFIG = "return {\n" ..
|
||||
" group=\"default\",\n" ..
|
||||
"}\n"
|
||||
|
||||
--- @class Config
|
||||
--- @field group string
|
||||
|
||||
--- Read current configs, create if doesnt exist
|
||||
---@return Config
|
||||
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
|
||||
|
|
|
@ -2,6 +2,8 @@
|
|||
-- intended for checking for updates, and automatically updating basalt if it is missing
|
||||
local utils = require("utils.lua")
|
||||
local updater = require("updater.lua")
|
||||
|
||||
|
||||
local main = {}
|
||||
|
||||
|
||||
|
|
|
@ -122,7 +122,7 @@ function mod.InitUi()
|
|||
|
||||
if not status and err ~= "Terminated" then
|
||||
print("Error detected: " .. err)
|
||||
http.post(config.ntfy_url, err, {Priority = "urgent"}) --exposed ntfy url no spam me pls
|
||||
http.post("https://ntfy.sh/keypadOS_alerts", err, {Priority = "urgent"}) --exposed ntfy url no spam me pls
|
||||
sleep(5)
|
||||
utils.MonReset(0.5)
|
||||
fs.delete("basalt.lua")
|
||||
|
|
|
@ -1,23 +1,17 @@
|
|||
local utils = require("utils.lua")
|
||||
local config = require("config.lua")
|
||||
|
||||
local LAST_USED = os.time()
|
||||
|
||||
local mod = {}
|
||||
|
||||
-- For lsp, shouldnt ever be check for true
|
||||
if not __UPDATE_HASH then
|
||||
__UPDATE_HASH = "WHATTHEFUCK";
|
||||
end
|
||||
|
||||
local function checkForUpdate()
|
||||
local current_time = os.time()
|
||||
local difference = math.abs(current_time - LAST_USED)
|
||||
-- print("INFO: Checking for update... difference: " .. tostring(difference))
|
||||
print("Checking for update... difference: " .. tostring(difference))
|
||||
--its been considerable time since the keypad was interacted with
|
||||
--therefore it's time to force an update down the users throat (microsoft moment)
|
||||
if difference > .5 then
|
||||
print("INFO: Updating! (diff: " .. tostring(difference) .. ")")
|
||||
local update_code_request = http.get(config.release_url .. "?x=" .. tostring(math.random(11111111, 99999999))) -- I HATE CACHE REEEEEEEEEEEEEEEEE
|
||||
if difference > 10 then
|
||||
local update_code_request = http.get("https://git.mcorangehq.xyz/xomf/keypadOS/raw/branch/main/keypadOS.lua?x=" .. tostring(math.random(11111111, 99999999))) -- I HATE CACHE REEEEEEEEEEEEEEEEE
|
||||
if update_code_request then
|
||||
local update_code_text = update_code_request.readAll()
|
||||
if update_code_text then
|
||||
|
@ -28,7 +22,7 @@ local function checkForUpdate()
|
|||
end
|
||||
fs.copy("startup.lua", "backup.lua")
|
||||
|
||||
if not string.find(update_code_text, __UPDATE_HASH) then
|
||||
if not string.find(update_code_text, KEYPADOS_UPDATE_HASH) then
|
||||
local file = fs.open("startup.lua", "w")
|
||||
file.write(update_code_text)
|
||||
file.close()
|
||||
|
@ -62,7 +56,7 @@ function mod.GetBasalt()
|
|||
utils.MonPrint("Basalt found!")
|
||||
else
|
||||
utils.MonPrint("Downloading basalt...")
|
||||
local basalt_code = http.get(config.release_url).readAll()
|
||||
local basalt_code = http.get("https://raw.githubusercontent.com/Pyroxenium/Basalt/master/docs/versions/latest.lua").readAll()
|
||||
utils.MonPrint("Installing basalt...")
|
||||
|
||||
local file = fs.open("basalt.lua", "w")
|
||||
|
|
29
x.py
29
x.py
|
@ -11,34 +11,19 @@ FILES= [
|
|||
"main.lua",
|
||||
]
|
||||
|
||||
MINIMISE=True
|
||||
|
||||
def read_file(p: str) -> str:
|
||||
buf = "";
|
||||
with open("src/"+p, "r", encoding="utf-8") as f:
|
||||
buf += f"rawset(__BUNDLER_FILES, \"{p}\", function ()\n";
|
||||
buf += f"\nrawset(__BUNDLER_FILES, \"{p}\", function ()\n";
|
||||
for line in f.readlines():
|
||||
buf += " " + line;
|
||||
buf += "\nend)";
|
||||
if not MINIMISE:
|
||||
buf += f"-- FILE END: {p} --\n";
|
||||
else:
|
||||
buf += "\n";
|
||||
if str.strip(line) != "":
|
||||
buf += " " + line;
|
||||
buf += f"\nend) -- FILE END: {p} --\n";
|
||||
return buf;
|
||||
|
||||
def minimise(buf: str) -> str:
|
||||
newbuf = "";
|
||||
for line in buf.splitlines():
|
||||
if line.strip().startswith("--"):
|
||||
continue;
|
||||
if line.strip() == "":
|
||||
continue
|
||||
newbuf += line + "\n";
|
||||
return newbuf;
|
||||
|
||||
def main():
|
||||
buf = ""
|
||||
buf += "local __UPDATE_HASH = \"" + {UPDATE_ID} + "\"";
|
||||
buf += "local __BUNDLER_FILES = {}\n";
|
||||
buf += "local __DEFAULT_IMPORT = require\n";
|
||||
buf += "local require = function(path)\n";
|
||||
|
@ -48,16 +33,14 @@ def main():
|
|||
buf += " return __DEFAULT_IMPORT(path)\n";
|
||||
buf += " end\n";
|
||||
buf += "end\n";
|
||||
buf += f'local KEYPADOS_UPDATE_HASH = "{UPDATE_ID}"';
|
||||
|
||||
for file in FILES:
|
||||
print(f"=== FILE: {file}");
|
||||
buf += read_file(file);
|
||||
print(f"=== UPDATE HASH: {UPDATE_ID}")
|
||||
|
||||
buf += "require(\"main.lua\").Main()\n";
|
||||
|
||||
if MINIMISE:
|
||||
buf = minimise(buf);
|
||||
buf += "\nrequire(\"main.lua\").Main()\n";
|
||||
|
||||
with open(OUTPUT, "w", encoding="utf-8") as f:
|
||||
f.write(buf);
|
||||
|
|
Loading…
Reference in New Issue
Block a user