xbot/snote.hpp

72 lines
1.5 KiB
C++
Raw Normal View History

2023-11-25 20:09:20 -08:00
#pragma once
2025-01-23 21:23:32 -08:00
#include "ircmsg.hpp"
2023-11-25 20:09:20 -08:00
2023-11-26 21:16:56 -08:00
#include <memory>
2023-11-28 11:34:27 -08:00
#include <regex>
2023-11-27 19:09:45 -08:00
#include <string_view>
2023-11-28 11:34:27 -08:00
#include <variant>
2025-01-23 21:23:32 -08:00
#include <tuple>
#include <optional>
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-29 13:54:34 -08:00
TooManyGlobalConnections,
2023-11-29 14:52:57 -08:00
SetVhostOnMarkedAccount,
2023-11-26 21:16:56 -08:00
};
2025-01-22 23:49:48 -08:00
class SnoteMatch
2023-11-25 20:09:20 -08:00
{
2023-11-28 11:34:27 -08:00
public:
2025-01-22 23:49:48 -08:00
SnoteMatch(std::regex const& regex, std::string_view full)
: components_{std::make_pair(std::ref(regex), full)}
2023-11-26 21:16:56 -08:00
{}
2023-11-28 11:34:27 -08:00
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_;
2023-11-25 20:09:20 -08:00
};
2025-01-23 21:23:32 -08:00
struct SnoteCore
2023-11-26 21:16:56 -08:00
{
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
};
2024-03-03 12:27:36 -08:00
/// @brief Database of server notice patterns
2023-11-27 19:09:45 -08:00
std::unique_ptr<hs_database, DbDeleter> db_;
2024-03-03 12:27:36 -08:00
/// @brief HyperScan scratch space
2023-11-27 19:09:45 -08:00
std::unique_ptr<hs_scratch, ScratchDeleter> scratch_;
2023-11-26 21:16:56 -08:00
2025-01-23 21:23:32 -08:00
SnoteCore() noexcept;
auto match(const IrcMsg &msg) -> std::optional<std::pair<SnoteTag, SnoteMatch>>;
2023-11-26 21:16:56 -08:00
};
2025-01-23 21:23:32 -08:00
extern SnoteCore snoteCore;