mirror of
https://github.com/CommunityOx/ox_lib.git
synced 2026-08-16 22:46:03 +01:00
feat(addCommand): longString (#597)
This commit is contained in:
@@ -1,7 +1,7 @@
|
|||||||
---@class OxCommandParams
|
---@class OxCommandParams
|
||||||
---@field name string
|
---@field name string
|
||||||
---@field help? string
|
---@field help? string
|
||||||
---@field type? 'number' | 'playerId' | 'string'
|
---@field type? 'number' | 'playerId' | 'string' | 'longString'
|
||||||
---@field optional? boolean
|
---@field optional? boolean
|
||||||
|
|
||||||
---@class OxCommandProperties
|
---@class OxCommandProperties
|
||||||
@@ -30,7 +30,8 @@ end)
|
|||||||
local function parseArguments(source, args, raw, params)
|
local function parseArguments(source, args, raw, params)
|
||||||
if not params then return args end
|
if not params then return args end
|
||||||
|
|
||||||
for i = 1, #params do
|
local paramsNum = #params
|
||||||
|
for i = 1, paramsNum do
|
||||||
local arg, param = args[i], params[i]
|
local arg, param = args[i], params[i]
|
||||||
local value
|
local value
|
||||||
|
|
||||||
@@ -44,6 +45,9 @@ local function parseArguments(source, args, raw, params)
|
|||||||
if not value or not DoesPlayerExist(value--[[@as string]]) then
|
if not value or not DoesPlayerExist(value--[[@as string]]) then
|
||||||
value = false
|
value = false
|
||||||
end
|
end
|
||||||
|
elseif param.type == 'longString' and i == paramsNum then
|
||||||
|
local start = raw:find(arg, 1, true)
|
||||||
|
value = start and raw:sub(start)
|
||||||
else
|
else
|
||||||
value = arg
|
value = arg
|
||||||
end
|
end
|
||||||
@@ -131,6 +135,7 @@ function lib.addCommand(commandName, properties, cb, ...)
|
|||||||
end
|
end
|
||||||
|
|
||||||
if properties then
|
if properties then
|
||||||
|
---@diagnostic disable-next-line: inject-field
|
||||||
properties.name = ('/%s'):format(commandName)
|
properties.name = ('/%s'):format(commandName)
|
||||||
properties.restricted = nil
|
properties.restricted = nil
|
||||||
registeredCommands[totalCommands] = properties
|
registeredCommands[totalCommands] = properties
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ type OxCommandArguments = Record<string | number, string | number | boolean>;
|
|||||||
interface OxCommandParams {
|
interface OxCommandParams {
|
||||||
name: string;
|
name: string;
|
||||||
help?: string;
|
help?: string;
|
||||||
paramType?: 'number' | 'playerId' | 'string';
|
paramType?: 'number' | 'playerId' | 'string' | 'longString';
|
||||||
optional?: boolean;
|
optional?: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -55,6 +55,10 @@ function parseArguments(
|
|||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case 'longString':
|
||||||
|
value = raw.substring(raw.indexOf(arg as string));
|
||||||
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
value = arg;
|
value = arg;
|
||||||
break;
|
break;
|
||||||
|
|||||||
Reference in New Issue
Block a user