feat(eventsub): implement suspicious user message (#6007)
This commit is contained in:
@@ -25,6 +25,8 @@ class CommentCommands:
|
||||
|
||||
inner_root: str = ""
|
||||
|
||||
default: Optional[str] = None
|
||||
|
||||
def __init__(self, parent: Optional["CommentCommands"] = None) -> None:
|
||||
if parent is not None:
|
||||
self.name_transform = parent.name_transform
|
||||
@@ -59,6 +61,8 @@ class CommentCommands:
|
||||
pass
|
||||
case "json_tag":
|
||||
self.tag = value
|
||||
case "default":
|
||||
self.default = value
|
||||
case other:
|
||||
log.warning(f"Unknown comment command found: {other} with value {value}")
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
from __future__ import annotations
|
||||
|
||||
from typing import List
|
||||
from typing import List, Optional
|
||||
|
||||
import logging
|
||||
|
||||
@@ -20,6 +20,7 @@ class Enum:
|
||||
self.comment_commands = CommentCommands()
|
||||
self.inner_root: str = ""
|
||||
self.namespace = namespace
|
||||
self.default: Optional[str] = None
|
||||
|
||||
@property
|
||||
def full_name(self) -> str:
|
||||
@@ -48,3 +49,4 @@ class Enum:
|
||||
|
||||
def apply_comment_commands(self, comment_commands: CommentCommands) -> None:
|
||||
self.inner_root = comment_commands.inner_root
|
||||
self.default = comment_commands.default
|
||||
|
||||
@@ -15,5 +15,9 @@ boost::json::result_for<{{enum.full_name}}, boost::json::value>::type tag_invoke
|
||||
}
|
||||
{%- endfor %}
|
||||
|
||||
{%- if enum.default -%}
|
||||
return {{enum.full_name}}::{{enum.default}};
|
||||
{%- else -%}
|
||||
EVENTSUB_BAIL_HERE(error::Kind::UnknownEnumValue);
|
||||
{%- endif -%}
|
||||
}
|
||||
|
||||
+11
-15
@@ -2,35 +2,31 @@
|
||||
|
||||
#include "twitch-eventsub-ws/payloads/structured-message.hpp"
|
||||
#include "twitch-eventsub-ws/payloads/subscription.hpp"
|
||||
#include "twitch-eventsub-ws/payloads/suspicious-users.hpp"
|
||||
|
||||
#include <boost/json.hpp>
|
||||
|
||||
#include <string>
|
||||
|
||||
namespace chatterino::eventsub::lib::payload::channel_suspicious_user_message::
|
||||
v1 {
|
||||
|
||||
struct Event {
|
||||
// Broadcaster of the channel the message was sent in
|
||||
std::string broadcasterUserID;
|
||||
std::string broadcasterUserLogin;
|
||||
std::string broadcasterUserName;
|
||||
String broadcasterUserID;
|
||||
String broadcasterUserLogin;
|
||||
String broadcasterUserName;
|
||||
|
||||
// User who sent the message
|
||||
std::string userID;
|
||||
std::string userLogin;
|
||||
std::string userName;
|
||||
String userID;
|
||||
String userLogin;
|
||||
String userName;
|
||||
|
||||
// "none", "active_monitoring", "restricted"
|
||||
std::string lowTrustStatus;
|
||||
suspicious_users::Status lowTrustStatus;
|
||||
|
||||
std::vector<std::string> sharedBanChannelIds;
|
||||
std::vector<String> sharedBanChannelIds;
|
||||
|
||||
// "manual", "ban_evader_detector", or "shared_channel_ban"
|
||||
std::vector<std::string> types;
|
||||
std::vector<suspicious_users::Type> types;
|
||||
|
||||
// "unknown", "possible", "likely"
|
||||
std::string banEvasionEvaluation;
|
||||
suspicious_users::BanEvasionEvaluation banEvasionEvaluation;
|
||||
// this event also has the ID in this message (hopefully we don't need it)
|
||||
chat::Message message;
|
||||
};
|
||||
|
||||
+12
-13
@@ -1,32 +1,31 @@
|
||||
#pragma once
|
||||
|
||||
#include "twitch-eventsub-ws/payloads/subscription.hpp"
|
||||
#include "twitch-eventsub-ws/payloads/suspicious-users.hpp"
|
||||
#include "twitch-eventsub-ws/string.hpp"
|
||||
|
||||
#include <boost/json.hpp>
|
||||
|
||||
#include <string>
|
||||
|
||||
namespace chatterino::eventsub::lib::payload::channel_suspicious_user_update::
|
||||
v1 {
|
||||
|
||||
struct Event {
|
||||
// Broadcaster of the channel
|
||||
std::string broadcasterUserID;
|
||||
std::string broadcasterUserLogin;
|
||||
std::string broadcasterUserName;
|
||||
String broadcasterUserID;
|
||||
String broadcasterUserLogin;
|
||||
String broadcasterUserName;
|
||||
|
||||
// Affected user
|
||||
std::string userID;
|
||||
std::string userLogin;
|
||||
std::string userName;
|
||||
String userID;
|
||||
String userLogin;
|
||||
String userName;
|
||||
|
||||
// Moderator who updated the user
|
||||
std::string moderatorUserID;
|
||||
std::string moderatorUserLogin;
|
||||
std::string moderatorUserName;
|
||||
String moderatorUserID;
|
||||
String moderatorUserLogin;
|
||||
String moderatorUserName;
|
||||
|
||||
// "none", "active_monitoring", or "restricted"
|
||||
std::string lowTrustStatus;
|
||||
suspicious_users::Status lowTrustStatus;
|
||||
};
|
||||
|
||||
struct Payload {
|
||||
|
||||
@@ -0,0 +1,31 @@
|
||||
#pragma once
|
||||
|
||||
#include <cstdint>
|
||||
|
||||
namespace chatterino::eventsub::lib::suspicious_users {
|
||||
|
||||
/// default=None
|
||||
enum class Status : std::uint8_t {
|
||||
None,
|
||||
ActiveMonitoring,
|
||||
Restricted,
|
||||
};
|
||||
|
||||
/// default=Unknown
|
||||
enum class Type : std::uint8_t {
|
||||
Unknown,
|
||||
Manual,
|
||||
BanEvaderDetector,
|
||||
SharedChannelBan
|
||||
};
|
||||
|
||||
/// default=Unknown
|
||||
enum class BanEvasionEvaluation : std::uint8_t {
|
||||
Unknown,
|
||||
Possible,
|
||||
Likely,
|
||||
};
|
||||
|
||||
#include "twitch-eventsub-ws/payloads/suspicious-users.inc"
|
||||
|
||||
} // namespace chatterino::eventsub::lib::suspicious_users
|
||||
@@ -0,0 +1,9 @@
|
||||
boost::json::result_for<Status, boost::json::value>::type tag_invoke(
|
||||
boost::json::try_value_to_tag<Status>, const boost::json::value &jvRoot);
|
||||
|
||||
boost::json::result_for<Type, boost::json::value>::type tag_invoke(
|
||||
boost::json::try_value_to_tag<Type>, const boost::json::value &jvRoot);
|
||||
|
||||
boost::json::result_for<BanEvasionEvaluation, boost::json::value>::type
|
||||
tag_invoke(boost::json::try_value_to_tag<BanEvasionEvaluation>,
|
||||
const boost::json::value &jvRoot);
|
||||
@@ -21,6 +21,7 @@ generate_json_impls(
|
||||
include/twitch-eventsub-ws/payloads/stream-online-v1.hpp
|
||||
include/twitch-eventsub-ws/payloads/structured-message.hpp
|
||||
include/twitch-eventsub-ws/payloads/subscription.hpp
|
||||
include/twitch-eventsub-ws/payloads/suspicious-users.hpp
|
||||
)
|
||||
|
||||
set(SOURCE_FILES
|
||||
|
||||
+23
-17
@@ -26,7 +26,7 @@ boost::json::result_for<Event, boost::json::value>::type tag_invoke(
|
||||
}
|
||||
|
||||
auto broadcasterUserID =
|
||||
boost::json::try_value_to<std::string>(*jvbroadcasterUserID);
|
||||
boost::json::try_value_to<String>(*jvbroadcasterUserID);
|
||||
|
||||
if (broadcasterUserID.has_error())
|
||||
{
|
||||
@@ -41,7 +41,7 @@ boost::json::result_for<Event, boost::json::value>::type tag_invoke(
|
||||
}
|
||||
|
||||
auto broadcasterUserLogin =
|
||||
boost::json::try_value_to<std::string>(*jvbroadcasterUserLogin);
|
||||
boost::json::try_value_to<String>(*jvbroadcasterUserLogin);
|
||||
|
||||
if (broadcasterUserLogin.has_error())
|
||||
{
|
||||
@@ -56,7 +56,7 @@ boost::json::result_for<Event, boost::json::value>::type tag_invoke(
|
||||
}
|
||||
|
||||
auto broadcasterUserName =
|
||||
boost::json::try_value_to<std::string>(*jvbroadcasterUserName);
|
||||
boost::json::try_value_to<String>(*jvbroadcasterUserName);
|
||||
|
||||
if (broadcasterUserName.has_error())
|
||||
{
|
||||
@@ -69,7 +69,7 @@ boost::json::result_for<Event, boost::json::value>::type tag_invoke(
|
||||
EVENTSUB_BAIL_HERE(error::Kind::FieldMissing);
|
||||
}
|
||||
|
||||
auto userID = boost::json::try_value_to<std::string>(*jvuserID);
|
||||
auto userID = boost::json::try_value_to<String>(*jvuserID);
|
||||
|
||||
if (userID.has_error())
|
||||
{
|
||||
@@ -82,7 +82,7 @@ boost::json::result_for<Event, boost::json::value>::type tag_invoke(
|
||||
EVENTSUB_BAIL_HERE(error::Kind::FieldMissing);
|
||||
}
|
||||
|
||||
auto userLogin = boost::json::try_value_to<std::string>(*jvuserLogin);
|
||||
auto userLogin = boost::json::try_value_to<String>(*jvuserLogin);
|
||||
|
||||
if (userLogin.has_error())
|
||||
{
|
||||
@@ -95,13 +95,15 @@ boost::json::result_for<Event, boost::json::value>::type tag_invoke(
|
||||
EVENTSUB_BAIL_HERE(error::Kind::FieldMissing);
|
||||
}
|
||||
|
||||
auto userName = boost::json::try_value_to<std::string>(*jvuserName);
|
||||
auto userName = boost::json::try_value_to<String>(*jvuserName);
|
||||
|
||||
if (userName.has_error())
|
||||
{
|
||||
return userName.error();
|
||||
}
|
||||
|
||||
static_assert(std::is_trivially_copyable_v<std::remove_reference_t<
|
||||
decltype(std::declval<Event>().lowTrustStatus)>>);
|
||||
const auto *jvlowTrustStatus = root.if_contains("low_trust_status");
|
||||
if (jvlowTrustStatus == nullptr)
|
||||
{
|
||||
@@ -109,21 +111,21 @@ boost::json::result_for<Event, boost::json::value>::type tag_invoke(
|
||||
}
|
||||
|
||||
auto lowTrustStatus =
|
||||
boost::json::try_value_to<std::string>(*jvlowTrustStatus);
|
||||
boost::json::try_value_to<suspicious_users::Status>(*jvlowTrustStatus);
|
||||
|
||||
if (lowTrustStatus.has_error())
|
||||
{
|
||||
return lowTrustStatus.error();
|
||||
}
|
||||
|
||||
std::vector<std::string> vsharedBanChannelIds;
|
||||
std::vector<chatterino::eventsub::lib::String> vsharedBanChannelIds;
|
||||
const auto *jvsharedBanChannelIds =
|
||||
root.if_contains("shared_ban_channel_ids");
|
||||
if (jvsharedBanChannelIds != nullptr && !jvsharedBanChannelIds->is_null())
|
||||
{
|
||||
auto sharedBanChannelIds =
|
||||
boost::json::try_value_to<std::vector<std::string>>(
|
||||
*jvsharedBanChannelIds);
|
||||
auto sharedBanChannelIds = boost::json::try_value_to<
|
||||
std::vector<chatterino::eventsub::lib::String>>(
|
||||
*jvsharedBanChannelIds);
|
||||
if (sharedBanChannelIds.has_error())
|
||||
{
|
||||
return sharedBanChannelIds.error();
|
||||
@@ -134,12 +136,13 @@ boost::json::result_for<Event, boost::json::value>::type tag_invoke(
|
||||
}
|
||||
}
|
||||
|
||||
std::vector<std::string> vtypes;
|
||||
std::vector<chatterino::eventsub::lib::suspicious_users::Type> vtypes;
|
||||
const auto *jvtypes = root.if_contains("types");
|
||||
if (jvtypes != nullptr && !jvtypes->is_null())
|
||||
{
|
||||
auto types =
|
||||
boost::json::try_value_to<std::vector<std::string>>(*jvtypes);
|
||||
auto types = boost::json::try_value_to<
|
||||
std::vector<chatterino::eventsub::lib::suspicious_users::Type>>(
|
||||
*jvtypes);
|
||||
if (types.has_error())
|
||||
{
|
||||
return types.error();
|
||||
@@ -149,6 +152,8 @@ boost::json::result_for<Event, boost::json::value>::type tag_invoke(
|
||||
vtypes = std::move(types.value());
|
||||
}
|
||||
}
|
||||
static_assert(std::is_trivially_copyable_v<std::remove_reference_t<
|
||||
decltype(std::declval<Event>().banEvasionEvaluation)>>);
|
||||
const auto *jvbanEvasionEvaluation =
|
||||
root.if_contains("ban_evasion_evaluation");
|
||||
if (jvbanEvasionEvaluation == nullptr)
|
||||
@@ -157,7 +162,8 @@ boost::json::result_for<Event, boost::json::value>::type tag_invoke(
|
||||
}
|
||||
|
||||
auto banEvasionEvaluation =
|
||||
boost::json::try_value_to<std::string>(*jvbanEvasionEvaluation);
|
||||
boost::json::try_value_to<suspicious_users::BanEvasionEvaluation>(
|
||||
*jvbanEvasionEvaluation);
|
||||
|
||||
if (banEvasionEvaluation.has_error())
|
||||
{
|
||||
@@ -184,10 +190,10 @@ boost::json::result_for<Event, boost::json::value>::type tag_invoke(
|
||||
.userID = std::move(userID.value()),
|
||||
.userLogin = std::move(userLogin.value()),
|
||||
.userName = std::move(userName.value()),
|
||||
.lowTrustStatus = std::move(lowTrustStatus.value()),
|
||||
.lowTrustStatus = lowTrustStatus.value(),
|
||||
.sharedBanChannelIds = std::move(vsharedBanChannelIds),
|
||||
.types = std::move(vtypes),
|
||||
.banEvasionEvaluation = std::move(banEvasionEvaluation.value()),
|
||||
.banEvasionEvaluation = banEvasionEvaluation.value(),
|
||||
.message = std::move(message.value()),
|
||||
};
|
||||
}
|
||||
|
||||
+13
-11
@@ -26,7 +26,7 @@ boost::json::result_for<Event, boost::json::value>::type tag_invoke(
|
||||
}
|
||||
|
||||
auto broadcasterUserID =
|
||||
boost::json::try_value_to<std::string>(*jvbroadcasterUserID);
|
||||
boost::json::try_value_to<String>(*jvbroadcasterUserID);
|
||||
|
||||
if (broadcasterUserID.has_error())
|
||||
{
|
||||
@@ -41,7 +41,7 @@ boost::json::result_for<Event, boost::json::value>::type tag_invoke(
|
||||
}
|
||||
|
||||
auto broadcasterUserLogin =
|
||||
boost::json::try_value_to<std::string>(*jvbroadcasterUserLogin);
|
||||
boost::json::try_value_to<String>(*jvbroadcasterUserLogin);
|
||||
|
||||
if (broadcasterUserLogin.has_error())
|
||||
{
|
||||
@@ -56,7 +56,7 @@ boost::json::result_for<Event, boost::json::value>::type tag_invoke(
|
||||
}
|
||||
|
||||
auto broadcasterUserName =
|
||||
boost::json::try_value_to<std::string>(*jvbroadcasterUserName);
|
||||
boost::json::try_value_to<String>(*jvbroadcasterUserName);
|
||||
|
||||
if (broadcasterUserName.has_error())
|
||||
{
|
||||
@@ -69,7 +69,7 @@ boost::json::result_for<Event, boost::json::value>::type tag_invoke(
|
||||
EVENTSUB_BAIL_HERE(error::Kind::FieldMissing);
|
||||
}
|
||||
|
||||
auto userID = boost::json::try_value_to<std::string>(*jvuserID);
|
||||
auto userID = boost::json::try_value_to<String>(*jvuserID);
|
||||
|
||||
if (userID.has_error())
|
||||
{
|
||||
@@ -82,7 +82,7 @@ boost::json::result_for<Event, boost::json::value>::type tag_invoke(
|
||||
EVENTSUB_BAIL_HERE(error::Kind::FieldMissing);
|
||||
}
|
||||
|
||||
auto userLogin = boost::json::try_value_to<std::string>(*jvuserLogin);
|
||||
auto userLogin = boost::json::try_value_to<String>(*jvuserLogin);
|
||||
|
||||
if (userLogin.has_error())
|
||||
{
|
||||
@@ -95,7 +95,7 @@ boost::json::result_for<Event, boost::json::value>::type tag_invoke(
|
||||
EVENTSUB_BAIL_HERE(error::Kind::FieldMissing);
|
||||
}
|
||||
|
||||
auto userName = boost::json::try_value_to<std::string>(*jvuserName);
|
||||
auto userName = boost::json::try_value_to<String>(*jvuserName);
|
||||
|
||||
if (userName.has_error())
|
||||
{
|
||||
@@ -109,7 +109,7 @@ boost::json::result_for<Event, boost::json::value>::type tag_invoke(
|
||||
}
|
||||
|
||||
auto moderatorUserID =
|
||||
boost::json::try_value_to<std::string>(*jvmoderatorUserID);
|
||||
boost::json::try_value_to<String>(*jvmoderatorUserID);
|
||||
|
||||
if (moderatorUserID.has_error())
|
||||
{
|
||||
@@ -123,7 +123,7 @@ boost::json::result_for<Event, boost::json::value>::type tag_invoke(
|
||||
}
|
||||
|
||||
auto moderatorUserLogin =
|
||||
boost::json::try_value_to<std::string>(*jvmoderatorUserLogin);
|
||||
boost::json::try_value_to<String>(*jvmoderatorUserLogin);
|
||||
|
||||
if (moderatorUserLogin.has_error())
|
||||
{
|
||||
@@ -137,13 +137,15 @@ boost::json::result_for<Event, boost::json::value>::type tag_invoke(
|
||||
}
|
||||
|
||||
auto moderatorUserName =
|
||||
boost::json::try_value_to<std::string>(*jvmoderatorUserName);
|
||||
boost::json::try_value_to<String>(*jvmoderatorUserName);
|
||||
|
||||
if (moderatorUserName.has_error())
|
||||
{
|
||||
return moderatorUserName.error();
|
||||
}
|
||||
|
||||
static_assert(std::is_trivially_copyable_v<std::remove_reference_t<
|
||||
decltype(std::declval<Event>().lowTrustStatus)>>);
|
||||
const auto *jvlowTrustStatus = root.if_contains("low_trust_status");
|
||||
if (jvlowTrustStatus == nullptr)
|
||||
{
|
||||
@@ -151,7 +153,7 @@ boost::json::result_for<Event, boost::json::value>::type tag_invoke(
|
||||
}
|
||||
|
||||
auto lowTrustStatus =
|
||||
boost::json::try_value_to<std::string>(*jvlowTrustStatus);
|
||||
boost::json::try_value_to<suspicious_users::Status>(*jvlowTrustStatus);
|
||||
|
||||
if (lowTrustStatus.has_error())
|
||||
{
|
||||
@@ -168,7 +170,7 @@ boost::json::result_for<Event, boost::json::value>::type tag_invoke(
|
||||
.moderatorUserID = std::move(moderatorUserID.value()),
|
||||
.moderatorUserLogin = std::move(moderatorUserLogin.value()),
|
||||
.moderatorUserName = std::move(moderatorUserName.value()),
|
||||
.lowTrustStatus = std::move(lowTrustStatus.value()),
|
||||
.lowTrustStatus = lowTrustStatus.value(),
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,93 @@
|
||||
// WARNING: This file is automatically generated. Any changes will be lost.
|
||||
#include "twitch-eventsub-ws/chrono.hpp" // IWYU pragma: keep
|
||||
#include "twitch-eventsub-ws/detail/errors.hpp"
|
||||
#include "twitch-eventsub-ws/detail/variant.hpp" // IWYU pragma: keep
|
||||
#include "twitch-eventsub-ws/payloads/suspicious-users.hpp"
|
||||
|
||||
#include <boost/json.hpp>
|
||||
|
||||
namespace chatterino::eventsub::lib::suspicious_users {
|
||||
|
||||
boost::json::result_for<Status, boost::json::value>::type tag_invoke(
|
||||
boost::json::try_value_to_tag<Status> /* tag */,
|
||||
const boost::json::value &jvRoot)
|
||||
{
|
||||
if (!jvRoot.is_string())
|
||||
{
|
||||
EVENTSUB_BAIL_HERE(error::Kind::ExpectedString);
|
||||
}
|
||||
std::string_view eString(jvRoot.get_string());
|
||||
|
||||
using namespace std::string_view_literals;
|
||||
if (eString == "none"sv)
|
||||
{
|
||||
return Status::None;
|
||||
}
|
||||
if (eString == "active_monitoring"sv)
|
||||
{
|
||||
return Status::ActiveMonitoring;
|
||||
}
|
||||
if (eString == "restricted"sv)
|
||||
{
|
||||
return Status::Restricted;
|
||||
}
|
||||
return Status::None;
|
||||
}
|
||||
|
||||
boost::json::result_for<Type, boost::json::value>::type tag_invoke(
|
||||
boost::json::try_value_to_tag<Type> /* tag */,
|
||||
const boost::json::value &jvRoot)
|
||||
{
|
||||
if (!jvRoot.is_string())
|
||||
{
|
||||
EVENTSUB_BAIL_HERE(error::Kind::ExpectedString);
|
||||
}
|
||||
std::string_view eString(jvRoot.get_string());
|
||||
|
||||
using namespace std::string_view_literals;
|
||||
if (eString == "unknown"sv)
|
||||
{
|
||||
return Type::Unknown;
|
||||
}
|
||||
if (eString == "manual"sv)
|
||||
{
|
||||
return Type::Manual;
|
||||
}
|
||||
if (eString == "ban_evader_detector"sv)
|
||||
{
|
||||
return Type::BanEvaderDetector;
|
||||
}
|
||||
if (eString == "shared_channel_ban"sv)
|
||||
{
|
||||
return Type::SharedChannelBan;
|
||||
}
|
||||
return Type::Unknown;
|
||||
}
|
||||
|
||||
boost::json::result_for<BanEvasionEvaluation, boost::json::value>::type
|
||||
tag_invoke(boost::json::try_value_to_tag<BanEvasionEvaluation> /* tag */,
|
||||
const boost::json::value &jvRoot)
|
||||
{
|
||||
if (!jvRoot.is_string())
|
||||
{
|
||||
EVENTSUB_BAIL_HERE(error::Kind::ExpectedString);
|
||||
}
|
||||
std::string_view eString(jvRoot.get_string());
|
||||
|
||||
using namespace std::string_view_literals;
|
||||
if (eString == "unknown"sv)
|
||||
{
|
||||
return BanEvasionEvaluation::Unknown;
|
||||
}
|
||||
if (eString == "possible"sv)
|
||||
{
|
||||
return BanEvasionEvaluation::Possible;
|
||||
}
|
||||
if (eString == "likely"sv)
|
||||
{
|
||||
return BanEvasionEvaluation::Likely;
|
||||
}
|
||||
return BanEvasionEvaluation::Unknown;
|
||||
}
|
||||
|
||||
} // namespace chatterino::eventsub::lib::suspicious_users
|
||||
Reference in New Issue
Block a user