Command parser now can catch exceptions (finally). Cleaned up code

This commit is contained in:
Logan G 2022-03-26 02:34:57 -06:00
parent 5c097d9fe0
commit fc64f35512
Signed by: logan
GPG key ID: E328528C921E7A7A

View file

@ -87,7 +87,7 @@ do
if plys == #find.allPlayers() then timer.remove("displaystats") displayStats() end
end)
core:log(log.INFO, "Collecting data, please wait.")
core:log(log.INFO, "Collecting data, please wait...")
end
local function hud()
@ -114,7 +114,9 @@ do
table.insert(modules, core.colors.logo)
table.insert(modules, "[L-SFT] ")
table.insert(modules, core.colors.info)
table.insert(modules, "\""..i.."\" | "..(v.desc or "No description provided.").."\n")
table.insert(modules, "\""..i.."\" | ")
table.insert(modules, core.colors.text)
table.insert(modules, (v.desc or "No description provided.").."\n")
end
modules[#modules] = modules[#modules]:sub(1, -2)
print(unpack(modules))
@ -130,7 +132,9 @@ do
table.insert(commands, core.colors.logo)
table.insert(commands, "[L-SFT] ")
table.insert(commands, core.colors.info)
table.insert(commands, "\""..i.."\" | Usage: "..(v.usage or "No usage provided.").."\n")
table.insert(commands, "\""..i.."\" | Usage: ")
table.insert(commands, core.colors.text)
table.insert(commands, (v.usage or "No usage provided.").."\n")
end
commands[#commands] = commands[#commands]:sub(1, -2)
print(unpack(commands))
@ -139,8 +143,8 @@ do
elseif module ~= nil and command ~= nil then
if not core.modules[module].commands[command] then core:log(log.ERROR, "Command does not exist in module \""..module.."\"!") return end
core:log(log.TEXT, "---------------------------")
core:log(log.INFO, "Usage: "..(core.modules[module].commands[command].usage or "Command: "..command.." (No usage provided)"))
core:log(log.INFO, "Description: "..(core.modules[module].commands[command].desc or "No description provided."))
core:log(log.INFO, "Usage: ", core.colors.text, (core.modules[module].commands[command].usage or "Command: "..command.." (No usage provided)"))
core:log(log.INFO, "Description: ", core.colors.text, (core.modules[module].commands[command].desc or "No description provided."))
core:log(log.TEXT, "---------------------------")
else
core:log(log.ERROR, "Universe is broken.")
@ -160,7 +164,7 @@ do
hud = {
func = hud,
usage = "hud",
desc = "Toggles the built in Starfall HUD",
desc = "Toggles the built in Starfall HUD.",
},
help = {
desc = "List modules, list commands in a module or gets information about a specific command.",
@ -179,7 +183,7 @@ core.defaultconfig = {
colors = {
logo = Color(255,200,50),
text = Color(255,255,255),
info = Color(50,150,255),
info = Color(150,200,255),
warn = Color(255,120,50),
error = Color(255,50,50),
},
@ -195,12 +199,14 @@ core.defaultconfig = {
},
}
core.colors = {}
core.maxCPU = 0
core.minNet = net.getBytesLeft()
core.maxRAM = 0
log = {
ERROR=0,
WARNING=1,
@ -294,7 +300,10 @@ function core:load_modules()
for i, v in pairs(core.modules) do
for commandin, commandthing in pairs(v["commands"]) do
if command == commandin then
commandthing.func({unpack(args)})
try(
function() commandthing.func({unpack(args)}) end,
function(err) core:log(log.ERROR, "Error executing command \""..str.."\"!") core:log(log.ERROR, "Reason: "..err["message"]) end
)
return ""
end
end
@ -433,5 +442,4 @@ timer.create("RAMCheck", 0.5, 0, function()
elseif ramUsed() > ramMax() * 0.9 then
core:log(log.ERROR, "RAM usage is critically high! ("..math.round(ramUsed()*100/ramMax()).."% used)")
end
end)
end)