Migrate /unban and /untimeout to Helix API (#4026)
Co-authored-by: Rasmus Karlsson <rasmus.karlsson@pajlada.com>
This commit is contained in:
@@ -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("/"));
|
||||
|
||||
@@ -401,6 +401,19 @@ enum class HelixRemoveChannelVIPError {
|
||||
Forwarded,
|
||||
};
|
||||
|
||||
// These changes are from the helix-command-migration/unban-untimeout branch
|
||||
enum class HelixUnbanUserError {
|
||||
Unknown,
|
||||
UserMissingScope,
|
||||
UserNotAuthorized,
|
||||
Ratelimited,
|
||||
ConflictingOperation,
|
||||
TargetNotBanned,
|
||||
|
||||
// The error message is forwarded directly from the Twitch API
|
||||
Forwarded,
|
||||
}; // These changes are from the helix-command-migration/unban-untimeout branch
|
||||
|
||||
class IHelix
|
||||
{
|
||||
public:
|
||||
@@ -567,6 +580,15 @@ public:
|
||||
FailureCallback<HelixRemoveChannelVIPError, QString>
|
||||
failureCallback) = 0;
|
||||
|
||||
// These changes are from the helix-command-migration/unban-untimeout branch
|
||||
// https://dev.twitch.tv/docs/api/reference#unban-user
|
||||
// These changes are from the helix-command-migration/unban-untimeout branch
|
||||
virtual void unbanUser(
|
||||
QString broadcasterID, QString moderatorID, QString userID,
|
||||
ResultCallback<> successCallback,
|
||||
FailureCallback<HelixUnbanUserError, QString> failureCallback) = 0;
|
||||
// These changes are from the helix-command-migration/unban-untimeout branch
|
||||
|
||||
virtual void update(QString clientId, QString oauthToken) = 0;
|
||||
};
|
||||
|
||||
@@ -727,6 +749,15 @@ public:
|
||||
FailureCallback<HelixRemoveChannelVIPError, QString>
|
||||
failureCallback) final;
|
||||
|
||||
// These changes are from the helix-command-migration/unban-untimeout branch
|
||||
// https://dev.twitch.tv/docs/api/reference#unban-user
|
||||
// These changes are from the helix-command-migration/unban-untimeout branch
|
||||
void unbanUser(
|
||||
QString broadcasterID, QString moderatorID, QString userID,
|
||||
ResultCallback<> successCallback,
|
||||
FailureCallback<HelixUnbanUserError, QString> failureCallback) final;
|
||||
// These changes are from the helix-command-migration/unban-untimeout branch
|
||||
|
||||
void update(QString clientId, QString oauthToken) final;
|
||||
|
||||
static void initialize();
|
||||
|
||||
Reference in New Issue
Block a user