feat(eventsub): implement automod message update (#6010)

This commit is contained in:
nerix
2025-03-01 15:46:41 +01:00
committed by GitHub
parent bced3c658d
commit 17a44e19bb
11 changed files with 1028 additions and 19 deletions
@@ -0,0 +1,297 @@
{
"input": [
{
"__subscription": "automod-message-hold",
"automod": {
"boundaries": [
{
"end_pos": 2,
"start_pos": 0
}
],
"category": "swearing",
"level": 4
},
"blocked_term": null,
"broadcaster_user_id": "11148817",
"broadcaster_user_login": "pajlada",
"broadcaster_user_name": "pajlada",
"held_at": "2025-02-28T16:15:15.008668809Z",
"message": {
"fragments": [
{
"cheermote": null,
"emote": null,
"text": "ass",
"type": "text"
}
],
"text": "ass"
},
"message_id": "19d067ff-89b5-4790-a720-97599894eb6b",
"reason": "automod",
"user_id": "129546453",
"user_login": "nerixyz",
"user_name": "nerixyz"
},
{
"automod": {
"boundaries": [
{
"end_pos": 2,
"start_pos": 0
}
],
"category": "swearing",
"level": 4
},
"blocked_term": null,
"broadcaster_user_id": "11148817",
"broadcaster_user_login": "pajlada",
"broadcaster_user_name": "pajlada",
"held_at": "2025-02-28T16:15:15.008668809Z",
"message": {
"fragments": [
{
"cheermote": null,
"emote": null,
"text": "ass",
"type": "text"
}
],
"text": "ass"
},
"message_id": "19d067ff-89b5-4790-a720-97599894eb6b",
"moderator_user_id": "489584266",
"moderator_user_login": "uint128",
"moderator_user_name": "uint128",
"reason": "automod",
"status": "approved",
"user_id": "129546453",
"user_login": "nerixyz",
"user_name": "nerixyz"
}
],
"output": [
{
"badgeInfos": {
},
"badges": [
],
"channelName": "pajlada",
"count": 1,
"displayName": "",
"elements": [
{
"emote": {
"homePage": "https://dashboard.twitch.tv/settings/moderation/automod",
"images": {
"1x": ""
},
"name": "",
"tooltip": "AutoMod"
},
"flags": "BadgeChannelAuthority",
"link": {
"type": "None",
"value": ""
},
"tooltip": "AutoMod",
"trailingSpace": true,
"type": "BadgeElement"
},
{
"color": "#ff0000ff",
"flags": "Text",
"link": {
"type": "None",
"value": ""
},
"style": "ChatMediumBold",
"tooltip": "",
"trailingSpace": true,
"type": "TextElement",
"words": [
"AutoMod:"
]
},
{
"color": "Text",
"flags": "Text",
"link": {
"type": "None",
"value": ""
},
"style": "ChatMedium",
"tooltip": "",
"trailingSpace": true,
"type": "TextElement",
"words": [
"Held",
"a",
"message",
"for",
"reason:",
"swearing",
"level",
"4.",
"Allow",
"will",
"post",
"it",
"in",
"chat.",
""
]
},
{
"color": "#ff00ff00",
"flags": "Text",
"link": {
"type": "AutoModAllow",
"value": "19d067ff-89b5-4790-a720-97599894eb6b"
},
"style": "ChatMediumBold",
"tooltip": "",
"trailingSpace": true,
"type": "TextElement",
"words": [
"Allow"
]
},
{
"color": "#ffff0000",
"flags": "Text",
"link": {
"type": "AutoModDeny",
"value": "19d067ff-89b5-4790-a720-97599894eb6b"
},
"style": "ChatMediumBold",
"tooltip": "",
"trailingSpace": true,
"type": "TextElement",
"words": [
"",
"Deny"
]
}
],
"flags": "Timeout|Disabled|PubSub|AutoMod|AutoModOffendingMessageHeader|EventSub",
"id": "automod_19d067ff-89b5-4790-a720-97599894eb6b",
"localizedName": "",
"loginName": "automod",
"messageText": "AutoMod: Held a message for reason: swearing level 4. Allow will post it in chat. Allow Deny",
"searchText": "AutoMod: Held a message for reason: swearing level 4. Allow will post it in chat. Allow Deny",
"serverReceivedTime": "2024-05-14T12:31:47Z",
"timeoutUser": "",
"userID": "",
"usernameColor": "#ff000000"
},
{
"badgeInfos": {
},
"badges": [
],
"channelName": "pajlada",
"count": 1,
"displayName": "",
"elements": [
{
"color": "System",
"flags": "ChannelName",
"link": {
"type": "JumpToChannel",
"value": "pajlada"
},
"style": "ChatMedium",
"tooltip": "",
"trailingSpace": true,
"type": "TextElement",
"words": [
"#pajlada"
]
},
{
"element": {
"color": "System",
"flags": "Timestamp",
"link": {
"type": "None",
"value": ""
},
"style": "ChatMedium",
"tooltip": "",
"trailingSpace": true,
"type": "TextElement",
"words": [
"12:31"
]
},
"flags": "Timestamp",
"format": "",
"link": {
"type": "None",
"value": ""
},
"time": "12:31:47",
"tooltip": "",
"trailingSpace": true,
"type": "TimestampElement"
},
{
"flags": "ModeratorTools",
"link": {
"type": "None",
"value": ""
},
"tooltip": "",
"trailingSpace": true,
"type": "TwitchModerationElement"
},
{
"color": "Text",
"fallbackColor": "Text",
"flags": "Text|Mention",
"link": {
"type": "None",
"value": ""
},
"style": "ChatMedium",
"tooltip": "",
"trailingSpace": true,
"type": "MentionElement",
"userColor": "Text",
"userLoginName": "nerixyz",
"words": [
"nerixyz:"
]
},
{
"color": "Text",
"flags": "Text",
"link": {
"type": "None",
"value": ""
},
"style": "ChatMedium",
"tooltip": "",
"trailingSpace": true,
"type": "TextElement",
"words": [
"ass"
]
}
],
"flags": "Timeout|PubSub|AutoMod|AutoModOffendingMessage|EventSub",
"id": "",
"localizedName": "",
"loginName": "nerixyz",
"messageText": "nerixyz: ass",
"searchText": "nerixyz: ass",
"serverReceivedTime": "2024-05-14T12:31:47Z",
"timeoutUser": "",
"userID": "",
"usernameColor": "#ff000000"
}
]
}
@@ -0,0 +1,297 @@
{
"input": [
{
"__subscription": "automod-message-hold",
"automod": {
"boundaries": [
{
"end_pos": 2,
"start_pos": 0
}
],
"category": "swearing",
"level": 4
},
"blocked_term": null,
"broadcaster_user_id": "11148817",
"broadcaster_user_login": "pajlada",
"broadcaster_user_name": "pajlada",
"held_at": "2025-02-28T16:15:15.008668809Z",
"message": {
"fragments": [
{
"cheermote": null,
"emote": null,
"text": "ass",
"type": "text"
}
],
"text": "ass"
},
"message_id": "19d067ff-89b5-4790-a720-97599894eb6b",
"reason": "automod",
"user_id": "129546453",
"user_login": "nerixyz",
"user_name": "nerixyz"
},
{
"automod": {
"boundaries": [
{
"end_pos": 2,
"start_pos": 0
}
],
"category": "swearing",
"level": 4
},
"blocked_term": null,
"broadcaster_user_id": "11148817",
"broadcaster_user_login": "pajlada",
"broadcaster_user_name": "pajlada",
"held_at": "2025-02-28T16:15:15.008668809Z",
"message": {
"fragments": [
{
"cheermote": null,
"emote": null,
"text": "ass",
"type": "text"
}
],
"text": "ass"
},
"message_id": "19d067ff-89b5-4790-a720-97599894eb6b",
"moderator_user_id": "489584266",
"moderator_user_login": "uint128",
"moderator_user_name": "uint128",
"reason": "automod",
"status": "denied",
"user_id": "129546453",
"user_login": "nerixyz",
"user_name": "nerixyz"
}
],
"output": [
{
"badgeInfos": {
},
"badges": [
],
"channelName": "pajlada",
"count": 1,
"displayName": "",
"elements": [
{
"emote": {
"homePage": "https://dashboard.twitch.tv/settings/moderation/automod",
"images": {
"1x": ""
},
"name": "",
"tooltip": "AutoMod"
},
"flags": "BadgeChannelAuthority",
"link": {
"type": "None",
"value": ""
},
"tooltip": "AutoMod",
"trailingSpace": true,
"type": "BadgeElement"
},
{
"color": "#ff0000ff",
"flags": "Text",
"link": {
"type": "None",
"value": ""
},
"style": "ChatMediumBold",
"tooltip": "",
"trailingSpace": true,
"type": "TextElement",
"words": [
"AutoMod:"
]
},
{
"color": "Text",
"flags": "Text",
"link": {
"type": "None",
"value": ""
},
"style": "ChatMedium",
"tooltip": "",
"trailingSpace": true,
"type": "TextElement",
"words": [
"Held",
"a",
"message",
"for",
"reason:",
"swearing",
"level",
"4.",
"Allow",
"will",
"post",
"it",
"in",
"chat.",
""
]
},
{
"color": "#ff00ff00",
"flags": "Text",
"link": {
"type": "AutoModAllow",
"value": "19d067ff-89b5-4790-a720-97599894eb6b"
},
"style": "ChatMediumBold",
"tooltip": "",
"trailingSpace": true,
"type": "TextElement",
"words": [
"Allow"
]
},
{
"color": "#ffff0000",
"flags": "Text",
"link": {
"type": "AutoModDeny",
"value": "19d067ff-89b5-4790-a720-97599894eb6b"
},
"style": "ChatMediumBold",
"tooltip": "",
"trailingSpace": true,
"type": "TextElement",
"words": [
"",
"Deny"
]
}
],
"flags": "Timeout|Disabled|PubSub|AutoMod|AutoModOffendingMessageHeader|EventSub",
"id": "automod_19d067ff-89b5-4790-a720-97599894eb6b",
"localizedName": "",
"loginName": "automod",
"messageText": "AutoMod: Held a message for reason: swearing level 4. Allow will post it in chat. Allow Deny",
"searchText": "AutoMod: Held a message for reason: swearing level 4. Allow will post it in chat. Allow Deny",
"serverReceivedTime": "2024-05-14T12:31:47Z",
"timeoutUser": "",
"userID": "",
"usernameColor": "#ff000000"
},
{
"badgeInfos": {
},
"badges": [
],
"channelName": "pajlada",
"count": 1,
"displayName": "",
"elements": [
{
"color": "System",
"flags": "ChannelName",
"link": {
"type": "JumpToChannel",
"value": "pajlada"
},
"style": "ChatMedium",
"tooltip": "",
"trailingSpace": true,
"type": "TextElement",
"words": [
"#pajlada"
]
},
{
"element": {
"color": "System",
"flags": "Timestamp",
"link": {
"type": "None",
"value": ""
},
"style": "ChatMedium",
"tooltip": "",
"trailingSpace": true,
"type": "TextElement",
"words": [
"12:31"
]
},
"flags": "Timestamp",
"format": "",
"link": {
"type": "None",
"value": ""
},
"time": "12:31:47",
"tooltip": "",
"trailingSpace": true,
"type": "TimestampElement"
},
{
"flags": "ModeratorTools",
"link": {
"type": "None",
"value": ""
},
"tooltip": "",
"trailingSpace": true,
"type": "TwitchModerationElement"
},
{
"color": "Text",
"fallbackColor": "Text",
"flags": "Text|Mention",
"link": {
"type": "None",
"value": ""
},
"style": "ChatMedium",
"tooltip": "",
"trailingSpace": true,
"type": "MentionElement",
"userColor": "Text",
"userLoginName": "nerixyz",
"words": [
"nerixyz:"
]
},
{
"color": "Text",
"flags": "Text",
"link": {
"type": "None",
"value": ""
},
"style": "ChatMedium",
"tooltip": "",
"trailingSpace": true,
"type": "TextElement",
"words": [
"ass"
]
}
],
"flags": "Timeout|PubSub|AutoMod|AutoModOffendingMessage|EventSub",
"id": "",
"localizedName": "",
"loginName": "nerixyz",
"messageText": "nerixyz: ass",
"searchText": "nerixyz: ass",
"serverReceivedTime": "2024-05-14T12:31:47Z",
"timeoutUser": "",
"userID": "",
"usernameColor": "#ff000000"
}
]
}
@@ -0,0 +1,297 @@
{
"input": [
{
"__subscription": "automod-message-hold",
"automod": {
"boundaries": [
{
"end_pos": 2,
"start_pos": 0
}
],
"category": "swearing",
"level": 4
},
"blocked_term": null,
"broadcaster_user_id": "11148817",
"broadcaster_user_login": "pajlada",
"broadcaster_user_name": "pajlada",
"held_at": "2025-02-28T16:15:15.008668809Z",
"message": {
"fragments": [
{
"cheermote": null,
"emote": null,
"text": "ass",
"type": "text"
}
],
"text": "ass"
},
"message_id": "19d067ff-89b5-4790-a720-97599894eb6b",
"reason": "automod",
"user_id": "129546453",
"user_login": "nerixyz",
"user_name": "nerixyz"
},
{
"automod": {
"boundaries": [
{
"end_pos": 2,
"start_pos": 0
}
],
"category": "swearing",
"level": 4
},
"blocked_term": null,
"broadcaster_user_id": "11148817",
"broadcaster_user_login": "pajlada",
"broadcaster_user_name": "pajlada",
"held_at": "2025-02-28T16:15:15.008668809Z",
"message": {
"fragments": [
{
"cheermote": null,
"emote": null,
"text": "ass",
"type": "text"
}
],
"text": "ass"
},
"message_id": "19d067ff-89b5-4790-a720-97599894eb6b",
"moderator_user_id": "489584266",
"moderator_user_login": "uint128",
"moderator_user_name": "uint128",
"reason": "automod",
"status": "expired",
"user_id": "129546453",
"user_login": "nerixyz",
"user_name": "nerixyz"
}
],
"output": [
{
"badgeInfos": {
},
"badges": [
],
"channelName": "pajlada",
"count": 1,
"displayName": "",
"elements": [
{
"emote": {
"homePage": "https://dashboard.twitch.tv/settings/moderation/automod",
"images": {
"1x": ""
},
"name": "",
"tooltip": "AutoMod"
},
"flags": "BadgeChannelAuthority",
"link": {
"type": "None",
"value": ""
},
"tooltip": "AutoMod",
"trailingSpace": true,
"type": "BadgeElement"
},
{
"color": "#ff0000ff",
"flags": "Text",
"link": {
"type": "None",
"value": ""
},
"style": "ChatMediumBold",
"tooltip": "",
"trailingSpace": true,
"type": "TextElement",
"words": [
"AutoMod:"
]
},
{
"color": "Text",
"flags": "Text",
"link": {
"type": "None",
"value": ""
},
"style": "ChatMedium",
"tooltip": "",
"trailingSpace": true,
"type": "TextElement",
"words": [
"Held",
"a",
"message",
"for",
"reason:",
"swearing",
"level",
"4.",
"Allow",
"will",
"post",
"it",
"in",
"chat.",
""
]
},
{
"color": "#ff00ff00",
"flags": "Text",
"link": {
"type": "AutoModAllow",
"value": "19d067ff-89b5-4790-a720-97599894eb6b"
},
"style": "ChatMediumBold",
"tooltip": "",
"trailingSpace": true,
"type": "TextElement",
"words": [
"Allow"
]
},
{
"color": "#ffff0000",
"flags": "Text",
"link": {
"type": "AutoModDeny",
"value": "19d067ff-89b5-4790-a720-97599894eb6b"
},
"style": "ChatMediumBold",
"tooltip": "",
"trailingSpace": true,
"type": "TextElement",
"words": [
"",
"Deny"
]
}
],
"flags": "Timeout|Disabled|PubSub|AutoMod|AutoModOffendingMessageHeader|EventSub",
"id": "automod_19d067ff-89b5-4790-a720-97599894eb6b",
"localizedName": "",
"loginName": "automod",
"messageText": "AutoMod: Held a message for reason: swearing level 4. Allow will post it in chat. Allow Deny",
"searchText": "AutoMod: Held a message for reason: swearing level 4. Allow will post it in chat. Allow Deny",
"serverReceivedTime": "2024-05-14T12:31:47Z",
"timeoutUser": "",
"userID": "",
"usernameColor": "#ff000000"
},
{
"badgeInfos": {
},
"badges": [
],
"channelName": "pajlada",
"count": 1,
"displayName": "",
"elements": [
{
"color": "System",
"flags": "ChannelName",
"link": {
"type": "JumpToChannel",
"value": "pajlada"
},
"style": "ChatMedium",
"tooltip": "",
"trailingSpace": true,
"type": "TextElement",
"words": [
"#pajlada"
]
},
{
"element": {
"color": "System",
"flags": "Timestamp",
"link": {
"type": "None",
"value": ""
},
"style": "ChatMedium",
"tooltip": "",
"trailingSpace": true,
"type": "TextElement",
"words": [
"12:31"
]
},
"flags": "Timestamp",
"format": "",
"link": {
"type": "None",
"value": ""
},
"time": "12:31:47",
"tooltip": "",
"trailingSpace": true,
"type": "TimestampElement"
},
{
"flags": "ModeratorTools",
"link": {
"type": "None",
"value": ""
},
"tooltip": "",
"trailingSpace": true,
"type": "TwitchModerationElement"
},
{
"color": "Text",
"fallbackColor": "Text",
"flags": "Text|Mention",
"link": {
"type": "None",
"value": ""
},
"style": "ChatMedium",
"tooltip": "",
"trailingSpace": true,
"type": "MentionElement",
"userColor": "Text",
"userLoginName": "nerixyz",
"words": [
"nerixyz:"
]
},
{
"color": "Text",
"flags": "Text",
"link": {
"type": "None",
"value": ""
},
"style": "ChatMedium",
"tooltip": "",
"trailingSpace": true,
"type": "TextElement",
"words": [
"ass"
]
}
],
"flags": "Timeout|PubSub|AutoMod|AutoModOffendingMessage|EventSub",
"id": "",
"localizedName": "",
"loginName": "nerixyz",
"messageText": "nerixyz: ass",
"searchText": "nerixyz: ass",
"serverReceivedTime": "2024-05-14T12:31:47Z",
"timeoutUser": "",
"userID": "",
"usernameColor": "#ff000000"
}
]
}
@@ -0,0 +1,41 @@
{
"input": {
"automod": {
"boundaries": [
{
"end_pos": 2,
"start_pos": 0
}
],
"category": "swearing",
"level": 4
},
"blocked_term": null,
"broadcaster_user_id": "11148817",
"broadcaster_user_login": "pajlada",
"broadcaster_user_name": "pajlada",
"held_at": "2025-02-28T16:15:15.008668809Z",
"message": {
"fragments": [
{
"cheermote": null,
"emote": null,
"text": "ass",
"type": "text"
}
],
"text": "ass"
},
"message_id": "19d067ff-89b5-4790-a720-97599894eb6b",
"moderator_user_id": "489584266",
"moderator_user_login": "uint128",
"moderator_user_name": "uint128",
"reason": "automod",
"status": "approved",
"user_id": "129546453",
"user_login": "nerixyz",
"user_name": "nerixyz"
},
"output": [
]
}
+47 -6
View File
@@ -82,6 +82,25 @@ const std::map<QString, std::string_view, QCompareCaseInsensitive>
"cost": 0
})",
},
{
"automod-message-update",
R"({
"id": "a3122e32-6498-4847-8675-109b9b94f29c",
"status": "enabled",
"type": "automod.message.update",
"version": "2",
"condition": {
"broadcaster_user_id": "489584266",
"moderator_user_id": "489584266"
},
"transport": {
"method":"websocket",
"session_id":"AgoQ59RRLw0mS6S000QtK8f54BIGY2VsbC1j"
},
"created_at": "2025-02-28T15:55:37.85489173Z",
"cost": 0
})",
},
{
"channel-suspicious-user-message",
R"({
@@ -222,13 +241,35 @@ TEST_P(TestEventSubMessagesP, Run)
auto subscription = SUBSCRIPTIONS.find(subcategory);
ASSERT_NE(subscription, SUBSCRIPTIONS.end()) << subcategory;
auto json = makePayload(subscription->second, snapshot->input().toObject());
QJsonArray input{snapshot->input()};
if (snapshot->input().isArray())
{
input = snapshot->input().toArray();
}
std::unique_ptr<eventsub::lib::Listener> listener =
std::make_unique<eventsub::Connection>();
auto ec = eventsub::lib::handleMessage(listener, json);
ASSERT_FALSE(ec.failed())
<< ec.what() << ec.message() << ec.location().to_string();
for (const auto inputRef : input)
{
auto inputObj = inputRef.toObject();
// "__subscription" overrides the subscription type the message is built
// as. By default, the subcategory (directory) name is used.
auto eventSubscription = subscription;
if (inputObj.contains(u"__subscription"))
{
eventSubscription =
SUBSCRIPTIONS.find(inputObj[u"__subscription"].toString());
ASSERT_NE(eventSubscription, SUBSCRIPTIONS.end());
inputObj.remove("__subscription");
}
auto json = makePayload(eventSubscription->second, inputObj);
std::unique_ptr<eventsub::lib::Listener> listener =
std::make_unique<eventsub::Connection>();
auto ec = eventsub::lib::handleMessage(listener, json);
ASSERT_FALSE(ec.failed())
<< ec.what() << ec.message() << ec.location().to_string();
}
auto messages = mainChannel->getMessageSnapshot();
QJsonArray output;