nit: fix some eventsub mini things (#5895)

This commit is contained in:
pajlada
2025-02-02 17:51:46 +01:00
committed by GitHub
parent 0f8a29fdb9
commit da0a247f16
10 changed files with 7 additions and 113 deletions
@@ -1,35 +0,0 @@
#pragma once
#include <boost/json/object.hpp>
#include <iostream>
#include <optional>
#include <string_view>
namespace chatterino::eventsub::lib {
template <typename T>
std::optional<T> readMember(const boost::json::object &obj,
std::string_view key)
{
const auto *it = obj.find(key);
if (it == obj.end())
{
// No member with the key found
std::cerr << "No member with the key " << key << " found\n";
return std::nullopt;
}
const auto result = boost::json::try_value_to<T>(it->value());
if (!result.has_value())
{
std::cerr << key << " could not be deserialized to the desired type\n";
// Member could not be serialized to this type
return std::nullopt;
}
return result.value();
}
} // namespace chatterino::eventsub::lib