summaryrefslogtreecommitdiff
path: root/src/commands/command.cpp
blob: b6852cc88d46358fd49fa3cda384a32ad9ebfa48 (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 "command.hpp"

#include <iostream>
#include <memory>
#include <optional>

#include "../modules/ping.hpp"

namespace bot {
  namespace command {
    CommandLoader::CommandLoader() {
      this->add_command(std::make_unique<mod::Ping>());
    }

    void CommandLoader::add_command(std::unique_ptr<Command> command) {
      this->commands.push_back(std::move(command));
    }

    std::optional<std::variant<std::vector<std::string>, std::string>>
    CommandLoader::run(const irc::Message<irc::MessageType::Privmsg> &msg) {
      for (const std::unique_ptr<Command> &command : this->commands) {
        if (command->get_name() == msg.message) {
          return command->run(msg);
        }
      }

      return std::nullopt;
    }
  }
}