// 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-chat-notification-v1.hpp" #include namespace chatterino::eventsub::lib::payload::channel_chat_notification::v1 { boost::json::result_for::type tag_invoke( boost::json::try_value_to_tag, const boost::json::value &jvRoot) { if (!jvRoot.is_object()) { EVENTSUB_BAIL_HERE(error::Kind::ExpectedObject); } const auto &root = jvRoot.get_object(); const auto *jvsetID = root.if_contains("set_id"); if (jvsetID == nullptr) { EVENTSUB_BAIL_HERE(error::Kind::FieldMissing); } auto setID = boost::json::try_value_to(*jvsetID); if (setID.has_error()) { return setID.error(); } const auto *jvid = root.if_contains("id"); if (jvid == nullptr) { EVENTSUB_BAIL_HERE(error::Kind::FieldMissing); } auto id = boost::json::try_value_to(*jvid); if (id.has_error()) { return id.error(); } const auto *jvinfo = root.if_contains("info"); if (jvinfo == nullptr) { EVENTSUB_BAIL_HERE(error::Kind::FieldMissing); } auto info = boost::json::try_value_to(*jvinfo); if (info.has_error()) { return info.error(); } return Badge{ .setID = std::move(setID.value()), .id = std::move(id.value()), .info = std::move(info.value()), }; } boost::json::result_for::type tag_invoke( boost::json::try_value_to_tag, const boost::json::value &jvRoot) { if (!jvRoot.is_object()) { EVENTSUB_BAIL_HERE(error::Kind::ExpectedObject); } const auto &root = jvRoot.get_object(); const auto *jvprefix = root.if_contains("prefix"); if (jvprefix == nullptr) { EVENTSUB_BAIL_HERE(error::Kind::FieldMissing); } auto prefix = boost::json::try_value_to(*jvprefix); if (prefix.has_error()) { return prefix.error(); } const auto *jvbits = root.if_contains("bits"); if (jvbits == nullptr) { EVENTSUB_BAIL_HERE(error::Kind::FieldMissing); } auto bits = boost::json::try_value_to(*jvbits); if (bits.has_error()) { return bits.error(); } const auto *jvtier = root.if_contains("tier"); if (jvtier == nullptr) { EVENTSUB_BAIL_HERE(error::Kind::FieldMissing); } auto tier = boost::json::try_value_to(*jvtier); if (tier.has_error()) { return tier.error(); } return Cheermote{ .prefix = std::move(prefix.value()), .bits = std::move(bits.value()), .tier = std::move(tier.value()), }; } boost::json::result_for::type tag_invoke( boost::json::try_value_to_tag, const boost::json::value &jvRoot) { if (!jvRoot.is_object()) { EVENTSUB_BAIL_HERE(error::Kind::ExpectedObject); } const auto &root = jvRoot.get_object(); const auto *jvid = root.if_contains("id"); if (jvid == nullptr) { EVENTSUB_BAIL_HERE(error::Kind::FieldMissing); } auto id = boost::json::try_value_to(*jvid); if (id.has_error()) { return id.error(); } const auto *jvemoteSetID = root.if_contains("emote_set_id"); if (jvemoteSetID == nullptr) { EVENTSUB_BAIL_HERE(error::Kind::FieldMissing); } auto emoteSetID = boost::json::try_value_to(*jvemoteSetID); if (emoteSetID.has_error()) { return emoteSetID.error(); } const auto *jvownerID = root.if_contains("owner_id"); if (jvownerID == nullptr) { EVENTSUB_BAIL_HERE(error::Kind::FieldMissing); } auto ownerID = boost::json::try_value_to(*jvownerID); if (ownerID.has_error()) { return ownerID.error(); } const auto *jvformat = root.if_contains("format"); if (jvformat == nullptr) { EVENTSUB_BAIL_HERE(error::Kind::FieldMissing); } const auto format = boost::json::try_value_to>(*jvformat); if (format.has_error()) { return format.error(); } return Emote{ .id = std::move(id.value()), .emoteSetID = std::move(emoteSetID.value()), .ownerID = std::move(ownerID.value()), .format = format.value(), }; } boost::json::result_for::type tag_invoke( boost::json::try_value_to_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 *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 *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(); } return Mention{ .userID = std::move(userID.value()), .userName = std::move(userName.value()), .userLogin = std::move(userLogin.value()), }; } boost::json::result_for::type tag_invoke( boost::json::try_value_to_tag, const boost::json::value &jvRoot) { if (!jvRoot.is_object()) { EVENTSUB_BAIL_HERE(error::Kind::ExpectedObject); } const auto &root = jvRoot.get_object(); const auto *jvtype = root.if_contains("type"); if (jvtype == nullptr) { EVENTSUB_BAIL_HERE(error::Kind::FieldMissing); } auto type = boost::json::try_value_to(*jvtype); if (type.has_error()) { return type.error(); } const auto *jvtext = root.if_contains("text"); if (jvtext == nullptr) { EVENTSUB_BAIL_HERE(error::Kind::FieldMissing); } auto text = boost::json::try_value_to(*jvtext); if (text.has_error()) { return text.error(); } std::optional cheermote = std::nullopt; const auto *jvcheermote = root.if_contains("cheermote"); if (jvcheermote != nullptr && !jvcheermote->is_null()) { auto tcheermote = boost::json::try_value_to(*jvcheermote); if (tcheermote.has_error()) { return tcheermote.error(); } cheermote = std::move(tcheermote.value()); } std::optional emote = std::nullopt; const auto *jvemote = root.if_contains("emote"); if (jvemote != nullptr && !jvemote->is_null()) { auto temote = boost::json::try_value_to(*jvemote); if (temote.has_error()) { return temote.error(); } emote = std::move(temote.value()); } std::optional mention = std::nullopt; const auto *jvmention = root.if_contains("mention"); if (jvmention != nullptr && !jvmention->is_null()) { auto tmention = boost::json::try_value_to(*jvmention); if (tmention.has_error()) { return tmention.error(); } mention = std::move(tmention.value()); } return MessageFragment{ .type = std::move(type.value()), .text = std::move(text.value()), .cheermote = std::move(cheermote), .emote = std::move(emote), .mention = std::move(mention), }; } boost::json::result_for::type tag_invoke( boost::json::try_value_to_tag, const boost::json::value &jvRoot) { if (!jvRoot.is_object()) { EVENTSUB_BAIL_HERE(error::Kind::ExpectedObject); } const auto &root = jvRoot.get_object(); const auto *jvsubTier = root.if_contains("sub_tier"); if (jvsubTier == nullptr) { EVENTSUB_BAIL_HERE(error::Kind::FieldMissing); } auto subTier = boost::json::try_value_to(*jvsubTier); if (subTier.has_error()) { return subTier.error(); } const auto *jvisPrime = root.if_contains("is_prime"); if (jvisPrime == nullptr) { EVENTSUB_BAIL_HERE(error::Kind::FieldMissing); } auto isPrime = boost::json::try_value_to(*jvisPrime); if (isPrime.has_error()) { return isPrime.error(); } const auto *jvdurationMonths = root.if_contains("duration_months"); if (jvdurationMonths == nullptr) { EVENTSUB_BAIL_HERE(error::Kind::FieldMissing); } auto durationMonths = boost::json::try_value_to(*jvdurationMonths); if (durationMonths.has_error()) { return durationMonths.error(); } return Subcription{ .subTier = std::move(subTier.value()), .isPrime = std::move(isPrime.value()), .durationMonths = std::move(durationMonths.value()), }; } boost::json::result_for::type tag_invoke( boost::json::try_value_to_tag, const boost::json::value &jvRoot) { if (!jvRoot.is_object()) { EVENTSUB_BAIL_HERE(error::Kind::ExpectedObject); } const auto &root = jvRoot.get_object(); const auto *jvcumulativeMonths = root.if_contains("cumulative_months"); if (jvcumulativeMonths == nullptr) { EVENTSUB_BAIL_HERE(error::Kind::FieldMissing); } auto cumulativeMonths = boost::json::try_value_to(*jvcumulativeMonths); if (cumulativeMonths.has_error()) { return cumulativeMonths.error(); } const auto *jvdurationMonths = root.if_contains("duration_months"); if (jvdurationMonths == nullptr) { EVENTSUB_BAIL_HERE(error::Kind::FieldMissing); } auto durationMonths = boost::json::try_value_to(*jvdurationMonths); if (durationMonths.has_error()) { return durationMonths.error(); } std::optional streakMonths = std::nullopt; const auto *jvstreakMonths = root.if_contains("streak_months"); if (jvstreakMonths != nullptr && !jvstreakMonths->is_null()) { auto tstreakMonths = boost::json::try_value_to(*jvstreakMonths); if (tstreakMonths.has_error()) { return tstreakMonths.error(); } streakMonths = std::move(tstreakMonths.value()); } const auto *jvsubTier = root.if_contains("sub_tier"); if (jvsubTier == nullptr) { EVENTSUB_BAIL_HERE(error::Kind::FieldMissing); } auto subTier = boost::json::try_value_to(*jvsubTier); if (subTier.has_error()) { return subTier.error(); } const auto *jvisPrime = root.if_contains("is_prime"); if (jvisPrime == nullptr) { EVENTSUB_BAIL_HERE(error::Kind::FieldMissing); } auto isPrime = boost::json::try_value_to(*jvisPrime); if (isPrime.has_error()) { return isPrime.error(); } const auto *jvisGift = root.if_contains("is_gift"); if (jvisGift == nullptr) { EVENTSUB_BAIL_HERE(error::Kind::FieldMissing); } auto isGift = boost::json::try_value_to(*jvisGift); if (isGift.has_error()) { return isGift.error(); } const auto *jvgifterIsAnonymous = root.if_contains("gifter_is_anonymous"); if (jvgifterIsAnonymous == nullptr) { EVENTSUB_BAIL_HERE(error::Kind::FieldMissing); } auto gifterIsAnonymous = boost::json::try_value_to(*jvgifterIsAnonymous); if (gifterIsAnonymous.has_error()) { return gifterIsAnonymous.error(); } std::optional gifterUserID = std::nullopt; const auto *jvgifterUserID = root.if_contains("gifter_user_id"); if (jvgifterUserID != nullptr && !jvgifterUserID->is_null()) { auto tgifterUserID = boost::json::try_value_to(*jvgifterUserID); if (tgifterUserID.has_error()) { return tgifterUserID.error(); } gifterUserID = std::move(tgifterUserID.value()); } std::optional gifterUserName = std::nullopt; const auto *jvgifterUserName = root.if_contains("gifter_user_name"); if (jvgifterUserName != nullptr && !jvgifterUserName->is_null()) { auto tgifterUserName = boost::json::try_value_to(*jvgifterUserName); if (tgifterUserName.has_error()) { return tgifterUserName.error(); } gifterUserName = std::move(tgifterUserName.value()); } std::optional gifterUserLogin = std::nullopt; const auto *jvgifterUserLogin = root.if_contains("gifter_user_login"); if (jvgifterUserLogin != nullptr && !jvgifterUserLogin->is_null()) { auto tgifterUserLogin = boost::json::try_value_to(*jvgifterUserLogin); if (tgifterUserLogin.has_error()) { return tgifterUserLogin.error(); } gifterUserLogin = std::move(tgifterUserLogin.value()); } return Resubscription{ .cumulativeMonths = std::move(cumulativeMonths.value()), .durationMonths = std::move(durationMonths.value()), .streakMonths = std::move(streakMonths), .subTier = std::move(subTier.value()), .isPrime = std::move(isPrime.value()), .isGift = std::move(isGift.value()), .gifterIsAnonymous = std::move(gifterIsAnonymous.value()), .gifterUserID = std::move(gifterUserID), .gifterUserName = std::move(gifterUserName), .gifterUserLogin = std::move(gifterUserLogin), }; } boost::json::result_for::type tag_invoke( boost::json::try_value_to_tag, const boost::json::value &jvRoot) { if (!jvRoot.is_object()) { EVENTSUB_BAIL_HERE(error::Kind::ExpectedObject); } const auto &root = jvRoot.get_object(); const auto *jvdurationMonths = root.if_contains("duration_months"); if (jvdurationMonths == nullptr) { EVENTSUB_BAIL_HERE(error::Kind::FieldMissing); } auto durationMonths = boost::json::try_value_to(*jvdurationMonths); if (durationMonths.has_error()) { return durationMonths.error(); } std::optional cumulativeTotal = std::nullopt; const auto *jvcumulativeTotal = root.if_contains("cumulative_total"); if (jvcumulativeTotal != nullptr && !jvcumulativeTotal->is_null()) { auto tcumulativeTotal = boost::json::try_value_to(*jvcumulativeTotal); if (tcumulativeTotal.has_error()) { return tcumulativeTotal.error(); } cumulativeTotal = std::move(tcumulativeTotal.value()); } std::optional streakMonths = std::nullopt; const auto *jvstreakMonths = root.if_contains("streak_months"); if (jvstreakMonths != nullptr && !jvstreakMonths->is_null()) { auto tstreakMonths = boost::json::try_value_to(*jvstreakMonths); if (tstreakMonths.has_error()) { return tstreakMonths.error(); } streakMonths = std::move(tstreakMonths.value()); } const auto *jvrecipientUserID = root.if_contains("recipient_user_id"); if (jvrecipientUserID == nullptr) { EVENTSUB_BAIL_HERE(error::Kind::FieldMissing); } auto recipientUserID = boost::json::try_value_to(*jvrecipientUserID); if (recipientUserID.has_error()) { return recipientUserID.error(); } const auto *jvrecipientUserName = root.if_contains("recipient_user_name"); if (jvrecipientUserName == nullptr) { EVENTSUB_BAIL_HERE(error::Kind::FieldMissing); } auto recipientUserName = boost::json::try_value_to(*jvrecipientUserName); if (recipientUserName.has_error()) { return recipientUserName.error(); } const auto *jvrecipientUserLogin = root.if_contains("recipient_user_login"); if (jvrecipientUserLogin == nullptr) { EVENTSUB_BAIL_HERE(error::Kind::FieldMissing); } auto recipientUserLogin = boost::json::try_value_to(*jvrecipientUserLogin); if (recipientUserLogin.has_error()) { return recipientUserLogin.error(); } const auto *jvsubTier = root.if_contains("sub_tier"); if (jvsubTier == nullptr) { EVENTSUB_BAIL_HERE(error::Kind::FieldMissing); } auto subTier = boost::json::try_value_to(*jvsubTier); if (subTier.has_error()) { return subTier.error(); } std::optional communityGiftID = std::nullopt; const auto *jvcommunityGiftID = root.if_contains("community_gift_id"); if (jvcommunityGiftID != nullptr && !jvcommunityGiftID->is_null()) { auto tcommunityGiftID = boost::json::try_value_to(*jvcommunityGiftID); if (tcommunityGiftID.has_error()) { return tcommunityGiftID.error(); } communityGiftID = std::move(tcommunityGiftID.value()); } return GiftSubscription{ .durationMonths = std::move(durationMonths.value()), .cumulativeTotal = std::move(cumulativeTotal), .streakMonths = std::move(streakMonths), .recipientUserID = std::move(recipientUserID.value()), .recipientUserName = std::move(recipientUserName.value()), .recipientUserLogin = std::move(recipientUserLogin.value()), .subTier = std::move(subTier.value()), .communityGiftID = std::move(communityGiftID), }; } boost::json::result_for::type tag_invoke(boost::json::try_value_to_tag, const boost::json::value &jvRoot) { if (!jvRoot.is_object()) { EVENTSUB_BAIL_HERE(error::Kind::ExpectedObject); } const auto &root = jvRoot.get_object(); const auto *jvid = root.if_contains("id"); if (jvid == nullptr) { EVENTSUB_BAIL_HERE(error::Kind::FieldMissing); } auto id = boost::json::try_value_to(*jvid); if (id.has_error()) { return id.error(); } const auto *jvtotal = root.if_contains("total"); if (jvtotal == nullptr) { EVENTSUB_BAIL_HERE(error::Kind::FieldMissing); } auto total = boost::json::try_value_to(*jvtotal); if (total.has_error()) { return total.error(); } const auto *jvsubTier = root.if_contains("sub_tier"); if (jvsubTier == nullptr) { EVENTSUB_BAIL_HERE(error::Kind::FieldMissing); } auto subTier = boost::json::try_value_to(*jvsubTier); if (subTier.has_error()) { return subTier.error(); } std::optional cumulativeTotal = std::nullopt; const auto *jvcumulativeTotal = root.if_contains("cumulative_total"); if (jvcumulativeTotal != nullptr && !jvcumulativeTotal->is_null()) { auto tcumulativeTotal = boost::json::try_value_to(*jvcumulativeTotal); if (tcumulativeTotal.has_error()) { return tcumulativeTotal.error(); } cumulativeTotal = std::move(tcumulativeTotal.value()); } return CommunityGiftSubscription{ .id = std::move(id.value()), .total = std::move(total.value()), .subTier = std::move(subTier.value()), .cumulativeTotal = std::move(cumulativeTotal), }; } boost::json::result_for::type tag_invoke( boost::json::try_value_to_tag, const boost::json::value &jvRoot) { if (!jvRoot.is_object()) { EVENTSUB_BAIL_HERE(error::Kind::ExpectedObject); } const auto &root = jvRoot.get_object(); const auto *jvgifterIsAnonymous = root.if_contains("gifter_is_anonymous"); if (jvgifterIsAnonymous == nullptr) { EVENTSUB_BAIL_HERE(error::Kind::FieldMissing); } auto gifterIsAnonymous = boost::json::try_value_to(*jvgifterIsAnonymous); if (gifterIsAnonymous.has_error()) { return gifterIsAnonymous.error(); } std::optional gifterUserID = std::nullopt; const auto *jvgifterUserID = root.if_contains("gifter_user_id"); if (jvgifterUserID != nullptr && !jvgifterUserID->is_null()) { auto tgifterUserID = boost::json::try_value_to(*jvgifterUserID); if (tgifterUserID.has_error()) { return tgifterUserID.error(); } gifterUserID = std::move(tgifterUserID.value()); } std::optional gifterUserName = std::nullopt; const auto *jvgifterUserName = root.if_contains("gifter_user_name"); if (jvgifterUserName != nullptr && !jvgifterUserName->is_null()) { auto tgifterUserName = boost::json::try_value_to(*jvgifterUserName); if (tgifterUserName.has_error()) { return tgifterUserName.error(); } gifterUserName = std::move(tgifterUserName.value()); } std::optional gifterUserLogin = std::nullopt; const auto *jvgifterUserLogin = root.if_contains("gifter_user_login"); if (jvgifterUserLogin != nullptr && !jvgifterUserLogin->is_null()) { auto tgifterUserLogin = boost::json::try_value_to(*jvgifterUserLogin); if (tgifterUserLogin.has_error()) { return tgifterUserLogin.error(); } gifterUserLogin = std::move(tgifterUserLogin.value()); } return GiftPaidUpgrade{ .gifterIsAnonymous = std::move(gifterIsAnonymous.value()), .gifterUserID = std::move(gifterUserID), .gifterUserName = std::move(gifterUserName), .gifterUserLogin = std::move(gifterUserLogin), }; } boost::json::result_for::type tag_invoke( boost::json::try_value_to_tag, const boost::json::value &jvRoot) { if (!jvRoot.is_object()) { EVENTSUB_BAIL_HERE(error::Kind::ExpectedObject); } const auto &root = jvRoot.get_object(); const auto *jvsubTier = root.if_contains("sub_tier"); if (jvsubTier == nullptr) { EVENTSUB_BAIL_HERE(error::Kind::FieldMissing); } auto subTier = boost::json::try_value_to(*jvsubTier); if (subTier.has_error()) { return subTier.error(); } return PrimePaidUpgrade{ .subTier = std::move(subTier.value()), }; } boost::json::result_for::type tag_invoke( boost::json::try_value_to_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 *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 *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 *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(); } const auto *jvprofileImageURL = root.if_contains("profile_image_url"); if (jvprofileImageURL == nullptr) { EVENTSUB_BAIL_HERE(error::Kind::FieldMissing); } auto profileImageURL = boost::json::try_value_to(*jvprofileImageURL); if (profileImageURL.has_error()) { return profileImageURL.error(); } return Raid{ .userID = std::move(userID.value()), .userName = std::move(userName.value()), .userLogin = std::move(userLogin.value()), .viewerCount = std::move(viewerCount.value()), .profileImageURL = std::move(profileImageURL.value()), }; } boost::json::result_for::type tag_invoke( boost::json::try_value_to_tag, const boost::json::value &jvRoot) { if (!jvRoot.is_object()) { EVENTSUB_BAIL_HERE(error::Kind::ExpectedObject); } const auto &root = jvRoot.get_object(); return Unraid{}; } boost::json::result_for::type tag_invoke( boost::json::try_value_to_tag, const boost::json::value &jvRoot) { if (!jvRoot.is_object()) { EVENTSUB_BAIL_HERE(error::Kind::ExpectedObject); } const auto &root = jvRoot.get_object(); const auto *jvgifterIsAnonymous = root.if_contains("gifter_is_anonymous"); if (jvgifterIsAnonymous == nullptr) { EVENTSUB_BAIL_HERE(error::Kind::FieldMissing); } auto gifterIsAnonymous = boost::json::try_value_to(*jvgifterIsAnonymous); if (gifterIsAnonymous.has_error()) { return gifterIsAnonymous.error(); } std::optional gifterUserID = std::nullopt; const auto *jvgifterUserID = root.if_contains("gifter_user_id"); if (jvgifterUserID != nullptr && !jvgifterUserID->is_null()) { auto tgifterUserID = boost::json::try_value_to(*jvgifterUserID); if (tgifterUserID.has_error()) { return tgifterUserID.error(); } gifterUserID = std::move(tgifterUserID.value()); } std::optional gifterUserName = std::nullopt; const auto *jvgifterUserName = root.if_contains("gifter_user_name"); if (jvgifterUserName != nullptr && !jvgifterUserName->is_null()) { auto tgifterUserName = boost::json::try_value_to(*jvgifterUserName); if (tgifterUserName.has_error()) { return tgifterUserName.error(); } gifterUserName = std::move(tgifterUserName.value()); } std::optional gifterUserLogin = std::nullopt; const auto *jvgifterUserLogin = root.if_contains("gifter_user_login"); if (jvgifterUserLogin != nullptr && !jvgifterUserLogin->is_null()) { auto tgifterUserLogin = boost::json::try_value_to(*jvgifterUserLogin); if (tgifterUserLogin.has_error()) { return tgifterUserLogin.error(); } gifterUserLogin = std::move(tgifterUserLogin.value()); } return PayItForward{ .gifterIsAnonymous = std::move(gifterIsAnonymous.value()), .gifterUserID = std::move(gifterUserID), .gifterUserName = std::move(gifterUserName), .gifterUserLogin = std::move(gifterUserLogin), }; } boost::json::result_for::type tag_invoke( boost::json::try_value_to_tag, const boost::json::value &jvRoot) { if (!jvRoot.is_object()) { EVENTSUB_BAIL_HERE(error::Kind::ExpectedObject); } const auto &root = jvRoot.get_object(); const auto *jvcolor = root.if_contains("color"); if (jvcolor == nullptr) { EVENTSUB_BAIL_HERE(error::Kind::FieldMissing); } auto color = boost::json::try_value_to(*jvcolor); if (color.has_error()) { return color.error(); } return Announcement{ .color = std::move(color.value()), }; } boost::json::result_for::type tag_invoke(boost::json::try_value_to_tag, const boost::json::value &jvRoot) { if (!jvRoot.is_object()) { EVENTSUB_BAIL_HERE(error::Kind::ExpectedObject); } const auto &root = jvRoot.get_object(); const auto *jvvalue = root.if_contains("value"); if (jvvalue == nullptr) { EVENTSUB_BAIL_HERE(error::Kind::FieldMissing); } auto value = boost::json::try_value_to(*jvvalue); if (value.has_error()) { return value.error(); } const auto *jvdecimalPlaces = root.if_contains("decimal_places"); if (jvdecimalPlaces == nullptr) { EVENTSUB_BAIL_HERE(error::Kind::FieldMissing); } auto decimalPlaces = boost::json::try_value_to(*jvdecimalPlaces); if (decimalPlaces.has_error()) { return decimalPlaces.error(); } const auto *jvcurrency = root.if_contains("currency"); if (jvcurrency == nullptr) { EVENTSUB_BAIL_HERE(error::Kind::FieldMissing); } auto currency = boost::json::try_value_to(*jvcurrency); if (currency.has_error()) { return currency.error(); } return CharityDonationAmount{ .value = std::move(value.value()), .decimalPlaces = std::move(decimalPlaces.value()), .currency = std::move(currency.value()), }; } boost::json::result_for::type tag_invoke( boost::json::try_value_to_tag, const boost::json::value &jvRoot) { if (!jvRoot.is_object()) { EVENTSUB_BAIL_HERE(error::Kind::ExpectedObject); } const auto &root = jvRoot.get_object(); const auto *jvcharityName = root.if_contains("charity_name"); if (jvcharityName == nullptr) { EVENTSUB_BAIL_HERE(error::Kind::FieldMissing); } auto charityName = boost::json::try_value_to(*jvcharityName); if (charityName.has_error()) { return charityName.error(); } const auto *jvamount = root.if_contains("amount"); if (jvamount == nullptr) { EVENTSUB_BAIL_HERE(error::Kind::FieldMissing); } auto amount = boost::json::try_value_to(*jvamount); if (amount.has_error()) { return amount.error(); } return CharityDonation{ .charityName = std::move(charityName.value()), .amount = std::move(amount.value()), }; } boost::json::result_for::type tag_invoke( boost::json::try_value_to_tag, const boost::json::value &jvRoot) { if (!jvRoot.is_object()) { EVENTSUB_BAIL_HERE(error::Kind::ExpectedObject); } const auto &root = jvRoot.get_object(); const auto *jvtier = root.if_contains("tier"); if (jvtier == nullptr) { EVENTSUB_BAIL_HERE(error::Kind::FieldMissing); } auto tier = boost::json::try_value_to(*jvtier); if (tier.has_error()) { return tier.error(); } return BitsBadgeTier{ .tier = std::move(tier.value()), }; } boost::json::result_for::type tag_invoke( boost::json::try_value_to_tag, const boost::json::value &jvRoot) { if (!jvRoot.is_object()) { EVENTSUB_BAIL_HERE(error::Kind::ExpectedObject); } const auto &root = jvRoot.get_object(); const auto *jvtext = root.if_contains("text"); if (jvtext == nullptr) { EVENTSUB_BAIL_HERE(error::Kind::FieldMissing); } auto text = boost::json::try_value_to(*jvtext); if (text.has_error()) { return text.error(); } const auto *jvfragments = root.if_contains("fragments"); if (jvfragments == nullptr) { EVENTSUB_BAIL_HERE(error::Kind::FieldMissing); } const auto fragments = boost::json::try_value_to>(*jvfragments); if (fragments.has_error()) { return fragments.error(); } return Message{ .text = std::move(text.value()), .fragments = fragments.value(), }; } boost::json::result_for::type tag_invoke( boost::json::try_value_to_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(); } const auto *jvchatterUserID = root.if_contains("chatter_user_id"); if (jvchatterUserID == nullptr) { EVENTSUB_BAIL_HERE(error::Kind::FieldMissing); } auto chatterUserID = boost::json::try_value_to(*jvchatterUserID); if (chatterUserID.has_error()) { return chatterUserID.error(); } const auto *jvchatterUserLogin = root.if_contains("chatter_user_login"); if (jvchatterUserLogin == nullptr) { EVENTSUB_BAIL_HERE(error::Kind::FieldMissing); } auto chatterUserLogin = boost::json::try_value_to(*jvchatterUserLogin); if (chatterUserLogin.has_error()) { return chatterUserLogin.error(); } const auto *jvchatterUserName = root.if_contains("chatter_user_name"); if (jvchatterUserName == nullptr) { EVENTSUB_BAIL_HERE(error::Kind::FieldMissing); } auto chatterUserName = boost::json::try_value_to(*jvchatterUserName); if (chatterUserName.has_error()) { return chatterUserName.error(); } const auto *jvchatterIsAnonymous = root.if_contains("chatter_is_anonymous"); if (jvchatterIsAnonymous == nullptr) { EVENTSUB_BAIL_HERE(error::Kind::FieldMissing); } auto chatterIsAnonymous = boost::json::try_value_to(*jvchatterIsAnonymous); if (chatterIsAnonymous.has_error()) { return chatterIsAnonymous.error(); } const auto *jvcolor = root.if_contains("color"); if (jvcolor == nullptr) { EVENTSUB_BAIL_HERE(error::Kind::FieldMissing); } auto color = boost::json::try_value_to(*jvcolor); if (color.has_error()) { return color.error(); } const auto *jvbadges = root.if_contains("badges"); if (jvbadges == nullptr) { EVENTSUB_BAIL_HERE(error::Kind::FieldMissing); } const auto badges = boost::json::try_value_to>(*jvbadges); if (badges.has_error()) { return badges.error(); } const auto *jvsystemMessage = root.if_contains("system_message"); if (jvsystemMessage == nullptr) { EVENTSUB_BAIL_HERE(error::Kind::FieldMissing); } auto systemMessage = boost::json::try_value_to(*jvsystemMessage); if (systemMessage.has_error()) { return systemMessage.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 *jvmessage = root.if_contains("message"); if (jvmessage == nullptr) { EVENTSUB_BAIL_HERE(error::Kind::FieldMissing); } auto message = boost::json::try_value_to(*jvmessage); if (message.has_error()) { return message.error(); } const auto *jvnoticeType = root.if_contains("notice_type"); if (jvnoticeType == nullptr) { EVENTSUB_BAIL_HERE(error::Kind::FieldMissing); } auto noticeType = boost::json::try_value_to(*jvnoticeType); if (noticeType.has_error()) { return noticeType.error(); } std::optional sub = std::nullopt; const auto *jvsub = root.if_contains("sub"); if (jvsub != nullptr && !jvsub->is_null()) { auto tsub = boost::json::try_value_to(*jvsub); if (tsub.has_error()) { return tsub.error(); } sub = std::move(tsub.value()); } std::optional resub = std::nullopt; const auto *jvresub = root.if_contains("resub"); if (jvresub != nullptr && !jvresub->is_null()) { auto tresub = boost::json::try_value_to(*jvresub); if (tresub.has_error()) { return tresub.error(); } resub = std::move(tresub.value()); } std::optional subGift = std::nullopt; const auto *jvsubGift = root.if_contains("sub_gift"); if (jvsubGift != nullptr && !jvsubGift->is_null()) { auto tsubGift = boost::json::try_value_to(*jvsubGift); if (tsubGift.has_error()) { return tsubGift.error(); } subGift = std::move(tsubGift.value()); } std::optional communitySubGift = std::nullopt; const auto *jvcommunitySubGift = root.if_contains("community_sub_gift"); if (jvcommunitySubGift != nullptr && !jvcommunitySubGift->is_null()) { auto tcommunitySubGift = boost::json::try_value_to( *jvcommunitySubGift); if (tcommunitySubGift.has_error()) { return tcommunitySubGift.error(); } communitySubGift = std::move(tcommunitySubGift.value()); } std::optional giftPaidUpgrade = std::nullopt; const auto *jvgiftPaidUpgrade = root.if_contains("gift_paid_upgrade"); if (jvgiftPaidUpgrade != nullptr && !jvgiftPaidUpgrade->is_null()) { auto tgiftPaidUpgrade = boost::json::try_value_to(*jvgiftPaidUpgrade); if (tgiftPaidUpgrade.has_error()) { return tgiftPaidUpgrade.error(); } giftPaidUpgrade = std::move(tgiftPaidUpgrade.value()); } std::optional primePaidUpgrade = std::nullopt; const auto *jvprimePaidUpgrade = root.if_contains("prime_paid_upgrade"); if (jvprimePaidUpgrade != nullptr && !jvprimePaidUpgrade->is_null()) { auto tprimePaidUpgrade = boost::json::try_value_to(*jvprimePaidUpgrade); if (tprimePaidUpgrade.has_error()) { return tprimePaidUpgrade.error(); } primePaidUpgrade = std::move(tprimePaidUpgrade.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 payItForward = std::nullopt; const auto *jvpayItForward = root.if_contains("pay_it_forward"); if (jvpayItForward != nullptr && !jvpayItForward->is_null()) { auto tpayItForward = boost::json::try_value_to(*jvpayItForward); if (tpayItForward.has_error()) { return tpayItForward.error(); } payItForward = std::move(tpayItForward.value()); } std::optional announcement = std::nullopt; const auto *jvannouncement = root.if_contains("announcement"); if (jvannouncement != nullptr && !jvannouncement->is_null()) { auto tannouncement = boost::json::try_value_to(*jvannouncement); if (tannouncement.has_error()) { return tannouncement.error(); } announcement = std::move(tannouncement.value()); } std::optional charityDonation = std::nullopt; const auto *jvcharityDonation = root.if_contains("charity_donation"); if (jvcharityDonation != nullptr && !jvcharityDonation->is_null()) { auto tcharityDonation = boost::json::try_value_to(*jvcharityDonation); if (tcharityDonation.has_error()) { return tcharityDonation.error(); } charityDonation = std::move(tcharityDonation.value()); } std::optional bitsBadgeTier = std::nullopt; const auto *jvbitsBadgeTier = root.if_contains("bits_badge_tier"); if (jvbitsBadgeTier != nullptr && !jvbitsBadgeTier->is_null()) { auto tbitsBadgeTier = boost::json::try_value_to(*jvbitsBadgeTier); if (tbitsBadgeTier.has_error()) { return tbitsBadgeTier.error(); } bitsBadgeTier = std::move(tbitsBadgeTier.value()); } return Event{ .broadcasterUserID = std::move(broadcasterUserID.value()), .broadcasterUserLogin = std::move(broadcasterUserLogin.value()), .broadcasterUserName = std::move(broadcasterUserName.value()), .chatterUserID = std::move(chatterUserID.value()), .chatterUserLogin = std::move(chatterUserLogin.value()), .chatterUserName = std::move(chatterUserName.value()), .chatterIsAnonymous = std::move(chatterIsAnonymous.value()), .color = std::move(color.value()), .badges = badges.value(), .systemMessage = std::move(systemMessage.value()), .messageID = std::move(messageID.value()), .message = std::move(message.value()), .noticeType = std::move(noticeType.value()), .sub = std::move(sub), .resub = std::move(resub), .subGift = std::move(subGift), .communitySubGift = std::move(communitySubGift), .giftPaidUpgrade = std::move(giftPaidUpgrade), .primePaidUpgrade = std::move(primePaidUpgrade), .raid = std::move(raid), .unraid = std::move(unraid), .payItForward = std::move(payItForward), .announcement = std::move(announcement), .charityDonation = std::move(charityDonation), .bitsBadgeTier = std::move(bitsBadgeTier), }; } boost::json::result_for::type tag_invoke( boost::json::try_value_to_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_chat_notification::v1