join channels that we're announcing to
This commit is contained in:
parent
44ef4c0689
commit
4fc8d4d49c
@ -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) {
|
||||
|
@ -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>;
|
||||
|
@ -1,7 +1,7 @@
|
||||
add_custom_command(
|
||||
OUTPUT irc_commands.inc
|
||||
COMMAND
|
||||
/opt/homebrew/bin/gperf
|
||||
gperf
|
||||
-C -Z IrcCommandHash -K text -L C++ -t
|
||||
--output-file irc_commands.inc
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/irc_commands.gperf
|
||||
|
@ -239,6 +239,11 @@ auto Client::is_channel(std::string_view name) const -> bool
|
||||
return not name.empty() && channel_prefix_.find(name[0]) != channel_prefix_.npos;
|
||||
}
|
||||
|
||||
auto Client::is_on_channel(std::string_view name) const -> bool
|
||||
{
|
||||
return channels_.contains(casemap(name));
|
||||
}
|
||||
|
||||
namespace {
|
||||
template <class... Ts>
|
||||
struct overloaded : Ts...
|
||||
|
@ -102,6 +102,7 @@ public:
|
||||
auto is_my_nick(std::string_view nick) const -> bool;
|
||||
auto is_my_mask(std::string_view mask) const -> bool;
|
||||
auto is_channel(std::string_view name) const -> bool;
|
||||
auto is_on_channel(std::string_view name) const -> bool;
|
||||
|
||||
auto casemap(std::string_view) const -> std::string;
|
||||
auto casemap_compare(std::string_view, std::string_view) const -> int;
|
||||
|
Loading…
x
Reference in New Issue
Block a user