refactor(eventsub): generate entire files (#5897)
This commit is contained in:
@@ -0,0 +1,109 @@
|
||||
|
||||
// WARNING: This file is automatically generated. Any changes will be lost.
|
||||
#include "twitch-eventsub-ws/chrono.hpp" // IWYU pragma: keep
|
||||
#include "twitch-eventsub-ws/errors.hpp"
|
||||
#include "twitch-eventsub-ws/messages/metadata.hpp"
|
||||
|
||||
#include <boost/json.hpp>
|
||||
|
||||
namespace chatterino::eventsub::lib::messages {
|
||||
|
||||
boost::json::result_for<Metadata, boost::json::value>::type tag_invoke(
|
||||
boost::json::try_value_to_tag<Metadata>, const boost::json::value &jvRoot)
|
||||
{
|
||||
if (!jvRoot.is_object())
|
||||
{
|
||||
static const error::ApplicationErrorCategory errorMustBeObject{
|
||||
"Metadata must be an object"};
|
||||
return boost::system::error_code{129, errorMustBeObject};
|
||||
}
|
||||
const auto &root = jvRoot.get_object();
|
||||
|
||||
const auto *jvmessageID = root.if_contains("message_id");
|
||||
if (jvmessageID == nullptr)
|
||||
{
|
||||
static const error::ApplicationErrorCategory
|
||||
error_missing_field_messageID{"Missing required key message_id"};
|
||||
return boost::system::error_code{129, error_missing_field_messageID};
|
||||
}
|
||||
|
||||
auto messageID = boost::json::try_value_to<std::string>(*jvmessageID);
|
||||
|
||||
if (messageID.has_error())
|
||||
{
|
||||
return messageID.error();
|
||||
}
|
||||
|
||||
const auto *jvmessageType = root.if_contains("message_type");
|
||||
if (jvmessageType == nullptr)
|
||||
{
|
||||
static const error::ApplicationErrorCategory
|
||||
error_missing_field_messageType{
|
||||
"Missing required key message_type"};
|
||||
return boost::system::error_code{129, error_missing_field_messageType};
|
||||
}
|
||||
|
||||
auto messageType = boost::json::try_value_to<std::string>(*jvmessageType);
|
||||
|
||||
if (messageType.has_error())
|
||||
{
|
||||
return messageType.error();
|
||||
}
|
||||
|
||||
const auto *jvmessageTimestamp = root.if_contains("message_timestamp");
|
||||
if (jvmessageTimestamp == nullptr)
|
||||
{
|
||||
static const error::ApplicationErrorCategory
|
||||
error_missing_field_messageTimestamp{
|
||||
"Missing required key message_timestamp"};
|
||||
return boost::system::error_code{129,
|
||||
error_missing_field_messageTimestamp};
|
||||
}
|
||||
|
||||
auto messageTimestamp =
|
||||
boost::json::try_value_to<std::string>(*jvmessageTimestamp);
|
||||
|
||||
if (messageTimestamp.has_error())
|
||||
{
|
||||
return messageTimestamp.error();
|
||||
}
|
||||
|
||||
std::optional<std::string> subscriptionType = std::nullopt;
|
||||
const auto *jvsubscriptionType = root.if_contains("subscription_type");
|
||||
if (jvsubscriptionType != nullptr && !jvsubscriptionType->is_null())
|
||||
{
|
||||
auto tsubscriptionType =
|
||||
boost::json::try_value_to<std::string>(*jvsubscriptionType);
|
||||
|
||||
if (tsubscriptionType.has_error())
|
||||
{
|
||||
return tsubscriptionType.error();
|
||||
}
|
||||
subscriptionType = std::move(tsubscriptionType.value());
|
||||
}
|
||||
|
||||
std::optional<std::string> subscriptionVersion = std::nullopt;
|
||||
const auto *jvsubscriptionVersion =
|
||||
root.if_contains("subscription_version");
|
||||
if (jvsubscriptionVersion != nullptr && !jvsubscriptionVersion->is_null())
|
||||
{
|
||||
auto tsubscriptionVersion =
|
||||
boost::json::try_value_to<std::string>(*jvsubscriptionVersion);
|
||||
|
||||
if (tsubscriptionVersion.has_error())
|
||||
{
|
||||
return tsubscriptionVersion.error();
|
||||
}
|
||||
subscriptionVersion = std::move(tsubscriptionVersion.value());
|
||||
}
|
||||
|
||||
return Metadata{
|
||||
.messageID = std::move(messageID.value()),
|
||||
.messageType = std::move(messageType.value()),
|
||||
.messageTimestamp = std::move(messageTimestamp.value()),
|
||||
.subscriptionType = std::move(subscriptionType),
|
||||
.subscriptionVersion = std::move(subscriptionVersion),
|
||||
};
|
||||
}
|
||||
|
||||
} // namespace chatterino::eventsub::lib::messages
|
||||
@@ -0,0 +1,306 @@
|
||||
|
||||
// WARNING: This file is automatically generated. Any changes will be lost.
|
||||
#include "twitch-eventsub-ws/chrono.hpp" // IWYU pragma: keep
|
||||
#include "twitch-eventsub-ws/errors.hpp"
|
||||
#include "twitch-eventsub-ws/payloads/channel-ban-v1.hpp"
|
||||
|
||||
#include <boost/json.hpp>
|
||||
|
||||
namespace chatterino::eventsub::lib::payload::channel_ban::v1 {
|
||||
|
||||
boost::json::result_for<Event, boost::json::value>::type tag_invoke(
|
||||
boost::json::try_value_to_tag<Event>, const boost::json::value &jvRoot)
|
||||
{
|
||||
if (!jvRoot.is_object())
|
||||
{
|
||||
static const error::ApplicationErrorCategory errorMustBeObject{
|
||||
"Event must be an object"};
|
||||
return boost::system::error_code{129, errorMustBeObject};
|
||||
}
|
||||
const auto &root = jvRoot.get_object();
|
||||
|
||||
const auto *jvbroadcasterUserID = root.if_contains("broadcaster_user_id");
|
||||
if (jvbroadcasterUserID == nullptr)
|
||||
{
|
||||
static const error::ApplicationErrorCategory
|
||||
error_missing_field_broadcasterUserID{
|
||||
"Missing required key broadcaster_user_id"};
|
||||
return boost::system::error_code{129,
|
||||
error_missing_field_broadcasterUserID};
|
||||
}
|
||||
|
||||
auto broadcasterUserID =
|
||||
boost::json::try_value_to<std::string>(*jvbroadcasterUserID);
|
||||
|
||||
if (broadcasterUserID.has_error())
|
||||
{
|
||||
return broadcasterUserID.error();
|
||||
}
|
||||
|
||||
const auto *jvbroadcasterUserLogin =
|
||||
root.if_contains("broadcaster_user_login");
|
||||
if (jvbroadcasterUserLogin == nullptr)
|
||||
{
|
||||
static const error::ApplicationErrorCategory
|
||||
error_missing_field_broadcasterUserLogin{
|
||||
"Missing required key broadcaster_user_login"};
|
||||
return boost::system::error_code{
|
||||
129, error_missing_field_broadcasterUserLogin};
|
||||
}
|
||||
|
||||
auto broadcasterUserLogin =
|
||||
boost::json::try_value_to<std::string>(*jvbroadcasterUserLogin);
|
||||
|
||||
if (broadcasterUserLogin.has_error())
|
||||
{
|
||||
return broadcasterUserLogin.error();
|
||||
}
|
||||
|
||||
const auto *jvbroadcasterUserName =
|
||||
root.if_contains("broadcaster_user_name");
|
||||
if (jvbroadcasterUserName == nullptr)
|
||||
{
|
||||
static const error::ApplicationErrorCategory
|
||||
error_missing_field_broadcasterUserName{
|
||||
"Missing required key broadcaster_user_name"};
|
||||
return boost::system::error_code{
|
||||
129, error_missing_field_broadcasterUserName};
|
||||
}
|
||||
|
||||
auto broadcasterUserName =
|
||||
boost::json::try_value_to<std::string>(*jvbroadcasterUserName);
|
||||
|
||||
if (broadcasterUserName.has_error())
|
||||
{
|
||||
return broadcasterUserName.error();
|
||||
}
|
||||
|
||||
const auto *jvmoderatorUserID = root.if_contains("moderator_user_id");
|
||||
if (jvmoderatorUserID == nullptr)
|
||||
{
|
||||
static const error::ApplicationErrorCategory
|
||||
error_missing_field_moderatorUserID{
|
||||
"Missing required key moderator_user_id"};
|
||||
return boost::system::error_code{129,
|
||||
error_missing_field_moderatorUserID};
|
||||
}
|
||||
|
||||
auto moderatorUserID =
|
||||
boost::json::try_value_to<std::string>(*jvmoderatorUserID);
|
||||
|
||||
if (moderatorUserID.has_error())
|
||||
{
|
||||
return moderatorUserID.error();
|
||||
}
|
||||
|
||||
const auto *jvmoderatorUserLogin = root.if_contains("moderator_user_login");
|
||||
if (jvmoderatorUserLogin == nullptr)
|
||||
{
|
||||
static const error::ApplicationErrorCategory
|
||||
error_missing_field_moderatorUserLogin{
|
||||
"Missing required key moderator_user_login"};
|
||||
return boost::system::error_code{
|
||||
129, error_missing_field_moderatorUserLogin};
|
||||
}
|
||||
|
||||
auto moderatorUserLogin =
|
||||
boost::json::try_value_to<std::string>(*jvmoderatorUserLogin);
|
||||
|
||||
if (moderatorUserLogin.has_error())
|
||||
{
|
||||
return moderatorUserLogin.error();
|
||||
}
|
||||
|
||||
const auto *jvmoderatorUserName = root.if_contains("moderator_user_name");
|
||||
if (jvmoderatorUserName == nullptr)
|
||||
{
|
||||
static const error::ApplicationErrorCategory
|
||||
error_missing_field_moderatorUserName{
|
||||
"Missing required key moderator_user_name"};
|
||||
return boost::system::error_code{129,
|
||||
error_missing_field_moderatorUserName};
|
||||
}
|
||||
|
||||
auto moderatorUserName =
|
||||
boost::json::try_value_to<std::string>(*jvmoderatorUserName);
|
||||
|
||||
if (moderatorUserName.has_error())
|
||||
{
|
||||
return moderatorUserName.error();
|
||||
}
|
||||
|
||||
const auto *jvuserID = root.if_contains("user_id");
|
||||
if (jvuserID == nullptr)
|
||||
{
|
||||
static const error::ApplicationErrorCategory error_missing_field_userID{
|
||||
"Missing required key user_id"};
|
||||
return boost::system::error_code{129, error_missing_field_userID};
|
||||
}
|
||||
|
||||
auto userID = boost::json::try_value_to<std::string>(*jvuserID);
|
||||
|
||||
if (userID.has_error())
|
||||
{
|
||||
return userID.error();
|
||||
}
|
||||
|
||||
const auto *jvuserLogin = root.if_contains("user_login");
|
||||
if (jvuserLogin == nullptr)
|
||||
{
|
||||
static const error::ApplicationErrorCategory
|
||||
error_missing_field_userLogin{"Missing required key user_login"};
|
||||
return boost::system::error_code{129, error_missing_field_userLogin};
|
||||
}
|
||||
|
||||
auto userLogin = boost::json::try_value_to<std::string>(*jvuserLogin);
|
||||
|
||||
if (userLogin.has_error())
|
||||
{
|
||||
return userLogin.error();
|
||||
}
|
||||
|
||||
const auto *jvuserName = root.if_contains("user_name");
|
||||
if (jvuserName == nullptr)
|
||||
{
|
||||
static const error::ApplicationErrorCategory
|
||||
error_missing_field_userName{"Missing required key user_name"};
|
||||
return boost::system::error_code{129, error_missing_field_userName};
|
||||
}
|
||||
|
||||
auto userName = boost::json::try_value_to<std::string>(*jvuserName);
|
||||
|
||||
if (userName.has_error())
|
||||
{
|
||||
return userName.error();
|
||||
}
|
||||
|
||||
const auto *jvreason = root.if_contains("reason");
|
||||
if (jvreason == nullptr)
|
||||
{
|
||||
static const error::ApplicationErrorCategory error_missing_field_reason{
|
||||
"Missing required key reason"};
|
||||
return boost::system::error_code{129, error_missing_field_reason};
|
||||
}
|
||||
|
||||
auto reason = boost::json::try_value_to<std::string>(*jvreason);
|
||||
|
||||
if (reason.has_error())
|
||||
{
|
||||
return reason.error();
|
||||
}
|
||||
|
||||
const auto *jvisPermanent = root.if_contains("is_permanent");
|
||||
if (jvisPermanent == nullptr)
|
||||
{
|
||||
static const error::ApplicationErrorCategory
|
||||
error_missing_field_isPermanent{
|
||||
"Missing required key is_permanent"};
|
||||
return boost::system::error_code{129, error_missing_field_isPermanent};
|
||||
}
|
||||
|
||||
auto isPermanent = boost::json::try_value_to<bool>(*jvisPermanent);
|
||||
|
||||
if (isPermanent.has_error())
|
||||
{
|
||||
return isPermanent.error();
|
||||
}
|
||||
|
||||
const auto *jvbannedAt = root.if_contains("banned_at");
|
||||
if (jvbannedAt == nullptr)
|
||||
{
|
||||
static const error::ApplicationErrorCategory
|
||||
error_missing_field_bannedAt{"Missing required key banned_at"};
|
||||
return boost::system::error_code{129, error_missing_field_bannedAt};
|
||||
}
|
||||
|
||||
auto bannedAt =
|
||||
boost::json::try_value_to<std::chrono::system_clock::time_point>(
|
||||
*jvbannedAt, AsISO8601());
|
||||
|
||||
if (bannedAt.has_error())
|
||||
{
|
||||
return bannedAt.error();
|
||||
}
|
||||
|
||||
std::optional<std::chrono::system_clock::time_point> endsAt = std::nullopt;
|
||||
const auto *jvendsAt = root.if_contains("ends_at");
|
||||
if (jvendsAt != nullptr && !jvendsAt->is_null())
|
||||
{
|
||||
auto tendsAt =
|
||||
boost::json::try_value_to<std::chrono::system_clock::time_point>(
|
||||
*jvendsAt, AsISO8601());
|
||||
|
||||
if (tendsAt.has_error())
|
||||
{
|
||||
return tendsAt.error();
|
||||
}
|
||||
endsAt = std::move(tendsAt.value());
|
||||
}
|
||||
|
||||
return Event{
|
||||
.broadcasterUserID = std::move(broadcasterUserID.value()),
|
||||
.broadcasterUserLogin = std::move(broadcasterUserLogin.value()),
|
||||
.broadcasterUserName = std::move(broadcasterUserName.value()),
|
||||
.moderatorUserID = std::move(moderatorUserID.value()),
|
||||
.moderatorUserLogin = std::move(moderatorUserLogin.value()),
|
||||
.moderatorUserName = std::move(moderatorUserName.value()),
|
||||
.userID = std::move(userID.value()),
|
||||
.userLogin = std::move(userLogin.value()),
|
||||
.userName = std::move(userName.value()),
|
||||
.reason = std::move(reason.value()),
|
||||
.isPermanent = std::move(isPermanent.value()),
|
||||
.bannedAt = std::move(bannedAt.value()),
|
||||
.endsAt = std::move(endsAt),
|
||||
};
|
||||
}
|
||||
|
||||
boost::json::result_for<Payload, boost::json::value>::type tag_invoke(
|
||||
boost::json::try_value_to_tag<Payload>, const boost::json::value &jvRoot)
|
||||
{
|
||||
if (!jvRoot.is_object())
|
||||
{
|
||||
static const error::ApplicationErrorCategory errorMustBeObject{
|
||||
"Payload must be an object"};
|
||||
return boost::system::error_code{129, errorMustBeObject};
|
||||
}
|
||||
const auto &root = jvRoot.get_object();
|
||||
|
||||
const auto *jvsubscription = root.if_contains("subscription");
|
||||
if (jvsubscription == nullptr)
|
||||
{
|
||||
static const error::ApplicationErrorCategory
|
||||
error_missing_field_subscription{
|
||||
"Missing required key subscription"};
|
||||
return boost::system::error_code{129, error_missing_field_subscription};
|
||||
}
|
||||
|
||||
auto subscription =
|
||||
boost::json::try_value_to<subscription::Subscription>(*jvsubscription);
|
||||
|
||||
if (subscription.has_error())
|
||||
{
|
||||
return subscription.error();
|
||||
}
|
||||
|
||||
const auto *jvevent = root.if_contains("event");
|
||||
if (jvevent == nullptr)
|
||||
{
|
||||
static const error::ApplicationErrorCategory error_missing_field_event{
|
||||
"Missing required key event"};
|
||||
return boost::system::error_code{129, error_missing_field_event};
|
||||
}
|
||||
|
||||
auto event = boost::json::try_value_to<Event>(*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_ban::v1
|
||||
@@ -0,0 +1,934 @@
|
||||
|
||||
// WARNING: This file is automatically generated. Any changes will be lost.
|
||||
#include "twitch-eventsub-ws/chrono.hpp" // IWYU pragma: keep
|
||||
#include "twitch-eventsub-ws/errors.hpp"
|
||||
#include "twitch-eventsub-ws/payloads/channel-chat-message-v1.hpp"
|
||||
|
||||
#include <boost/json.hpp>
|
||||
|
||||
namespace chatterino::eventsub::lib::payload::channel_chat_message::v1 {
|
||||
|
||||
boost::json::result_for<Badge, boost::json::value>::type tag_invoke(
|
||||
boost::json::try_value_to_tag<Badge>, const boost::json::value &jvRoot)
|
||||
{
|
||||
if (!jvRoot.is_object())
|
||||
{
|
||||
static const error::ApplicationErrorCategory errorMustBeObject{
|
||||
"Badge must be an object"};
|
||||
return boost::system::error_code{129, errorMustBeObject};
|
||||
}
|
||||
const auto &root = jvRoot.get_object();
|
||||
|
||||
const auto *jvsetID = root.if_contains("set_id");
|
||||
if (jvsetID == nullptr)
|
||||
{
|
||||
static const error::ApplicationErrorCategory error_missing_field_setID{
|
||||
"Missing required key set_id"};
|
||||
return boost::system::error_code{129, error_missing_field_setID};
|
||||
}
|
||||
|
||||
auto setID = boost::json::try_value_to<std::string>(*jvsetID);
|
||||
|
||||
if (setID.has_error())
|
||||
{
|
||||
return setID.error();
|
||||
}
|
||||
|
||||
const auto *jvid = root.if_contains("id");
|
||||
if (jvid == nullptr)
|
||||
{
|
||||
static const error::ApplicationErrorCategory error_missing_field_id{
|
||||
"Missing required key id"};
|
||||
return boost::system::error_code{129, error_missing_field_id};
|
||||
}
|
||||
|
||||
auto id = boost::json::try_value_to<std::string>(*jvid);
|
||||
|
||||
if (id.has_error())
|
||||
{
|
||||
return id.error();
|
||||
}
|
||||
|
||||
const auto *jvinfo = root.if_contains("info");
|
||||
if (jvinfo == nullptr)
|
||||
{
|
||||
static const error::ApplicationErrorCategory error_missing_field_info{
|
||||
"Missing required key info"};
|
||||
return boost::system::error_code{129, error_missing_field_info};
|
||||
}
|
||||
|
||||
auto info = boost::json::try_value_to<std::string>(*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<Cheermote, boost::json::value>::type tag_invoke(
|
||||
boost::json::try_value_to_tag<Cheermote>, const boost::json::value &jvRoot)
|
||||
{
|
||||
if (!jvRoot.is_object())
|
||||
{
|
||||
static const error::ApplicationErrorCategory errorMustBeObject{
|
||||
"Cheermote must be an object"};
|
||||
return boost::system::error_code{129, errorMustBeObject};
|
||||
}
|
||||
const auto &root = jvRoot.get_object();
|
||||
|
||||
const auto *jvprefix = root.if_contains("prefix");
|
||||
if (jvprefix == nullptr)
|
||||
{
|
||||
static const error::ApplicationErrorCategory error_missing_field_prefix{
|
||||
"Missing required key prefix"};
|
||||
return boost::system::error_code{129, error_missing_field_prefix};
|
||||
}
|
||||
|
||||
auto prefix = boost::json::try_value_to<std::string>(*jvprefix);
|
||||
|
||||
if (prefix.has_error())
|
||||
{
|
||||
return prefix.error();
|
||||
}
|
||||
|
||||
const auto *jvbits = root.if_contains("bits");
|
||||
if (jvbits == nullptr)
|
||||
{
|
||||
static const error::ApplicationErrorCategory error_missing_field_bits{
|
||||
"Missing required key bits"};
|
||||
return boost::system::error_code{129, error_missing_field_bits};
|
||||
}
|
||||
|
||||
auto bits = boost::json::try_value_to<int>(*jvbits);
|
||||
|
||||
if (bits.has_error())
|
||||
{
|
||||
return bits.error();
|
||||
}
|
||||
|
||||
const auto *jvtier = root.if_contains("tier");
|
||||
if (jvtier == nullptr)
|
||||
{
|
||||
static const error::ApplicationErrorCategory error_missing_field_tier{
|
||||
"Missing required key tier"};
|
||||
return boost::system::error_code{129, error_missing_field_tier};
|
||||
}
|
||||
|
||||
auto tier = boost::json::try_value_to<int>(*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<Emote, boost::json::value>::type tag_invoke(
|
||||
boost::json::try_value_to_tag<Emote>, const boost::json::value &jvRoot)
|
||||
{
|
||||
if (!jvRoot.is_object())
|
||||
{
|
||||
static const error::ApplicationErrorCategory errorMustBeObject{
|
||||
"Emote must be an object"};
|
||||
return boost::system::error_code{129, errorMustBeObject};
|
||||
}
|
||||
const auto &root = jvRoot.get_object();
|
||||
|
||||
const auto *jvid = root.if_contains("id");
|
||||
if (jvid == nullptr)
|
||||
{
|
||||
static const error::ApplicationErrorCategory error_missing_field_id{
|
||||
"Missing required key id"};
|
||||
return boost::system::error_code{129, error_missing_field_id};
|
||||
}
|
||||
|
||||
auto id = boost::json::try_value_to<std::string>(*jvid);
|
||||
|
||||
if (id.has_error())
|
||||
{
|
||||
return id.error();
|
||||
}
|
||||
|
||||
const auto *jvemoteSetID = root.if_contains("emote_set_id");
|
||||
if (jvemoteSetID == nullptr)
|
||||
{
|
||||
static const error::ApplicationErrorCategory
|
||||
error_missing_field_emoteSetID{"Missing required key emote_set_id"};
|
||||
return boost::system::error_code{129, error_missing_field_emoteSetID};
|
||||
}
|
||||
|
||||
auto emoteSetID = boost::json::try_value_to<std::string>(*jvemoteSetID);
|
||||
|
||||
if (emoteSetID.has_error())
|
||||
{
|
||||
return emoteSetID.error();
|
||||
}
|
||||
|
||||
const auto *jvownerID = root.if_contains("owner_id");
|
||||
if (jvownerID == nullptr)
|
||||
{
|
||||
static const error::ApplicationErrorCategory
|
||||
error_missing_field_ownerID{"Missing required key owner_id"};
|
||||
return boost::system::error_code{129, error_missing_field_ownerID};
|
||||
}
|
||||
|
||||
auto ownerID = boost::json::try_value_to<std::string>(*jvownerID);
|
||||
|
||||
if (ownerID.has_error())
|
||||
{
|
||||
return ownerID.error();
|
||||
}
|
||||
|
||||
const auto *jvformat = root.if_contains("format");
|
||||
if (jvformat == nullptr)
|
||||
{
|
||||
static const error::ApplicationErrorCategory error_missing_field_format{
|
||||
"Missing required key format"};
|
||||
return boost::system::error_code{129, error_missing_field_format};
|
||||
}
|
||||
const auto format =
|
||||
boost::json::try_value_to<std::vector<std::string>>(*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<Mention, boost::json::value>::type tag_invoke(
|
||||
boost::json::try_value_to_tag<Mention>, const boost::json::value &jvRoot)
|
||||
{
|
||||
if (!jvRoot.is_object())
|
||||
{
|
||||
static const error::ApplicationErrorCategory errorMustBeObject{
|
||||
"Mention must be an object"};
|
||||
return boost::system::error_code{129, errorMustBeObject};
|
||||
}
|
||||
const auto &root = jvRoot.get_object();
|
||||
|
||||
const auto *jvuserID = root.if_contains("user_id");
|
||||
if (jvuserID == nullptr)
|
||||
{
|
||||
static const error::ApplicationErrorCategory error_missing_field_userID{
|
||||
"Missing required key user_id"};
|
||||
return boost::system::error_code{129, error_missing_field_userID};
|
||||
}
|
||||
|
||||
auto userID = boost::json::try_value_to<std::string>(*jvuserID);
|
||||
|
||||
if (userID.has_error())
|
||||
{
|
||||
return userID.error();
|
||||
}
|
||||
|
||||
const auto *jvuserName = root.if_contains("user_name");
|
||||
if (jvuserName == nullptr)
|
||||
{
|
||||
static const error::ApplicationErrorCategory
|
||||
error_missing_field_userName{"Missing required key user_name"};
|
||||
return boost::system::error_code{129, error_missing_field_userName};
|
||||
}
|
||||
|
||||
auto userName = boost::json::try_value_to<std::string>(*jvuserName);
|
||||
|
||||
if (userName.has_error())
|
||||
{
|
||||
return userName.error();
|
||||
}
|
||||
|
||||
const auto *jvuserLogin = root.if_contains("user_login");
|
||||
if (jvuserLogin == nullptr)
|
||||
{
|
||||
static const error::ApplicationErrorCategory
|
||||
error_missing_field_userLogin{"Missing required key user_login"};
|
||||
return boost::system::error_code{129, error_missing_field_userLogin};
|
||||
}
|
||||
|
||||
auto userLogin = boost::json::try_value_to<std::string>(*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<MessageFragment, boost::json::value>::type tag_invoke(
|
||||
boost::json::try_value_to_tag<MessageFragment>,
|
||||
const boost::json::value &jvRoot)
|
||||
{
|
||||
if (!jvRoot.is_object())
|
||||
{
|
||||
static const error::ApplicationErrorCategory errorMustBeObject{
|
||||
"MessageFragment must be an object"};
|
||||
return boost::system::error_code{129, errorMustBeObject};
|
||||
}
|
||||
const auto &root = jvRoot.get_object();
|
||||
|
||||
const auto *jvtype = root.if_contains("type");
|
||||
if (jvtype == nullptr)
|
||||
{
|
||||
static const error::ApplicationErrorCategory error_missing_field_type{
|
||||
"Missing required key type"};
|
||||
return boost::system::error_code{129, error_missing_field_type};
|
||||
}
|
||||
|
||||
auto type = boost::json::try_value_to<std::string>(*jvtype);
|
||||
|
||||
if (type.has_error())
|
||||
{
|
||||
return type.error();
|
||||
}
|
||||
|
||||
const auto *jvtext = root.if_contains("text");
|
||||
if (jvtext == nullptr)
|
||||
{
|
||||
static const error::ApplicationErrorCategory error_missing_field_text{
|
||||
"Missing required key text"};
|
||||
return boost::system::error_code{129, error_missing_field_text};
|
||||
}
|
||||
|
||||
auto text = boost::json::try_value_to<std::string>(*jvtext);
|
||||
|
||||
if (text.has_error())
|
||||
{
|
||||
return text.error();
|
||||
}
|
||||
|
||||
std::optional<Cheermote> cheermote = std::nullopt;
|
||||
const auto *jvcheermote = root.if_contains("cheermote");
|
||||
if (jvcheermote != nullptr && !jvcheermote->is_null())
|
||||
{
|
||||
auto tcheermote = boost::json::try_value_to<Cheermote>(*jvcheermote);
|
||||
|
||||
if (tcheermote.has_error())
|
||||
{
|
||||
return tcheermote.error();
|
||||
}
|
||||
cheermote = std::move(tcheermote.value());
|
||||
}
|
||||
|
||||
std::optional<Emote> emote = std::nullopt;
|
||||
const auto *jvemote = root.if_contains("emote");
|
||||
if (jvemote != nullptr && !jvemote->is_null())
|
||||
{
|
||||
auto temote = boost::json::try_value_to<Emote>(*jvemote);
|
||||
|
||||
if (temote.has_error())
|
||||
{
|
||||
return temote.error();
|
||||
}
|
||||
emote = std::move(temote.value());
|
||||
}
|
||||
|
||||
std::optional<Mention> mention = std::nullopt;
|
||||
const auto *jvmention = root.if_contains("mention");
|
||||
if (jvmention != nullptr && !jvmention->is_null())
|
||||
{
|
||||
auto tmention = boost::json::try_value_to<Mention>(*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<Message, boost::json::value>::type tag_invoke(
|
||||
boost::json::try_value_to_tag<Message>, const boost::json::value &jvRoot)
|
||||
{
|
||||
if (!jvRoot.is_object())
|
||||
{
|
||||
static const error::ApplicationErrorCategory errorMustBeObject{
|
||||
"Message must be an object"};
|
||||
return boost::system::error_code{129, errorMustBeObject};
|
||||
}
|
||||
const auto &root = jvRoot.get_object();
|
||||
|
||||
const auto *jvtext = root.if_contains("text");
|
||||
if (jvtext == nullptr)
|
||||
{
|
||||
static const error::ApplicationErrorCategory error_missing_field_text{
|
||||
"Missing required key text"};
|
||||
return boost::system::error_code{129, error_missing_field_text};
|
||||
}
|
||||
|
||||
auto text = boost::json::try_value_to<std::string>(*jvtext);
|
||||
|
||||
if (text.has_error())
|
||||
{
|
||||
return text.error();
|
||||
}
|
||||
|
||||
const auto *jvfragments = root.if_contains("fragments");
|
||||
if (jvfragments == nullptr)
|
||||
{
|
||||
static const error::ApplicationErrorCategory
|
||||
error_missing_field_fragments{"Missing required key fragments"};
|
||||
return boost::system::error_code{129, error_missing_field_fragments};
|
||||
}
|
||||
const auto fragments =
|
||||
boost::json::try_value_to<std::vector<MessageFragment>>(*jvfragments);
|
||||
if (fragments.has_error())
|
||||
{
|
||||
return fragments.error();
|
||||
}
|
||||
|
||||
return Message{
|
||||
.text = std::move(text.value()),
|
||||
.fragments = fragments.value(),
|
||||
};
|
||||
}
|
||||
|
||||
boost::json::result_for<Cheer, boost::json::value>::type tag_invoke(
|
||||
boost::json::try_value_to_tag<Cheer>, const boost::json::value &jvRoot)
|
||||
{
|
||||
if (!jvRoot.is_object())
|
||||
{
|
||||
static const error::ApplicationErrorCategory errorMustBeObject{
|
||||
"Cheer must be an object"};
|
||||
return boost::system::error_code{129, errorMustBeObject};
|
||||
}
|
||||
const auto &root = jvRoot.get_object();
|
||||
|
||||
const auto *jvbits = root.if_contains("bits");
|
||||
if (jvbits == nullptr)
|
||||
{
|
||||
static const error::ApplicationErrorCategory error_missing_field_bits{
|
||||
"Missing required key bits"};
|
||||
return boost::system::error_code{129, error_missing_field_bits};
|
||||
}
|
||||
|
||||
auto bits = boost::json::try_value_to<int>(*jvbits);
|
||||
|
||||
if (bits.has_error())
|
||||
{
|
||||
return bits.error();
|
||||
}
|
||||
|
||||
return Cheer{
|
||||
.bits = std::move(bits.value()),
|
||||
};
|
||||
}
|
||||
|
||||
boost::json::result_for<Reply, boost::json::value>::type tag_invoke(
|
||||
boost::json::try_value_to_tag<Reply>, const boost::json::value &jvRoot)
|
||||
{
|
||||
if (!jvRoot.is_object())
|
||||
{
|
||||
static const error::ApplicationErrorCategory errorMustBeObject{
|
||||
"Reply must be an object"};
|
||||
return boost::system::error_code{129, errorMustBeObject};
|
||||
}
|
||||
const auto &root = jvRoot.get_object();
|
||||
|
||||
const auto *jvparentMessageID = root.if_contains("parent_message_id");
|
||||
if (jvparentMessageID == nullptr)
|
||||
{
|
||||
static const error::ApplicationErrorCategory
|
||||
error_missing_field_parentMessageID{
|
||||
"Missing required key parent_message_id"};
|
||||
return boost::system::error_code{129,
|
||||
error_missing_field_parentMessageID};
|
||||
}
|
||||
|
||||
auto parentMessageID =
|
||||
boost::json::try_value_to<std::string>(*jvparentMessageID);
|
||||
|
||||
if (parentMessageID.has_error())
|
||||
{
|
||||
return parentMessageID.error();
|
||||
}
|
||||
|
||||
const auto *jvparentUserID = root.if_contains("parent_user_id");
|
||||
if (jvparentUserID == nullptr)
|
||||
{
|
||||
static const error::ApplicationErrorCategory
|
||||
error_missing_field_parentUserID{
|
||||
"Missing required key parent_user_id"};
|
||||
return boost::system::error_code{129, error_missing_field_parentUserID};
|
||||
}
|
||||
|
||||
auto parentUserID = boost::json::try_value_to<std::string>(*jvparentUserID);
|
||||
|
||||
if (parentUserID.has_error())
|
||||
{
|
||||
return parentUserID.error();
|
||||
}
|
||||
|
||||
const auto *jvparentUserLogin = root.if_contains("parent_user_login");
|
||||
if (jvparentUserLogin == nullptr)
|
||||
{
|
||||
static const error::ApplicationErrorCategory
|
||||
error_missing_field_parentUserLogin{
|
||||
"Missing required key parent_user_login"};
|
||||
return boost::system::error_code{129,
|
||||
error_missing_field_parentUserLogin};
|
||||
}
|
||||
|
||||
auto parentUserLogin =
|
||||
boost::json::try_value_to<std::string>(*jvparentUserLogin);
|
||||
|
||||
if (parentUserLogin.has_error())
|
||||
{
|
||||
return parentUserLogin.error();
|
||||
}
|
||||
|
||||
const auto *jvparentUserName = root.if_contains("parent_user_name");
|
||||
if (jvparentUserName == nullptr)
|
||||
{
|
||||
static const error::ApplicationErrorCategory
|
||||
error_missing_field_parentUserName{
|
||||
"Missing required key parent_user_name"};
|
||||
return boost::system::error_code{129,
|
||||
error_missing_field_parentUserName};
|
||||
}
|
||||
|
||||
auto parentUserName =
|
||||
boost::json::try_value_to<std::string>(*jvparentUserName);
|
||||
|
||||
if (parentUserName.has_error())
|
||||
{
|
||||
return parentUserName.error();
|
||||
}
|
||||
|
||||
const auto *jvparentMessageBody = root.if_contains("parent_message_body");
|
||||
if (jvparentMessageBody == nullptr)
|
||||
{
|
||||
static const error::ApplicationErrorCategory
|
||||
error_missing_field_parentMessageBody{
|
||||
"Missing required key parent_message_body"};
|
||||
return boost::system::error_code{129,
|
||||
error_missing_field_parentMessageBody};
|
||||
}
|
||||
|
||||
auto parentMessageBody =
|
||||
boost::json::try_value_to<std::string>(*jvparentMessageBody);
|
||||
|
||||
if (parentMessageBody.has_error())
|
||||
{
|
||||
return parentMessageBody.error();
|
||||
}
|
||||
|
||||
const auto *jvthreadMessageID = root.if_contains("thread_message_id");
|
||||
if (jvthreadMessageID == nullptr)
|
||||
{
|
||||
static const error::ApplicationErrorCategory
|
||||
error_missing_field_threadMessageID{
|
||||
"Missing required key thread_message_id"};
|
||||
return boost::system::error_code{129,
|
||||
error_missing_field_threadMessageID};
|
||||
}
|
||||
|
||||
auto threadMessageID =
|
||||
boost::json::try_value_to<std::string>(*jvthreadMessageID);
|
||||
|
||||
if (threadMessageID.has_error())
|
||||
{
|
||||
return threadMessageID.error();
|
||||
}
|
||||
|
||||
const auto *jvthreadUserID = root.if_contains("thread_user_id");
|
||||
if (jvthreadUserID == nullptr)
|
||||
{
|
||||
static const error::ApplicationErrorCategory
|
||||
error_missing_field_threadUserID{
|
||||
"Missing required key thread_user_id"};
|
||||
return boost::system::error_code{129, error_missing_field_threadUserID};
|
||||
}
|
||||
|
||||
auto threadUserID = boost::json::try_value_to<std::string>(*jvthreadUserID);
|
||||
|
||||
if (threadUserID.has_error())
|
||||
{
|
||||
return threadUserID.error();
|
||||
}
|
||||
|
||||
const auto *jvthreadUserLogin = root.if_contains("thread_user_login");
|
||||
if (jvthreadUserLogin == nullptr)
|
||||
{
|
||||
static const error::ApplicationErrorCategory
|
||||
error_missing_field_threadUserLogin{
|
||||
"Missing required key thread_user_login"};
|
||||
return boost::system::error_code{129,
|
||||
error_missing_field_threadUserLogin};
|
||||
}
|
||||
|
||||
auto threadUserLogin =
|
||||
boost::json::try_value_to<std::string>(*jvthreadUserLogin);
|
||||
|
||||
if (threadUserLogin.has_error())
|
||||
{
|
||||
return threadUserLogin.error();
|
||||
}
|
||||
|
||||
const auto *jvthreadUserName = root.if_contains("thread_user_name");
|
||||
if (jvthreadUserName == nullptr)
|
||||
{
|
||||
static const error::ApplicationErrorCategory
|
||||
error_missing_field_threadUserName{
|
||||
"Missing required key thread_user_name"};
|
||||
return boost::system::error_code{129,
|
||||
error_missing_field_threadUserName};
|
||||
}
|
||||
|
||||
auto threadUserName =
|
||||
boost::json::try_value_to<std::string>(*jvthreadUserName);
|
||||
|
||||
if (threadUserName.has_error())
|
||||
{
|
||||
return threadUserName.error();
|
||||
}
|
||||
|
||||
return Reply{
|
||||
.parentMessageID = std::move(parentMessageID.value()),
|
||||
.parentUserID = std::move(parentUserID.value()),
|
||||
.parentUserLogin = std::move(parentUserLogin.value()),
|
||||
.parentUserName = std::move(parentUserName.value()),
|
||||
.parentMessageBody = std::move(parentMessageBody.value()),
|
||||
.threadMessageID = std::move(threadMessageID.value()),
|
||||
.threadUserID = std::move(threadUserID.value()),
|
||||
.threadUserLogin = std::move(threadUserLogin.value()),
|
||||
.threadUserName = std::move(threadUserName.value()),
|
||||
};
|
||||
}
|
||||
|
||||
boost::json::result_for<Event, boost::json::value>::type tag_invoke(
|
||||
boost::json::try_value_to_tag<Event>, const boost::json::value &jvRoot)
|
||||
{
|
||||
if (!jvRoot.is_object())
|
||||
{
|
||||
static const error::ApplicationErrorCategory errorMustBeObject{
|
||||
"Event must be an object"};
|
||||
return boost::system::error_code{129, errorMustBeObject};
|
||||
}
|
||||
const auto &root = jvRoot.get_object();
|
||||
|
||||
const auto *jvbroadcasterUserID = root.if_contains("broadcaster_user_id");
|
||||
if (jvbroadcasterUserID == nullptr)
|
||||
{
|
||||
static const error::ApplicationErrorCategory
|
||||
error_missing_field_broadcasterUserID{
|
||||
"Missing required key broadcaster_user_id"};
|
||||
return boost::system::error_code{129,
|
||||
error_missing_field_broadcasterUserID};
|
||||
}
|
||||
|
||||
auto broadcasterUserID =
|
||||
boost::json::try_value_to<std::string>(*jvbroadcasterUserID);
|
||||
|
||||
if (broadcasterUserID.has_error())
|
||||
{
|
||||
return broadcasterUserID.error();
|
||||
}
|
||||
|
||||
const auto *jvbroadcasterUserLogin =
|
||||
root.if_contains("broadcaster_user_login");
|
||||
if (jvbroadcasterUserLogin == nullptr)
|
||||
{
|
||||
static const error::ApplicationErrorCategory
|
||||
error_missing_field_broadcasterUserLogin{
|
||||
"Missing required key broadcaster_user_login"};
|
||||
return boost::system::error_code{
|
||||
129, error_missing_field_broadcasterUserLogin};
|
||||
}
|
||||
|
||||
auto broadcasterUserLogin =
|
||||
boost::json::try_value_to<std::string>(*jvbroadcasterUserLogin);
|
||||
|
||||
if (broadcasterUserLogin.has_error())
|
||||
{
|
||||
return broadcasterUserLogin.error();
|
||||
}
|
||||
|
||||
const auto *jvbroadcasterUserName =
|
||||
root.if_contains("broadcaster_user_name");
|
||||
if (jvbroadcasterUserName == nullptr)
|
||||
{
|
||||
static const error::ApplicationErrorCategory
|
||||
error_missing_field_broadcasterUserName{
|
||||
"Missing required key broadcaster_user_name"};
|
||||
return boost::system::error_code{
|
||||
129, error_missing_field_broadcasterUserName};
|
||||
}
|
||||
|
||||
auto broadcasterUserName =
|
||||
boost::json::try_value_to<std::string>(*jvbroadcasterUserName);
|
||||
|
||||
if (broadcasterUserName.has_error())
|
||||
{
|
||||
return broadcasterUserName.error();
|
||||
}
|
||||
|
||||
const auto *jvchatterUserID = root.if_contains("chatter_user_id");
|
||||
if (jvchatterUserID == nullptr)
|
||||
{
|
||||
static const error::ApplicationErrorCategory
|
||||
error_missing_field_chatterUserID{
|
||||
"Missing required key chatter_user_id"};
|
||||
return boost::system::error_code{129,
|
||||
error_missing_field_chatterUserID};
|
||||
}
|
||||
|
||||
auto chatterUserID =
|
||||
boost::json::try_value_to<std::string>(*jvchatterUserID);
|
||||
|
||||
if (chatterUserID.has_error())
|
||||
{
|
||||
return chatterUserID.error();
|
||||
}
|
||||
|
||||
const auto *jvchatterUserLogin = root.if_contains("chatter_user_login");
|
||||
if (jvchatterUserLogin == nullptr)
|
||||
{
|
||||
static const error::ApplicationErrorCategory
|
||||
error_missing_field_chatterUserLogin{
|
||||
"Missing required key chatter_user_login"};
|
||||
return boost::system::error_code{129,
|
||||
error_missing_field_chatterUserLogin};
|
||||
}
|
||||
|
||||
auto chatterUserLogin =
|
||||
boost::json::try_value_to<std::string>(*jvchatterUserLogin);
|
||||
|
||||
if (chatterUserLogin.has_error())
|
||||
{
|
||||
return chatterUserLogin.error();
|
||||
}
|
||||
|
||||
const auto *jvchatterUserName = root.if_contains("chatter_user_name");
|
||||
if (jvchatterUserName == nullptr)
|
||||
{
|
||||
static const error::ApplicationErrorCategory
|
||||
error_missing_field_chatterUserName{
|
||||
"Missing required key chatter_user_name"};
|
||||
return boost::system::error_code{129,
|
||||
error_missing_field_chatterUserName};
|
||||
}
|
||||
|
||||
auto chatterUserName =
|
||||
boost::json::try_value_to<std::string>(*jvchatterUserName);
|
||||
|
||||
if (chatterUserName.has_error())
|
||||
{
|
||||
return chatterUserName.error();
|
||||
}
|
||||
|
||||
const auto *jvcolor = root.if_contains("color");
|
||||
if (jvcolor == nullptr)
|
||||
{
|
||||
static const error::ApplicationErrorCategory error_missing_field_color{
|
||||
"Missing required key color"};
|
||||
return boost::system::error_code{129, error_missing_field_color};
|
||||
}
|
||||
|
||||
auto color = boost::json::try_value_to<std::string>(*jvcolor);
|
||||
|
||||
if (color.has_error())
|
||||
{
|
||||
return color.error();
|
||||
}
|
||||
|
||||
const auto *jvbadges = root.if_contains("badges");
|
||||
if (jvbadges == nullptr)
|
||||
{
|
||||
static const error::ApplicationErrorCategory error_missing_field_badges{
|
||||
"Missing required key badges"};
|
||||
return boost::system::error_code{129, error_missing_field_badges};
|
||||
}
|
||||
const auto badges =
|
||||
boost::json::try_value_to<std::vector<Badge>>(*jvbadges);
|
||||
if (badges.has_error())
|
||||
{
|
||||
return badges.error();
|
||||
}
|
||||
|
||||
const auto *jvmessageID = root.if_contains("message_id");
|
||||
if (jvmessageID == nullptr)
|
||||
{
|
||||
static const error::ApplicationErrorCategory
|
||||
error_missing_field_messageID{"Missing required key message_id"};
|
||||
return boost::system::error_code{129, error_missing_field_messageID};
|
||||
}
|
||||
|
||||
auto messageID = boost::json::try_value_to<std::string>(*jvmessageID);
|
||||
|
||||
if (messageID.has_error())
|
||||
{
|
||||
return messageID.error();
|
||||
}
|
||||
|
||||
const auto *jvmessageType = root.if_contains("message_type");
|
||||
if (jvmessageType == nullptr)
|
||||
{
|
||||
static const error::ApplicationErrorCategory
|
||||
error_missing_field_messageType{
|
||||
"Missing required key message_type"};
|
||||
return boost::system::error_code{129, error_missing_field_messageType};
|
||||
}
|
||||
|
||||
auto messageType = boost::json::try_value_to<std::string>(*jvmessageType);
|
||||
|
||||
if (messageType.has_error())
|
||||
{
|
||||
return messageType.error();
|
||||
}
|
||||
|
||||
const auto *jvmessage = root.if_contains("message");
|
||||
if (jvmessage == nullptr)
|
||||
{
|
||||
static const error::ApplicationErrorCategory
|
||||
error_missing_field_message{"Missing required key message"};
|
||||
return boost::system::error_code{129, error_missing_field_message};
|
||||
}
|
||||
|
||||
auto message = boost::json::try_value_to<Message>(*jvmessage);
|
||||
|
||||
if (message.has_error())
|
||||
{
|
||||
return message.error();
|
||||
}
|
||||
|
||||
std::optional<Cheer> cheer = std::nullopt;
|
||||
const auto *jvcheer = root.if_contains("cheer");
|
||||
if (jvcheer != nullptr && !jvcheer->is_null())
|
||||
{
|
||||
auto tcheer = boost::json::try_value_to<Cheer>(*jvcheer);
|
||||
|
||||
if (tcheer.has_error())
|
||||
{
|
||||
return tcheer.error();
|
||||
}
|
||||
cheer = std::move(tcheer.value());
|
||||
}
|
||||
|
||||
std::optional<Reply> reply = std::nullopt;
|
||||
const auto *jvreply = root.if_contains("reply");
|
||||
if (jvreply != nullptr && !jvreply->is_null())
|
||||
{
|
||||
auto treply = boost::json::try_value_to<Reply>(*jvreply);
|
||||
|
||||
if (treply.has_error())
|
||||
{
|
||||
return treply.error();
|
||||
}
|
||||
reply = std::move(treply.value());
|
||||
}
|
||||
|
||||
std::optional<std::string> channelPointsCustomRewardID = std::nullopt;
|
||||
const auto *jvchannelPointsCustomRewardID =
|
||||
root.if_contains("channel_points_custom_reward_id");
|
||||
if (jvchannelPointsCustomRewardID != nullptr &&
|
||||
!jvchannelPointsCustomRewardID->is_null())
|
||||
{
|
||||
auto tchannelPointsCustomRewardID =
|
||||
boost::json::try_value_to<std::string>(
|
||||
*jvchannelPointsCustomRewardID);
|
||||
|
||||
if (tchannelPointsCustomRewardID.has_error())
|
||||
{
|
||||
return tchannelPointsCustomRewardID.error();
|
||||
}
|
||||
channelPointsCustomRewardID =
|
||||
std::move(tchannelPointsCustomRewardID.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()),
|
||||
.color = std::move(color.value()),
|
||||
.badges = badges.value(),
|
||||
.messageID = std::move(messageID.value()),
|
||||
.messageType = std::move(messageType.value()),
|
||||
.message = std::move(message.value()),
|
||||
.cheer = std::move(cheer),
|
||||
.reply = std::move(reply),
|
||||
.channelPointsCustomRewardID = std::move(channelPointsCustomRewardID),
|
||||
};
|
||||
}
|
||||
|
||||
boost::json::result_for<Payload, boost::json::value>::type tag_invoke(
|
||||
boost::json::try_value_to_tag<Payload>, const boost::json::value &jvRoot)
|
||||
{
|
||||
if (!jvRoot.is_object())
|
||||
{
|
||||
static const error::ApplicationErrorCategory errorMustBeObject{
|
||||
"Payload must be an object"};
|
||||
return boost::system::error_code{129, errorMustBeObject};
|
||||
}
|
||||
const auto &root = jvRoot.get_object();
|
||||
|
||||
const auto *jvsubscription = root.if_contains("subscription");
|
||||
if (jvsubscription == nullptr)
|
||||
{
|
||||
static const error::ApplicationErrorCategory
|
||||
error_missing_field_subscription{
|
||||
"Missing required key subscription"};
|
||||
return boost::system::error_code{129, error_missing_field_subscription};
|
||||
}
|
||||
|
||||
auto subscription =
|
||||
boost::json::try_value_to<subscription::Subscription>(*jvsubscription);
|
||||
|
||||
if (subscription.has_error())
|
||||
{
|
||||
return subscription.error();
|
||||
}
|
||||
|
||||
const auto *jvevent = root.if_contains("event");
|
||||
if (jvevent == nullptr)
|
||||
{
|
||||
static const error::ApplicationErrorCategory error_missing_field_event{
|
||||
"Missing required key event"};
|
||||
return boost::system::error_code{129, error_missing_field_event};
|
||||
}
|
||||
|
||||
auto event = boost::json::try_value_to<Event>(*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_message::v1
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,215 @@
|
||||
|
||||
// WARNING: This file is automatically generated. Any changes will be lost.
|
||||
#include "twitch-eventsub-ws/chrono.hpp" // IWYU pragma: keep
|
||||
#include "twitch-eventsub-ws/errors.hpp"
|
||||
#include "twitch-eventsub-ws/payloads/channel-update-v1.hpp"
|
||||
|
||||
#include <boost/json.hpp>
|
||||
|
||||
namespace chatterino::eventsub::lib::payload::channel_update::v1 {
|
||||
|
||||
boost::json::result_for<Event, boost::json::value>::type tag_invoke(
|
||||
boost::json::try_value_to_tag<Event>, const boost::json::value &jvRoot)
|
||||
{
|
||||
if (!jvRoot.is_object())
|
||||
{
|
||||
static const error::ApplicationErrorCategory errorMustBeObject{
|
||||
"Event must be an object"};
|
||||
return boost::system::error_code{129, errorMustBeObject};
|
||||
}
|
||||
const auto &root = jvRoot.get_object();
|
||||
|
||||
const auto *jvbroadcasterUserID = root.if_contains("broadcaster_user_id");
|
||||
if (jvbroadcasterUserID == nullptr)
|
||||
{
|
||||
static const error::ApplicationErrorCategory
|
||||
error_missing_field_broadcasterUserID{
|
||||
"Missing required key broadcaster_user_id"};
|
||||
return boost::system::error_code{129,
|
||||
error_missing_field_broadcasterUserID};
|
||||
}
|
||||
|
||||
auto broadcasterUserID =
|
||||
boost::json::try_value_to<std::string>(*jvbroadcasterUserID);
|
||||
|
||||
if (broadcasterUserID.has_error())
|
||||
{
|
||||
return broadcasterUserID.error();
|
||||
}
|
||||
|
||||
const auto *jvbroadcasterUserLogin =
|
||||
root.if_contains("broadcaster_user_login");
|
||||
if (jvbroadcasterUserLogin == nullptr)
|
||||
{
|
||||
static const error::ApplicationErrorCategory
|
||||
error_missing_field_broadcasterUserLogin{
|
||||
"Missing required key broadcaster_user_login"};
|
||||
return boost::system::error_code{
|
||||
129, error_missing_field_broadcasterUserLogin};
|
||||
}
|
||||
|
||||
auto broadcasterUserLogin =
|
||||
boost::json::try_value_to<std::string>(*jvbroadcasterUserLogin);
|
||||
|
||||
if (broadcasterUserLogin.has_error())
|
||||
{
|
||||
return broadcasterUserLogin.error();
|
||||
}
|
||||
|
||||
const auto *jvbroadcasterUserName =
|
||||
root.if_contains("broadcaster_user_name");
|
||||
if (jvbroadcasterUserName == nullptr)
|
||||
{
|
||||
static const error::ApplicationErrorCategory
|
||||
error_missing_field_broadcasterUserName{
|
||||
"Missing required key broadcaster_user_name"};
|
||||
return boost::system::error_code{
|
||||
129, error_missing_field_broadcasterUserName};
|
||||
}
|
||||
|
||||
auto broadcasterUserName =
|
||||
boost::json::try_value_to<std::string>(*jvbroadcasterUserName);
|
||||
|
||||
if (broadcasterUserName.has_error())
|
||||
{
|
||||
return broadcasterUserName.error();
|
||||
}
|
||||
|
||||
const auto *jvtitle = root.if_contains("title");
|
||||
if (jvtitle == nullptr)
|
||||
{
|
||||
static const error::ApplicationErrorCategory error_missing_field_title{
|
||||
"Missing required key title"};
|
||||
return boost::system::error_code{129, error_missing_field_title};
|
||||
}
|
||||
|
||||
auto title = boost::json::try_value_to<std::string>(*jvtitle);
|
||||
|
||||
if (title.has_error())
|
||||
{
|
||||
return title.error();
|
||||
}
|
||||
|
||||
const auto *jvlanguage = root.if_contains("language");
|
||||
if (jvlanguage == nullptr)
|
||||
{
|
||||
static const error::ApplicationErrorCategory
|
||||
error_missing_field_language{"Missing required key language"};
|
||||
return boost::system::error_code{129, error_missing_field_language};
|
||||
}
|
||||
|
||||
auto language = boost::json::try_value_to<std::string>(*jvlanguage);
|
||||
|
||||
if (language.has_error())
|
||||
{
|
||||
return language.error();
|
||||
}
|
||||
|
||||
const auto *jvcategoryID = root.if_contains("category_id");
|
||||
if (jvcategoryID == nullptr)
|
||||
{
|
||||
static const error::ApplicationErrorCategory
|
||||
error_missing_field_categoryID{"Missing required key category_id"};
|
||||
return boost::system::error_code{129, error_missing_field_categoryID};
|
||||
}
|
||||
|
||||
auto categoryID = boost::json::try_value_to<std::string>(*jvcategoryID);
|
||||
|
||||
if (categoryID.has_error())
|
||||
{
|
||||
return categoryID.error();
|
||||
}
|
||||
|
||||
const auto *jvcategoryName = root.if_contains("category_name");
|
||||
if (jvcategoryName == nullptr)
|
||||
{
|
||||
static const error::ApplicationErrorCategory
|
||||
error_missing_field_categoryName{
|
||||
"Missing required key category_name"};
|
||||
return boost::system::error_code{129, error_missing_field_categoryName};
|
||||
}
|
||||
|
||||
auto categoryName = boost::json::try_value_to<std::string>(*jvcategoryName);
|
||||
|
||||
if (categoryName.has_error())
|
||||
{
|
||||
return categoryName.error();
|
||||
}
|
||||
|
||||
const auto *jvisMature = root.if_contains("is_mature");
|
||||
if (jvisMature == nullptr)
|
||||
{
|
||||
static const error::ApplicationErrorCategory
|
||||
error_missing_field_isMature{"Missing required key is_mature"};
|
||||
return boost::system::error_code{129, error_missing_field_isMature};
|
||||
}
|
||||
|
||||
auto isMature = boost::json::try_value_to<bool>(*jvisMature);
|
||||
|
||||
if (isMature.has_error())
|
||||
{
|
||||
return isMature.error();
|
||||
}
|
||||
|
||||
return Event{
|
||||
.broadcasterUserID = std::move(broadcasterUserID.value()),
|
||||
.broadcasterUserLogin = std::move(broadcasterUserLogin.value()),
|
||||
.broadcasterUserName = std::move(broadcasterUserName.value()),
|
||||
.title = std::move(title.value()),
|
||||
.language = std::move(language.value()),
|
||||
.categoryID = std::move(categoryID.value()),
|
||||
.categoryName = std::move(categoryName.value()),
|
||||
.isMature = std::move(isMature.value()),
|
||||
};
|
||||
}
|
||||
|
||||
boost::json::result_for<Payload, boost::json::value>::type tag_invoke(
|
||||
boost::json::try_value_to_tag<Payload>, const boost::json::value &jvRoot)
|
||||
{
|
||||
if (!jvRoot.is_object())
|
||||
{
|
||||
static const error::ApplicationErrorCategory errorMustBeObject{
|
||||
"Payload must be an object"};
|
||||
return boost::system::error_code{129, errorMustBeObject};
|
||||
}
|
||||
const auto &root = jvRoot.get_object();
|
||||
|
||||
const auto *jvsubscription = root.if_contains("subscription");
|
||||
if (jvsubscription == nullptr)
|
||||
{
|
||||
static const error::ApplicationErrorCategory
|
||||
error_missing_field_subscription{
|
||||
"Missing required key subscription"};
|
||||
return boost::system::error_code{129, error_missing_field_subscription};
|
||||
}
|
||||
|
||||
auto subscription =
|
||||
boost::json::try_value_to<subscription::Subscription>(*jvsubscription);
|
||||
|
||||
if (subscription.has_error())
|
||||
{
|
||||
return subscription.error();
|
||||
}
|
||||
|
||||
const auto *jvevent = root.if_contains("event");
|
||||
if (jvevent == nullptr)
|
||||
{
|
||||
static const error::ApplicationErrorCategory error_missing_field_event{
|
||||
"Missing required key event"};
|
||||
return boost::system::error_code{129, error_missing_field_event};
|
||||
}
|
||||
|
||||
auto event = boost::json::try_value_to<Event>(*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_update::v1
|
||||
@@ -0,0 +1,57 @@
|
||||
|
||||
// WARNING: This file is automatically generated. Any changes will be lost.
|
||||
#include "twitch-eventsub-ws/chrono.hpp" // IWYU pragma: keep
|
||||
#include "twitch-eventsub-ws/errors.hpp"
|
||||
#include "twitch-eventsub-ws/payloads/session-welcome.hpp"
|
||||
|
||||
#include <boost/json.hpp>
|
||||
|
||||
namespace chatterino::eventsub::lib::payload::session_welcome {
|
||||
|
||||
boost::json::result_for<Payload, boost::json::value>::type tag_invoke(
|
||||
boost::json::try_value_to_tag<Payload>, const boost::json::value &jvRoot)
|
||||
{
|
||||
if (!jvRoot.is_object())
|
||||
{
|
||||
static const error::ApplicationErrorCategory errorMustBeObject{
|
||||
"Payload must be an object"};
|
||||
return boost::system::error_code{129, errorMustBeObject};
|
||||
}
|
||||
const auto &outerRoot = jvRoot.get_object();
|
||||
|
||||
const auto *jvInnerRoot = outerRoot.if_contains("session");
|
||||
if (jvInnerRoot == nullptr)
|
||||
{
|
||||
static const error::ApplicationErrorCategory errorMissing{
|
||||
"Payload's key session is missing"};
|
||||
return boost::system::error_code{129, errorMissing};
|
||||
}
|
||||
if (!jvInnerRoot->is_object())
|
||||
{
|
||||
static const error::ApplicationErrorCategory errorMustBeObject{
|
||||
"Payload's session must be an object"};
|
||||
return boost::system::error_code{129, errorMustBeObject};
|
||||
}
|
||||
const auto &root = jvInnerRoot->get_object();
|
||||
|
||||
const auto *jvid = root.if_contains("id");
|
||||
if (jvid == nullptr)
|
||||
{
|
||||
static const error::ApplicationErrorCategory error_missing_field_id{
|
||||
"Missing required key id"};
|
||||
return boost::system::error_code{129, error_missing_field_id};
|
||||
}
|
||||
|
||||
auto id = boost::json::try_value_to<std::string>(*jvid);
|
||||
|
||||
if (id.has_error())
|
||||
{
|
||||
return id.error();
|
||||
}
|
||||
|
||||
return Payload{
|
||||
.id = std::move(id.value()),
|
||||
};
|
||||
}
|
||||
|
||||
} // namespace chatterino::eventsub::lib::payload::session_welcome
|
||||
@@ -0,0 +1,134 @@
|
||||
|
||||
// WARNING: This file is automatically generated. Any changes will be lost.
|
||||
#include "twitch-eventsub-ws/chrono.hpp" // IWYU pragma: keep
|
||||
#include "twitch-eventsub-ws/errors.hpp"
|
||||
#include "twitch-eventsub-ws/payloads/stream-offline-v1.hpp"
|
||||
|
||||
#include <boost/json.hpp>
|
||||
|
||||
namespace chatterino::eventsub::lib::payload::stream_offline::v1 {
|
||||
|
||||
boost::json::result_for<Event, boost::json::value>::type tag_invoke(
|
||||
boost::json::try_value_to_tag<Event>, const boost::json::value &jvRoot)
|
||||
{
|
||||
if (!jvRoot.is_object())
|
||||
{
|
||||
static const error::ApplicationErrorCategory errorMustBeObject{
|
||||
"Event must be an object"};
|
||||
return boost::system::error_code{129, errorMustBeObject};
|
||||
}
|
||||
const auto &root = jvRoot.get_object();
|
||||
|
||||
const auto *jvbroadcasterUserID = root.if_contains("broadcaster_user_id");
|
||||
if (jvbroadcasterUserID == nullptr)
|
||||
{
|
||||
static const error::ApplicationErrorCategory
|
||||
error_missing_field_broadcasterUserID{
|
||||
"Missing required key broadcaster_user_id"};
|
||||
return boost::system::error_code{129,
|
||||
error_missing_field_broadcasterUserID};
|
||||
}
|
||||
|
||||
auto broadcasterUserID =
|
||||
boost::json::try_value_to<std::string>(*jvbroadcasterUserID);
|
||||
|
||||
if (broadcasterUserID.has_error())
|
||||
{
|
||||
return broadcasterUserID.error();
|
||||
}
|
||||
|
||||
const auto *jvbroadcasterUserLogin =
|
||||
root.if_contains("broadcaster_user_login");
|
||||
if (jvbroadcasterUserLogin == nullptr)
|
||||
{
|
||||
static const error::ApplicationErrorCategory
|
||||
error_missing_field_broadcasterUserLogin{
|
||||
"Missing required key broadcaster_user_login"};
|
||||
return boost::system::error_code{
|
||||
129, error_missing_field_broadcasterUserLogin};
|
||||
}
|
||||
|
||||
auto broadcasterUserLogin =
|
||||
boost::json::try_value_to<std::string>(*jvbroadcasterUserLogin);
|
||||
|
||||
if (broadcasterUserLogin.has_error())
|
||||
{
|
||||
return broadcasterUserLogin.error();
|
||||
}
|
||||
|
||||
const auto *jvbroadcasterUserName =
|
||||
root.if_contains("broadcaster_user_name");
|
||||
if (jvbroadcasterUserName == nullptr)
|
||||
{
|
||||
static const error::ApplicationErrorCategory
|
||||
error_missing_field_broadcasterUserName{
|
||||
"Missing required key broadcaster_user_name"};
|
||||
return boost::system::error_code{
|
||||
129, error_missing_field_broadcasterUserName};
|
||||
}
|
||||
|
||||
auto broadcasterUserName =
|
||||
boost::json::try_value_to<std::string>(*jvbroadcasterUserName);
|
||||
|
||||
if (broadcasterUserName.has_error())
|
||||
{
|
||||
return broadcasterUserName.error();
|
||||
}
|
||||
|
||||
return Event{
|
||||
.broadcasterUserID = std::move(broadcasterUserID.value()),
|
||||
.broadcasterUserLogin = std::move(broadcasterUserLogin.value()),
|
||||
.broadcasterUserName = std::move(broadcasterUserName.value()),
|
||||
};
|
||||
}
|
||||
|
||||
boost::json::result_for<Payload, boost::json::value>::type tag_invoke(
|
||||
boost::json::try_value_to_tag<Payload>, const boost::json::value &jvRoot)
|
||||
{
|
||||
if (!jvRoot.is_object())
|
||||
{
|
||||
static const error::ApplicationErrorCategory errorMustBeObject{
|
||||
"Payload must be an object"};
|
||||
return boost::system::error_code{129, errorMustBeObject};
|
||||
}
|
||||
const auto &root = jvRoot.get_object();
|
||||
|
||||
const auto *jvsubscription = root.if_contains("subscription");
|
||||
if (jvsubscription == nullptr)
|
||||
{
|
||||
static const error::ApplicationErrorCategory
|
||||
error_missing_field_subscription{
|
||||
"Missing required key subscription"};
|
||||
return boost::system::error_code{129, error_missing_field_subscription};
|
||||
}
|
||||
|
||||
auto subscription =
|
||||
boost::json::try_value_to<subscription::Subscription>(*jvsubscription);
|
||||
|
||||
if (subscription.has_error())
|
||||
{
|
||||
return subscription.error();
|
||||
}
|
||||
|
||||
const auto *jvevent = root.if_contains("event");
|
||||
if (jvevent == nullptr)
|
||||
{
|
||||
static const error::ApplicationErrorCategory error_missing_field_event{
|
||||
"Missing required key event"};
|
||||
return boost::system::error_code{129, error_missing_field_event};
|
||||
}
|
||||
|
||||
auto event = boost::json::try_value_to<Event>(*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::stream_offline::v1
|
||||
@@ -0,0 +1,182 @@
|
||||
|
||||
// WARNING: This file is automatically generated. Any changes will be lost.
|
||||
#include "twitch-eventsub-ws/chrono.hpp" // IWYU pragma: keep
|
||||
#include "twitch-eventsub-ws/errors.hpp"
|
||||
#include "twitch-eventsub-ws/payloads/stream-online-v1.hpp"
|
||||
|
||||
#include <boost/json.hpp>
|
||||
|
||||
namespace chatterino::eventsub::lib::payload::stream_online::v1 {
|
||||
|
||||
boost::json::result_for<Event, boost::json::value>::type tag_invoke(
|
||||
boost::json::try_value_to_tag<Event>, const boost::json::value &jvRoot)
|
||||
{
|
||||
if (!jvRoot.is_object())
|
||||
{
|
||||
static const error::ApplicationErrorCategory errorMustBeObject{
|
||||
"Event must be an object"};
|
||||
return boost::system::error_code{129, errorMustBeObject};
|
||||
}
|
||||
const auto &root = jvRoot.get_object();
|
||||
|
||||
const auto *jvid = root.if_contains("id");
|
||||
if (jvid == nullptr)
|
||||
{
|
||||
static const error::ApplicationErrorCategory error_missing_field_id{
|
||||
"Missing required key id"};
|
||||
return boost::system::error_code{129, error_missing_field_id};
|
||||
}
|
||||
|
||||
auto id = boost::json::try_value_to<std::string>(*jvid);
|
||||
|
||||
if (id.has_error())
|
||||
{
|
||||
return id.error();
|
||||
}
|
||||
|
||||
const auto *jvbroadcasterUserID = root.if_contains("broadcaster_user_id");
|
||||
if (jvbroadcasterUserID == nullptr)
|
||||
{
|
||||
static const error::ApplicationErrorCategory
|
||||
error_missing_field_broadcasterUserID{
|
||||
"Missing required key broadcaster_user_id"};
|
||||
return boost::system::error_code{129,
|
||||
error_missing_field_broadcasterUserID};
|
||||
}
|
||||
|
||||
auto broadcasterUserID =
|
||||
boost::json::try_value_to<std::string>(*jvbroadcasterUserID);
|
||||
|
||||
if (broadcasterUserID.has_error())
|
||||
{
|
||||
return broadcasterUserID.error();
|
||||
}
|
||||
|
||||
const auto *jvbroadcasterUserLogin =
|
||||
root.if_contains("broadcaster_user_login");
|
||||
if (jvbroadcasterUserLogin == nullptr)
|
||||
{
|
||||
static const error::ApplicationErrorCategory
|
||||
error_missing_field_broadcasterUserLogin{
|
||||
"Missing required key broadcaster_user_login"};
|
||||
return boost::system::error_code{
|
||||
129, error_missing_field_broadcasterUserLogin};
|
||||
}
|
||||
|
||||
auto broadcasterUserLogin =
|
||||
boost::json::try_value_to<std::string>(*jvbroadcasterUserLogin);
|
||||
|
||||
if (broadcasterUserLogin.has_error())
|
||||
{
|
||||
return broadcasterUserLogin.error();
|
||||
}
|
||||
|
||||
const auto *jvbroadcasterUserName =
|
||||
root.if_contains("broadcaster_user_name");
|
||||
if (jvbroadcasterUserName == nullptr)
|
||||
{
|
||||
static const error::ApplicationErrorCategory
|
||||
error_missing_field_broadcasterUserName{
|
||||
"Missing required key broadcaster_user_name"};
|
||||
return boost::system::error_code{
|
||||
129, error_missing_field_broadcasterUserName};
|
||||
}
|
||||
|
||||
auto broadcasterUserName =
|
||||
boost::json::try_value_to<std::string>(*jvbroadcasterUserName);
|
||||
|
||||
if (broadcasterUserName.has_error())
|
||||
{
|
||||
return broadcasterUserName.error();
|
||||
}
|
||||
|
||||
const auto *jvtype = root.if_contains("type");
|
||||
if (jvtype == nullptr)
|
||||
{
|
||||
static const error::ApplicationErrorCategory error_missing_field_type{
|
||||
"Missing required key type"};
|
||||
return boost::system::error_code{129, error_missing_field_type};
|
||||
}
|
||||
|
||||
auto type = boost::json::try_value_to<std::string>(*jvtype);
|
||||
|
||||
if (type.has_error())
|
||||
{
|
||||
return type.error();
|
||||
}
|
||||
|
||||
const auto *jvstartedAt = root.if_contains("started_at");
|
||||
if (jvstartedAt == nullptr)
|
||||
{
|
||||
static const error::ApplicationErrorCategory
|
||||
error_missing_field_startedAt{"Missing required key started_at"};
|
||||
return boost::system::error_code{129, error_missing_field_startedAt};
|
||||
}
|
||||
|
||||
auto startedAt = boost::json::try_value_to<std::string>(*jvstartedAt);
|
||||
|
||||
if (startedAt.has_error())
|
||||
{
|
||||
return startedAt.error();
|
||||
}
|
||||
|
||||
return Event{
|
||||
.id = std::move(id.value()),
|
||||
.broadcasterUserID = std::move(broadcasterUserID.value()),
|
||||
.broadcasterUserLogin = std::move(broadcasterUserLogin.value()),
|
||||
.broadcasterUserName = std::move(broadcasterUserName.value()),
|
||||
.type = std::move(type.value()),
|
||||
.startedAt = std::move(startedAt.value()),
|
||||
};
|
||||
}
|
||||
|
||||
boost::json::result_for<Payload, boost::json::value>::type tag_invoke(
|
||||
boost::json::try_value_to_tag<Payload>, const boost::json::value &jvRoot)
|
||||
{
|
||||
if (!jvRoot.is_object())
|
||||
{
|
||||
static const error::ApplicationErrorCategory errorMustBeObject{
|
||||
"Payload must be an object"};
|
||||
return boost::system::error_code{129, errorMustBeObject};
|
||||
}
|
||||
const auto &root = jvRoot.get_object();
|
||||
|
||||
const auto *jvsubscription = root.if_contains("subscription");
|
||||
if (jvsubscription == nullptr)
|
||||
{
|
||||
static const error::ApplicationErrorCategory
|
||||
error_missing_field_subscription{
|
||||
"Missing required key subscription"};
|
||||
return boost::system::error_code{129, error_missing_field_subscription};
|
||||
}
|
||||
|
||||
auto subscription =
|
||||
boost::json::try_value_to<subscription::Subscription>(*jvsubscription);
|
||||
|
||||
if (subscription.has_error())
|
||||
{
|
||||
return subscription.error();
|
||||
}
|
||||
|
||||
const auto *jvevent = root.if_contains("event");
|
||||
if (jvevent == nullptr)
|
||||
{
|
||||
static const error::ApplicationErrorCategory error_missing_field_event{
|
||||
"Missing required key event"};
|
||||
return boost::system::error_code{129, error_missing_field_event};
|
||||
}
|
||||
|
||||
auto event = boost::json::try_value_to<Event>(*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::stream_online::v1
|
||||
@@ -0,0 +1,186 @@
|
||||
|
||||
// WARNING: This file is automatically generated. Any changes will be lost.
|
||||
#include "twitch-eventsub-ws/chrono.hpp" // IWYU pragma: keep
|
||||
#include "twitch-eventsub-ws/errors.hpp"
|
||||
#include "twitch-eventsub-ws/payloads/subscription.hpp"
|
||||
|
||||
#include <boost/json.hpp>
|
||||
|
||||
namespace chatterino::eventsub::lib::payload::subscription {
|
||||
|
||||
boost::json::result_for<Transport, boost::json::value>::type tag_invoke(
|
||||
boost::json::try_value_to_tag<Transport>, const boost::json::value &jvRoot)
|
||||
{
|
||||
if (!jvRoot.is_object())
|
||||
{
|
||||
static const error::ApplicationErrorCategory errorMustBeObject{
|
||||
"Transport must be an object"};
|
||||
return boost::system::error_code{129, errorMustBeObject};
|
||||
}
|
||||
const auto &root = jvRoot.get_object();
|
||||
|
||||
const auto *jvmethod = root.if_contains("method");
|
||||
if (jvmethod == nullptr)
|
||||
{
|
||||
static const error::ApplicationErrorCategory error_missing_field_method{
|
||||
"Missing required key method"};
|
||||
return boost::system::error_code{129, error_missing_field_method};
|
||||
}
|
||||
|
||||
auto method = boost::json::try_value_to<std::string>(*jvmethod);
|
||||
|
||||
if (method.has_error())
|
||||
{
|
||||
return method.error();
|
||||
}
|
||||
|
||||
const auto *jvsessionID = root.if_contains("session_id");
|
||||
if (jvsessionID == nullptr)
|
||||
{
|
||||
static const error::ApplicationErrorCategory
|
||||
error_missing_field_sessionID{"Missing required key session_id"};
|
||||
return boost::system::error_code{129, error_missing_field_sessionID};
|
||||
}
|
||||
|
||||
auto sessionID = boost::json::try_value_to<std::string>(*jvsessionID);
|
||||
|
||||
if (sessionID.has_error())
|
||||
{
|
||||
return sessionID.error();
|
||||
}
|
||||
|
||||
return Transport{
|
||||
.method = std::move(method.value()),
|
||||
.sessionID = std::move(sessionID.value()),
|
||||
};
|
||||
}
|
||||
|
||||
boost::json::result_for<Subscription, boost::json::value>::type tag_invoke(
|
||||
boost::json::try_value_to_tag<Subscription>,
|
||||
const boost::json::value &jvRoot)
|
||||
{
|
||||
if (!jvRoot.is_object())
|
||||
{
|
||||
static const error::ApplicationErrorCategory errorMustBeObject{
|
||||
"Subscription must be an object"};
|
||||
return boost::system::error_code{129, errorMustBeObject};
|
||||
}
|
||||
const auto &root = jvRoot.get_object();
|
||||
|
||||
const auto *jvid = root.if_contains("id");
|
||||
if (jvid == nullptr)
|
||||
{
|
||||
static const error::ApplicationErrorCategory error_missing_field_id{
|
||||
"Missing required key id"};
|
||||
return boost::system::error_code{129, error_missing_field_id};
|
||||
}
|
||||
|
||||
auto id = boost::json::try_value_to<std::string>(*jvid);
|
||||
|
||||
if (id.has_error())
|
||||
{
|
||||
return id.error();
|
||||
}
|
||||
|
||||
const auto *jvstatus = root.if_contains("status");
|
||||
if (jvstatus == nullptr)
|
||||
{
|
||||
static const error::ApplicationErrorCategory error_missing_field_status{
|
||||
"Missing required key status"};
|
||||
return boost::system::error_code{129, error_missing_field_status};
|
||||
}
|
||||
|
||||
auto status = boost::json::try_value_to<std::string>(*jvstatus);
|
||||
|
||||
if (status.has_error())
|
||||
{
|
||||
return status.error();
|
||||
}
|
||||
|
||||
const auto *jvtype = root.if_contains("type");
|
||||
if (jvtype == nullptr)
|
||||
{
|
||||
static const error::ApplicationErrorCategory error_missing_field_type{
|
||||
"Missing required key type"};
|
||||
return boost::system::error_code{129, error_missing_field_type};
|
||||
}
|
||||
|
||||
auto type = boost::json::try_value_to<std::string>(*jvtype);
|
||||
|
||||
if (type.has_error())
|
||||
{
|
||||
return type.error();
|
||||
}
|
||||
|
||||
const auto *jvversion = root.if_contains("version");
|
||||
if (jvversion == nullptr)
|
||||
{
|
||||
static const error::ApplicationErrorCategory
|
||||
error_missing_field_version{"Missing required key version"};
|
||||
return boost::system::error_code{129, error_missing_field_version};
|
||||
}
|
||||
|
||||
auto version = boost::json::try_value_to<std::string>(*jvversion);
|
||||
|
||||
if (version.has_error())
|
||||
{
|
||||
return version.error();
|
||||
}
|
||||
|
||||
const auto *jvtransport = root.if_contains("transport");
|
||||
if (jvtransport == nullptr)
|
||||
{
|
||||
static const error::ApplicationErrorCategory
|
||||
error_missing_field_transport{"Missing required key transport"};
|
||||
return boost::system::error_code{129, error_missing_field_transport};
|
||||
}
|
||||
|
||||
auto transport = boost::json::try_value_to<Transport>(*jvtransport);
|
||||
|
||||
if (transport.has_error())
|
||||
{
|
||||
return transport.error();
|
||||
}
|
||||
|
||||
const auto *jvcreatedAt = root.if_contains("created_at");
|
||||
if (jvcreatedAt == nullptr)
|
||||
{
|
||||
static const error::ApplicationErrorCategory
|
||||
error_missing_field_createdAt{"Missing required key created_at"};
|
||||
return boost::system::error_code{129, error_missing_field_createdAt};
|
||||
}
|
||||
|
||||
auto createdAt = boost::json::try_value_to<std::string>(*jvcreatedAt);
|
||||
|
||||
if (createdAt.has_error())
|
||||
{
|
||||
return createdAt.error();
|
||||
}
|
||||
|
||||
const auto *jvcost = root.if_contains("cost");
|
||||
if (jvcost == nullptr)
|
||||
{
|
||||
static const error::ApplicationErrorCategory error_missing_field_cost{
|
||||
"Missing required key cost"};
|
||||
return boost::system::error_code{129, error_missing_field_cost};
|
||||
}
|
||||
|
||||
auto cost = boost::json::try_value_to<int>(*jvcost);
|
||||
|
||||
if (cost.has_error())
|
||||
{
|
||||
return cost.error();
|
||||
}
|
||||
|
||||
return Subscription{
|
||||
.id = std::move(id.value()),
|
||||
.status = std::move(status.value()),
|
||||
.type = std::move(type.value()),
|
||||
.version = std::move(version.value()),
|
||||
.transport = std::move(transport.value()),
|
||||
.createdAt = std::move(createdAt.value()),
|
||||
.cost = std::move(cost.value()),
|
||||
};
|
||||
}
|
||||
|
||||
} // namespace chatterino::eventsub::lib::payload::subscription
|
||||
Reference in New Issue
Block a user