diff options
| author | Markus Mittendrein <git@maxmitti.tk> | 2015-11-08 02:03:31 +0100 |
|---|---|---|
| committer | Markus Mittendrein <git@maxmitti.tk> | 2015-11-08 03:04:38 +0100 |
| commit | 7f8ded233bba4b803eb787526c59a69477dce068 (patch) | |
| tree | c532f8af017c896b1285d54e2226f1cba122b002 | |
| parent | b63aed7253a307a4011d2a39e51dcc584e90d372 (diff) | |
| download | manager-7f8ded233bba4b803eb787526c59a69477dce068.tar.gz manager-7f8ded233bba4b803eb787526c59a69477dce068.zip | |
Allow optional suffixes for commands (e.g. for punctuation marks)
| -rw-r--r-- | src/CRSMConfig.hpp | 2 | ||||
| -rw-r--r-- | src/crsm.cpp | 23 | ||||
| -rw-r--r-- | src/crsm.hpp | 1 |
3 files changed, 25 insertions, 1 deletions
diff --git a/src/CRSMConfig.hpp b/src/CRSMConfig.hpp index 576447d..921e56e 100644 --- a/src/CRSMConfig.hpp +++ b/src/CRSMConfig.hpp @@ -12,6 +12,7 @@ public: String SessionFile = "CrServerManager.session"; String PacksFile = "CrServerManager.packs"; Map(String, String) CommandAlias; + List(String) CommandSuffixes; } CRSM; struct { @@ -96,6 +97,7 @@ public: ConfigVal(CRSM.SessionFile), ConfigVal(CRSM.PacksFile), ConfigVal(CRSM.CommandAlias), + ConfigVal(CRSM.CommandSuffixes), 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) diff --git a/src/crsm.hpp b/src/crsm.hpp index 56f2a29..56d9b18 100644 --- a/src/crsm.hpp +++ b/src/crsm.hpp @@ -291,6 +291,7 @@ private: int findWishFromUser(const ClientInfo& client); QString getCommand(const QString& message); bool isChannelName(const QString& name); + void removeCommandSuffixes(QString& command); void substituteCommandAlias(QString& command); CMD_FUNCTION(help); |
