feat(eventsub): implement (shared-chat) timeout (#5995)

This commit is contained in:
nerix
2025-02-26 22:00:53 +01:00
committed by GitHub
parent e59defb864
commit a89c1910ba
9 changed files with 522 additions and 31 deletions
@@ -477,7 +477,7 @@ boost::json::result_for<Timeout, boost::json::value>::type tag_invoke(
EVENTSUB_BAIL_HERE(error::Kind::FieldMissing);
}
auto userID = boost::json::try_value_to<std::string>(*jvuserID);
auto userID = boost::json::try_value_to<String>(*jvuserID);
if (userID.has_error())
{
@@ -490,7 +490,7 @@ boost::json::result_for<Timeout, boost::json::value>::type tag_invoke(
EVENTSUB_BAIL_HERE(error::Kind::FieldMissing);
}
auto userLogin = boost::json::try_value_to<std::string>(*jvuserLogin);
auto userLogin = boost::json::try_value_to<String>(*jvuserLogin);
if (userLogin.has_error())
{
@@ -503,7 +503,7 @@ boost::json::result_for<Timeout, boost::json::value>::type tag_invoke(
EVENTSUB_BAIL_HERE(error::Kind::FieldMissing);
}
auto userName = boost::json::try_value_to<std::string>(*jvuserName);
auto userName = boost::json::try_value_to<String>(*jvuserName);
if (userName.has_error())
{
@@ -516,20 +516,24 @@ boost::json::result_for<Timeout, boost::json::value>::type tag_invoke(
EVENTSUB_BAIL_HERE(error::Kind::FieldMissing);
}
auto reason = boost::json::try_value_to<std::string>(*jvreason);
auto reason = boost::json::try_value_to<String>(*jvreason);
if (reason.has_error())
{
return reason.error();
}
static_assert(std::is_trivially_copyable_v<std::remove_reference_t<
decltype(std::declval<Timeout>().expiresAt)>>);
const auto *jvexpiresAt = root.if_contains("expires_at");
if (jvexpiresAt == nullptr)
{
EVENTSUB_BAIL_HERE(error::Kind::FieldMissing);
}
auto expiresAt = boost::json::try_value_to<std::string>(*jvexpiresAt);
auto expiresAt =
boost::json::try_value_to<std::chrono::system_clock::time_point>(
*jvexpiresAt, AsISO8601());
if (expiresAt.has_error())
{
@@ -541,7 +545,7 @@ boost::json::result_for<Timeout, boost::json::value>::type tag_invoke(
.userLogin = std::move(userLogin.value()),
.userName = std::move(userName.value()),
.reason = std::move(reason.value()),
.expiresAt = std::move(expiresAt.value()),
.expiresAt = expiresAt.value(),
};
}
@@ -549,7 +553,7 @@ boost::json::result_for<SharedChatTimeout, boost::json::value>::type tag_invoke(
boost::json::try_value_to_tag<SharedChatTimeout> /* tag */,
const boost::json::value &jvRoot)
{
auto base = boost::json::try_value_to<Ban>(jvRoot);
auto base = boost::json::try_value_to<Timeout>(jvRoot);
if (base.has_error())
{
return base.error();
@@ -618,7 +622,7 @@ boost::json::result_for<SharedChatUntimeout, boost::json::value>::type
tag_invoke(boost::json::try_value_to_tag<SharedChatUntimeout> /* tag */,
const boost::json::value &jvRoot)
{
auto base = boost::json::try_value_to<Ban>(jvRoot);
auto base = boost::json::try_value_to<Untimeout>(jvRoot);
if (base.has_error())
{
return base.error();