xbot/snote_thread.hpp
2023-11-27 18:47:32 -08:00

68 lines
1.2 KiB
C++

#pragma once
#include "event.hpp"
#include <hs.h>
#include <memory>
class Connection;
enum class SnoteTag
{
ClientConnecting,
ClientExiting,
RejectingKlined,
NickChange,
CreateChannel,
TemporaryKlineExpired,
PropagatedBanExpired,
DisconnectingKlined,
NewPropagatedKline,
NewTemporaryKline,
LoginAttempts,
PossibleFlooder,
Killed,
};
struct SnoteEvent : Event
{
SnoteEvent(SnoteTag tag, std::vector<std::string_view> parts)
: tag{tag}
, parts{std::move(parts)}
{}
SnoteTag tag;
std::vector<std::string_view> parts;
};
struct SnoteThread
{
struct DbDeleter
{
auto operator()(hs_database_t * db) const -> void
{
if (HS_SUCCESS != hs_free_database(db))
{
abort();
}
}
};
struct ScratchDeleter
{
auto operator()(hs_scratch_t * scratch) const -> void
{
if (HS_SUCCESS != hs_free_scratch(scratch))
{
abort();
}
}
};
std::unique_ptr<hs_database_t, DbDeleter> db_;
std::unique_ptr<hs_scratch_t, ScratchDeleter> scratch_;
static auto start(Connection& connection) -> std::shared_ptr<SnoteThread>;
};