irccd  3.0.3
api.hpp
1 /*
2  * api.hpp -- Javascript API module
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_JS_API_HPP
20 #define IRCCD_JS_API_HPP
21 
27 #include <functional>
28 #include <memory>
29 #include <string_view>
30 #include <vector>
31 
32 #include "duk.hpp"
33 
34 namespace irccd {
35 
36 namespace daemon {
37 
38 class bot;
39 
40 } // !daemon
41 
42 namespace js {
43 
44 class plugin;
45 
51 class api {
52 public:
56  using constructor = std::function<std::unique_ptr<api> ()>;
57 
61  static auto registry() noexcept -> const std::vector<constructor>&;
62 
66  api() noexcept = default;
67 
71  virtual ~api() noexcept = default;
72 
78  virtual auto get_name() const noexcept -> std::string_view = 0;
79 
86  virtual void load(daemon::bot& bot, js::plugin& plugin) = 0;
87 };
88 
89 } // !js
90 
91 } // !irccd
92 
93 #endif // !IRCCD_JS_API_HPP
irccd::js::plugin
Javascript plugins for irccd.
Definition: plugin.hpp:44
irccd::js::api::get_name
virtual auto get_name() const noexcept -> std::string_view=0
irccd::js::api::load
virtual void load(daemon::bot &bot, js::plugin &plugin)=0
irccd::js::api
Javascript API module.
Definition: api.hpp:51
irccd
Parent namespace.
Definition: acceptor.hpp:43
std
Definition: bot.hpp:253
irccd::js::api::constructor
std::function< std::unique_ptr< api >()> constructor
Command constructor factory.
Definition: api.hpp:56
irccd::js::api::registry
static auto registry() noexcept -> const std::vector< constructor > &
Registry of all commands.