spiffbot/lua/loader.lua
2024-10-11 01:46:51 -03:00

76 lines
2.7 KiB
Lua

sys.registerCommand({
aliases = { "h" }, -- other strings that you can run the command from
pretty_name = "Help", -- the name of the command as it shows up in menues and other commands that use its pretty name
name = "help", -- the main required string used to call the command
command_category = commandCategory.info, -- this can be any string, but the bot provides a few categories already
help = "Shows you helpful information for the bot. Seems you already know how to use it. :loafplink:",
timeout = nil, -- time in milliseconds that the user must wait before running the command again
hidden = false, -- whether or not other commands should acknowledge its existence, for example we dont want dev commands showing up in the help info for regular users, regardless if they can use them or not
permissions = nil, -- which discord permissions they need to run the command
arguments = {
{
type = "positional",
position = 0,
optional = true,
data_type = "string",
checker = function(var)
for index, value in ipairs(sys.getCommandTable()) do
if value == var then
return; -- exit normally because the command was found
end
end
-- throw an error to whoever ran this function saying the command does not exist
error("Command `" .. var .. "` does not exist.", 2)
end,
},
},
func = function(context, message, guildid, commandArguments)
if commandArguments.getArgument(0) ~= nil then
log.info("Help info for command `" .. commandArguments.getArgument(0) .. "`")
else
log.info("Here is a list of all commands:")
for index, value in pairs(sys.getCommandTable()) do
if not value.hidden then
log.info("\tCommand pretty name: " .. value.pretty_name)
log.info("\tCommand name: " .. value.name)
log.info("\tCommand aliases: " .. value.aliases)
log.info("\tCommand category: " .. value.category)
log.info("\tCommand help info: " .. value.help)
end
end
end
end
})
sys.executeCommand("help", "help")
sys.executeCommand("help")
-- since the next usage will throw an error, catch the error
log.info(pcall(sys.executeCommand, "help", "invalid_command"))
log.info("end")
-- exit(0)
-- local seen={}
-- local function dump(t,i)
-- seen[t]=true
-- local s={}
-- local n=0
-- for k, v in pairs(t) do
-- n=n+1
-- s[n]=tostring(k)
-- end
-- table.sort(s)
-- for k,v in ipairs(s) do
-- print(i .. v)
-- v=t[v]
-- if type(v)=="table" and not seen[v] then
-- dump(v,i.."\t")
-- end
-- end
-- end
-- dump(_G,"")