Migrate /unban and /untimeout to Helix API (#4026)

Co-authored-by: Rasmus Karlsson <rasmus.karlsson@pajlada.com>
This commit is contained in:
Aiden
2022-10-01 16:10:06 +01:00
committed by GitHub
parent adbc4690af
commit a275a1793a
5 changed files with 297 additions and 3 deletions
+112
View File
@@ -1335,6 +1335,118 @@ void Helix::removeChannelVIP(
.execute();
}
// These changes are from the helix-command-migration/unban-untimeout branch
// These changes are from the helix-command-migration/unban-untimeout branch
// These changes are from the helix-command-migration/unban-untimeout branch
// These changes are from the helix-command-migration/unban-untimeout branch
// These changes are from the helix-command-migration/unban-untimeout branch
// These changes are from the helix-command-migration/unban-untimeout branch
// These changes are from the helix-command-migration/unban-untimeout branch
// These changes are from the helix-command-migration/unban-untimeout branch
// These changes are from the helix-command-migration/unban-untimeout branch
// These changes are from the helix-command-migration/unban-untimeout branch
void Helix::unbanUser(
QString broadcasterID, QString moderatorID, QString userID,
ResultCallback<> successCallback,
FailureCallback<HelixUnbanUserError, QString> failureCallback)
{
using Error = HelixUnbanUserError;
QUrlQuery urlQuery;
urlQuery.addQueryItem("broadcaster_id", broadcasterID);
urlQuery.addQueryItem("moderator_id", moderatorID);
urlQuery.addQueryItem("user_id", userID);
this->makeRequest("moderation/bans", urlQuery)
.type(NetworkRequestType::Delete)
.onSuccess([successCallback, failureCallback](auto result) -> Outcome {
if (result.status() != 204)
{
qCWarning(chatterinoTwitch)
<< "Success result for unbanning user was"
<< result.status() << "but we only expected it to be 204";
}
successCallback();
return Success;
})
.onError([failureCallback](auto result) {
auto obj = result.parseJson();
auto message = obj.value("message").toString();
switch (result.status())
{
case 400: {
if (message.startsWith("The user in the user_id query "
"parameter is not banned",
Qt::CaseInsensitive))
{
failureCallback(Error::TargetNotBanned, message);
}
else
{
failureCallback(Error::Forwarded, message);
}
}
break;
case 409: {
failureCallback(Error::ConflictingOperation, message);
}
break;
case 401: {
if (message.startsWith("Missing scope",
Qt::CaseInsensitive))
{
// Handle this error specifically because its API error is especially unfriendly
failureCallback(Error::UserMissingScope, message);
}
else if (message.compare("incorrect user authorization",
Qt::CaseInsensitive) == 0 ||
message.startsWith("the id in broadcaster_id must "
"match the user id",
Qt::CaseInsensitive))
{
// This error is particularly ugly, but is the equivalent to a user not having permissions
failureCallback(Error::UserNotAuthorized, message);
}
else
{
failureCallback(Error::Forwarded, message);
}
}
break;
case 429: {
failureCallback(Error::Ratelimited, message);
}
break;
default: {
qCDebug(chatterinoTwitch)
<< "Unhandled error unbanning user:" << result.status()
<< result.getData() << obj;
failureCallback(Error::Unknown, message);
}
break;
}
})
.execute();
} // These changes are from the helix-command-migration/unban-untimeout branch
// These changes are from the helix-command-migration/unban-untimeout branch
// These changes are from the helix-command-migration/unban-untimeout branch
// These changes are from the helix-command-migration/unban-untimeout branch
// These changes are from the helix-command-migration/unban-untimeout branch
// These changes are from the helix-command-migration/unban-untimeout branch
// These changes are from the helix-command-migration/unban-untimeout branch
// These changes are from the helix-command-migration/unban-untimeout branch
// These changes are from the helix-command-migration/unban-untimeout branch
// These changes are from the helix-command-migration/unban-untimeout branch
// These changes are from the helix-command-migration/unban-untimeout branch
// These changes are from the helix-command-migration/unban-untimeout branch
NetworkRequest Helix::makeRequest(QString url, QUrlQuery urlQuery)
{
assert(!url.startsWith("/"));