rename
This commit is contained in:
parent
178d7dfcfe
commit
53771396ca
@ -63,7 +63,7 @@ auto configure_sasl(const Settings &settings) -> std::unique_ptr<SaslMechanism>
|
||||
static auto start(
|
||||
boost::asio::io_context &io,
|
||||
const Settings &settings,
|
||||
std::shared_ptr<GithubWebhook> webhook
|
||||
std::shared_ptr<Webhooks> webhook
|
||||
) -> void
|
||||
{
|
||||
Ref<X509> tls_cert;
|
||||
|
@ -64,7 +64,7 @@ static auto compute_signature(const std::string_view secret, const std::string_v
|
||||
}
|
||||
|
||||
static auto process_event(
|
||||
std::shared_ptr<GithubWebhook> self,
|
||||
std::shared_ptr<Webhooks> 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 <class Body, class Allocator>
|
||||
static auto handle_request(
|
||||
std::shared_ptr<GithubWebhook> self,
|
||||
std::shared_ptr<Webhooks> self,
|
||||
http::request<Body, http::basic_fields<Allocator>> &&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<GithubWebhook> self) -> boost::asio::awaitable<void>
|
||||
auto read_loop(tcp::socket socket, std::shared_ptr<Webhooks> self) -> boost::asio::awaitable<void>
|
||||
{
|
||||
beast::tcp_stream stream{std::move(socket)};
|
||||
beast::flat_buffer buffer;
|
||||
@ -200,7 +200,7 @@ auto read_loop(tcp::socket socket, std::shared_ptr<GithubWebhook> self) -> boost
|
||||
|
||||
auto accept_loop(
|
||||
tcp::acceptor acceptor,
|
||||
std::shared_ptr<GithubWebhook> self
|
||||
std::shared_ptr<Webhooks> self
|
||||
) -> boost::asio::awaitable<void>
|
||||
{
|
||||
for (;;)
|
||||
@ -216,7 +216,7 @@ auto accept_loop(
|
||||
|
||||
auto spawn_webhook(
|
||||
boost::asio::io_context &io,
|
||||
const std::shared_ptr<GithubWebhook> webhook
|
||||
const std::shared_ptr<Webhooks> webhook
|
||||
) -> boost::asio::awaitable<void>
|
||||
{
|
||||
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<GithubWebhook>
|
||||
) -> std::shared_ptr<Webhooks>
|
||||
{
|
||||
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<GithubWebhook>(std::move(settings), webhook_settings_filename);
|
||||
auto webhook = std::make_shared<Webhooks>(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<myirc::Connection> connection) -> void
|
||||
auto Webhooks::set_connection(std::shared_ptr<myirc::Connection> connection) -> void
|
||||
{
|
||||
connection_ = std::move(connection);
|
||||
for (auto &&event : events_)
|
||||
@ -405,20 +405,20 @@ auto GithubWebhook::set_connection(std::shared_ptr<myirc::Connection> connection
|
||||
events_.clear();
|
||||
}
|
||||
|
||||
auto GithubWebhook::clear_connection() -> void
|
||||
auto Webhooks::clear_connection() -> void
|
||||
{
|
||||
connection_.reset();
|
||||
}
|
||||
|
||||
static auto reply_to(std::shared_ptr<GithubWebhook> webhooks, const myirc::Bot::Command &cmd, std::string message) -> void
|
||||
static auto reply_to(std::shared_ptr<Webhooks> 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<std::string, void (*)(std::shared_ptr<GithubWebhook>, const myirc::Bot::Command &)> webhook_commands{
|
||||
{"add-credential", [](std::shared_ptr<GithubWebhook> webhooks, const myirc::Bot::Command &cmd) {
|
||||
std::map<std::string, void (*)(std::shared_ptr<Webhooks>, const myirc::Bot::Command &)> webhook_commands{
|
||||
{"add-credential", [](std::shared_ptr<Webhooks> webhooks, const myirc::Bot::Command &cmd) {
|
||||
//if (cmd.oper.empty())
|
||||
//{
|
||||
// return;
|
||||
@ -442,7 +442,7 @@ std::map<std::string, void (*)(std::shared_ptr<GithubWebhook>, const myirc::Bot:
|
||||
reply_to(webhooks, cmd, "Added credential " + name);
|
||||
}
|
||||
}},
|
||||
{"drop-credential", [](std::shared_ptr<GithubWebhook> webhooks, const myirc::Bot::Command &cmd) {
|
||||
{"drop-credential", [](std::shared_ptr<Webhooks> webhooks, const myirc::Bot::Command &cmd) {
|
||||
//if (cmd.oper.empty())
|
||||
//{
|
||||
// return;
|
||||
@ -456,7 +456,7 @@ std::map<std::string, void (*)(std::shared_ptr<GithubWebhook>, const myirc::Bot:
|
||||
reply_to(webhooks, cmd, "Dropped credential " + name);
|
||||
}
|
||||
}},
|
||||
{"enable-project", [](std::shared_ptr<GithubWebhook> webhooks, const myirc::Bot::Command &cmd) {
|
||||
{"enable-project", [](std::shared_ptr<Webhooks> 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<std::string, void (*)(std::shared_ptr<GithubWebhook>, const myirc::Bot:
|
||||
reply_to(webhooks, cmd, "Enabled project " + name);
|
||||
}
|
||||
}},
|
||||
{"disable-project", [](std::shared_ptr<GithubWebhook> webhooks, const myirc::Bot::Command &cmd) {
|
||||
{"disable-project", [](std::shared_ptr<Webhooks> webhooks, const myirc::Bot::Command &cmd) {
|
||||
//if (cmd.oper.empty())
|
||||
//{
|
||||
// return;
|
||||
@ -493,7 +493,7 @@ std::map<std::string, void (*)(std::shared_ptr<GithubWebhook>, 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;
|
||||
}
|
||||
|
||||
|
@ -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<myirc::Connection> connection) -> void;
|
||||
auto clear_connection() -> void;
|
||||
auto save_settings() const -> void;
|
||||
};
|
||||
|
||||
auto start_webhook(boost::asio::io_context &io, const char *) -> std::shared_ptr<GithubWebhook>;
|
||||
auto start_webhook(boost::asio::io_context &io, const char *) -> std::shared_ptr<Webhooks>;
|
||||
|
||||
extern std::map<std::string, void(*)(std::shared_ptr<GithubWebhook>, const myirc::Bot::Command &)> webhook_commands;
|
||||
extern std::map<std::string, void(*)(std::shared_ptr<Webhooks>, const myirc::Bot::Command &)> webhook_commands;
|
||||
|
Loading…
x
Reference in New Issue
Block a user