refactor(eventsub): use variants for sum types (#5930)

This commit is contained in:
nerix
2025-02-08 14:33:29 +01:00
committed by GitHub
parent 0d02a6344b
commit 992f9195a7
25 changed files with 925 additions and 684 deletions
@@ -1,6 +1,7 @@
// 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/messages/metadata.hpp"
#include <boost/json.hpp>
@@ -1,6 +1,7 @@
// 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/channel-ban-v1.hpp"
#include <boost/json.hpp>
@@ -1,6 +1,7 @@
// 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/channel-chat-message-v1.hpp"
#include <boost/json.hpp>
@@ -1,6 +1,7 @@
// 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/channel-chat-notification-v1.hpp"
#include <boost/json.hpp>
@@ -979,7 +980,7 @@ boost::json::result_for<Raid, boost::json::value>::type tag_invoke(
boost::json::result_for<Unraid, boost::json::value>::type tag_invoke(
boost::json::try_value_to_tag<Unraid> /* tag */,
const boost::json::value &jvRoot)
const boost::json::value & /* jvRoot */)
{
return Unraid{};
}
@@ -1439,186 +1440,204 @@ boost::json::result_for<Event, boost::json::value>::type tag_invoke(
return message.error();
}
const auto *jvnoticeType = root.if_contains("notice_type");
if (jvnoticeType == nullptr)
const auto *jvinnerTag = root.if_contains("notice_type");
if (jvinnerTag == nullptr)
{
EVENTSUB_BAIL_HERE(error::Kind::FieldMissing);
}
auto noticeType = boost::json::try_value_to<std::string>(*jvnoticeType);
if (noticeType.has_error())
auto innerTagRes =
boost::json::try_value_to<boost::json::string>(*jvinnerTag);
if (innerTagRes.has_error())
{
return noticeType.error();
return innerTagRes.error();
}
std::optional<Subcription> sub = std::nullopt;
const auto *jvsub = root.if_contains("sub");
if (jvsub != nullptr && !jvsub->is_null())
std::string_view innerTag = *innerTagRes;
decltype(std::declval<Event>().inner) inner;
if (innerTag == Subcription::TAG)
{
auto tsub = boost::json::try_value_to<Subcription>(*jvsub);
if (tsub.has_error())
const auto *innerVal =
root.if_contains(detail::fieldFor<Subcription>());
if (!innerVal)
{
return tsub.error();
EVENTSUB_BAIL_HERE(error::Kind::FieldMissing);
}
sub = std::move(tsub.value());
auto innerSubcription =
boost::json::try_value_to<Subcription>(*innerVal);
if (innerSubcription.has_error())
{
return innerSubcription.error();
}
inner.emplace<Subcription>(std::move(innerSubcription.value()));
}
std::optional<Resubscription> resub = std::nullopt;
const auto *jvresub = root.if_contains("resub");
if (jvresub != nullptr && !jvresub->is_null())
else if (innerTag == Resubscription::TAG)
{
auto tresub = boost::json::try_value_to<Resubscription>(*jvresub);
if (tresub.has_error())
const auto *innerVal =
root.if_contains(detail::fieldFor<Resubscription>());
if (!innerVal)
{
return tresub.error();
EVENTSUB_BAIL_HERE(error::Kind::FieldMissing);
}
resub = std::move(tresub.value());
auto innerResubscription =
boost::json::try_value_to<Resubscription>(*innerVal);
if (innerResubscription.has_error())
{
return innerResubscription.error();
}
inner.emplace<Resubscription>(std::move(innerResubscription.value()));
}
std::optional<GiftSubscription> subGift = std::nullopt;
const auto *jvsubGift = root.if_contains("sub_gift");
if (jvsubGift != nullptr && !jvsubGift->is_null())
else if (innerTag == GiftSubscription::TAG)
{
auto tsubGift = boost::json::try_value_to<GiftSubscription>(*jvsubGift);
if (tsubGift.has_error())
const auto *innerVal =
root.if_contains(detail::fieldFor<GiftSubscription>());
if (!innerVal)
{
return tsubGift.error();
EVENTSUB_BAIL_HERE(error::Kind::FieldMissing);
}
subGift = std::move(tsubGift.value());
auto innerGiftSubscription =
boost::json::try_value_to<GiftSubscription>(*innerVal);
if (innerGiftSubscription.has_error())
{
return innerGiftSubscription.error();
}
inner.emplace<GiftSubscription>(
std::move(innerGiftSubscription.value()));
}
std::optional<CommunityGiftSubscription> communitySubGift = std::nullopt;
const auto *jvcommunitySubGift = root.if_contains("community_sub_gift");
if (jvcommunitySubGift != nullptr && !jvcommunitySubGift->is_null())
else if (innerTag == CommunityGiftSubscription::TAG)
{
auto tcommunitySubGift =
boost::json::try_value_to<CommunityGiftSubscription>(
*jvcommunitySubGift);
if (tcommunitySubGift.has_error())
const auto *innerVal =
root.if_contains(detail::fieldFor<CommunityGiftSubscription>());
if (!innerVal)
{
return tcommunitySubGift.error();
EVENTSUB_BAIL_HERE(error::Kind::FieldMissing);
}
communitySubGift = std::move(tcommunitySubGift.value());
auto innerCommunityGiftSubscription =
boost::json::try_value_to<CommunityGiftSubscription>(*innerVal);
if (innerCommunityGiftSubscription.has_error())
{
return innerCommunityGiftSubscription.error();
}
inner.emplace<CommunityGiftSubscription>(
std::move(innerCommunityGiftSubscription.value()));
}
std::optional<GiftPaidUpgrade> giftPaidUpgrade = std::nullopt;
const auto *jvgiftPaidUpgrade = root.if_contains("gift_paid_upgrade");
if (jvgiftPaidUpgrade != nullptr && !jvgiftPaidUpgrade->is_null())
else if (innerTag == GiftPaidUpgrade::TAG)
{
auto tgiftPaidUpgrade =
boost::json::try_value_to<GiftPaidUpgrade>(*jvgiftPaidUpgrade);
if (tgiftPaidUpgrade.has_error())
const auto *innerVal =
root.if_contains(detail::fieldFor<GiftPaidUpgrade>());
if (!innerVal)
{
return tgiftPaidUpgrade.error();
EVENTSUB_BAIL_HERE(error::Kind::FieldMissing);
}
giftPaidUpgrade = std::move(tgiftPaidUpgrade.value());
auto innerGiftPaidUpgrade =
boost::json::try_value_to<GiftPaidUpgrade>(*innerVal);
if (innerGiftPaidUpgrade.has_error())
{
return innerGiftPaidUpgrade.error();
}
inner.emplace<GiftPaidUpgrade>(std::move(innerGiftPaidUpgrade.value()));
}
std::optional<PrimePaidUpgrade> primePaidUpgrade = std::nullopt;
const auto *jvprimePaidUpgrade = root.if_contains("prime_paid_upgrade");
if (jvprimePaidUpgrade != nullptr && !jvprimePaidUpgrade->is_null())
else if (innerTag == PrimePaidUpgrade::TAG)
{
auto tprimePaidUpgrade =
boost::json::try_value_to<PrimePaidUpgrade>(*jvprimePaidUpgrade);
if (tprimePaidUpgrade.has_error())
const auto *innerVal =
root.if_contains(detail::fieldFor<PrimePaidUpgrade>());
if (!innerVal)
{
return tprimePaidUpgrade.error();
EVENTSUB_BAIL_HERE(error::Kind::FieldMissing);
}
primePaidUpgrade = std::move(tprimePaidUpgrade.value());
auto innerPrimePaidUpgrade =
boost::json::try_value_to<PrimePaidUpgrade>(*innerVal);
if (innerPrimePaidUpgrade.has_error())
{
return innerPrimePaidUpgrade.error();
}
inner.emplace<PrimePaidUpgrade>(
std::move(innerPrimePaidUpgrade.value()));
}
std::optional<Raid> raid = std::nullopt;
const auto *jvraid = root.if_contains("raid");
if (jvraid != nullptr && !jvraid->is_null())
else if (innerTag == Raid::TAG)
{
auto traid = boost::json::try_value_to<Raid>(*jvraid);
if (traid.has_error())
const auto *innerVal = root.if_contains(detail::fieldFor<Raid>());
if (!innerVal)
{
return traid.error();
EVENTSUB_BAIL_HERE(error::Kind::FieldMissing);
}
raid = std::move(traid.value());
auto innerRaid = boost::json::try_value_to<Raid>(*innerVal);
if (innerRaid.has_error())
{
return innerRaid.error();
}
inner.emplace<Raid>(std::move(innerRaid.value()));
}
static_assert(
std::is_trivially_copyable_v<
std::remove_reference_t<decltype(std::declval<Event>().unraid)>>);
std::optional<Unraid> unraid = std::nullopt;
const auto *jvunraid = root.if_contains("unraid");
if (jvunraid != nullptr && !jvunraid->is_null())
else if (innerTag == Unraid::TAG)
{
auto tunraid = boost::json::try_value_to<Unraid>(*jvunraid);
if (tunraid.has_error())
{
return tunraid.error();
}
unraid = tunraid.value();
inner.emplace<Unraid>();
}
std::optional<PayItForward> payItForward = std::nullopt;
const auto *jvpayItForward = root.if_contains("pay_it_forward");
if (jvpayItForward != nullptr && !jvpayItForward->is_null())
else if (innerTag == PayItForward::TAG)
{
auto tpayItForward =
boost::json::try_value_to<PayItForward>(*jvpayItForward);
if (tpayItForward.has_error())
const auto *innerVal =
root.if_contains(detail::fieldFor<PayItForward>());
if (!innerVal)
{
return tpayItForward.error();
EVENTSUB_BAIL_HERE(error::Kind::FieldMissing);
}
payItForward = std::move(tpayItForward.value());
auto innerPayItForward =
boost::json::try_value_to<PayItForward>(*innerVal);
if (innerPayItForward.has_error())
{
return innerPayItForward.error();
}
inner.emplace<PayItForward>(std::move(innerPayItForward.value()));
}
std::optional<Announcement> announcement = std::nullopt;
const auto *jvannouncement = root.if_contains("announcement");
if (jvannouncement != nullptr && !jvannouncement->is_null())
else if (innerTag == Announcement::TAG)
{
auto tannouncement =
boost::json::try_value_to<Announcement>(*jvannouncement);
if (tannouncement.has_error())
const auto *innerVal =
root.if_contains(detail::fieldFor<Announcement>());
if (!innerVal)
{
return tannouncement.error();
EVENTSUB_BAIL_HERE(error::Kind::FieldMissing);
}
announcement = std::move(tannouncement.value());
auto innerAnnouncement =
boost::json::try_value_to<Announcement>(*innerVal);
if (innerAnnouncement.has_error())
{
return innerAnnouncement.error();
}
inner.emplace<Announcement>(std::move(innerAnnouncement.value()));
}
std::optional<CharityDonation> charityDonation = std::nullopt;
const auto *jvcharityDonation = root.if_contains("charity_donation");
if (jvcharityDonation != nullptr && !jvcharityDonation->is_null())
else if (innerTag == CharityDonation::TAG)
{
auto tcharityDonation =
boost::json::try_value_to<CharityDonation>(*jvcharityDonation);
if (tcharityDonation.has_error())
const auto *innerVal =
root.if_contains(detail::fieldFor<CharityDonation>());
if (!innerVal)
{
return tcharityDonation.error();
EVENTSUB_BAIL_HERE(error::Kind::FieldMissing);
}
charityDonation = std::move(tcharityDonation.value());
auto innerCharityDonation =
boost::json::try_value_to<CharityDonation>(*innerVal);
if (innerCharityDonation.has_error())
{
return innerCharityDonation.error();
}
inner.emplace<CharityDonation>(std::move(innerCharityDonation.value()));
}
static_assert(std::is_trivially_copyable_v<std::remove_reference_t<
decltype(std::declval<Event>().bitsBadgeTier)>>);
std::optional<BitsBadgeTier> bitsBadgeTier = std::nullopt;
const auto *jvbitsBadgeTier = root.if_contains("bits_badge_tier");
if (jvbitsBadgeTier != nullptr && !jvbitsBadgeTier->is_null())
else if (innerTag == BitsBadgeTier::TAG)
{
auto tbitsBadgeTier =
boost::json::try_value_to<BitsBadgeTier>(*jvbitsBadgeTier);
if (tbitsBadgeTier.has_error())
const auto *innerVal =
root.if_contains(detail::fieldFor<BitsBadgeTier>());
if (!innerVal)
{
return tbitsBadgeTier.error();
EVENTSUB_BAIL_HERE(error::Kind::FieldMissing);
}
bitsBadgeTier = tbitsBadgeTier.value();
auto innerBitsBadgeTier =
boost::json::try_value_to<BitsBadgeTier>(*innerVal);
if (innerBitsBadgeTier.has_error())
{
return innerBitsBadgeTier.error();
}
inner.emplace<BitsBadgeTier>(innerBitsBadgeTier.value());
}
else
{
inner.emplace<std::string>(innerTag);
}
return Event{
@@ -1634,19 +1653,7 @@ boost::json::result_for<Event, boost::json::value>::type tag_invoke(
.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 = unraid,
.payItForward = std::move(payItForward),
.announcement = std::move(announcement),
.charityDonation = std::move(charityDonation),
.bitsBadgeTier = bitsBadgeTier,
.inner = std::move(inner),
};
}
@@ -1,163 +1,13 @@
// 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/channel-moderate-v2.hpp"
#include <boost/json.hpp>
namespace chatterino::eventsub::lib::payload::channel_moderate::v2 {
boost::json::result_for<Action, boost::json::value>::type tag_invoke(
boost::json::try_value_to_tag<Action> /* 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<Followers, boost::json::value>::type tag_invoke(
boost::json::try_value_to_tag<Followers> /* tag */,
const boost::json::value &jvRoot)
@@ -191,6 +41,13 @@ boost::json::result_for<Followers, boost::json::value>::type tag_invoke(
};
}
boost::json::result_for<FollowersOff, boost::json::value>::type tag_invoke(
boost::json::try_value_to_tag<FollowersOff> /* tag */,
const boost::json::value & /* jvRoot */)
{
return FollowersOff{};
}
boost::json::result_for<Slow, boost::json::value>::type tag_invoke(
boost::json::try_value_to_tag<Slow> /* tag */,
const boost::json::value &jvRoot)
@@ -221,6 +78,13 @@ boost::json::result_for<Slow, boost::json::value>::type tag_invoke(
};
}
boost::json::result_for<SlowOff, boost::json::value>::type tag_invoke(
boost::json::try_value_to_tag<SlowOff> /* tag */,
const boost::json::value & /* jvRoot */)
{
return SlowOff{};
}
boost::json::result_for<Vip, boost::json::value>::type tag_invoke(
boost::json::try_value_to_tag<Vip> /* tag */,
const boost::json::value &jvRoot)
@@ -515,6 +379,13 @@ boost::json::result_for<Ban, boost::json::value>::type tag_invoke(
};
}
boost::json::result_for<SharedChatBan, boost::json::value>::type tag_invoke(
boost::json::try_value_to_tag<SharedChatBan> /* tag */,
const boost::json::value & /* jvRoot */)
{
return SharedChatBan{};
}
boost::json::result_for<Unban, boost::json::value>::type tag_invoke(
boost::json::try_value_to_tag<Unban> /* tag */,
const boost::json::value &jvRoot)
@@ -571,6 +442,13 @@ boost::json::result_for<Unban, boost::json::value>::type tag_invoke(
};
}
boost::json::result_for<SharedChatUnban, boost::json::value>::type tag_invoke(
boost::json::try_value_to_tag<SharedChatUnban> /* tag */,
const boost::json::value & /* jvRoot */)
{
return SharedChatUnban{};
}
boost::json::result_for<Timeout, boost::json::value>::type tag_invoke(
boost::json::try_value_to_tag<Timeout> /* tag */,
const boost::json::value &jvRoot)
@@ -655,6 +533,13 @@ boost::json::result_for<Timeout, boost::json::value>::type tag_invoke(
};
}
boost::json::result_for<SharedChatTimeout, boost::json::value>::type tag_invoke(
boost::json::try_value_to_tag<SharedChatTimeout> /* tag */,
const boost::json::value & /* jvRoot */)
{
return SharedChatTimeout{};
}
boost::json::result_for<Untimeout, boost::json::value>::type tag_invoke(
boost::json::try_value_to_tag<Untimeout> /* tag */,
const boost::json::value &jvRoot)
@@ -711,6 +596,13 @@ boost::json::result_for<Untimeout, boost::json::value>::type tag_invoke(
};
}
boost::json::result_for<SharedChatUntimeout, boost::json::value>::type
tag_invoke(boost::json::try_value_to_tag<SharedChatUntimeout> /* tag */,
const boost::json::value & /* jvRoot */)
{
return SharedChatUntimeout{};
}
boost::json::result_for<Raid, boost::json::value>::type tag_invoke(
boost::json::try_value_to_tag<Raid> /* tag */,
const boost::json::value &jvRoot)
@@ -923,6 +815,13 @@ boost::json::result_for<Delete, boost::json::value>::type tag_invoke(
};
}
boost::json::result_for<SharedChatDelete, boost::json::value>::type tag_invoke(
boost::json::try_value_to_tag<SharedChatDelete> /* tag */,
const boost::json::value & /* jvRoot */)
{
return SharedChatDelete{};
}
boost::json::result_for<AutomodTerms, boost::json::value>::type tag_invoke(
boost::json::try_value_to_tag<AutomodTerms> /* tag */,
const boost::json::value &jvRoot)
@@ -993,6 +892,34 @@ boost::json::result_for<AutomodTerms, boost::json::value>::type tag_invoke(
};
}
boost::json::result_for<AddBlockedTerm, boost::json::value>::type tag_invoke(
boost::json::try_value_to_tag<AddBlockedTerm> /* tag */,
const boost::json::value & /* jvRoot */)
{
return AddBlockedTerm{};
}
boost::json::result_for<AddPermittedTerm, boost::json::value>::type tag_invoke(
boost::json::try_value_to_tag<AddPermittedTerm> /* tag */,
const boost::json::value & /* jvRoot */)
{
return AddPermittedTerm{};
}
boost::json::result_for<RemoveBlockedTerm, boost::json::value>::type tag_invoke(
boost::json::try_value_to_tag<RemoveBlockedTerm> /* tag */,
const boost::json::value & /* jvRoot */)
{
return RemoveBlockedTerm{};
}
boost::json::result_for<RemovePermittedTerm, boost::json::value>::type
tag_invoke(boost::json::try_value_to_tag<RemovePermittedTerm> /* tag */,
const boost::json::value & /* jvRoot */)
{
return RemovePermittedTerm{};
}
boost::json::result_for<UnbanRequest, boost::json::value>::type tag_invoke(
boost::json::try_value_to_tag<UnbanRequest> /* tag */,
const boost::json::value &jvRoot)
@@ -1080,6 +1007,20 @@ boost::json::result_for<UnbanRequest, boost::json::value>::type tag_invoke(
};
}
boost::json::result_for<ApproveUnbanRequest, boost::json::value>::type
tag_invoke(boost::json::try_value_to_tag<ApproveUnbanRequest> /* tag */,
const boost::json::value & /* jvRoot */)
{
return ApproveUnbanRequest{};
}
boost::json::result_for<DenyUnbanRequest, boost::json::value>::type tag_invoke(
boost::json::try_value_to_tag<DenyUnbanRequest> /* tag */,
const boost::json::value & /* jvRoot */)
{
return DenyUnbanRequest{};
}
boost::json::result_for<Warn, boost::json::value>::type tag_invoke(
boost::json::try_value_to_tag<Warn> /* tag */,
const boost::json::value &jvRoot)
@@ -1163,6 +1104,55 @@ boost::json::result_for<Warn, boost::json::value>::type tag_invoke(
};
}
boost::json::result_for<Clear, boost::json::value>::type tag_invoke(
boost::json::try_value_to_tag<Clear> /* tag */,
const boost::json::value & /* jvRoot */)
{
return Clear{};
}
boost::json::result_for<EmoteOnly, boost::json::value>::type tag_invoke(
boost::json::try_value_to_tag<EmoteOnly> /* tag */,
const boost::json::value & /* jvRoot */)
{
return EmoteOnly{};
}
boost::json::result_for<EmoteOnlyOff, boost::json::value>::type tag_invoke(
boost::json::try_value_to_tag<EmoteOnlyOff> /* tag */,
const boost::json::value & /* jvRoot */)
{
return EmoteOnlyOff{};
}
boost::json::result_for<Uniquechat, boost::json::value>::type tag_invoke(
boost::json::try_value_to_tag<Uniquechat> /* tag */,
const boost::json::value & /* jvRoot */)
{
return Uniquechat{};
}
boost::json::result_for<UniquechatOff, boost::json::value>::type tag_invoke(
boost::json::try_value_to_tag<UniquechatOff> /* tag */,
const boost::json::value & /* jvRoot */)
{
return UniquechatOff{};
}
boost::json::result_for<Subscribers, boost::json::value>::type tag_invoke(
boost::json::try_value_to_tag<Subscribers> /* tag */,
const boost::json::value & /* jvRoot */)
{
return Subscribers{};
}
boost::json::result_for<SubscribersOff, boost::json::value>::type tag_invoke(
boost::json::try_value_to_tag<SubscribersOff> /* tag */,
const boost::json::value & /* jvRoot */)
{
return SubscribersOff{};
}
boost::json::result_for<Event, boost::json::value>::type tag_invoke(
boost::json::try_value_to_tag<Event> /* tag */,
const boost::json::value &jvRoot)
@@ -1311,293 +1301,299 @@ boost::json::result_for<Event, boost::json::value>::type tag_invoke(
return moderatorUserName.error();
}
static_assert(
std::is_trivially_copyable_v<
std::remove_reference_t<decltype(std::declval<Event>().action)>>);
const auto *jvaction = root.if_contains("action");
if (jvaction == nullptr)
const auto *jvactionTag = root.if_contains("action");
if (jvactionTag == nullptr)
{
EVENTSUB_BAIL_HERE(error::Kind::FieldMissing);
}
auto action = boost::json::try_value_to<Action>(*jvaction);
if (action.has_error())
auto actionTagRes =
boost::json::try_value_to<boost::json::string>(*jvactionTag);
if (actionTagRes.has_error())
{
return action.error();
return actionTagRes.error();
}
static_assert(std::is_trivially_copyable_v<std::remove_reference_t<
decltype(std::declval<Event>().followers)>>);
std::optional<Followers> followers = std::nullopt;
const auto *jvfollowers = root.if_contains("followers");
if (jvfollowers != nullptr && !jvfollowers->is_null())
std::string_view actionTag = *actionTagRes;
decltype(std::declval<Event>().action) action;
if (actionTag == Ban::TAG)
{
auto tfollowers = boost::json::try_value_to<Followers>(*jvfollowers);
if (tfollowers.has_error())
const auto *actionVal = root.if_contains(detail::fieldFor<Ban>());
if (!actionVal)
{
return tfollowers.error();
EVENTSUB_BAIL_HERE(error::Kind::FieldMissing);
}
followers = tfollowers.value();
auto actionBan = boost::json::try_value_to<Ban>(*actionVal);
if (actionBan.has_error())
{
return actionBan.error();
}
action.emplace<Ban>(std::move(actionBan.value()));
}
static_assert(
std::is_trivially_copyable_v<
std::remove_reference_t<decltype(std::declval<Event>().slow)>>);
std::optional<Slow> slow = std::nullopt;
const auto *jvslow = root.if_contains("slow");
if (jvslow != nullptr && !jvslow->is_null())
else if (actionTag == Timeout::TAG)
{
auto tslow = boost::json::try_value_to<Slow>(*jvslow);
if (tslow.has_error())
const auto *actionVal = root.if_contains(detail::fieldFor<Timeout>());
if (!actionVal)
{
return tslow.error();
EVENTSUB_BAIL_HERE(error::Kind::FieldMissing);
}
slow = tslow.value();
auto actionTimeout = boost::json::try_value_to<Timeout>(*actionVal);
if (actionTimeout.has_error())
{
return actionTimeout.error();
}
action.emplace<Timeout>(std::move(actionTimeout.value()));
}
std::optional<Vip> vip = std::nullopt;
const auto *jvvip = root.if_contains("vip");
if (jvvip != nullptr && !jvvip->is_null())
else if (actionTag == Unban::TAG)
{
auto tvip = boost::json::try_value_to<Vip>(*jvvip);
if (tvip.has_error())
const auto *actionVal = root.if_contains(detail::fieldFor<Unban>());
if (!actionVal)
{
return tvip.error();
EVENTSUB_BAIL_HERE(error::Kind::FieldMissing);
}
vip = std::move(tvip.value());
auto actionUnban = boost::json::try_value_to<Unban>(*actionVal);
if (actionUnban.has_error())
{
return actionUnban.error();
}
action.emplace<Unban>(std::move(actionUnban.value()));
}
std::optional<Unvip> unvip = std::nullopt;
const auto *jvunvip = root.if_contains("unvip");
if (jvunvip != nullptr && !jvunvip->is_null())
else if (actionTag == Untimeout::TAG)
{
auto tunvip = boost::json::try_value_to<Unvip>(*jvunvip);
if (tunvip.has_error())
const auto *actionVal = root.if_contains(detail::fieldFor<Untimeout>());
if (!actionVal)
{
return tunvip.error();
EVENTSUB_BAIL_HERE(error::Kind::FieldMissing);
}
unvip = std::move(tunvip.value());
auto actionUntimeout = boost::json::try_value_to<Untimeout>(*actionVal);
if (actionUntimeout.has_error())
{
return actionUntimeout.error();
}
action.emplace<Untimeout>(std::move(actionUntimeout.value()));
}
std::optional<Unmod> unmod = std::nullopt;
const auto *jvunmod = root.if_contains("unmod");
if (jvunmod != nullptr && !jvunmod->is_null())
else if (actionTag == Clear::TAG)
{
auto tunmod = boost::json::try_value_to<Unmod>(*jvunmod);
if (tunmod.has_error())
{
return tunmod.error();
}
unmod = std::move(tunmod.value());
action.emplace<Clear>();
}
std::optional<Ban> ban = std::nullopt;
const auto *jvban = root.if_contains("ban");
if (jvban != nullptr && !jvban->is_null())
else if (actionTag == EmoteOnly::TAG)
{
auto tban = boost::json::try_value_to<Ban>(*jvban);
if (tban.has_error())
{
return tban.error();
}
ban = std::move(tban.value());
action.emplace<EmoteOnly>();
}
std::optional<Unban> unban = std::nullopt;
const auto *jvunban = root.if_contains("unban");
if (jvunban != nullptr && !jvunban->is_null())
else if (actionTag == EmoteOnlyOff::TAG)
{
auto tunban = boost::json::try_value_to<Unban>(*jvunban);
if (tunban.has_error())
{
return tunban.error();
}
unban = std::move(tunban.value());
action.emplace<EmoteOnlyOff>();
}
std::optional<Timeout> timeout = std::nullopt;
const auto *jvtimeout = root.if_contains("timeout");
if (jvtimeout != nullptr && !jvtimeout->is_null())
else if (actionTag == Followers::TAG)
{
auto ttimeout = boost::json::try_value_to<Timeout>(*jvtimeout);
if (ttimeout.has_error())
const auto *actionVal = root.if_contains(detail::fieldFor<Followers>());
if (!actionVal)
{
return ttimeout.error();
EVENTSUB_BAIL_HERE(error::Kind::FieldMissing);
}
timeout = std::move(ttimeout.value());
auto actionFollowers = boost::json::try_value_to<Followers>(*actionVal);
if (actionFollowers.has_error())
{
return actionFollowers.error();
}
action.emplace<Followers>(actionFollowers.value());
}
std::optional<Untimeout> untimeout = std::nullopt;
const auto *jvuntimeout = root.if_contains("untimeout");
if (jvuntimeout != nullptr && !jvuntimeout->is_null())
else if (actionTag == FollowersOff::TAG)
{
auto tuntimeout = boost::json::try_value_to<Untimeout>(*jvuntimeout);
if (tuntimeout.has_error())
{
return tuntimeout.error();
}
untimeout = std::move(tuntimeout.value());
action.emplace<FollowersOff>();
}
std::optional<Raid> raid = std::nullopt;
const auto *jvraid = root.if_contains("raid");
if (jvraid != nullptr && !jvraid->is_null())
else if (actionTag == Uniquechat::TAG)
{
auto traid = boost::json::try_value_to<Raid>(*jvraid);
if (traid.has_error())
{
return traid.error();
}
raid = std::move(traid.value());
action.emplace<Uniquechat>();
}
std::optional<Unraid> unraid = std::nullopt;
const auto *jvunraid = root.if_contains("unraid");
if (jvunraid != nullptr && !jvunraid->is_null())
else if (actionTag == UniquechatOff::TAG)
{
auto tunraid = boost::json::try_value_to<Unraid>(*jvunraid);
if (tunraid.has_error())
{
return tunraid.error();
}
unraid = std::move(tunraid.value());
action.emplace<UniquechatOff>();
}
std::optional<Delete> deleteMessage = std::nullopt;
const auto *jvdeleteMessage = root.if_contains("delete");
if (jvdeleteMessage != nullptr && !jvdeleteMessage->is_null())
else if (actionTag == Slow::TAG)
{
auto tdeleteMessage =
boost::json::try_value_to<Delete>(*jvdeleteMessage);
if (tdeleteMessage.has_error())
const auto *actionVal = root.if_contains(detail::fieldFor<Slow>());
if (!actionVal)
{
return tdeleteMessage.error();
EVENTSUB_BAIL_HERE(error::Kind::FieldMissing);
}
deleteMessage = std::move(tdeleteMessage.value());
auto actionSlow = boost::json::try_value_to<Slow>(*actionVal);
if (actionSlow.has_error())
{
return actionSlow.error();
}
action.emplace<Slow>(actionSlow.value());
}
std::optional<AutomodTerms> automodTerms = std::nullopt;
const auto *jvautomodTerms = root.if_contains("automod_terms");
if (jvautomodTerms != nullptr && !jvautomodTerms->is_null())
else if (actionTag == SlowOff::TAG)
{
auto tautomodTerms =
boost::json::try_value_to<AutomodTerms>(*jvautomodTerms);
if (tautomodTerms.has_error())
{
return tautomodTerms.error();
}
automodTerms = std::move(tautomodTerms.value());
action.emplace<SlowOff>();
}
std::optional<UnbanRequest> unbanRequest = std::nullopt;
const auto *jvunbanRequest = root.if_contains("unban_request");
if (jvunbanRequest != nullptr && !jvunbanRequest->is_null())
else if (actionTag == Subscribers::TAG)
{
auto tunbanRequest =
boost::json::try_value_to<UnbanRequest>(*jvunbanRequest);
if (tunbanRequest.has_error())
{
return tunbanRequest.error();
}
unbanRequest = std::move(tunbanRequest.value());
action.emplace<Subscribers>();
}
std::optional<Warn> warn = std::nullopt;
const auto *jvwarn = root.if_contains("warn");
if (jvwarn != nullptr && !jvwarn->is_null())
else if (actionTag == SubscribersOff::TAG)
{
auto twarn = boost::json::try_value_to<Warn>(*jvwarn);
if (twarn.has_error())
{
return twarn.error();
}
warn = std::move(twarn.value());
action.emplace<SubscribersOff>();
}
std::optional<Ban> sharedChatBan = std::nullopt;
const auto *jvsharedChatBan = root.if_contains("shared_chat_ban");
if (jvsharedChatBan != nullptr && !jvsharedChatBan->is_null())
else if (actionTag == Unraid::TAG)
{
auto tsharedChatBan = boost::json::try_value_to<Ban>(*jvsharedChatBan);
if (tsharedChatBan.has_error())
const auto *actionVal = root.if_contains(detail::fieldFor<Unraid>());
if (!actionVal)
{
return tsharedChatBan.error();
EVENTSUB_BAIL_HERE(error::Kind::FieldMissing);
}
sharedChatBan = std::move(tsharedChatBan.value());
auto actionUnraid = boost::json::try_value_to<Unraid>(*actionVal);
if (actionUnraid.has_error())
{
return actionUnraid.error();
}
action.emplace<Unraid>(std::move(actionUnraid.value()));
}
std::optional<Unban> sharedChatUnban = std::nullopt;
const auto *jvsharedChatUnban = root.if_contains("shared_chat_unban");
if (jvsharedChatUnban != nullptr && !jvsharedChatUnban->is_null())
else if (actionTag == Delete::TAG)
{
auto tsharedChatUnban =
boost::json::try_value_to<Unban>(*jvsharedChatUnban);
if (tsharedChatUnban.has_error())
const auto *actionVal = root.if_contains(detail::fieldFor<Delete>());
if (!actionVal)
{
return tsharedChatUnban.error();
EVENTSUB_BAIL_HERE(error::Kind::FieldMissing);
}
sharedChatUnban = std::move(tsharedChatUnban.value());
auto actionDelete = boost::json::try_value_to<Delete>(*actionVal);
if (actionDelete.has_error())
{
return actionDelete.error();
}
action.emplace<Delete>(std::move(actionDelete.value()));
}
std::optional<Timeout> sharedChatTimeout = std::nullopt;
const auto *jvsharedChatTimeout = root.if_contains("shared_chat_timeout");
if (jvsharedChatTimeout != nullptr && !jvsharedChatTimeout->is_null())
else if (actionTag == Unvip::TAG)
{
auto tsharedChatTimeout =
boost::json::try_value_to<Timeout>(*jvsharedChatTimeout);
if (tsharedChatTimeout.has_error())
const auto *actionVal = root.if_contains(detail::fieldFor<Unvip>());
if (!actionVal)
{
return tsharedChatTimeout.error();
EVENTSUB_BAIL_HERE(error::Kind::FieldMissing);
}
sharedChatTimeout = std::move(tsharedChatTimeout.value());
auto actionUnvip = boost::json::try_value_to<Unvip>(*actionVal);
if (actionUnvip.has_error())
{
return actionUnvip.error();
}
action.emplace<Unvip>(std::move(actionUnvip.value()));
}
std::optional<Untimeout> sharedChatUntimeout = std::nullopt;
const auto *jvsharedChatUntimeout =
root.if_contains("shared_chat_untimeout");
if (jvsharedChatUntimeout != nullptr && !jvsharedChatUntimeout->is_null())
else if (actionTag == Vip::TAG)
{
auto tsharedChatUntimeout =
boost::json::try_value_to<Untimeout>(*jvsharedChatUntimeout);
if (tsharedChatUntimeout.has_error())
const auto *actionVal = root.if_contains(detail::fieldFor<Vip>());
if (!actionVal)
{
return tsharedChatUntimeout.error();
EVENTSUB_BAIL_HERE(error::Kind::FieldMissing);
}
sharedChatUntimeout = std::move(tsharedChatUntimeout.value());
auto actionVip = boost::json::try_value_to<Vip>(*actionVal);
if (actionVip.has_error())
{
return actionVip.error();
}
action.emplace<Vip>(std::move(actionVip.value()));
}
std::optional<Delete> sharedChatDelete = std::nullopt;
const auto *jvsharedChatDelete = root.if_contains("shared_chat_delete");
if (jvsharedChatDelete != nullptr && !jvsharedChatDelete->is_null())
else if (actionTag == Raid::TAG)
{
auto tsharedChatDelete =
boost::json::try_value_to<Delete>(*jvsharedChatDelete);
if (tsharedChatDelete.has_error())
const auto *actionVal = root.if_contains(detail::fieldFor<Raid>());
if (!actionVal)
{
return tsharedChatDelete.error();
EVENTSUB_BAIL_HERE(error::Kind::FieldMissing);
}
sharedChatDelete = std::move(tsharedChatDelete.value());
auto actionRaid = boost::json::try_value_to<Raid>(*actionVal);
if (actionRaid.has_error())
{
return actionRaid.error();
}
action.emplace<Raid>(std::move(actionRaid.value()));
}
else if (actionTag == AddBlockedTerm::TAG)
{
action.emplace<AddBlockedTerm>();
}
else if (actionTag == AddPermittedTerm::TAG)
{
action.emplace<AddPermittedTerm>();
}
else if (actionTag == RemoveBlockedTerm::TAG)
{
action.emplace<RemoveBlockedTerm>();
}
else if (actionTag == RemovePermittedTerm::TAG)
{
action.emplace<RemovePermittedTerm>();
}
else if (actionTag == Mod::TAG)
{
const auto *actionVal = root.if_contains(detail::fieldFor<Mod>());
if (!actionVal)
{
EVENTSUB_BAIL_HERE(error::Kind::FieldMissing);
}
auto actionMod = boost::json::try_value_to<Mod>(*actionVal);
if (actionMod.has_error())
{
return actionMod.error();
}
action.emplace<Mod>(std::move(actionMod.value()));
}
else if (actionTag == Unmod::TAG)
{
const auto *actionVal = root.if_contains(detail::fieldFor<Unmod>());
if (!actionVal)
{
EVENTSUB_BAIL_HERE(error::Kind::FieldMissing);
}
auto actionUnmod = boost::json::try_value_to<Unmod>(*actionVal);
if (actionUnmod.has_error())
{
return actionUnmod.error();
}
action.emplace<Unmod>(std::move(actionUnmod.value()));
}
else if (actionTag == ApproveUnbanRequest::TAG)
{
action.emplace<ApproveUnbanRequest>();
}
else if (actionTag == DenyUnbanRequest::TAG)
{
action.emplace<DenyUnbanRequest>();
}
else if (actionTag == Warn::TAG)
{
const auto *actionVal = root.if_contains(detail::fieldFor<Warn>());
if (!actionVal)
{
EVENTSUB_BAIL_HERE(error::Kind::FieldMissing);
}
auto actionWarn = boost::json::try_value_to<Warn>(*actionVal);
if (actionWarn.has_error())
{
return actionWarn.error();
}
action.emplace<Warn>(std::move(actionWarn.value()));
}
else if (actionTag == SharedChatBan::TAG)
{
action.emplace<SharedChatBan>();
}
else if (actionTag == SharedChatTimeout::TAG)
{
action.emplace<SharedChatTimeout>();
}
else if (actionTag == SharedChatUnban::TAG)
{
action.emplace<SharedChatUnban>();
}
else if (actionTag == SharedChatUntimeout::TAG)
{
action.emplace<SharedChatUntimeout>();
}
else if (actionTag == SharedChatDelete::TAG)
{
action.emplace<SharedChatDelete>();
}
else
{
action.emplace<std::string>(actionTag);
}
return Event{
@@ -1610,27 +1606,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()),
.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),
.action = std::move(action),
};
}
@@ -1,6 +1,7 @@
// 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/channel-update-v1.hpp"
#include <boost/json.hpp>
@@ -1,6 +1,7 @@
// 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/session-welcome.hpp"
#include <boost/json.hpp>
@@ -1,6 +1,7 @@
// 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/stream-offline-v1.hpp"
#include <boost/json.hpp>
@@ -1,6 +1,7 @@
// 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/stream-online-v1.hpp"
#include <boost/json.hpp>
@@ -1,6 +1,7 @@
// 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/subscription.hpp"
#include <boost/json.hpp>