join channels that we're announcing to

This commit is contained in:
2025-02-03 11:05:01 -08:00
parent 44ef4c0689
commit 4fc8d4d49c
5 changed files with 37 additions and 12 deletions

View File

@@ -417,20 +417,38 @@ auto Webhooks::send_notice(std::string_view target, std::string message) -> void
{
client_->send_notice(target, message);
}
else
{
events_.emplace_back(std::string(target), std::move(message));
}
auto Webhooks::refresh_channels() const -> void
{
if (not client_) return;
std::stringstream ss;
std::set<std::string_view> added;
bool first = true;
for (auto &&[_, project] : settings_.projects) {
auto &channel = project.channel;
if (!channel.empty() &&
!client_->is_on_channel(channel) &&
added.insert(channel).second)
{
if (first) {
first = false;
} else {
ss << ",";
}
ss << channel;
}
}
if (not first) {
client_->send_join(ss.str());
}
}
auto Webhooks::set_client(std::shared_ptr<myirc::Client> client) -> void
{
client_ = std::move(client);
for (auto &&[target, message] : std::move(events_))
{
client_->send_notice(target, message);
}
events_.clear();
refresh_channels();
}
auto Webhooks::clear_client() -> void
@@ -591,6 +609,8 @@ std::map<std::string, void (*)(std::shared_ptr<Webhooks>, const myirc::Bot::Comm
project.channel = channel;
webhooks->save_settings();
reply_to(webhooks, cmd, "Channel assigned");
webhooks->refresh_channels();
}
}},
{"rehash", [](std::shared_ptr<Webhooks> webhooks, const myirc::Bot::Command &cmd) {

View File

@@ -51,11 +51,9 @@ class Webhooks {
// IRC connection to announce on; could be empty
std::shared_ptr<myirc::Client> client_;
// Buffered events in case connection was inactive when event was received
std::vector<std::pair<std::string, std::string>> events_;
const char * settings_filename_;
public:
WebhookSettings settings_;
@@ -70,6 +68,7 @@ public:
auto clear_client() -> void;
auto save_settings() const -> void;
auto load_settings() -> void;
auto refresh_channels() const -> void;
};
auto start_webhook(boost::asio::io_context &io, const char *) -> std::shared_ptr<Webhooks>;