summaryrefslogtreecommitdiff
path: root/bot/src/irc/message.cpp
blob: 569e691dc300c0bf04e9668945ba70256b22b22d (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
#include "message.hpp"

#include <optional>
#include <string>
#include <vector>

namespace bot {
  namespace irc {
    std::optional<MessageType> define_message_type(const std::string &msg) {
      std::vector<std::string> parts = utils::string::split_text(msg, ' ');
      int i;

      if (msg[0] == '@') {
        i = 2;
      } else if (msg[0] == ':') {
        i = 1;
      } else {
        return std::nullopt;
      }

      if (parts[i] == "NOTICE") {
        return MessageType::Notice;
      } else if (parts[i] == "PRIVMSG") {
        return MessageType::Privmsg;
      }

      return std::nullopt;
    }
  }
}