diff options
| author | ilotterytea <iltsu@alright.party> | 2024-04-21 16:33:23 +0500 |
|---|---|---|
| committer | ilotterytea <iltsu@alright.party> | 2024-04-21 16:33:23 +0500 |
| commit | 854e052b3a75bd4f77dd404341ea5c1070a2009c (patch) | |
| tree | c4d2533bb0cad05ded7575aaea1945414e14c88a /src/irc/client.cpp | |
| parent | 88bc263e64b62995a57bfb8231bb10c6da6fa090 (diff) | |
feat: join() method
Diffstat (limited to 'src/irc/client.cpp')
| -rw-r--r-- | src/irc/client.cpp | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/src/irc/client.cpp b/src/irc/client.cpp index 2604186..08a3ff3 100644 --- a/src/irc/client.cpp +++ b/src/irc/client.cpp @@ -74,6 +74,11 @@ void Client::run() { case ix::WebSocketMessageType::Close: { std::cout << "Twitch IRC Connection closed!\n"; this->is_connected = false; + + for (const auto &x : this->joined_channels) { + this->raw("JOIN #" + x); + } + break; } default: { @@ -85,6 +90,19 @@ void Client::run() { this->websocket.run(); } +bool Client::join(const std::string &channel_login) { + auto already_joined = + std::any_of(this->joined_channels.begin(), this->joined_channels.end(), + [&](const auto &x) { return x == channel_login; }); + + if (!already_joined) { + this->raw("JOIN #" + channel_login); + this->joined_channels.push_back(channel_login); + } + + return !already_joined; +} + void Client::raw(const std::string &raw_message) { std::string msg = raw_message + "\r\n"; if (this->is_connected) { |
