diff --git a/driver/main.cpp b/driver/main.cpp index 388f5e7..8817678 100644 --- a/driver/main.cpp +++ b/driver/main.cpp @@ -63,7 +63,7 @@ auto configure_sasl(const Settings &settings) -> std::unique_ptr static auto start( boost::asio::io_context &io, const Settings &settings, - std::shared_ptr webhook + std::shared_ptr webhook ) -> void { Ref tls_cert; diff --git a/driver/web.cpp b/driver/web.cpp index 9d10ad8..8fcd1e9 100644 --- a/driver/web.cpp +++ b/driver/web.cpp @@ -64,7 +64,7 @@ static auto compute_signature(const std::string_view secret, const std::string_v } static auto process_event( - std::shared_ptr self, + std::shared_ptr self, const std::string_view notify_user, const std::string_view event, const boost::json::value &json @@ -102,12 +102,12 @@ static auto process_event( } const auto message = std::string{event} + " on " + full_name; - self->add_event({settings.channel, message}); + self->send_notice({settings.channel, message}); } template static auto handle_request( - std::shared_ptr self, + std::shared_ptr self, http::request> &&req ) -> http::message_generator { @@ -162,7 +162,7 @@ static auto handle_request( return simple_response(http::status::ok, req.version(), req.keep_alive()); } -auto read_loop(tcp::socket socket, std::shared_ptr self) -> boost::asio::awaitable +auto read_loop(tcp::socket socket, std::shared_ptr self) -> boost::asio::awaitable { beast::tcp_stream stream{std::move(socket)}; beast::flat_buffer buffer; @@ -200,7 +200,7 @@ auto read_loop(tcp::socket socket, std::shared_ptr self) -> boost auto accept_loop( tcp::acceptor acceptor, - std::shared_ptr self + std::shared_ptr self ) -> boost::asio::awaitable { for (;;) @@ -216,7 +216,7 @@ auto accept_loop( auto spawn_webhook( boost::asio::io_context &io, - const std::shared_ptr webhook + const std::shared_ptr webhook ) -> boost::asio::awaitable { tcp::resolver resolver{io}; @@ -240,7 +240,7 @@ auto spawn_webhook( auto start_webhook( boost::asio::io_context &io, const char *webhook_settings_filename -) -> std::shared_ptr +) -> std::shared_ptr { std::ifstream webhook_settings_file{webhook_settings_filename}; if (!webhook_settings_file) @@ -252,12 +252,12 @@ auto start_webhook( auto webhook_settings = toml::parse(webhook_settings_file); WebhookSettings settings = WebhookSettings::from_toml(webhook_settings); BOOST_LOG_TRIVIAL(info) << "Webhook settings: " << settings.to_toml(); - auto webhook = std::make_shared(std::move(settings), webhook_settings_filename); + auto webhook = std::make_shared(std::move(settings), webhook_settings_filename); boost::asio::co_spawn(io, spawn_webhook(io, webhook), report_error); return webhook; } -auto GithubWebhook::save_settings() const -> void +auto Webhooks::save_settings() const -> void { std::ofstream webhook_settings_file{settings_file}; if (!webhook_settings_file) @@ -383,7 +383,7 @@ auto WebhookSettings::to_toml() const -> toml::table } // Either emit the event now or save it until a connection is set -auto GithubWebhook::add_event(Notice notice) -> void +auto Webhooks::send_notice(Notice notice) -> void { if (connection_) { @@ -395,7 +395,7 @@ auto GithubWebhook::add_event(Notice notice) -> void } } -auto GithubWebhook::set_connection(std::shared_ptr connection) -> void +auto Webhooks::set_connection(std::shared_ptr connection) -> void { connection_ = std::move(connection); for (auto &&event : events_) @@ -405,20 +405,20 @@ auto GithubWebhook::set_connection(std::shared_ptr connection events_.clear(); } -auto GithubWebhook::clear_connection() -> void +auto Webhooks::clear_connection() -> void { connection_.reset(); } -static auto reply_to(std::shared_ptr webhooks, const myirc::Bot::Command &cmd, std::string message) -> void +static auto reply_to(std::shared_ptr webhooks, const myirc::Bot::Command &cmd, std::string message) -> void { if (cmd.target.starts_with("#")) { - webhooks->add_event({std::string{cmd.target}, std::move(message)}); + webhooks->send_notice({std::string{cmd.target}, std::move(message)}); } else { - webhooks->add_event({std::string{cmd.nick()}, std::move(message)}); + webhooks->send_notice({std::string{cmd.nick()}, std::move(message)}); } } @@ -427,8 +427,8 @@ static auto authorized_for_project(const ProjectSettings &project, const std::st return project.authorized_accounts.find(std::string{nick}) != project.authorized_accounts.end(); } -std::map, const myirc::Bot::Command &)> webhook_commands{ - {"add-credential", [](std::shared_ptr webhooks, const myirc::Bot::Command &cmd) { +std::map, const myirc::Bot::Command &)> webhook_commands{ + {"add-credential", [](std::shared_ptr webhooks, const myirc::Bot::Command &cmd) { //if (cmd.oper.empty()) //{ // return; @@ -442,7 +442,7 @@ std::map, const myirc::Bot: reply_to(webhooks, cmd, "Added credential " + name); } }}, - {"drop-credential", [](std::shared_ptr webhooks, const myirc::Bot::Command &cmd) { + {"drop-credential", [](std::shared_ptr webhooks, const myirc::Bot::Command &cmd) { //if (cmd.oper.empty()) //{ // return; @@ -456,7 +456,7 @@ std::map, const myirc::Bot: reply_to(webhooks, cmd, "Dropped credential " + name); } }}, - {"enable-project", [](std::shared_ptr webhooks, const myirc::Bot::Command &cmd) { + {"enable-project", [](std::shared_ptr webhooks, const myirc::Bot::Command &cmd) { std::istringstream iss{std::string{cmd.arguments}}; std::string name; if (iss >> name) @@ -481,7 +481,7 @@ std::map, const myirc::Bot: reply_to(webhooks, cmd, "Enabled project " + name); } }}, - {"disable-project", [](std::shared_ptr webhooks, const myirc::Bot::Command &cmd) { + {"disable-project", [](std::shared_ptr webhooks, const myirc::Bot::Command &cmd) { //if (cmd.oper.empty()) //{ // return; @@ -493,7 +493,7 @@ std::map, const myirc::Bot: auto cursor = webhooks->settings_.projects.find(name); if (cursor == webhooks->settings_.projects.end()) { - webhooks->add_event({std::string{cmd.nick()}, "Unknown project " + name}); + webhooks->send_notice({std::string{cmd.nick()}, "Unknown project " + name}); return; } diff --git a/driver/web.hpp b/driver/web.hpp index 28186c0..2d29c02 100644 --- a/driver/web.hpp +++ b/driver/web.hpp @@ -47,7 +47,7 @@ struct WebhookSettings { static auto from_toml(const toml::table &v) -> WebhookSettings; }; -class GithubWebhook { +class Webhooks { public: struct Notice { std::string target; @@ -66,19 +66,19 @@ private: public: WebhookSettings settings_; - GithubWebhook(WebhookSettings settings, const char * settings_file) + Webhooks(WebhookSettings settings, const char * settings_file) : settings_(std::move(settings)) , settings_file(settings_file) { } // Either emit the event now or save it until a connection is set - auto add_event(Notice event) -> void; + auto send_notice(Notice event) -> void; auto set_connection(std::shared_ptr connection) -> void; auto clear_connection() -> void; auto save_settings() const -> void; }; -auto start_webhook(boost::asio::io_context &io, const char *) -> std::shared_ptr; +auto start_webhook(boost::asio::io_context &io, const char *) -> std::shared_ptr; -extern std::map, const myirc::Bot::Command &)> webhook_commands; +extern std::map, const myirc::Bot::Command &)> webhook_commands;