From 7f8ded233bba4b803eb787526c59a69477dce068 Mon Sep 17 00:00:00 2001 From: Markus Mittendrein Date: Sun, 8 Nov 2015 02:03:31 +0100 Subject: Allow optional suffixes for commands (e.g. for punctuation marks) --- src/crsm.cpp | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) (limited to 'src/crsm.cpp') diff --git a/src/crsm.cpp b/src/crsm.cpp index 021a63b..e99fabb 100644 --- a/src/crsm.cpp +++ b/src/crsm.cpp @@ -1244,7 +1244,7 @@ CmdFunctionRef* CRSM::findCommand(QStringList&& cmd, ClientInterface interface, } } -bool CRSM::cmd(QString cmd, const ClientInfo &client) +bool CRSM::cmd(const QString& cmd, const ClientInfo &client) { CmdFunctionRef* cmdPtr; QString realCmd = cmd; @@ -1252,6 +1252,7 @@ bool CRSM::cmd(QString cmd, const ClientInfo &client) { CmdFunctionRef cmdRef = *cmdPtr; QString args = cmd.mid(realCmd.length()).trimmed(); + removeCommandSuffixes(args); switch(client.interface) { case Clonk: @@ -1827,6 +1828,26 @@ bool CRSM::isChannelName(const QString &name) } } +void CRSM::removeCommandSuffixes(QString& command) +{ + foreach(const QString& suffix, Config.CRSM.CommandSuffixes) + { + if(command.length() > suffix.length() && command.right(suffix.length()) == suffix) + { + command.chop(suffix.length()); + break; + } + } +} + +void CRSM::substituteCommandAlias(QString &command) +{ + while(Config.CRSM.CommandAlias.contains(command)) + { + command = Config.CRSM.CommandAlias.value(command); + } +} + CMD_FUNCTION_IMPL(help) bool longHelp = (args == "long"); if(args.isEmpty() || longHelp) -- cgit v1.2.3-54-g00ecf