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("/"));
|
||||
|
||||
@@ -205,6 +205,14 @@ enum class HelixStreamMarkerError {
|
||||
UserNotAuthenticated,
|
||||
};
|
||||
|
||||
enum class HelixAutoModMessageError {
|
||||
Unknown,
|
||||
MessageAlreadyProcessed,
|
||||
UserNotAuthenticated,
|
||||
UserNotAuthorized,
|
||||
MessageNotFound,
|
||||
};
|
||||
|
||||
class Helix final : boost::noncopyable
|
||||
{
|
||||
public:
|
||||
@@ -307,6 +315,12 @@ public:
|
||||
std::function<void(NetworkResult)> successCallback,
|
||||
HelixFailureCallback failureCallback);
|
||||
|
||||
// https://dev.twitch.tv/docs/api/reference#manage-held-automod-messages
|
||||
void manageAutoModMessages(
|
||||
QString userID, QString msgID, QString action,
|
||||
std::function<void()> successCallback,
|
||||
std::function<void(HelixAutoModMessageError)> failureCallback);
|
||||
|
||||
void update(QString clientId, QString oauthToken);
|
||||
|
||||
static void initialize();
|
||||
|
||||
@@ -4,7 +4,7 @@ this folder describes what sort of API requests we do, what permissions are requ
|
||||
|
||||
## Kraken (V5)
|
||||
|
||||
We use a bunch of Kraken (V5) in Chatterino2.
|
||||
We use few Kraken endpoints in Chatterino2.
|
||||
|
||||
### Get Cheermotes
|
||||
|
||||
@@ -23,18 +23,6 @@ Migration path: **Unknown**
|
||||
|
||||
- We use this in `providers/twitch/TwitchAccount.cpp loadEmotes` to figure out which emotes a user is allowed to use!
|
||||
|
||||
### AUTOMOD APPROVE
|
||||
|
||||
**Unofficial** documentation: https://discuss.dev.twitch.tv/t/allowing-others-aka-bots-to-use-twitchbot-reject/8508/2
|
||||
|
||||
- We use this in `providers/twitch/TwitchAccount.cpp autoModAllow` to approve an automod deny/allow question
|
||||
|
||||
### AUTOMOD DENY
|
||||
|
||||
**Unofficial** documentation: https://discuss.dev.twitch.tv/t/allowing-others-aka-bots-to-use-twitchbot-reject/8508/2
|
||||
|
||||
- We use this in `providers/twitch/TwitchAccount.cpp autoModDeny` to deny an automod deny/allow question
|
||||
|
||||
## Helix
|
||||
|
||||
Full Helix API reference: https://dev.twitch.tv/docs/api/reference
|
||||
@@ -160,6 +148,15 @@ URL: https://dev.twitch.tv/docs/api/reference#search-categories
|
||||
Used in:
|
||||
- `controllers/commands/CommandController.cpp` in `/setgame` command to fuzzy search for game titles
|
||||
|
||||
### Manage Held AutoMod Messages
|
||||
|
||||
URL: https://dev.twitch.tv/docs/api/reference#manage-held-automod-messages
|
||||
Requires `moderator:manage:automod` scope
|
||||
|
||||
- We implement this in `providers/twitch/api/Helix.cpp manageAutoModMessages`
|
||||
Used in:
|
||||
- `providers/twitch/TwitchAccount.cpp` to approve/deny held AutoMod messages
|
||||
|
||||
## TMI
|
||||
|
||||
The TMI api is undocumented.
|
||||
|
||||
Reference in New Issue
Block a user