irccd  3.0.3
rule_service.hpp
1 /*
2  * rule_service.hpp -- rule service
3  *
4  * Copyright (c) 2013-2019 David Demelier <markand@malikania.fr>
5  *
6  * Permission to use, copy, modify, and/or distribute this software for any
7  * purpose with or without fee is hereby granted, provided that the above
8  * copyright notice and this permission notice appear in all copies.
9  *
10  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17  */
18 
19 #ifndef IRCCD_DAEMON_RULE_SERVICE_HPP
20 #define IRCCD_DAEMON_RULE_SERVICE_HPP
21 
27 #include <irccd/sysconfig.hpp>
28 
29 #include <vector>
30 
31 #include <json.hpp>
32 
33 #include "rule.hpp"
34 
35 namespace irccd {
36 
37 class config;
38 
39 namespace daemon {
40 
41 class bot;
42 
47 class rule_service {
48 private:
49  bot& bot_;
50  std::vector<rule> rules_;
51 
52 public:
59 
65  auto list() const noexcept -> const std::vector<rule>&;
66 
72  void add(rule rule);
73 
80  void insert(rule rule, std::size_t position);
81 
88  void remove(std::size_t position);
89 
97  auto require(std::size_t position) const -> const rule&;
98 
104  auto require(std::size_t position) -> rule&;
105 
116  auto solve(std::string_view server,
117  std::string_view channel,
118  std::string_view origin,
119  std::string_view plugin,
120  std::string_view event) noexcept -> bool;
121 
127  void load(const config& cfg) noexcept;
128 };
129 
130 namespace logger {
131 
132 template <typename T>
133 struct type_traits;
134 
139 template <>
140 struct type_traits<rule> {
147  static auto get_category(const rule& rule) -> std::string_view;
148 
155  static auto get_component(const rule& rule) -> std::string_view;
156 };
157 
158 } // !logger
159 
160 } // !daemon
161 
162 } // !irccd
163 
164 #endif // !IRCCD_DAEMON_RULE_SERVICE_HPP
irccd::daemon::rule_service::load
void load(const config &cfg) noexcept
irccd::daemon::logger::type_traits
Traits for loggable objects.
Definition: logger.hpp:78
irccd::daemon::rule_service
Store and solve rules.
Definition: rule_service.hpp:47
irccd::config
Read .ini configuration file for irccd.
Definition: config.hpp:39
irccd::daemon::plugin
Abstract plugin.
Definition: plugin.hpp:61
irccd::daemon::event
std::variant< std::monostate, connect_event, disconnect_event, invite_event, join_event, kick_event, me_event, message_event, mode_event, names_event, nick_event, notice_event, part_event, topic_event, whois_event > event
Store all possible events.
Definition: server.hpp:247
irccd::daemon::rule_service::insert
void insert(rule rule, std::size_t position)
irccd::daemon::logger::type_traits< rule >::get_component
static auto get_component(const rule &rule) -> std::string_view
irccd::daemon::logger::type_traits< rule >::get_category
static auto get_category(const rule &rule) -> std::string_view
irccd::daemon::rule_service::solve
auto solve(std::string_view server, std::string_view channel, std::string_view origin, std::string_view plugin, std::string_view event) noexcept -> bool
irccd::daemon::rule_service::require
auto require(std::size_t position) const -> const rule &
irccd::daemon::rule_service::rule_service
rule_service(bot &bot)
irccd::daemon::channel
A channel to join with an optional password.
Definition: server.hpp:63
irccd::daemon::bot
Irccd main instance.
Definition: bot.hpp:58
irccd::daemon::rule_service::list
auto list() const noexcept -> const std::vector< rule > &
irccd::daemon::server
The class that connect to a IRC server.
Definition: server.hpp:256
irccd
Parent namespace.
Definition: acceptor.hpp:43
std
Definition: bot.hpp:253
irccd::daemon::rule_service::remove
void remove(std::size_t position)
irccd::daemon::rule
Manage rule to activate or deactive events.
Definition: rule.hpp:39
irccd::daemon::rule_service::add
void add(rule rule)