feat: add /warn command (#5474)
This commit is contained in:
@@ -77,6 +77,7 @@ static const QStringList TWITCH_DEFAULT_COMMANDS{
|
||||
"delete",
|
||||
"announce",
|
||||
"requests",
|
||||
"warn",
|
||||
};
|
||||
|
||||
static const QStringList TWITCH_WHISPER_COMMANDS{"/w", ".w"};
|
||||
|
||||
@@ -1463,16 +1463,6 @@ 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,
|
||||
@@ -1572,18 +1562,7 @@ void Helix::unbanUser(
|
||||
}
|
||||
})
|
||||
.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
|
||||
}
|
||||
|
||||
void Helix::startRaid(
|
||||
QString fromBroadcasterID, QString toBroadcasterID,
|
||||
@@ -2266,6 +2245,107 @@ void Helix::banUser(QString broadcasterID, QString moderatorID, QString userID,
|
||||
.execute();
|
||||
}
|
||||
|
||||
// Warn a user
|
||||
// https://dev.twitch.tv/docs/api/reference#warn-chat-user
|
||||
void Helix::warnUser(
|
||||
QString broadcasterID, QString moderatorID, QString userID, QString reason,
|
||||
ResultCallback<> successCallback,
|
||||
FailureCallback<HelixWarnUserError, QString> failureCallback)
|
||||
{
|
||||
using Error = HelixWarnUserError;
|
||||
|
||||
QUrlQuery urlQuery;
|
||||
|
||||
urlQuery.addQueryItem("broadcaster_id", broadcasterID);
|
||||
urlQuery.addQueryItem("moderator_id", moderatorID);
|
||||
|
||||
QJsonObject payload;
|
||||
{
|
||||
QJsonObject data;
|
||||
data["reason"] = reason;
|
||||
data["user_id"] = userID;
|
||||
|
||||
payload["data"] = data;
|
||||
}
|
||||
|
||||
this->makePost("moderation/warnings", urlQuery)
|
||||
.json(payload)
|
||||
.onSuccess([successCallback](auto result) {
|
||||
if (result.status() != 200)
|
||||
{
|
||||
qCWarning(chatterinoTwitch)
|
||||
<< "Success result for warning a user was"
|
||||
<< result.formatError() << "but we expected it to be 200";
|
||||
}
|
||||
// we don't care about the response
|
||||
successCallback();
|
||||
})
|
||||
.onError([failureCallback](const auto &result) -> void {
|
||||
if (!result.status())
|
||||
{
|
||||
failureCallback(Error::Unknown, result.formatError());
|
||||
return;
|
||||
}
|
||||
|
||||
auto obj = result.parseJson();
|
||||
auto message = obj.value("message").toString();
|
||||
|
||||
switch (*result.status())
|
||||
{
|
||||
case 400: {
|
||||
if (message.startsWith("The user specified in the user_id "
|
||||
"field may not be warned",
|
||||
Qt::CaseInsensitive))
|
||||
{
|
||||
failureCallback(Error::CannotWarnUser, message);
|
||||
}
|
||||
else
|
||||
{
|
||||
failureCallback(Error::Forwarded, message);
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case 401: {
|
||||
if (message.startsWith("Missing scope",
|
||||
Qt::CaseInsensitive))
|
||||
{
|
||||
failureCallback(Error::UserMissingScope, message);
|
||||
}
|
||||
else
|
||||
{
|
||||
failureCallback(Error::Forwarded, message);
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case 403: {
|
||||
failureCallback(Error::UserNotAuthorized, message);
|
||||
}
|
||||
break;
|
||||
|
||||
case 409: {
|
||||
failureCallback(Error::ConflictingOperation, message);
|
||||
}
|
||||
break;
|
||||
|
||||
case 429: {
|
||||
failureCallback(Error::Ratelimited, message);
|
||||
}
|
||||
break;
|
||||
|
||||
default: {
|
||||
qCDebug(chatterinoTwitch)
|
||||
<< "Unhandled error warning user:"
|
||||
<< result.formatError() << result.getData() << obj;
|
||||
failureCallback(Error::Unknown, message);
|
||||
}
|
||||
break;
|
||||
}
|
||||
})
|
||||
.execute();
|
||||
}
|
||||
|
||||
// https://dev.twitch.tv/docs/api/reference#send-whisper
|
||||
void Helix::sendWhisper(
|
||||
QString fromUserID, QString toUserID, QString message,
|
||||
|
||||
@@ -621,6 +621,18 @@ enum class HelixBanUserError { // /timeout, /ban
|
||||
Forwarded,
|
||||
}; // /timeout, /ban
|
||||
|
||||
enum class HelixWarnUserError { // /warn
|
||||
Unknown,
|
||||
UserMissingScope,
|
||||
UserNotAuthorized,
|
||||
Ratelimited,
|
||||
ConflictingOperation,
|
||||
CannotWarnUser,
|
||||
|
||||
// The error message is forwarded directly from the Twitch API
|
||||
Forwarded,
|
||||
}; // /warn
|
||||
|
||||
enum class HelixWhisperError { // /w
|
||||
Unknown,
|
||||
UserMissingScope,
|
||||
@@ -1024,6 +1036,13 @@ public:
|
||||
ResultCallback<> successCallback,
|
||||
FailureCallback<HelixBanUserError, QString> failureCallback) = 0;
|
||||
|
||||
// Warn a user
|
||||
// https://dev.twitch.tv/docs/api/reference#warn-chat-user
|
||||
virtual void warnUser(
|
||||
QString broadcasterID, QString moderatorID, QString userID,
|
||||
QString reason, ResultCallback<> successCallback,
|
||||
FailureCallback<HelixWarnUserError, QString> failureCallback) = 0;
|
||||
|
||||
// Send a whisper
|
||||
// https://dev.twitch.tv/docs/api/reference#send-whisper
|
||||
virtual void sendWhisper(
|
||||
@@ -1346,6 +1365,13 @@ public:
|
||||
ResultCallback<> successCallback,
|
||||
FailureCallback<HelixBanUserError, QString> failureCallback) final;
|
||||
|
||||
// Warn a user
|
||||
// https://dev.twitch.tv/docs/api/reference#warn-chat-user
|
||||
void warnUser(
|
||||
QString broadcasterID, QString moderatorID, QString userID,
|
||||
QString reason, ResultCallback<> successCallback,
|
||||
FailureCallback<HelixWarnUserError, QString> failureCallback) final;
|
||||
|
||||
// Send a whisper
|
||||
// https://dev.twitch.tv/docs/api/reference#send-whisper
|
||||
void sendWhisper(
|
||||
|
||||
@@ -178,13 +178,21 @@ Used in:
|
||||
|
||||
- `controllers/commands/CommandController.cpp` to send Twitch native shoutout using "/shoutout <username>"
|
||||
|
||||
### Warn Chat User
|
||||
|
||||
URL: https://dev.twitch.tv/docs/api/reference/#warn-chat-user
|
||||
|
||||
Used in:
|
||||
|
||||
- `controllers/commands/CommandController.cpp` to warn users via "/warn" command
|
||||
|
||||
## PubSub
|
||||
|
||||
### Whispers
|
||||
|
||||
We listen to the `whispers.<user_id>` PubSub topic to receive information about incoming whispers to the user
|
||||
|
||||
No EventSub alternative available.
|
||||
The EventSub alternative (`user.whisper.message`) is not yet implemented.
|
||||
|
||||
### Chat Moderator Actions
|
||||
|
||||
@@ -192,25 +200,17 @@ We listen to the `chat_moderator_actions.<user_id>.<channel_id>` PubSub topic to
|
||||
|
||||
We listen to this topic in every channel the user is a moderator.
|
||||
|
||||
No complete EventSub alternative available yet. Some functionality can be pieced together but it would not be zero cost, causing the `max_total_cost` of 10 to cause issues.
|
||||
We have not yet migrated to the EventSub equivalent topics:
|
||||
|
||||
- For showing bans & timeouts: `channel.ban`, but does not work with moderator token???
|
||||
- For showing unbans & untimeouts: `channel.unban`, but does not work with moderator token???
|
||||
- Clear/delete message: not in eventsub, and IRC doesn't tell us which mod performed the action
|
||||
- Roomstate (slow(off), followers(off), r9k(off), emoteonly(off), subscribers(off)) => not in eventsub, and IRC doesn't tell us which mod performed the action
|
||||
- VIP added => not in eventsub, but not critical
|
||||
- VIP removed => not in eventsub, but not critical
|
||||
- Moderator added => channel.moderator.add eventsub, but doesn't work with moderator token
|
||||
- Moderator removed => channel.moderator.remove eventsub, but doesn't work with moderator token
|
||||
- Raid started => channel.raid eventsub, but cost=1 for moderator token
|
||||
- Unraid => not in eventsub
|
||||
- Add permitted term => not in eventsub
|
||||
- Delete permitted term => not in eventsub
|
||||
- Add blocked term => not in eventsub
|
||||
- Delete blocked term => not in eventsub
|
||||
- Modified automod properties => not in eventsub
|
||||
- Approve unban request => cannot read moderator message in eventsub
|
||||
- Deny unban request => not in eventsub
|
||||
- For showing bans & timeouts => `channel.moderate`
|
||||
- For showing unbans & untimeouts => `channel.moderate`
|
||||
- Clear/delete message => `channel.moderate`
|
||||
- Roomstate (slow(off), followers(off), r9k(off), emoteonly(off), subscribers(off)) => `channel.moderate`
|
||||
- VIP/Moderator added/removed => `channel.moderate`
|
||||
- Raid started/cancelled => `channel.moderate`
|
||||
- Add/delete permitted/blocked term => `channel.moderate` (or `automod.terms.update`)
|
||||
- Modified automod properties => `automod.settings.update`
|
||||
- Approve/deny unban request => `channel.moderate` (or `channel.unban_request.resolve`)
|
||||
|
||||
### AutoMod Queue
|
||||
|
||||
@@ -218,7 +218,7 @@ We listen to the `automod-queue.<moderator_id>.<channel_id>` PubSub topic to rec
|
||||
|
||||
We listen to this topic in every channel the user is a moderator.
|
||||
|
||||
No EventSub alternative available yet.
|
||||
The EventSub alternative (`automod.message.hold` and `automod.message.update`) is not yet implemented.
|
||||
|
||||
### Channel Point Rewards
|
||||
|
||||
@@ -230,4 +230,4 @@ The EventSub alternative requires broadcaster auth, which is not a feasible alte
|
||||
|
||||
We want to listen to the `low-trust-users` PubSub topic to receive information about messages from users who are marked as low-trust.
|
||||
|
||||
There is no EventSub alternative available yet.
|
||||
The EventSub alternative (`channel.suspicious_user.message` and `channel.suspicious_user.update`) is not yet implemented.
|
||||
|
||||
Reference in New Issue
Block a user