mirror of
https://github.com/Chatterino/chatterino2.git
synced 2024-11-13 19:49:51 +01:00
Add ban user by id command /banid
(#4411)
Co-authored-by: Felanbird <41973452+Felanbird@users.noreply.github.com> Co-authored-by: pajlada <rasmus.karlsson@pajlada.com>
This commit is contained in:
parent
f9b23882f4
commit
b5b85501ee
|
@ -3,6 +3,7 @@
|
|||
## Unversioned
|
||||
|
||||
- Minor: Delete all but the last 5 crashdumps on application start. (#4392)
|
||||
- Minor: Added `/banid` command that allows banning by user ID. (#4411)
|
||||
- Bugfix: Fixed uploaded AppImage not being able most web requests. (#4400)
|
||||
- Bugfix: Fixed a potential race condition due to using the wrong lock when loading 7TV badges. (#4402)
|
||||
- Dev: Add capability to build Chatterino with Qt6. (#4393)
|
||||
|
|
|
@ -2632,7 +2632,7 @@ void CommandController::initialize(Settings &, Paths &paths)
|
|||
|
||||
auto formatBanTimeoutError =
|
||||
[](const char *operation, HelixBanUserError error,
|
||||
const QString &message, const QString &userDisplayName) -> QString {
|
||||
const QString &message, const QString &userTarget) -> QString {
|
||||
using Error = HelixBanUserError;
|
||||
|
||||
QString errorMessage = QString("Failed to %1 user - ").arg(operation);
|
||||
|
@ -2659,7 +2659,7 @@ void CommandController::initialize(Settings &, Paths &paths)
|
|||
case Error::TargetBanned: {
|
||||
// Equivalent IRC error
|
||||
errorMessage += QString("%1 is already banned in this channel.")
|
||||
.arg(userDisplayName);
|
||||
.arg(userTarget);
|
||||
}
|
||||
break;
|
||||
|
||||
|
@ -2669,8 +2669,8 @@ void CommandController::initialize(Settings &, Paths &paths)
|
|||
// The messages from IRC are formatted like this:
|
||||
// "You cannot {op} moderator {mod} unless you are the owner of this channel."
|
||||
// "You cannot {op} the broadcaster."
|
||||
errorMessage += QString("You cannot %1 %2.")
|
||||
.arg(operation, userDisplayName);
|
||||
errorMessage +=
|
||||
QString("You cannot %1 %2.").arg(operation, userTarget);
|
||||
}
|
||||
break;
|
||||
|
||||
|
@ -2829,6 +2829,53 @@ void CommandController::initialize(Settings &, Paths &paths)
|
|||
return "";
|
||||
});
|
||||
|
||||
this->registerCommand("/banid", [formatBanTimeoutError](
|
||||
const QStringList &words,
|
||||
auto channel) {
|
||||
auto *twitchChannel = dynamic_cast<TwitchChannel *>(channel.get());
|
||||
if (twitchChannel == nullptr)
|
||||
{
|
||||
channel->addMessage(makeSystemMessage(
|
||||
QString("The /banid command only works in Twitch channels")));
|
||||
return "";
|
||||
}
|
||||
|
||||
const auto *usageStr =
|
||||
"Usage: \"/banid <userID> [reason]\" - Permanently prevent a user "
|
||||
"from chatting via their user ID. Reason is optional and will be "
|
||||
"shown to the target user and other moderators.";
|
||||
if (words.size() < 2)
|
||||
{
|
||||
channel->addMessage(makeSystemMessage(usageStr));
|
||||
return "";
|
||||
}
|
||||
|
||||
auto currentUser = getApp()->accounts->twitch.getCurrent();
|
||||
if (currentUser->isAnon())
|
||||
{
|
||||
channel->addMessage(
|
||||
makeSystemMessage("You must be logged in to ban someone!"));
|
||||
return "";
|
||||
}
|
||||
|
||||
auto target = words.at(1);
|
||||
auto reason = words.mid(2).join(' ');
|
||||
|
||||
getHelix()->banUser(
|
||||
twitchChannel->roomId(), currentUser->getUserId(), target,
|
||||
boost::none, reason,
|
||||
[] {
|
||||
// No response for bans, they're emitted over pubsub/IRC instead
|
||||
},
|
||||
[channel, target, formatBanTimeoutError](auto error, auto message) {
|
||||
auto errorMessage =
|
||||
formatBanTimeoutError("ban", error, message, "#" + target);
|
||||
channel->addMessage(makeSystemMessage(errorMessage));
|
||||
});
|
||||
|
||||
return "";
|
||||
});
|
||||
|
||||
for (const auto &cmd : TWITCH_WHISPER_COMMANDS)
|
||||
{
|
||||
this->registerCommand(cmd, [](const QStringList &words, auto channel) {
|
||||
|
|
Loading…
Reference in a new issue