2025-02-01 11:04:33 -08:00
|
|
|
#pragma once
|
2025-02-01 20:57:57 -08:00
|
|
|
|
2025-02-02 14:56:34 -08:00
|
|
|
#include <myirc/bot.hpp>
|
2025-02-01 20:57:57 -08:00
|
|
|
#include <myirc/connection.hpp>
|
|
|
|
|
|
|
|
#include <toml++/toml.hpp>
|
|
|
|
|
|
|
|
#include <boost/asio.hpp>
|
|
|
|
#include <boost/signals2.hpp>
|
|
|
|
|
|
|
|
#include <memory>
|
|
|
|
#include <map>
|
|
|
|
#include <set>
|
|
|
|
|
|
|
|
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<std::string> authorized_accounts;
|
|
|
|
|
|
|
|
// *** User settings ***
|
|
|
|
|
|
|
|
// Events to announce
|
|
|
|
std::set<std::string> 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<std::string, std::string> credentials;
|
|
|
|
std::map<std::string, ProjectSettings> projects;
|
|
|
|
|
|
|
|
auto to_toml() const -> toml::table;
|
|
|
|
static auto from_toml(const toml::table &v) -> WebhookSettings;
|
|
|
|
};
|
|
|
|
|
2025-02-02 15:02:08 -08:00
|
|
|
class Webhooks {
|
2025-02-01 20:57:57 -08:00
|
|
|
// IRC connection to announce on; could be empty
|
|
|
|
std::shared_ptr<myirc::Connection> connection_;
|
|
|
|
|
|
|
|
// Buffered events in case connection was inactive when event was received
|
2025-02-02 16:20:52 -08:00
|
|
|
std::vector<std::pair<std::string, std::string>> events_;
|
2025-02-01 20:57:57 -08:00
|
|
|
|
2025-02-02 14:56:34 -08:00
|
|
|
const char * settings_file;
|
2025-02-01 20:57:57 -08:00
|
|
|
|
|
|
|
public:
|
|
|
|
WebhookSettings settings_;
|
|
|
|
|
2025-02-02 15:02:08 -08:00
|
|
|
Webhooks(WebhookSettings settings, const char * settings_file)
|
2025-02-01 20:57:57 -08:00
|
|
|
: settings_(std::move(settings))
|
2025-02-02 14:56:34 -08:00
|
|
|
, settings_file(settings_file)
|
2025-02-01 20:57:57 -08:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
// Either emit the event now or save it until a connection is set
|
2025-02-02 16:20:52 -08:00
|
|
|
auto send_notice(std::string_view, std::string) -> void;
|
2025-02-02 14:56:34 -08:00
|
|
|
auto set_connection(std::shared_ptr<myirc::Connection> connection) -> void;
|
|
|
|
auto clear_connection() -> void;
|
|
|
|
auto save_settings() const -> void;
|
2025-02-01 20:57:57 -08:00
|
|
|
};
|
|
|
|
|
2025-02-02 15:02:08 -08:00
|
|
|
auto start_webhook(boost::asio::io_context &io, const char *) -> std::shared_ptr<Webhooks>;
|
2025-02-02 14:56:34 -08:00
|
|
|
|
2025-02-02 15:02:08 -08:00
|
|
|
extern std::map<std::string, void(*)(std::shared_ptr<Webhooks>, const myirc::Bot::Command &)> webhook_commands;
|