Skip to content

Commit

Permalink
added client commands from chat (issue #47)
Browse files Browse the repository at this point in the history
  • Loading branch information
Timo Smit committed Feb 19, 2016
1 parent 1adeb63 commit 54ec062
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 7 deletions.
4 changes: 2 additions & 2 deletions luascripts/commands/client/ac.lua
Expand Up @@ -44,5 +44,5 @@ function commandAdminChat(clientId, cmdArguments)

return true
end
commands.addclient("adminchat", commandAdminChat, "~", "[^2message^7]")
commands.addclient("ac", commandAdminChat, "~", "[^2message^7]")
commands.addclient("adminchat", commandAdminChat, "~", "[^2message^7]", true)
commands.addclient("ac", commandAdminChat, "~", "[^2message^7]", true)
4 changes: 2 additions & 2 deletions luascripts/commands/client/pm.lua
Expand Up @@ -35,5 +35,5 @@ function commandPersonalMessage(clientId, cmdArguments)
end
end
end
commands.addclient("pm", commandPersonalMessage, "", "")
commands.addclient("m", commandPersonalMessage, "", "")
commands.addclient("pm", commandPersonalMessage, "", "", true)
commands.addclient("m", commandPersonalMessage, "", "", true)
2 changes: 1 addition & 1 deletion luascripts/commands/client/r.lua
Expand Up @@ -42,4 +42,4 @@ function commandR(clientId, cmdArguments)

return true
end
commands.addclient("r", commandR, "", "[^2message^7]")
commands.addclient("r", commandR, "", "[^2message^7]", true)
44 changes: 42 additions & 2 deletions luascripts/commands/commands.lua
Expand Up @@ -54,11 +54,12 @@ function commands.getadmin(command)
return admincmds
end

function commands.addclient(command, func, flag, syntax)
function commands.addclient(command, func, flag, syntax, chat)
clientcmds[command] = {
["function"] = func,
["flag"] = flag,
["syntax"] = "^2!"..command..(syntax and " "..syntax or ""),
["syntax"] = "^7"..command..(syntax and " "..syntax or ""),
["chat"] = chat,
}
end

Expand Down Expand Up @@ -238,6 +239,45 @@ function commands.onclientcommand(clientId, cmdText)
end
end

-- client cmds
local clientCmd = nil

-- say and say_*
if (wolfCmd == "say" or wolfCmd == "say_team" or wolfCmd == "say_buddy") and string.find(et.trap_Argv(1), "/") == 1 then
cmdArguments = util.split(et.trap_Argv(1), " ")

-- say "/command param1 param2 paramN"
if #cmdArguments > 1 then
clientCmd = string.sub(cmdArguments[1], 2, string.len(cmdArguments[1]))
table.remove(cmdArguments, 1)
-- say /command param1 param2 paramN
else
clientCmd = string.sub(et.trap_Argv(1), 2, string.len(et.trap_Argv(1)))

for i = 2, et.trap_Argc() - 1 do
cmdArguments[(i - 1)] = et.trap_Argv(i)
end
if cmdArguments[1] == et.trap_Argv(1) then table.remove(cmdArguments, 1) end
end
-- !command
elseif string.find(wolfCmd, "!") == 1 then
clientCmd = string.sub(wolfCmd, 2, string.len(wolfCmd))

for i = 1, et.trap_Argc() - 1 do
cmdArguments[i] = et.trap_Argv(i)
end
end

if clientCmd then
clientCmd = string.lower(clientCmd)

if clientcmds[clientCmd] and clientcmds[clientCmd]["function"] and clientcmds[clientCmd]["chat"] then
if clientcmds[clientCmd]["flag"] == "" or et.G_shrubbot_permission(clientId, clientcmds[clientCmd]["flag"]) == 1 then
return clientcmds[clientCmd]["function"](clientId, cmdArguments) and 1 or 0
end
end
end

-- shrub cmds
local shrubCmd = nil

Expand Down

0 comments on commit 54ec062

Please sign in to comment.