mirror of
https://github.com/PHIDIAS0303/ExpCluster.git
synced 2025-12-27 11:35:22 +09:00
Update Command Lib
This commit is contained in:
@@ -2,23 +2,26 @@
|
||||
Game command to list and search all registered commands in a nice format
|
||||
@commands _system-ipc
|
||||
|
||||
@usage-- Get all messages related to banning a player
|
||||
--- Get all messages related to banning a player
|
||||
/commands ban
|
||||
-- Get the second page of results
|
||||
/commands ban 2
|
||||
]]
|
||||
|
||||
local Global = require("modules/exp_util/global")
|
||||
local Storage = require("modules/exp_util/storage")
|
||||
local Commands = require("modules/exp_commands")
|
||||
|
||||
local PAGE_SIZE = 5
|
||||
|
||||
local search_cache = {}
|
||||
Global.register(search_cache, function(tbl)
|
||||
Storage.register(search_cache, function(tbl)
|
||||
search_cache = tbl
|
||||
end)
|
||||
|
||||
--- Format commands into a strings across multiple pages
|
||||
--- @param commands { [string]: Commands.Command } The commands to split into pages
|
||||
--- @param page_size number The number of requests to show per page
|
||||
--- @return LocalisedString[][], number
|
||||
local function format_as_pages(commands, page_size)
|
||||
local pages = { {} }
|
||||
local page_length = 0
|
||||
@@ -34,22 +37,37 @@ local function format_as_pages(commands, page_size)
|
||||
page_length = 1
|
||||
end
|
||||
|
||||
local description
|
||||
if command.defined_at then
|
||||
--- @cast command Commands.ExpCommand
|
||||
description = { "", command.help_text[2], "- ", command.description }
|
||||
else
|
||||
description = command.description
|
||||
end
|
||||
|
||||
local aliases = #command.aliases > 0 and { "exp-commands-help.aliases", table.concat(command.aliases, ", ") } or ""
|
||||
pages[current_page][page_length] = { "exp-commands-help.format", command.name, command.description, command.help, aliases }
|
||||
pages[current_page][page_length] = { "exp-commands-help.format", command.name, description, aliases }
|
||||
end
|
||||
|
||||
return pages, total
|
||||
end
|
||||
|
||||
Commands.new("commands", "List and search all commands for a keyword")
|
||||
Commands.new("commands", { "exp-commands-help.description" })
|
||||
:add_aliases{ "chelp", "helpp" }
|
||||
:argument("keyword", "string")
|
||||
:optional("page", "integer")
|
||||
:defaults{ page = 1 }
|
||||
:optional("keyword", { "exp-commands-help.arg-keyword" }, Commands.types.string)
|
||||
:optional("page", { "exp-commands-help.arg-page" }, Commands.types.integer)
|
||||
:defaults{ keyword = "", page = 1 }
|
||||
:register(function(player, keyword, page)
|
||||
-- Allow listing of all commands
|
||||
local as_number = tonumber(keyword)
|
||||
local cache = search_cache[player.index]
|
||||
if as_number and page == 1 then
|
||||
keyword = cache and cache.keyword or ""
|
||||
page = as_number
|
||||
end
|
||||
|
||||
keyword = keyword:lower()
|
||||
local pages, found
|
||||
local cache = search_cache[player.index]
|
||||
if cache and cache.keyword == keyword then
|
||||
-- Cached value found, no search is needed
|
||||
pages = cache.pages
|
||||
|
||||
Reference in New Issue
Block a user