Allow Hotkeys to execute moderation actions in usercards (#3483)

Co-authored-by: Rasmus Karlsson <rasmus.karlsson@pajlada.com>
This commit is contained in:
Mm2PL 2022-01-29 16:54:57 +00:00 committed by GitHub
parent ddbeb356a5
commit f4c82dfa59
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 57 additions and 0 deletions

View file

@ -45,6 +45,7 @@
- Minor: Mod list, VIP list, and Users joined/parted messages are now searchable. (#3426)
- Minor: Add search to emote popup. (#3404, #3527)
- Minor: Messages can now be highlighted by subscriber or founder badges. (#3445)
- Minor: User timeout buttons can now be triggered using hotkeys. (#3483)
- Minor: Add workaround for multipart emoji as described in [the RFC](https://mm2pl.github.io/emoji_rfc.pdf). (#3469)
- Minor: Add feedback when using the whisper command `/w` incorrectly. (#3439)
- Minor: Add feedback when writing a non-command message in the `/whispers` split. (#3439)

View file

@ -44,6 +44,10 @@ inline const std::map<HotkeyCategory, ActionDefinitionMap> actionNames{
1,
}},
{"search", ActionDefinition{"Focus search box"}},
{"execModeratorAction",
ActionDefinition{
"Usercard: execute moderation action",
"<ban, unban or number of the timeout button to use>", 1}},
}},
{HotkeyCategory::Split,
{

View file

@ -174,6 +174,58 @@ UserInfoPopup::UserInfoPopup(bool closeAutomatically, QWidget *parent)
}
return "";
}},
{"execModeratorAction",
[this](std::vector<QString> arguments) -> QString {
if (arguments.empty())
{
return "execModeratorAction action needs an argument, which "
"moderation action to execute, see description in the "
"editor";
}
auto target = arguments.at(0);
QString msg;
// these can't have /timeout/ buttons because they are not timeouts
if (target == "ban")
{
msg = QString("/ban %1").arg(this->userName_);
}
else if (target == "unban")
{
msg = QString("/unban %1").arg(this->userName_);
}
else
{
// find and execute timeout button #TARGET
bool ok;
int buttonNum = target.toInt(&ok);
if (!ok)
{
return QString("Invalid argument for execModeratorAction: "
"%1. Use "
"\"ban\", \"unban\" or the number of the "
"timeout "
"button to execute")
.arg(target);
}
const auto &timeoutButtons =
getSettings()->timeoutButtons.getValue();
if (timeoutButtons.size() < buttonNum || 0 >= buttonNum)
{
return QString("Invalid argument for execModeratorAction: "
"%1. Integer out of usable range: [1, %2]")
.arg(buttonNum, timeoutButtons.size() - 1);
}
const auto &button = timeoutButtons.at(buttonNum - 1);
msg = QString("/timeout %1 %2")
.arg(this->userName_)
.arg(calculateTimeoutDuration(button));
}
this->channel_->sendMessage(msg);
return "";
}},
// these actions make no sense in the context of a usercard, so they aren't implemented
{"reject", nullptr},