#pragma once #include #include #include #include #include #include #include #include struct ProjectSettings { // *** Administrative settings *** // IRC channel to announce to std::string channel; // name extracted from notify/$user std::string credential_name; // Authorized accounts can edit the event list std::set authorized_accounts; // *** User settings *** // Events to announce std::set events; // Whether to announce events bool enabled; auto to_toml() const -> toml::table; static auto from_toml(const toml::table &v) -> ProjectSettings; }; struct WebhookSettings { std::string host; std::string service; std::map credentials; std::map projects; auto to_toml() const -> toml::table; static auto from_toml(const toml::table &v) -> WebhookSettings; }; class Webhooks { // IRC connection to announce on; could be empty std::shared_ptr connection_; // Buffered events in case connection was inactive when event was received std::vector> events_; const char * settings_file; public: WebhookSettings settings_; 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 send_notice(std::string_view, std::string) -> 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; extern std::map, const myirc::Bot::Command &)> webhook_commands;