xbot/snote_thread.hpp

58 lines
1.0 KiB
C++
Raw Normal View History

2023-11-25 20:09:20 -08:00
#pragma once
2023-11-27 14:12:20 -08:00
#include "event.hpp"
2023-11-25 20:09:20 -08:00
2023-11-26 21:16:56 -08:00
#include <memory>
2023-11-27 19:09:45 -08:00
#include <string_view>
#include <vector>
2023-11-26 21:16:56 -08:00
2023-11-25 20:09:20 -08:00
class Connection;
2023-11-27 19:09:45 -08:00
struct hs_database;
struct hs_scratch;
2023-11-25 20:09:20 -08:00
2023-11-26 21:16:56 -08:00
enum class SnoteTag
{
ClientConnecting,
ClientExiting,
2023-11-27 14:12:20 -08:00
RejectingKlined,
NickChange,
CreateChannel,
TemporaryKlineExpired,
2023-11-27 18:47:32 -08:00
PropagatedBanExpired,
2023-11-27 14:12:20 -08:00
DisconnectingKlined,
2023-11-27 18:47:32 -08:00
NewPropagatedKline,
NewTemporaryKline,
LoginAttempts,
PossibleFlooder,
Killed,
2023-11-26 21:16:56 -08:00
};
2023-11-25 20:09:20 -08:00
struct SnoteEvent : Event
{
2023-11-26 21:16:56 -08:00
SnoteEvent(SnoteTag tag, std::vector<std::string_view> parts)
: tag{tag}
, parts{std::move(parts)}
{}
SnoteTag tag;
std::vector<std::string_view> parts;
2023-11-25 20:09:20 -08:00
};
2023-11-26 21:16:56 -08:00
struct SnoteThread
{
struct DbDeleter
{
2023-11-27 19:09:45 -08:00
auto operator()(hs_database * db) const -> void;
2023-11-26 21:16:56 -08:00
};
struct ScratchDeleter
{
2023-11-27 19:09:45 -08:00
auto operator()(hs_scratch * scratch) const -> void;
2023-11-26 21:16:56 -08:00
};
2023-11-27 19:09:45 -08:00
std::unique_ptr<hs_database, DbDeleter> db_;
std::unique_ptr<hs_scratch, ScratchDeleter> scratch_;
2023-11-26 21:16:56 -08:00
static auto start(Connection& connection) -> std::shared_ptr<SnoteThread>;
};