summaryrefslogtreecommitdiff
path: root/bot/src/irc/client.hpp
blob: cff867ff13d8eec49be3cac5e3fe4c6538f91b3d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#pragma once

#include <ixwebsocket/IXWebSocket.h>

#include <string>
#include <vector>

#include "message.hpp"

namespace bot {
  namespace irc {
    class Client {
      public:
        Client(std::string client_id, std::string token);
        ~Client() = default;

        void run();

        void say(const std::string &channel_login, const std::string &message);
        bool join(const std::string &channel_login);
        void raw(const std::string &raw_message);

        template <MessageType T>
        void on(typename MessageHandler<T>::fn function) {
          switch (T) {
            case Privmsg:
              this->onPrivmsg = function;
              break;
            default:
              break;
          }
        }

        const std::string &get_bot_username() const { return this->username; };
        const int &get_bot_id() const { return this->id; }

      private:
        void authorize();

        std::string client_id, token, username;

        std::string host;
        std::string port;

        int id;

        ix::WebSocket websocket;

        bool is_connected = false;
        std::vector<std::string> pool;

        std::vector<std::string> joined_channels;

        // Message handlers
        typename MessageHandler<MessageType::Privmsg>::fn onPrivmsg;
    };
  }
}