| 225 | } |
| 226 | |
| 227 | bool ChatProcessor::handleCommand(ChatReceivedMessage& message) { |
| 228 | if (!message.text.beginsWith("/")) { |
| 229 | return false; |
| 230 | } else if (message.text.beginsWith("//")) { |
| 231 | message.text = message.text.substr(1); |
| 232 | return false; |
| 233 | } |
| 234 | |
| 235 | String commandLine = message.text.substr(1); |
| 236 | String command = commandLine.extract(); |
| 237 | |
| 238 | String response; |
| 239 | |
| 240 | if (command == "nick") { |
| 241 | auto newNick = renick(message.fromConnection, commandLine.trim()); |
| 242 | response = strf("Nick changed to {}", newNick); |
| 243 | } else if (command == "w") { |
| 244 | String target = commandLine.extract(); |
| 245 | if (m_nicks.contains(target)) |
| 246 | whisper(message.fromConnection, m_nicks.get(target), commandLine.trim()); |
| 247 | else |
| 248 | response = strf("No such nick {}", target); |
| 249 | } else if (m_commandHandler) { |
| 250 | response = m_commandHandler(message.fromConnection, command, commandLine); |
| 251 | } else { |
| 252 | response = strf("No such command {}", command); |
| 253 | } |
| 254 | |
| 255 | if (!response.empty()) { |
| 256 | m_clients.get(message.fromConnection).pendingMessages.append({ |
| 257 | MessageContext(MessageContext::CommandResult), |
| 258 | ServerConnectionId, |
| 259 | connectionNick(ServerConnectionId), |
| 260 | response |
| 261 | }); |
| 262 | } |
| 263 | |
| 264 | return true; |
| 265 | } |
| 266 | |
| 267 | } |
nothing calls this directly
no test coverage detected