// 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/payloads/channel-moderate-v2.hpp" #include namespace chatterino::eventsub::lib::payload::channel_moderate::v2 { boost::json::result_for::type tag_invoke( boost::json::try_value_to_tag /* 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 == "ban"sv) { return Action::Ban; } if (eString == "timeout"sv) { return Action::Timeout; } if (eString == "unban"sv) { return Action::Unban; } if (eString == "untimeout"sv) { return Action::Untimeout; } if (eString == "clear"sv) { return Action::Clear; } if (eString == "emoteonly"sv) { return Action::Emoteonly; } if (eString == "emoteonlyoff"sv) { return Action::Emoteonlyoff; } if (eString == "followers"sv) { return Action::Followers; } if (eString == "followersoff"sv) { return Action::Followersoff; } if (eString == "uniquechat"sv) { return Action::Uniquechat; } if (eString == "uniquechatoff"sv) { return Action::Uniquechatoff; } if (eString == "slow"sv) { return Action::Slow; } if (eString == "slowoff"sv) { return Action::Slowoff; } if (eString == "subscribers"sv) { return Action::Subscribers; } if (eString == "subscribersoff"sv) { return Action::Subscribersoff; } if (eString == "unraid"sv) { return Action::Unraid; } if (eString == "delete"sv) { return Action::DeleteMessage; } if (eString == "unvip"sv) { return Action::Unvip; } if (eString == "vip"sv) { return Action::Vip; } if (eString == "raid"sv) { return Action::Raid; } if (eString == "add_blocked_term"sv) { return Action::AddBlockedTerm; } if (eString == "add_permitted_term"sv) { return Action::AddPermittedTerm; } if (eString == "remove_blocked_term"sv) { return Action::RemoveBlockedTerm; } if (eString == "remove_permitted_term"sv) { return Action::RemovePermittedTerm; } if (eString == "mod"sv) { return Action::Mod; } if (eString == "unmod"sv) { return Action::Unmod; } if (eString == "approve_unban_request"sv) { return Action::ApproveUnbanRequest; } if (eString == "deny_unban_request"sv) { return Action::DenyUnbanRequest; } if (eString == "warn"sv) { return Action::Warn; } if (eString == "shared_chat_ban"sv) { return Action::SharedChatBan; } if (eString == "shared_chat_timeout"sv) { return Action::SharedChatTimeout; } if (eString == "shared_chat_unban"sv) { return Action::SharedChatUnban; } if (eString == "shared_chat_untimeout"sv) { return Action::SharedChatUntimeout; } if (eString == "shared_chat_delete"sv) { return Action::SharedChatDelete; } EVENTSUB_BAIL_HERE(error::Kind::UnknownEnumValue); } boost::json::result_for::type tag_invoke( boost::json::try_value_to_tag /* tag */, const boost::json::value &jvRoot) { if (!jvRoot.is_object()) { EVENTSUB_BAIL_HERE(error::Kind::ExpectedObject); } const auto &root = jvRoot.get_object(); static_assert( std::is_trivially_copyable_v().followDurationMinutes)>>); const auto *jvfollowDurationMinutes = root.if_contains("follow_duration_minutes"); if (jvfollowDurationMinutes == nullptr) { EVENTSUB_BAIL_HERE(error::Kind::FieldMissing); } auto followDurationMinutes = boost::json::try_value_to(*jvfollowDurationMinutes); if (followDurationMinutes.has_error()) { return followDurationMinutes.error(); } return Followers{ .followDurationMinutes = followDurationMinutes.value(), }; } boost::json::result_for::type tag_invoke( boost::json::try_value_to_tag /* tag */, const boost::json::value &jvRoot) { if (!jvRoot.is_object()) { EVENTSUB_BAIL_HERE(error::Kind::ExpectedObject); } const auto &root = jvRoot.get_object(); static_assert(std::is_trivially_copyable_v().waitTimeSeconds)>>); const auto *jvwaitTimeSeconds = root.if_contains("wait_time_seconds"); if (jvwaitTimeSeconds == nullptr) { EVENTSUB_BAIL_HERE(error::Kind::FieldMissing); } auto waitTimeSeconds = boost::json::try_value_to(*jvwaitTimeSeconds); if (waitTimeSeconds.has_error()) { return waitTimeSeconds.error(); } return Slow{ .waitTimeSeconds = waitTimeSeconds.value(), }; } boost::json::result_for::type tag_invoke( boost::json::try_value_to_tag /* tag */, const boost::json::value &jvRoot) { if (!jvRoot.is_object()) { EVENTSUB_BAIL_HERE(error::Kind::ExpectedObject); } const auto &root = jvRoot.get_object(); const auto *jvuserID = root.if_contains("user_id"); if (jvuserID == nullptr) { EVENTSUB_BAIL_HERE(error::Kind::FieldMissing); } auto userID = boost::json::try_value_to(*jvuserID); if (userID.has_error()) { return userID.error(); } const auto *jvuserLogin = root.if_contains("user_login"); if (jvuserLogin == nullptr) { EVENTSUB_BAIL_HERE(error::Kind::FieldMissing); } auto userLogin = boost::json::try_value_to(*jvuserLogin); if (userLogin.has_error()) { return userLogin.error(); } const auto *jvuserName = root.if_contains("user_name"); if (jvuserName == nullptr) { EVENTSUB_BAIL_HERE(error::Kind::FieldMissing); } auto userName = boost::json::try_value_to(*jvuserName); if (userName.has_error()) { return userName.error(); } return Vip{ .userID = std::move(userID.value()), .userLogin = std::move(userLogin.value()), .userName = std::move(userName.value()), }; } boost::json::result_for::type tag_invoke( boost::json::try_value_to_tag /* tag */, const boost::json::value &jvRoot) { if (!jvRoot.is_object()) { EVENTSUB_BAIL_HERE(error::Kind::ExpectedObject); } const auto &root = jvRoot.get_object(); const auto *jvuserID = root.if_contains("user_id"); if (jvuserID == nullptr) { EVENTSUB_BAIL_HERE(error::Kind::FieldMissing); } auto userID = boost::json::try_value_to(*jvuserID); if (userID.has_error()) { return userID.error(); } const auto *jvuserLogin = root.if_contains("user_login"); if (jvuserLogin == nullptr) { EVENTSUB_BAIL_HERE(error::Kind::FieldMissing); } auto userLogin = boost::json::try_value_to(*jvuserLogin); if (userLogin.has_error()) { return userLogin.error(); } const auto *jvuserName = root.if_contains("user_name"); if (jvuserName == nullptr) { EVENTSUB_BAIL_HERE(error::Kind::FieldMissing); } auto userName = boost::json::try_value_to(*jvuserName); if (userName.has_error()) { return userName.error(); } return Unvip{ .userID = std::move(userID.value()), .userLogin = std::move(userLogin.value()), .userName = std::move(userName.value()), }; } boost::json::result_for::type tag_invoke( boost::json::try_value_to_tag /* tag */, const boost::json::value &jvRoot) { if (!jvRoot.is_object()) { EVENTSUB_BAIL_HERE(error::Kind::ExpectedObject); } const auto &root = jvRoot.get_object(); const auto *jvuserID = root.if_contains("user_id"); if (jvuserID == nullptr) { EVENTSUB_BAIL_HERE(error::Kind::FieldMissing); } auto userID = boost::json::try_value_to(*jvuserID); if (userID.has_error()) { return userID.error(); } const auto *jvuserLogin = root.if_contains("user_login"); if (jvuserLogin == nullptr) { EVENTSUB_BAIL_HERE(error::Kind::FieldMissing); } auto userLogin = boost::json::try_value_to(*jvuserLogin); if (userLogin.has_error()) { return userLogin.error(); } const auto *jvuserName = root.if_contains("user_name"); if (jvuserName == nullptr) { EVENTSUB_BAIL_HERE(error::Kind::FieldMissing); } auto userName = boost::json::try_value_to(*jvuserName); if (userName.has_error()) { return userName.error(); } return Mod{ .userID = std::move(userID.value()), .userLogin = std::move(userLogin.value()), .userName = std::move(userName.value()), }; } boost::json::result_for::type tag_invoke( boost::json::try_value_to_tag /* tag */, const boost::json::value &jvRoot) { if (!jvRoot.is_object()) { EVENTSUB_BAIL_HERE(error::Kind::ExpectedObject); } const auto &root = jvRoot.get_object(); const auto *jvuserID = root.if_contains("user_id"); if (jvuserID == nullptr) { EVENTSUB_BAIL_HERE(error::Kind::FieldMissing); } auto userID = boost::json::try_value_to(*jvuserID); if (userID.has_error()) { return userID.error(); } const auto *jvuserLogin = root.if_contains("user_login"); if (jvuserLogin == nullptr) { EVENTSUB_BAIL_HERE(error::Kind::FieldMissing); } auto userLogin = boost::json::try_value_to(*jvuserLogin); if (userLogin.has_error()) { return userLogin.error(); } const auto *jvuserName = root.if_contains("user_name"); if (jvuserName == nullptr) { EVENTSUB_BAIL_HERE(error::Kind::FieldMissing); } auto userName = boost::json::try_value_to(*jvuserName); if (userName.has_error()) { return userName.error(); } return Unmod{ .userID = std::move(userID.value()), .userLogin = std::move(userLogin.value()), .userName = std::move(userName.value()), }; } boost::json::result_for::type tag_invoke( boost::json::try_value_to_tag /* tag */, const boost::json::value &jvRoot) { if (!jvRoot.is_object()) { EVENTSUB_BAIL_HERE(error::Kind::ExpectedObject); } const auto &root = jvRoot.get_object(); const auto *jvuserID = root.if_contains("user_id"); if (jvuserID == nullptr) { EVENTSUB_BAIL_HERE(error::Kind::FieldMissing); } auto userID = boost::json::try_value_to(*jvuserID); if (userID.has_error()) { return userID.error(); } const auto *jvuserLogin = root.if_contains("user_login"); if (jvuserLogin == nullptr) { EVENTSUB_BAIL_HERE(error::Kind::FieldMissing); } auto userLogin = boost::json::try_value_to(*jvuserLogin); if (userLogin.has_error()) { return userLogin.error(); } const auto *jvuserName = root.if_contains("user_name"); if (jvuserName == nullptr) { EVENTSUB_BAIL_HERE(error::Kind::FieldMissing); } auto userName = boost::json::try_value_to(*jvuserName); if (userName.has_error()) { return userName.error(); } const auto *jvreason = root.if_contains("reason"); if (jvreason == nullptr) { EVENTSUB_BAIL_HERE(error::Kind::FieldMissing); } auto reason = boost::json::try_value_to(*jvreason); if (reason.has_error()) { return reason.error(); } return Ban{ .userID = std::move(userID.value()), .userLogin = std::move(userLogin.value()), .userName = std::move(userName.value()), .reason = std::move(reason.value()), }; } boost::json::result_for::type tag_invoke( boost::json::try_value_to_tag /* tag */, const boost::json::value &jvRoot) { if (!jvRoot.is_object()) { EVENTSUB_BAIL_HERE(error::Kind::ExpectedObject); } const auto &root = jvRoot.get_object(); const auto *jvuserID = root.if_contains("user_id"); if (jvuserID == nullptr) { EVENTSUB_BAIL_HERE(error::Kind::FieldMissing); } auto userID = boost::json::try_value_to(*jvuserID); if (userID.has_error()) { return userID.error(); } const auto *jvuserLogin = root.if_contains("user_login"); if (jvuserLogin == nullptr) { EVENTSUB_BAIL_HERE(error::Kind::FieldMissing); } auto userLogin = boost::json::try_value_to(*jvuserLogin); if (userLogin.has_error()) { return userLogin.error(); } const auto *jvuserName = root.if_contains("user_name"); if (jvuserName == nullptr) { EVENTSUB_BAIL_HERE(error::Kind::FieldMissing); } auto userName = boost::json::try_value_to(*jvuserName); if (userName.has_error()) { return userName.error(); } return Unban{ .userID = std::move(userID.value()), .userLogin = std::move(userLogin.value()), .userName = std::move(userName.value()), }; } boost::json::result_for::type tag_invoke( boost::json::try_value_to_tag /* tag */, const boost::json::value &jvRoot) { if (!jvRoot.is_object()) { EVENTSUB_BAIL_HERE(error::Kind::ExpectedObject); } const auto &root = jvRoot.get_object(); const auto *jvuserID = root.if_contains("user_id"); if (jvuserID == nullptr) { EVENTSUB_BAIL_HERE(error::Kind::FieldMissing); } auto userID = boost::json::try_value_to(*jvuserID); if (userID.has_error()) { return userID.error(); } const auto *jvuserLogin = root.if_contains("user_login"); if (jvuserLogin == nullptr) { EVENTSUB_BAIL_HERE(error::Kind::FieldMissing); } auto userLogin = boost::json::try_value_to(*jvuserLogin); if (userLogin.has_error()) { return userLogin.error(); } const auto *jvuserName = root.if_contains("user_name"); if (jvuserName == nullptr) { EVENTSUB_BAIL_HERE(error::Kind::FieldMissing); } auto userName = boost::json::try_value_to(*jvuserName); if (userName.has_error()) { return userName.error(); } const auto *jvreason = root.if_contains("reason"); if (jvreason == nullptr) { EVENTSUB_BAIL_HERE(error::Kind::FieldMissing); } auto reason = boost::json::try_value_to(*jvreason); if (reason.has_error()) { return reason.error(); } const auto *jvexpiresAt = root.if_contains("expires_at"); if (jvexpiresAt == nullptr) { EVENTSUB_BAIL_HERE(error::Kind::FieldMissing); } auto expiresAt = boost::json::try_value_to(*jvexpiresAt); if (expiresAt.has_error()) { return expiresAt.error(); } return Timeout{ .userID = std::move(userID.value()), .userLogin = std::move(userLogin.value()), .userName = std::move(userName.value()), .reason = std::move(reason.value()), .expiresAt = std::move(expiresAt.value()), }; } boost::json::result_for::type tag_invoke( boost::json::try_value_to_tag /* tag */, const boost::json::value &jvRoot) { if (!jvRoot.is_object()) { EVENTSUB_BAIL_HERE(error::Kind::ExpectedObject); } const auto &root = jvRoot.get_object(); const auto *jvuserID = root.if_contains("user_id"); if (jvuserID == nullptr) { EVENTSUB_BAIL_HERE(error::Kind::FieldMissing); } auto userID = boost::json::try_value_to(*jvuserID); if (userID.has_error()) { return userID.error(); } const auto *jvuserLogin = root.if_contains("user_login"); if (jvuserLogin == nullptr) { EVENTSUB_BAIL_HERE(error::Kind::FieldMissing); } auto userLogin = boost::json::try_value_to(*jvuserLogin); if (userLogin.has_error()) { return userLogin.error(); } const auto *jvuserName = root.if_contains("user_name"); if (jvuserName == nullptr) { EVENTSUB_BAIL_HERE(error::Kind::FieldMissing); } auto userName = boost::json::try_value_to(*jvuserName); if (userName.has_error()) { return userName.error(); } return Untimeout{ .userID = std::move(userID.value()), .userLogin = std::move(userLogin.value()), .userName = std::move(userName.value()), }; } boost::json::result_for::type tag_invoke( boost::json::try_value_to_tag /* tag */, const boost::json::value &jvRoot) { if (!jvRoot.is_object()) { EVENTSUB_BAIL_HERE(error::Kind::ExpectedObject); } const auto &root = jvRoot.get_object(); const auto *jvuserID = root.if_contains("user_id"); if (jvuserID == nullptr) { EVENTSUB_BAIL_HERE(error::Kind::FieldMissing); } auto userID = boost::json::try_value_to(*jvuserID); if (userID.has_error()) { return userID.error(); } const auto *jvuserLogin = root.if_contains("user_login"); if (jvuserLogin == nullptr) { EVENTSUB_BAIL_HERE(error::Kind::FieldMissing); } auto userLogin = boost::json::try_value_to(*jvuserLogin); if (userLogin.has_error()) { return userLogin.error(); } const auto *jvuserName = root.if_contains("user_name"); if (jvuserName == nullptr) { EVENTSUB_BAIL_HERE(error::Kind::FieldMissing); } auto userName = boost::json::try_value_to(*jvuserName); if (userName.has_error()) { return userName.error(); } static_assert(std::is_trivially_copyable_v().viewerCount)>>); const auto *jvviewerCount = root.if_contains("viewer_count"); if (jvviewerCount == nullptr) { EVENTSUB_BAIL_HERE(error::Kind::FieldMissing); } auto viewerCount = boost::json::try_value_to(*jvviewerCount); if (viewerCount.has_error()) { return viewerCount.error(); } return Raid{ .userID = std::move(userID.value()), .userLogin = std::move(userLogin.value()), .userName = std::move(userName.value()), .viewerCount = viewerCount.value(), }; } boost::json::result_for::type tag_invoke( boost::json::try_value_to_tag /* tag */, const boost::json::value &jvRoot) { if (!jvRoot.is_object()) { EVENTSUB_BAIL_HERE(error::Kind::ExpectedObject); } const auto &root = jvRoot.get_object(); const auto *jvuserID = root.if_contains("user_id"); if (jvuserID == nullptr) { EVENTSUB_BAIL_HERE(error::Kind::FieldMissing); } auto userID = boost::json::try_value_to(*jvuserID); if (userID.has_error()) { return userID.error(); } const auto *jvuserLogin = root.if_contains("user_login"); if (jvuserLogin == nullptr) { EVENTSUB_BAIL_HERE(error::Kind::FieldMissing); } auto userLogin = boost::json::try_value_to(*jvuserLogin); if (userLogin.has_error()) { return userLogin.error(); } const auto *jvuserName = root.if_contains("user_name"); if (jvuserName == nullptr) { EVENTSUB_BAIL_HERE(error::Kind::FieldMissing); } auto userName = boost::json::try_value_to(*jvuserName); if (userName.has_error()) { return userName.error(); } return Unraid{ .userID = std::move(userID.value()), .userLogin = std::move(userLogin.value()), .userName = std::move(userName.value()), }; } boost::json::result_for::type tag_invoke( boost::json::try_value_to_tag /* tag */, const boost::json::value &jvRoot) { if (!jvRoot.is_object()) { EVENTSUB_BAIL_HERE(error::Kind::ExpectedObject); } const auto &root = jvRoot.get_object(); const auto *jvuserID = root.if_contains("user_id"); if (jvuserID == nullptr) { EVENTSUB_BAIL_HERE(error::Kind::FieldMissing); } auto userID = boost::json::try_value_to(*jvuserID); if (userID.has_error()) { return userID.error(); } const auto *jvuserLogin = root.if_contains("user_login"); if (jvuserLogin == nullptr) { EVENTSUB_BAIL_HERE(error::Kind::FieldMissing); } auto userLogin = boost::json::try_value_to(*jvuserLogin); if (userLogin.has_error()) { return userLogin.error(); } const auto *jvuserName = root.if_contains("user_name"); if (jvuserName == nullptr) { EVENTSUB_BAIL_HERE(error::Kind::FieldMissing); } auto userName = boost::json::try_value_to(*jvuserName); if (userName.has_error()) { return userName.error(); } const auto *jvmessageID = root.if_contains("message_id"); if (jvmessageID == nullptr) { EVENTSUB_BAIL_HERE(error::Kind::FieldMissing); } auto messageID = boost::json::try_value_to(*jvmessageID); if (messageID.has_error()) { return messageID.error(); } const auto *jvmessageBody = root.if_contains("message_body"); if (jvmessageBody == nullptr) { EVENTSUB_BAIL_HERE(error::Kind::FieldMissing); } auto messageBody = boost::json::try_value_to(*jvmessageBody); if (messageBody.has_error()) { return messageBody.error(); } return Delete{ .userID = std::move(userID.value()), .userLogin = std::move(userLogin.value()), .userName = std::move(userName.value()), .messageID = std::move(messageID.value()), .messageBody = std::move(messageBody.value()), }; } boost::json::result_for::type tag_invoke( boost::json::try_value_to_tag /* tag */, const boost::json::value &jvRoot) { if (!jvRoot.is_object()) { EVENTSUB_BAIL_HERE(error::Kind::ExpectedObject); } const auto &root = jvRoot.get_object(); const auto *jvaction = root.if_contains("action"); if (jvaction == nullptr) { EVENTSUB_BAIL_HERE(error::Kind::FieldMissing); } auto action = boost::json::try_value_to(*jvaction); if (action.has_error()) { return action.error(); } const auto *jvlist = root.if_contains("list"); if (jvlist == nullptr) { EVENTSUB_BAIL_HERE(error::Kind::FieldMissing); } auto list = boost::json::try_value_to(*jvlist); if (list.has_error()) { return list.error(); } const auto *jvterms = root.if_contains("terms"); if (jvterms == nullptr) { EVENTSUB_BAIL_HERE(error::Kind::FieldMissing); } auto terms = boost::json::try_value_to>(*jvterms); if (terms.has_error()) { return terms.error(); } static_assert(std::is_trivially_copyable_v().fromAutomod)>>); const auto *jvfromAutomod = root.if_contains("from_automod"); if (jvfromAutomod == nullptr) { EVENTSUB_BAIL_HERE(error::Kind::FieldMissing); } auto fromAutomod = boost::json::try_value_to(*jvfromAutomod); if (fromAutomod.has_error()) { return fromAutomod.error(); } return AutomodTerms{ .action = std::move(action.value()), .list = std::move(list.value()), .terms = std::move(terms.value()), .fromAutomod = fromAutomod.value(), }; } boost::json::result_for::type tag_invoke( boost::json::try_value_to_tag /* tag */, const boost::json::value &jvRoot) { if (!jvRoot.is_object()) { EVENTSUB_BAIL_HERE(error::Kind::ExpectedObject); } const auto &root = jvRoot.get_object(); static_assert(std::is_trivially_copyable_v().isApproved)>>); const auto *jvisApproved = root.if_contains("is_approved"); if (jvisApproved == nullptr) { EVENTSUB_BAIL_HERE(error::Kind::FieldMissing); } auto isApproved = boost::json::try_value_to(*jvisApproved); if (isApproved.has_error()) { return isApproved.error(); } const auto *jvuserID = root.if_contains("user_id"); if (jvuserID == nullptr) { EVENTSUB_BAIL_HERE(error::Kind::FieldMissing); } auto userID = boost::json::try_value_to(*jvuserID); if (userID.has_error()) { return userID.error(); } const auto *jvuserLogin = root.if_contains("user_login"); if (jvuserLogin == nullptr) { EVENTSUB_BAIL_HERE(error::Kind::FieldMissing); } auto userLogin = boost::json::try_value_to(*jvuserLogin); if (userLogin.has_error()) { return userLogin.error(); } const auto *jvuserName = root.if_contains("user_name"); if (jvuserName == nullptr) { EVENTSUB_BAIL_HERE(error::Kind::FieldMissing); } auto userName = boost::json::try_value_to(*jvuserName); if (userName.has_error()) { return userName.error(); } const auto *jvmoderatorMessage = root.if_contains("moderator_message"); if (jvmoderatorMessage == nullptr) { EVENTSUB_BAIL_HERE(error::Kind::FieldMissing); } auto moderatorMessage = boost::json::try_value_to(*jvmoderatorMessage); if (moderatorMessage.has_error()) { return moderatorMessage.error(); } return UnbanRequest{ .isApproved = isApproved.value(), .userID = std::move(userID.value()), .userLogin = std::move(userLogin.value()), .userName = std::move(userName.value()), .moderatorMessage = std::move(moderatorMessage.value()), }; } boost::json::result_for::type tag_invoke( boost::json::try_value_to_tag /* tag */, const boost::json::value &jvRoot) { if (!jvRoot.is_object()) { EVENTSUB_BAIL_HERE(error::Kind::ExpectedObject); } const auto &root = jvRoot.get_object(); const auto *jvuserID = root.if_contains("user_id"); if (jvuserID == nullptr) { EVENTSUB_BAIL_HERE(error::Kind::FieldMissing); } auto userID = boost::json::try_value_to(*jvuserID); if (userID.has_error()) { return userID.error(); } const auto *jvuserLogin = root.if_contains("user_login"); if (jvuserLogin == nullptr) { EVENTSUB_BAIL_HERE(error::Kind::FieldMissing); } auto userLogin = boost::json::try_value_to(*jvuserLogin); if (userLogin.has_error()) { return userLogin.error(); } const auto *jvuserName = root.if_contains("user_name"); if (jvuserName == nullptr) { EVENTSUB_BAIL_HERE(error::Kind::FieldMissing); } auto userName = boost::json::try_value_to(*jvuserName); if (userName.has_error()) { return userName.error(); } const auto *jvreason = root.if_contains("reason"); if (jvreason == nullptr) { EVENTSUB_BAIL_HERE(error::Kind::FieldMissing); } auto reason = boost::json::try_value_to(*jvreason); if (reason.has_error()) { return reason.error(); } const auto *jvchatRulesCited = root.if_contains("chat_rules_cited"); if (jvchatRulesCited == nullptr) { EVENTSUB_BAIL_HERE(error::Kind::FieldMissing); } auto chatRulesCited = boost::json::try_value_to>(*jvchatRulesCited); if (chatRulesCited.has_error()) { return chatRulesCited.error(); } return Warn{ .userID = std::move(userID.value()), .userLogin = std::move(userLogin.value()), .userName = std::move(userName.value()), .reason = std::move(reason.value()), .chatRulesCited = std::move(chatRulesCited.value()), }; } boost::json::result_for::type tag_invoke( boost::json::try_value_to_tag /* tag */, const boost::json::value &jvRoot) { if (!jvRoot.is_object()) { EVENTSUB_BAIL_HERE(error::Kind::ExpectedObject); } const auto &root = jvRoot.get_object(); const auto *jvbroadcasterUserID = root.if_contains("broadcaster_user_id"); if (jvbroadcasterUserID == nullptr) { EVENTSUB_BAIL_HERE(error::Kind::FieldMissing); } auto broadcasterUserID = boost::json::try_value_to(*jvbroadcasterUserID); if (broadcasterUserID.has_error()) { return broadcasterUserID.error(); } const auto *jvbroadcasterUserLogin = root.if_contains("broadcaster_user_login"); if (jvbroadcasterUserLogin == nullptr) { EVENTSUB_BAIL_HERE(error::Kind::FieldMissing); } auto broadcasterUserLogin = boost::json::try_value_to(*jvbroadcasterUserLogin); if (broadcasterUserLogin.has_error()) { return broadcasterUserLogin.error(); } const auto *jvbroadcasterUserName = root.if_contains("broadcaster_user_name"); if (jvbroadcasterUserName == nullptr) { EVENTSUB_BAIL_HERE(error::Kind::FieldMissing); } auto broadcasterUserName = boost::json::try_value_to(*jvbroadcasterUserName); if (broadcasterUserName.has_error()) { return broadcasterUserName.error(); } std::optional sourceBroadcasterUserID = std::nullopt; const auto *jvsourceBroadcasterUserID = root.if_contains("source_broadcaster_user_id"); if (jvsourceBroadcasterUserID != nullptr && !jvsourceBroadcasterUserID->is_null()) { auto tsourceBroadcasterUserID = boost::json::try_value_to(*jvsourceBroadcasterUserID); if (tsourceBroadcasterUserID.has_error()) { return tsourceBroadcasterUserID.error(); } sourceBroadcasterUserID = std::move(tsourceBroadcasterUserID.value()); } std::optional sourceBroadcasterUserLogin = std::nullopt; const auto *jvsourceBroadcasterUserLogin = root.if_contains("source_broadcaster_user_login"); if (jvsourceBroadcasterUserLogin != nullptr && !jvsourceBroadcasterUserLogin->is_null()) { auto tsourceBroadcasterUserLogin = boost::json::try_value_to( *jvsourceBroadcasterUserLogin); if (tsourceBroadcasterUserLogin.has_error()) { return tsourceBroadcasterUserLogin.error(); } sourceBroadcasterUserLogin = std::move(tsourceBroadcasterUserLogin.value()); } std::optional sourceBroadcasterUserName = std::nullopt; const auto *jvsourceBroadcasterUserName = root.if_contains("source_broadcaster_user_name"); if (jvsourceBroadcasterUserName != nullptr && !jvsourceBroadcasterUserName->is_null()) { auto tsourceBroadcasterUserName = boost::json::try_value_to( *jvsourceBroadcasterUserName); if (tsourceBroadcasterUserName.has_error()) { return tsourceBroadcasterUserName.error(); } sourceBroadcasterUserName = std::move(tsourceBroadcasterUserName.value()); } const auto *jvmoderatorUserID = root.if_contains("moderator_user_id"); if (jvmoderatorUserID == nullptr) { EVENTSUB_BAIL_HERE(error::Kind::FieldMissing); } auto moderatorUserID = boost::json::try_value_to(*jvmoderatorUserID); if (moderatorUserID.has_error()) { return moderatorUserID.error(); } const auto *jvmoderatorUserLogin = root.if_contains("moderator_user_login"); if (jvmoderatorUserLogin == nullptr) { EVENTSUB_BAIL_HERE(error::Kind::FieldMissing); } auto moderatorUserLogin = boost::json::try_value_to(*jvmoderatorUserLogin); if (moderatorUserLogin.has_error()) { return moderatorUserLogin.error(); } const auto *jvmoderatorUserName = root.if_contains("moderator_user_name"); if (jvmoderatorUserName == nullptr) { EVENTSUB_BAIL_HERE(error::Kind::FieldMissing); } auto moderatorUserName = boost::json::try_value_to(*jvmoderatorUserName); if (moderatorUserName.has_error()) { return moderatorUserName.error(); } static_assert( std::is_trivially_copyable_v< std::remove_reference_t().action)>>); const auto *jvaction = root.if_contains("action"); if (jvaction == nullptr) { EVENTSUB_BAIL_HERE(error::Kind::FieldMissing); } auto action = boost::json::try_value_to(*jvaction); if (action.has_error()) { return action.error(); } static_assert(std::is_trivially_copyable_v().followers)>>); std::optional followers = std::nullopt; const auto *jvfollowers = root.if_contains("followers"); if (jvfollowers != nullptr && !jvfollowers->is_null()) { auto tfollowers = boost::json::try_value_to(*jvfollowers); if (tfollowers.has_error()) { return tfollowers.error(); } followers = tfollowers.value(); } static_assert( std::is_trivially_copyable_v< std::remove_reference_t().slow)>>); std::optional slow = std::nullopt; const auto *jvslow = root.if_contains("slow"); if (jvslow != nullptr && !jvslow->is_null()) { auto tslow = boost::json::try_value_to(*jvslow); if (tslow.has_error()) { return tslow.error(); } slow = tslow.value(); } std::optional vip = std::nullopt; const auto *jvvip = root.if_contains("vip"); if (jvvip != nullptr && !jvvip->is_null()) { auto tvip = boost::json::try_value_to(*jvvip); if (tvip.has_error()) { return tvip.error(); } vip = std::move(tvip.value()); } std::optional unvip = std::nullopt; const auto *jvunvip = root.if_contains("unvip"); if (jvunvip != nullptr && !jvunvip->is_null()) { auto tunvip = boost::json::try_value_to(*jvunvip); if (tunvip.has_error()) { return tunvip.error(); } unvip = std::move(tunvip.value()); } std::optional unmod = std::nullopt; const auto *jvunmod = root.if_contains("unmod"); if (jvunmod != nullptr && !jvunmod->is_null()) { auto tunmod = boost::json::try_value_to(*jvunmod); if (tunmod.has_error()) { return tunmod.error(); } unmod = std::move(tunmod.value()); } std::optional ban = std::nullopt; const auto *jvban = root.if_contains("ban"); if (jvban != nullptr && !jvban->is_null()) { auto tban = boost::json::try_value_to(*jvban); if (tban.has_error()) { return tban.error(); } ban = std::move(tban.value()); } std::optional unban = std::nullopt; const auto *jvunban = root.if_contains("unban"); if (jvunban != nullptr && !jvunban->is_null()) { auto tunban = boost::json::try_value_to(*jvunban); if (tunban.has_error()) { return tunban.error(); } unban = std::move(tunban.value()); } std::optional timeout = std::nullopt; const auto *jvtimeout = root.if_contains("timeout"); if (jvtimeout != nullptr && !jvtimeout->is_null()) { auto ttimeout = boost::json::try_value_to(*jvtimeout); if (ttimeout.has_error()) { return ttimeout.error(); } timeout = std::move(ttimeout.value()); } std::optional untimeout = std::nullopt; const auto *jvuntimeout = root.if_contains("untimeout"); if (jvuntimeout != nullptr && !jvuntimeout->is_null()) { auto tuntimeout = boost::json::try_value_to(*jvuntimeout); if (tuntimeout.has_error()) { return tuntimeout.error(); } untimeout = std::move(tuntimeout.value()); } std::optional raid = std::nullopt; const auto *jvraid = root.if_contains("raid"); if (jvraid != nullptr && !jvraid->is_null()) { auto traid = boost::json::try_value_to(*jvraid); if (traid.has_error()) { return traid.error(); } raid = std::move(traid.value()); } std::optional unraid = std::nullopt; const auto *jvunraid = root.if_contains("unraid"); if (jvunraid != nullptr && !jvunraid->is_null()) { auto tunraid = boost::json::try_value_to(*jvunraid); if (tunraid.has_error()) { return tunraid.error(); } unraid = std::move(tunraid.value()); } std::optional deleteMessage = std::nullopt; const auto *jvdeleteMessage = root.if_contains("delete"); if (jvdeleteMessage != nullptr && !jvdeleteMessage->is_null()) { auto tdeleteMessage = boost::json::try_value_to(*jvdeleteMessage); if (tdeleteMessage.has_error()) { return tdeleteMessage.error(); } deleteMessage = std::move(tdeleteMessage.value()); } std::optional automodTerms = std::nullopt; const auto *jvautomodTerms = root.if_contains("automod_terms"); if (jvautomodTerms != nullptr && !jvautomodTerms->is_null()) { auto tautomodTerms = boost::json::try_value_to(*jvautomodTerms); if (tautomodTerms.has_error()) { return tautomodTerms.error(); } automodTerms = std::move(tautomodTerms.value()); } std::optional unbanRequest = std::nullopt; const auto *jvunbanRequest = root.if_contains("unban_request"); if (jvunbanRequest != nullptr && !jvunbanRequest->is_null()) { auto tunbanRequest = boost::json::try_value_to(*jvunbanRequest); if (tunbanRequest.has_error()) { return tunbanRequest.error(); } unbanRequest = std::move(tunbanRequest.value()); } std::optional warn = std::nullopt; const auto *jvwarn = root.if_contains("warn"); if (jvwarn != nullptr && !jvwarn->is_null()) { auto twarn = boost::json::try_value_to(*jvwarn); if (twarn.has_error()) { return twarn.error(); } warn = std::move(twarn.value()); } std::optional sharedChatBan = std::nullopt; const auto *jvsharedChatBan = root.if_contains("shared_chat_ban"); if (jvsharedChatBan != nullptr && !jvsharedChatBan->is_null()) { auto tsharedChatBan = boost::json::try_value_to(*jvsharedChatBan); if (tsharedChatBan.has_error()) { return tsharedChatBan.error(); } sharedChatBan = std::move(tsharedChatBan.value()); } std::optional sharedChatUnban = std::nullopt; const auto *jvsharedChatUnban = root.if_contains("shared_chat_unban"); if (jvsharedChatUnban != nullptr && !jvsharedChatUnban->is_null()) { auto tsharedChatUnban = boost::json::try_value_to(*jvsharedChatUnban); if (tsharedChatUnban.has_error()) { return tsharedChatUnban.error(); } sharedChatUnban = std::move(tsharedChatUnban.value()); } std::optional sharedChatTimeout = std::nullopt; const auto *jvsharedChatTimeout = root.if_contains("shared_chat_timeout"); if (jvsharedChatTimeout != nullptr && !jvsharedChatTimeout->is_null()) { auto tsharedChatTimeout = boost::json::try_value_to(*jvsharedChatTimeout); if (tsharedChatTimeout.has_error()) { return tsharedChatTimeout.error(); } sharedChatTimeout = std::move(tsharedChatTimeout.value()); } std::optional sharedChatUntimeout = std::nullopt; const auto *jvsharedChatUntimeout = root.if_contains("shared_chat_untimeout"); if (jvsharedChatUntimeout != nullptr && !jvsharedChatUntimeout->is_null()) { auto tsharedChatUntimeout = boost::json::try_value_to(*jvsharedChatUntimeout); if (tsharedChatUntimeout.has_error()) { return tsharedChatUntimeout.error(); } sharedChatUntimeout = std::move(tsharedChatUntimeout.value()); } std::optional sharedChatDelete = std::nullopt; const auto *jvsharedChatDelete = root.if_contains("shared_chat_delete"); if (jvsharedChatDelete != nullptr && !jvsharedChatDelete->is_null()) { auto tsharedChatDelete = boost::json::try_value_to(*jvsharedChatDelete); if (tsharedChatDelete.has_error()) { return tsharedChatDelete.error(); } sharedChatDelete = std::move(tsharedChatDelete.value()); } return Event{ .broadcasterUserID = std::move(broadcasterUserID.value()), .broadcasterUserLogin = std::move(broadcasterUserLogin.value()), .broadcasterUserName = std::move(broadcasterUserName.value()), .sourceBroadcasterUserID = std::move(sourceBroadcasterUserID), .sourceBroadcasterUserLogin = std::move(sourceBroadcasterUserLogin), .sourceBroadcasterUserName = std::move(sourceBroadcasterUserName), .moderatorUserID = std::move(moderatorUserID.value()), .moderatorUserLogin = std::move(moderatorUserLogin.value()), .moderatorUserName = std::move(moderatorUserName.value()), .action = action.value(), .followers = followers, .slow = slow, .vip = std::move(vip), .unvip = std::move(unvip), .unmod = std::move(unmod), .ban = std::move(ban), .unban = std::move(unban), .timeout = std::move(timeout), .untimeout = std::move(untimeout), .raid = std::move(raid), .unraid = std::move(unraid), .deleteMessage = std::move(deleteMessage), .automodTerms = std::move(automodTerms), .unbanRequest = std::move(unbanRequest), .warn = std::move(warn), .sharedChatBan = std::move(sharedChatBan), .sharedChatUnban = std::move(sharedChatUnban), .sharedChatTimeout = std::move(sharedChatTimeout), .sharedChatUntimeout = std::move(sharedChatUntimeout), .sharedChatDelete = std::move(sharedChatDelete), }; } boost::json::result_for::type tag_invoke( boost::json::try_value_to_tag /* tag */, const boost::json::value &jvRoot) { if (!jvRoot.is_object()) { EVENTSUB_BAIL_HERE(error::Kind::ExpectedObject); } const auto &root = jvRoot.get_object(); const auto *jvsubscription = root.if_contains("subscription"); if (jvsubscription == nullptr) { EVENTSUB_BAIL_HERE(error::Kind::FieldMissing); } auto subscription = boost::json::try_value_to(*jvsubscription); if (subscription.has_error()) { return subscription.error(); } const auto *jvevent = root.if_contains("event"); if (jvevent == nullptr) { EVENTSUB_BAIL_HERE(error::Kind::FieldMissing); } auto event = boost::json::try_value_to(*jvevent); if (event.has_error()) { return event.error(); } return Payload{ .subscription = std::move(subscription.value()), .event = std::move(event.value()), }; } } // namespace chatterino::eventsub::lib::payload::channel_moderate::v2