small refactoring, using new util function tokenize instead of split in slash.lua
This commit is contained in:
@@ -1,7 +1,7 @@
|
|||||||
SLASH_AUX1 = '/aux'
|
SLASH_AUX1 = '/aux'
|
||||||
function SlashCmdList.AUX(command)
|
function SlashCmdList.AUX(command)
|
||||||
if not command then return end
|
if not command then return end
|
||||||
local arguments = Aux.util.split(command, " ")
|
local arguments = Aux.util.tokenize(command)
|
||||||
if command == 'clear history' then
|
if command == 'clear history' then
|
||||||
Aux.persistence.load_dataset().history = nil
|
Aux.persistence.load_dataset().history = nil
|
||||||
Aux.log('History cleared.')
|
Aux.log('History cleared.')
|
||||||
@@ -47,11 +47,11 @@ function SlashCmdList.AUX(command)
|
|||||||
Aux.log('Ignoring of owner '..(aux_ignore_owner and 'enabled' or 'disabled')..'.')
|
Aux.log('Ignoring of owner '..(aux_ignore_owner and 'enabled' or 'disabled')..'.')
|
||||||
elseif arguments[1] == 'addchar' and arguments[2] then
|
elseif arguments[1] == 'addchar' and arguments[2] then
|
||||||
local exists = false
|
local exists = false
|
||||||
for i=2, table.getn(arguments) do
|
for i=2, getn(arguments) do
|
||||||
exists = false
|
exists = false
|
||||||
if arguments[i] ~= "" then
|
if arguments[i] ~= '' then
|
||||||
arguments[i] = strupper(strsub(arguments[i], 1, 1))..strsub(arguments[i], 2) -- force uppercase
|
arguments[i] = string.gsub(arguments[i], '^%l', strupper) -- force uppercase
|
||||||
for i_aux,v in ipairs(aux_characters) do
|
for i_aux,_ in ipairs(aux_characters) do
|
||||||
if (aux_characters[i_aux] == arguments[i]) then
|
if (aux_characters[i_aux] == arguments[i]) then
|
||||||
exists = true
|
exists = true
|
||||||
break
|
break
|
||||||
@@ -68,7 +68,7 @@ function SlashCmdList.AUX(command)
|
|||||||
if arguments[i] ~= "" then
|
if arguments[i] ~= "" then
|
||||||
arguments[i] = strupper(strsub(arguments[i], 1, 1))..strsub(arguments[i], 2)
|
arguments[i] = strupper(strsub(arguments[i], 1, 1))..strsub(arguments[i], 2)
|
||||||
for i_aux,v in ipairs(aux_characters) do
|
for i_aux,v in ipairs(aux_characters) do
|
||||||
if (aux_characters[i_aux] == arguments[i]) then
|
if aux_characters[i_aux] == arguments[i] then
|
||||||
table.remove(aux_characters, i_aux)
|
table.remove(aux_characters, i_aux)
|
||||||
Aux.log('Character "'..arguments[i]..'" removed.')
|
Aux.log('Character "'..arguments[i]..'" removed.')
|
||||||
break
|
break
|
||||||
@@ -77,20 +77,20 @@ function SlashCmdList.AUX(command)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
elseif command == 'chars' then
|
elseif command == 'chars' then
|
||||||
local chars = nil
|
local chars
|
||||||
local num = table.getn(aux_characters);
|
local num = table.getn(aux_characters)
|
||||||
for i,v in ipairs(aux_characters) do
|
for i,v in ipairs(aux_characters) do
|
||||||
if( i ~= num) then
|
if i ~= num then
|
||||||
if chars ~= nil then
|
if chars then
|
||||||
chars = chars .. v .. ", ";
|
chars = chars .. v .. ", "
|
||||||
else
|
else
|
||||||
chars = v .. ", ";
|
chars = v .. ", "
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
if chars ~= nil then
|
if chars then
|
||||||
chars = chars .. v;
|
chars = chars .. v
|
||||||
else
|
else
|
||||||
chars = v;
|
chars = v
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -334,6 +334,14 @@ function public.join(array, separator)
|
|||||||
return str
|
return str
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function public.tokenize(str)
|
||||||
|
local tokens = {}
|
||||||
|
for token in string.gfind(str, '%S+') do
|
||||||
|
tinsert(tokens, token)
|
||||||
|
end
|
||||||
|
return tokens
|
||||||
|
end
|
||||||
|
|
||||||
function public.split(str, separator)
|
function public.split(str, separator)
|
||||||
|
|
||||||
local array = {}
|
local array = {}
|
||||||
|
|||||||
Reference in New Issue
Block a user