xbot/snote.hpp

78 lines
1.6 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>
2025-01-24 14:48:15 -08:00
#include <optional>
2023-11-28 11:34:27 -08:00
#include <regex>
2023-11-27 19:09:45 -08:00
#include <string_view>
2025-01-24 14:48:15 -08:00
#include <utility>
2023-11-28 11:34:27 -08:00
#include <variant>
2023-11-26 21:16:56 -08:00
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,
2025-01-28 20:01:51 -08:00
IsNowOper,
NickCollision,
2025-01-28 21:43:44 -08:00
OperspyWhois,
Freeze,
2025-01-28 22:54:55 -08:00
Spambot,
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
{
2025-01-24 14:48:15 -08:00
SnoteTag tag_;
2025-01-25 21:24:33 -08:00
std::variant<std::pair<const std::regex &, std::string_view>, std::match_results<std::string_view::const_iterator>> components_;
2025-01-24 14:48:15 -08:00
2023-11-28 11:34:27 -08:00
public:
2025-01-25 21:24:33 -08:00
SnoteMatch(SnoteTag tag, const std::regex &regex, std::string_view full)
: tag_{tag}
, components_{std::make_pair(std::ref(regex), full)}
{
}
2023-11-26 21:16:56 -08:00
2025-01-24 14:48:15 -08:00
auto get_tag() -> SnoteTag { return tag_; }
2025-01-25 21:24:33 -08:00
auto get_results() -> const std::match_results<std::string_view::const_iterator> &;
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
{
2025-01-25 21:24:33 -08:00
auto operator()(hs_database *db) const -> void;
2023-11-26 21:16:56 -08:00
};
struct ScratchDeleter
{
2025-01-25 21:24:33 -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-24 14:48:15 -08:00
SnoteCore();
auto match(const IrcMsg &msg) -> std::optional<SnoteMatch>;
2023-11-26 21:16:56 -08:00
};
2025-01-23 21:23:32 -08:00
extern SnoteCore snoteCore;