| 154 | } |
| 155 | |
| 156 | static void parseCommand(const std::string &rawCommandComponent, |
| 157 | IRCMessage &message) |
| 158 | { |
| 159 | std::vector<std::string> commandParts; |
| 160 | size_t pos = 0; |
| 161 | size_t endPos; |
| 162 | |
| 163 | while ((endPos = rawCommandComponent.find(' ', pos)) != |
| 164 | std::string::npos) { |
| 165 | commandParts.push_back( |
| 166 | rawCommandComponent.substr(pos, endPos - pos)); |
| 167 | pos = endPos + 1; |
| 168 | } |
| 169 | |
| 170 | commandParts.push_back(rawCommandComponent.substr(pos)); |
| 171 | |
| 172 | if (commandParts.empty()) { |
| 173 | return; |
| 174 | } |
| 175 | |
| 176 | message.command.command = commandParts[0]; |
| 177 | if (message.command.command == "CAP") { |
| 178 | if (commandParts.size() < 3) { |
| 179 | return; |
| 180 | } |
| 181 | message.type = IRCMessage::Type::OTHER; |
| 182 | message.command.parameters = (commandParts[2] == "ACK"); |
| 183 | } else if (message.command.command == "RECONNECT") { |
| 184 | blog(LOG_INFO, |
| 185 | "The Twitch IRC server is about to terminate the connection for maintenance."); |
| 186 | message.type = IRCMessage::Type::OTHER; |
| 187 | } else if (message.command.command == "421") { |
| 188 | // Unsupported command |
| 189 | message.type = IRCMessage::Type::OTHER; |
| 190 | return; |
| 191 | } else if (message.command.command == "PRIVMSG") { |
| 192 | if (commandParts.size() < 2) { |
| 193 | return; |
| 194 | } |
| 195 | message.type = IRCMessage::Type::MESSAGE_RECEIVED; |
| 196 | message.command.parameters = commandParts[1]; |
| 197 | } else if (message.command.command == "CLEARCHAT") { |
| 198 | if (commandParts.size() < 1) { |
| 199 | return; |
| 200 | } |
| 201 | message.type = IRCMessage::Type::MESSAGE_CLEARED; |
| 202 | message.command.parameters = commandParts[1]; |
| 203 | } else if (message.command.command == "CLEARMSG") { |
| 204 | if (commandParts.size() < 2) { |
| 205 | return; |
| 206 | } |
| 207 | message.type = IRCMessage::Type::MESSAGE_REMOVED; |
| 208 | message.command.parameters = commandParts[1]; |
| 209 | } else if (message.command.command == "PING" || |
| 210 | message.command.command == "001" || |
| 211 | message.command.command == "NOTICE" || |
| 212 | message.command.command == "HOSTTARGET") { |
| 213 | if (commandParts.size() < 2) { |