Refactored and Migrated to Helix AutoMod message management (#2779)
This uses new Helix endpoint which requires new scopes and users need to reauthenticate to approve/deny AutoMod messages again.
This commit is contained in:
@@ -659,6 +659,68 @@ void Helix::updateChannel(QString broadcasterId, QString gameId,
|
||||
})
|
||||
.execute();
|
||||
}
|
||||
|
||||
void Helix::manageAutoModMessages(
|
||||
QString userID, QString msgID, QString action,
|
||||
std::function<void()> successCallback,
|
||||
std::function<void(HelixAutoModMessageError)> failureCallback)
|
||||
{
|
||||
QJsonObject payload;
|
||||
|
||||
payload.insert("user_id", userID);
|
||||
payload.insert("msg_id", msgID);
|
||||
payload.insert("action", action);
|
||||
|
||||
this->makeRequest("moderation/automod/message", QUrlQuery())
|
||||
.type(NetworkRequestType::Post)
|
||||
.header("Content-Type", "application/json")
|
||||
.payload(QJsonDocument(payload).toJson(QJsonDocument::Compact))
|
||||
.onSuccess([successCallback, failureCallback](auto result) -> Outcome {
|
||||
successCallback();
|
||||
return Success;
|
||||
})
|
||||
.onError([failureCallback, msgID, action](NetworkResult result) {
|
||||
switch (result.status())
|
||||
{
|
||||
case 400: {
|
||||
// Message was already processed
|
||||
failureCallback(
|
||||
HelixAutoModMessageError::MessageAlreadyProcessed);
|
||||
}
|
||||
break;
|
||||
|
||||
case 401: {
|
||||
// User is missing the required scope
|
||||
failureCallback(
|
||||
HelixAutoModMessageError::UserNotAuthenticated);
|
||||
}
|
||||
break;
|
||||
|
||||
case 403: {
|
||||
// Requesting user is not authorized to manage messages
|
||||
failureCallback(
|
||||
HelixAutoModMessageError::UserNotAuthorized);
|
||||
}
|
||||
break;
|
||||
|
||||
case 404: {
|
||||
// Message not found or invalid msgID
|
||||
failureCallback(HelixAutoModMessageError::MessageNotFound);
|
||||
}
|
||||
break;
|
||||
|
||||
default: {
|
||||
qCDebug(chatterinoTwitch)
|
||||
<< "Failed to manage automod message: " << action
|
||||
<< msgID << result.status() << result.getData();
|
||||
failureCallback(HelixAutoModMessageError::Unknown);
|
||||
}
|
||||
break;
|
||||
}
|
||||
})
|
||||
.execute();
|
||||
}
|
||||
|
||||
NetworkRequest Helix::makeRequest(QString url, QUrlQuery urlQuery)
|
||||
{
|
||||
assert(!url.startsWith("/"));
|
||||
|
||||
Reference in New Issue
Block a user