From c8f5d35042dd7cbbb7e2c4888e9c518e0bb3fe07 Mon Sep 17 00:00:00 2001 From: Mm2PL Date: Sun, 29 May 2022 12:23:29 +0000 Subject: [PATCH] Added mod button-like placeholders in right click commands (#3765) Implemented input.text to return altText when it makes no sense to contain data Co-authored-by: Kasia --- CHANGELOG.md | 2 +- .../commands/CommandController.cpp | 22 +++++++++++----- src/widgets/helper/ChannelView.cpp | 26 ++++++++++++++++--- 3 files changed, 40 insertions(+), 10 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b320fed61..137d231f3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -18,7 +18,7 @@ - Minor: Streamer mode now automatically detects if XSplit, PRISM Live Studio, Twitch Studio, or vMix are running. (#3740) - Minor: Add scrollbar to `Select filters` dialog. (#3737) - Minor: Added `/requests` command. Usage: `/requests [channel]`. Opens the channel points requests queue for the provided channel or the current channel if no input is provided. (#3746) -- Minor: Added ability to execute commands on chat messages using the message context menu. (#3738) +- Minor: Added ability to execute commands on chat messages using the message context menu. (#3738, #3765) - Minor: Added `/copy` command. Usage: `/copy `. Copies provided text to clipboard - can be useful with custom commands. (#3763) - Bugfix: Fixed viewers list search not working when used before loading finishes. (#3774) - Bugfix: Fixed live notifications for usernames containing uppercase characters. (#3646) diff --git a/src/controllers/commands/CommandController.cpp b/src/controllers/commands/CommandController.cpp index 843b953a4..7aa82c7d4 100644 --- a/src/controllers/commands/CommandController.cpp +++ b/src/controllers/commands/CommandController.cpp @@ -177,6 +177,11 @@ bool appendWhisperMessageStringLocally(const QString &textNoEmoji) return false; } +const std::function + noOpPlaceholder = [](const auto &altText, const auto &channel) { + return altText; + }; + const std::map> COMMAND_VARS{ @@ -240,6 +245,11 @@ const std::mapsecond(altText, channel); + result += var->second.isEmpty() ? altText : var->second; } else { - auto it = context.find(varName); - if (it != context.end()) + auto it = COMMAND_VARS.find(varName); + if (it != COMMAND_VARS.end()) { - result += it->second.isEmpty() ? altText : it->second; + result += it->second(altText, channel); } else { diff --git a/src/widgets/helper/ChannelView.cpp b/src/widgets/helper/ChannelView.cpp index c2fb1d2cc..1b9c37f0b 100644 --- a/src/widgets/helper/ChannelView.cpp +++ b/src/widgets/helper/ChannelView.cpp @@ -2119,7 +2119,7 @@ void ChannelView::addCommandExecutionContextMenuItems( inputText.push_front(cmd.name + " "); - cmdMenu->addAction(cmd.name, [this, inputText] { + cmdMenu->addAction(cmd.name, [this, layout, cmd, inputText] { ChannelPtr channel; /* Search popups and user message history's underlyingChannels aren't of type TwitchChannel, but @@ -2132,9 +2132,29 @@ void ChannelView::addCommandExecutionContextMenuItems( { channel = this->underlyingChannel_; } + auto split = dynamic_cast(this->parentWidget()); + QString userText; + if (split) + { + userText = split->getInput().getInputText(); + } + QString value = getApp()->commands->execCustomCommand( + inputText.split(' '), cmd, true, channel, + { + {"user.name", layout->getMessage()->loginName}, + {"msg.id", layout->getMessage()->id}, + {"msg.text", layout->getMessage()->messageText}, + {"input.text", userText}, - QString value = - getApp()->commands->execCommand(inputText, channel, false); + // old placeholders + {"user", layout->getMessage()->loginName}, + {"msg-id", layout->getMessage()->id}, + {"message", layout->getMessage()->messageText}, + + {"channel", this->channel()->getName()}, + }); + + value = getApp()->commands->execCommand(value, channel, false); channel->sendMessage(value); });