feat(eventsub): implement (shared-chat) timeout (#5995)
This commit is contained in:
@@ -5,6 +5,7 @@
|
||||
|
||||
#include <boost/json.hpp>
|
||||
|
||||
#include <chrono>
|
||||
#include <string>
|
||||
|
||||
namespace chatterino::eventsub::lib::payload::channel_moderate::v2 {
|
||||
@@ -197,15 +198,14 @@ struct SharedChatUnban : public Unban {
|
||||
struct Timeout {
|
||||
static constexpr std::string_view TAG = "timeout";
|
||||
|
||||
std::string userID;
|
||||
std::string userLogin;
|
||||
std::string userName;
|
||||
// TODO: Verify that we handle null here
|
||||
std::string reason;
|
||||
// TODO: This should be a timestamp?
|
||||
std::string expiresAt;
|
||||
String userID;
|
||||
String userLogin;
|
||||
String userName;
|
||||
String reason;
|
||||
/// json_tag=AsISO8601
|
||||
std::chrono::system_clock::time_point expiresAt;
|
||||
};
|
||||
struct SharedChatTimeout : public Ban {
|
||||
struct SharedChatTimeout : public Timeout {
|
||||
static constexpr std::string_view TAG = "shared_chat_timeout";
|
||||
};
|
||||
|
||||
@@ -220,7 +220,7 @@ struct Untimeout {
|
||||
std::string userLogin;
|
||||
std::string userName;
|
||||
};
|
||||
struct SharedChatUntimeout : public Ban {
|
||||
struct SharedChatUntimeout : public Untimeout {
|
||||
static constexpr std::string_view TAG = "shared_chat_untimeout";
|
||||
};
|
||||
|
||||
|
||||
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user