From 9fba0bd4abba17b4d38368b315d8e2eb79ca5671 Mon Sep 17 00:00:00 2001 From: nerix Date: Sat, 19 Nov 2022 14:34:07 +0100 Subject: [PATCH] fix: `/ban` messages for self/mod bans (#4164) --- CHANGELOG.md | 4 ++-- src/controllers/commands/CommandController.cpp | 15 +++++++++++++-- src/providers/twitch/api/Helix.cpp | 7 +++++++ src/providers/twitch/api/Helix.hpp | 1 + 4 files changed, 23 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 70b5d8dfa..c3dde8720 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -68,8 +68,8 @@ - Minor: Migrated /followersoff to Helix API. (#4040) - Minor: Migrated /raid command to Helix API. Chat command will continue to be used until February 11th 2023. (#4029) - Minor: Migrated /unraid command to Helix API. Chat command will continue to be used until February 11th 2023. (#4030) -- Minor: Migrated /ban to Helix API. (#4049) -- Minor: Migrated /timeout to Helix API. (#4049) +- Minor: Migrated /ban to Helix API. (#4049, #4164) +- Minor: Migrated /timeout to Helix API. (#4049, #4164) - Minor: Migrated /w to Helix API. Chat command will continue to be used until February 11th 2023. (#4052) - Minor: Migrated /vips to Helix API. Chat command will continue to be used until February 11th 2023. (#4053) - Minor: Migrated /uniquechat and /r9kbeta to Helix API. (#4057) diff --git a/src/controllers/commands/CommandController.cpp b/src/controllers/commands/CommandController.cpp index 8eb66df07..21cb34f59 100644 --- a/src/controllers/commands/CommandController.cpp +++ b/src/controllers/commands/CommandController.cpp @@ -2658,8 +2658,19 @@ void CommandController::initialize(Settings &, Paths &paths) case Error::TargetBanned: { // Equivalent IRC error - errorMessage = QString("%1 is already banned in this channel.") - .arg(userDisplayName); + errorMessage += QString("%1 is already banned in this channel.") + .arg(userDisplayName); + } + break; + + case Error::CannotBanUser: { + // We can't provide the identical error as in IRC, + // because we don't have enough information about the user. + // 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); } break; diff --git a/src/providers/twitch/api/Helix.cpp b/src/providers/twitch/api/Helix.cpp index 6a7ec76f5..e9dc0308a 100644 --- a/src/providers/twitch/api/Helix.cpp +++ b/src/providers/twitch/api/Helix.cpp @@ -2064,6 +2064,13 @@ void Helix::banUser(QString broadcasterID, QString moderatorID, QString userID, { failureCallback(Error::TargetBanned, message); } + else if (message.startsWith( + "The user specified in the user_id field may " + "not be banned", + Qt::CaseInsensitive)) + { + failureCallback(Error::CannotBanUser, message); + } else { failureCallback(Error::Forwarded, message); diff --git a/src/providers/twitch/api/Helix.hpp b/src/providers/twitch/api/Helix.hpp index c5c0a768f..a63d3feaf 100644 --- a/src/providers/twitch/api/Helix.hpp +++ b/src/providers/twitch/api/Helix.hpp @@ -551,6 +551,7 @@ enum class HelixBanUserError { // /timeout, /ban Ratelimited, ConflictingOperation, TargetBanned, + CannotBanUser, // The error message is forwarded directly from the Twitch API Forwarded,