From 3ee23b2baec8aae0d0718b552df0d6b0dfc5ec3d Mon Sep 17 00:00:00 2001 From: Mm2PL Date: Sat, 17 Apr 2021 10:33:18 +0000 Subject: [PATCH] Allow for usage of builtin Chatterino commands in custom commands. (#2632) Co-authored-by: pajlada --- CHANGELOG.md | 1 + .../commands/CommandController.cpp | 28 +++++++++++++------ 2 files changed, 20 insertions(+), 9 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 77c262a4..baded6d4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,7 @@ ## Unversioned +- Minor: Allow for built-in Chatterino commands to be used in custom commands. (#2632) - Bugfix: Fix crash that could occur when the user changed the "Custom stream player URI Scheme" setting if the user had closed down and splits in the application runtime. (#2592) ## 2.3.0 diff --git a/src/controllers/commands/CommandController.cpp b/src/controllers/commands/CommandController.cpp index e6b7a941..baf90cea 100644 --- a/src/controllers/commands/CommandController.cpp +++ b/src/controllers/commands/CommandController.cpp @@ -769,6 +769,25 @@ QString CommandController::execCommand(const QString &textNoEmoji, auto *twitchChannel = dynamic_cast(channel.get()); + { + // check if user command exists + const auto it = this->userCommands_.find(commandName); + if (it != this->userCommands_.end()) + { + text = getApp()->emotes->emojis.replaceShortCodes( + this->execCustomCommand(words, it.value(), dryRun)); + + words = text.split(' ', QString::SkipEmptyParts); + + if (words.length() == 0) + { + return text; + } + + commandName = words[0]; + } + } + // works only in a valid twitch channel if (!dryRun && twitchChannel != nullptr) { @@ -780,15 +799,6 @@ QString CommandController::execCommand(const QString &textNoEmoji, } } - { - // check if user command exists - const auto it = this->userCommands_.find(commandName); - if (it != this->userCommands_.end()) - { - return this->execCustomCommand(words, it.value(), dryRun); - } - } - auto maxSpaces = std::min(this->maxSpaces_, words.length() - 1); for (int i = 0; i < maxSpaces; ++i) {