feat(eventsub): implement channel.chat.user_message_(hold/update) (#6008)

This commit is contained in:
pajlada
2025-03-01 17:00:40 +01:00
committed by GitHub
parent f4541b0208
commit c03b883f05
22 changed files with 1123 additions and 1 deletions
@@ -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/detail/errors.hpp"
#include "twitch-eventsub-ws/detail/variant.hpp" // IWYU pragma: keep
#include "twitch-eventsub-ws/payloads/channel-chat-user-message-hold-v1.hpp"
#include <boost/json.hpp>
namespace chatterino::eventsub::lib::payload::channel_chat_user_message_hold::
v1 {
boost::json::result_for<Event, boost::json::value>::type tag_invoke(
boost::json::try_value_to_tag<Event> /* tag */,
const boost::json::value &jvRoot)
{
if (!jvRoot.is_object())
{
EVENTSUB_BAIL_HERE(error::Kind::ExpectedObject);
}
const auto &root = jvRoot.get_object();
const auto *jvbroadcasterUserID = root.if_contains("broadcaster_user_id");
if (jvbroadcasterUserID == nullptr)
{
EVENTSUB_BAIL_HERE(error::Kind::FieldMissing);
}
auto broadcasterUserID =
boost::json::try_value_to<String>(*jvbroadcasterUserID);
if (broadcasterUserID.has_error())
{
return broadcasterUserID.error();
}
const auto *jvbroadcasterUserLogin =
root.if_contains("broadcaster_user_login");
if (jvbroadcasterUserLogin == nullptr)
{
EVENTSUB_BAIL_HERE(error::Kind::FieldMissing);
}
auto broadcasterUserLogin =
boost::json::try_value_to<String>(*jvbroadcasterUserLogin);
if (broadcasterUserLogin.has_error())
{
return broadcasterUserLogin.error();
}
const auto *jvbroadcasterUserName =
root.if_contains("broadcaster_user_name");
if (jvbroadcasterUserName == nullptr)
{
EVENTSUB_BAIL_HERE(error::Kind::FieldMissing);
}
auto broadcasterUserName =
boost::json::try_value_to<String>(*jvbroadcasterUserName);
if (broadcasterUserName.has_error())
{
return broadcasterUserName.error();
}
const auto *jvuserID = root.if_contains("user_id");
if (jvuserID == nullptr)
{
EVENTSUB_BAIL_HERE(error::Kind::FieldMissing);
}
auto userID = boost::json::try_value_to<String>(*jvuserID);
if (userID.has_error())
{
return userID.error();
}
const auto *jvuserLogin = root.if_contains("user_login");
if (jvuserLogin == nullptr)
{
EVENTSUB_BAIL_HERE(error::Kind::FieldMissing);
}
auto userLogin = boost::json::try_value_to<String>(*jvuserLogin);
if (userLogin.has_error())
{
return userLogin.error();
}
const auto *jvuserName = root.if_contains("user_name");
if (jvuserName == nullptr)
{
EVENTSUB_BAIL_HERE(error::Kind::FieldMissing);
}
auto userName = boost::json::try_value_to<String>(*jvuserName);
if (userName.has_error())
{
return userName.error();
}
const auto *jvmessageID = root.if_contains("message_id");
if (jvmessageID == nullptr)
{
EVENTSUB_BAIL_HERE(error::Kind::FieldMissing);
}
auto messageID = boost::json::try_value_to<String>(*jvmessageID);
if (messageID.has_error())
{
return messageID.error();
}
const auto *jvmessage = root.if_contains("message");
if (jvmessage == nullptr)
{
EVENTSUB_BAIL_HERE(error::Kind::FieldMissing);
}
auto message = boost::json::try_value_to<chat::Message>(*jvmessage);
if (message.has_error())
{
return message.error();
}
return Event{
.broadcasterUserID = std::move(broadcasterUserID.value()),
.broadcasterUserLogin = std::move(broadcasterUserLogin.value()),
.broadcasterUserName = std::move(broadcasterUserName.value()),
.userID = std::move(userID.value()),
.userLogin = std::move(userLogin.value()),
.userName = std::move(userName.value()),
.messageID = std::move(messageID.value()),
.message = std::move(message.value()),
};
}
boost::json::result_for<Payload, boost::json::value>::type tag_invoke(
boost::json::try_value_to_tag<Payload> /* tag */,
const boost::json::value &jvRoot)
{
if (!jvRoot.is_object())
{
EVENTSUB_BAIL_HERE(error::Kind::ExpectedObject);
}
const auto &root = jvRoot.get_object();
const auto *jvsubscription = root.if_contains("subscription");
if (jvsubscription == nullptr)
{
EVENTSUB_BAIL_HERE(error::Kind::FieldMissing);
}
auto subscription =
boost::json::try_value_to<subscription::Subscription>(*jvsubscription);
if (subscription.has_error())
{
return subscription.error();
}
const auto *jvevent = root.if_contains("event");
if (jvevent == nullptr)
{
EVENTSUB_BAIL_HERE(error::Kind::FieldMissing);
}
auto event = boost::json::try_value_to<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_user_message_hold::v1
@@ -0,0 +1,229 @@
// 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-user-message-update-v1.hpp"
#include <boost/json.hpp>
namespace chatterino::eventsub::lib::payload::channel_chat_user_message_update::
v1 {
boost::json::result_for<Status, boost::json::value>::type tag_invoke(
boost::json::try_value_to_tag<Status> /* tag */,
const boost::json::value &jvRoot)
{
if (!jvRoot.is_string())
{
EVENTSUB_BAIL_HERE(error::Kind::ExpectedString);
}
std::string_view eString(jvRoot.get_string());
using namespace std::string_view_literals;
if (eString == "approved"sv)
{
return Status::Approved;
}
if (eString == "denied"sv)
{
return Status::Denied;
}
if (eString == "invalid"sv)
{
return Status::Invalid;
}
EVENTSUB_BAIL_HERE(error::Kind::UnknownEnumValue);
}
boost::json::result_for<Event, boost::json::value>::type tag_invoke(
boost::json::try_value_to_tag<Event> /* tag */,
const boost::json::value &jvRoot)
{
if (!jvRoot.is_object())
{
EVENTSUB_BAIL_HERE(error::Kind::ExpectedObject);
}
const auto &root = jvRoot.get_object();
const auto *jvbroadcasterUserID = root.if_contains("broadcaster_user_id");
if (jvbroadcasterUserID == nullptr)
{
EVENTSUB_BAIL_HERE(error::Kind::FieldMissing);
}
auto broadcasterUserID =
boost::json::try_value_to<String>(*jvbroadcasterUserID);
if (broadcasterUserID.has_error())
{
return broadcasterUserID.error();
}
const auto *jvbroadcasterUserLogin =
root.if_contains("broadcaster_user_login");
if (jvbroadcasterUserLogin == nullptr)
{
EVENTSUB_BAIL_HERE(error::Kind::FieldMissing);
}
auto broadcasterUserLogin =
boost::json::try_value_to<String>(*jvbroadcasterUserLogin);
if (broadcasterUserLogin.has_error())
{
return broadcasterUserLogin.error();
}
const auto *jvbroadcasterUserName =
root.if_contains("broadcaster_user_name");
if (jvbroadcasterUserName == nullptr)
{
EVENTSUB_BAIL_HERE(error::Kind::FieldMissing);
}
auto broadcasterUserName =
boost::json::try_value_to<String>(*jvbroadcasterUserName);
if (broadcasterUserName.has_error())
{
return broadcasterUserName.error();
}
const auto *jvuserID = root.if_contains("user_id");
if (jvuserID == nullptr)
{
EVENTSUB_BAIL_HERE(error::Kind::FieldMissing);
}
auto userID = boost::json::try_value_to<String>(*jvuserID);
if (userID.has_error())
{
return userID.error();
}
const auto *jvuserLogin = root.if_contains("user_login");
if (jvuserLogin == nullptr)
{
EVENTSUB_BAIL_HERE(error::Kind::FieldMissing);
}
auto userLogin = boost::json::try_value_to<String>(*jvuserLogin);
if (userLogin.has_error())
{
return userLogin.error();
}
const auto *jvuserName = root.if_contains("user_name");
if (jvuserName == nullptr)
{
EVENTSUB_BAIL_HERE(error::Kind::FieldMissing);
}
auto userName = boost::json::try_value_to<String>(*jvuserName);
if (userName.has_error())
{
return userName.error();
}
static_assert(
std::is_trivially_copyable_v<
std::remove_reference_t<decltype(std::declval<Event>().status)>>);
const auto *jvstatus = root.if_contains("status");
if (jvstatus == nullptr)
{
EVENTSUB_BAIL_HERE(error::Kind::FieldMissing);
}
auto status = boost::json::try_value_to<Status>(*jvstatus);
if (status.has_error())
{
return status.error();
}
const auto *jvmessageID = root.if_contains("message_id");
if (jvmessageID == nullptr)
{
EVENTSUB_BAIL_HERE(error::Kind::FieldMissing);
}
auto messageID = boost::json::try_value_to<String>(*jvmessageID);
if (messageID.has_error())
{
return messageID.error();
}
const auto *jvmessage = root.if_contains("message");
if (jvmessage == nullptr)
{
EVENTSUB_BAIL_HERE(error::Kind::FieldMissing);
}
auto message = boost::json::try_value_to<chat::Message>(*jvmessage);
if (message.has_error())
{
return message.error();
}
return Event{
.broadcasterUserID = std::move(broadcasterUserID.value()),
.broadcasterUserLogin = std::move(broadcasterUserLogin.value()),
.broadcasterUserName = std::move(broadcasterUserName.value()),
.userID = std::move(userID.value()),
.userLogin = std::move(userLogin.value()),
.userName = std::move(userName.value()),
.status = status.value(),
.messageID = std::move(messageID.value()),
.message = std::move(message.value()),
};
}
boost::json::result_for<Payload, boost::json::value>::type tag_invoke(
boost::json::try_value_to_tag<Payload> /* tag */,
const boost::json::value &jvRoot)
{
if (!jvRoot.is_object())
{
EVENTSUB_BAIL_HERE(error::Kind::ExpectedObject);
}
const auto &root = jvRoot.get_object();
const auto *jvsubscription = root.if_contains("subscription");
if (jvsubscription == nullptr)
{
EVENTSUB_BAIL_HERE(error::Kind::FieldMissing);
}
auto subscription =
boost::json::try_value_to<subscription::Subscription>(*jvsubscription);
if (subscription.has_error())
{
return subscription.error();
}
const auto *jvevent = root.if_contains("event");
if (jvevent == nullptr)
{
EVENTSUB_BAIL_HERE(error::Kind::FieldMissing);
}
auto event = boost::json::try_value_to<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_user_message_update::v1