xbot/snote_thread.hpp
2023-11-29 13:54:34 -08:00

65 lines
1.4 KiB
C++

#pragma once
#include "event.hpp"
#include <memory>
#include <regex>
#include <string_view>
#include <variant>
class Connection;
struct hs_database;
struct hs_scratch;
enum class SnoteTag
{
ClientConnecting,
ClientExiting,
RejectingKlined,
NickChange,
CreateChannel,
TemporaryKlineExpired,
PropagatedBanExpired,
DisconnectingKlined,
NewPropagatedKline,
NewTemporaryKline,
LoginAttempts,
PossibleFlooder,
Killed,
TooManyGlobalConnections,
};
class SnoteEvent : public Event
{
public:
SnoteEvent(SnoteTag tag, std::regex const& regex, std::string_view full)
: tag_{tag}
, components_{std::make_pair(std::ref(regex), full)}
{}
auto get_tag() const -> SnoteTag;
auto get_results() -> std::match_results<std::string_view::const_iterator> const&;
private:
SnoteTag tag_;
std::variant<std::pair<std::regex const&, std::string_view>, std::match_results<std::string_view::const_iterator>> components_;
};
struct SnoteThread
{
struct DbDeleter
{
auto operator()(hs_database * db) const -> void;
};
struct ScratchDeleter
{
auto operator()(hs_scratch * scratch) const -> void;
};
std::unique_ptr<hs_database, DbDeleter> db_;
std::unique_ptr<hs_scratch, ScratchDeleter> scratch_;
static auto start(Connection& connection) -> std::shared_ptr<SnoteThread>;
};