diff options
| -rw-r--r-- | src/irc/client.cpp | 18 | ||||
| -rw-r--r-- | src/irc/client.hpp | 3 | ||||
| -rw-r--r-- | src/main.cpp | 1 |
3 files changed, 22 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) { diff --git a/src/irc/client.hpp b/src/irc/client.hpp index 0194750..2598550 100644 --- a/src/irc/client.hpp +++ b/src/irc/client.hpp @@ -16,6 +16,7 @@ namespace bot { void run(); + bool join(const std::string &channel_login); void raw(const std::string &raw_message); template <MessageType T> @@ -43,6 +44,8 @@ namespace bot { bool is_connected = false; std::vector<std::string> pool; + std::vector<std::string> joined_channels; + // Message handlers typename MessageHandler<MessageType::Privmsg>::fn onPrivmsg; }; diff --git a/src/main.cpp b/src/main.cpp index 9477b96..dffe4d0 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -27,6 +27,7 @@ int main(int argc, char *argv[]) { bot::command::CommandLoader command_loader; bot::loc::Localization localization("localization"); + client.join(cfg.bot_username); client.run(); return 0; |
