mirror of
https://github.com/Chatterino/chatterino2.git
synced 2024-11-21 22:24:07 +01:00
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 <zneix@zneix.eu>
This commit is contained in:
parent
0ad66c0af4
commit
c8f5d35042
3 changed files with 40 additions and 10 deletions
|
@ -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 <text>`. 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)
|
||||
|
|
|
@ -177,6 +177,11 @@ bool appendWhisperMessageStringLocally(const QString &textNoEmoji)
|
|||
return false;
|
||||
}
|
||||
|
||||
const std::function<QString(const QString &, const ChannelPtr &)>
|
||||
noOpPlaceholder = [](const auto &altText, const auto &channel) {
|
||||
return altText;
|
||||
};
|
||||
|
||||
const std::map<QString,
|
||||
std::function<QString(const QString &, const ChannelPtr &)>>
|
||||
COMMAND_VARS{
|
||||
|
@ -240,6 +245,11 @@ const std::map<QString,
|
|||
return name.isEmpty() ? altText : name;
|
||||
},
|
||||
},
|
||||
// variables used in mod buttons and the like, these make no sense in normal commands, so they are left empty
|
||||
{"input.text", noOpPlaceholder},
|
||||
{"msg.id", noOpPlaceholder},
|
||||
{"user.name", noOpPlaceholder},
|
||||
{"msg.text", noOpPlaceholder},
|
||||
};
|
||||
|
||||
} // namespace
|
||||
|
@ -1151,18 +1161,18 @@ QString CommandController::execCustomCommand(const QStringList &words,
|
|||
auto varName = match.captured(4);
|
||||
auto altText = match.captured(5); // alt text or empty string
|
||||
|
||||
auto var = COMMAND_VARS.find(varName);
|
||||
auto var = context.find(varName);
|
||||
|
||||
if (var != COMMAND_VARS.end())
|
||||
if (var != context.end())
|
||||
{
|
||||
result += var->second(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
|
||||
{
|
||||
|
|
|
@ -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<Split *>(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);
|
||||
});
|
||||
|
|
Loading…
Reference in a new issue