summaryrefslogtreecommitdiff
path: root/src/commands/command.hpp
blob: 498a1f296ef4a09085afc262708185b69711d87c (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
#pragma once

#include <memory>
#include <optional>
#include <string>
#include <variant>
#include <vector>

#include "../bundle.hpp"
#include "request.hpp"

namespace bot {
  namespace command {
    class Command {
      public:
        virtual std::string get_name() const = 0;
        virtual std::variant<std::vector<std::string>, std::string> run(
            const InstanceBundle &bundle, const Request &request) const = 0;
    };

    class CommandLoader {
      public:
        CommandLoader();
        ~CommandLoader() = default;

        void add_command(std::unique_ptr<Command> cmd);
        std::optional<std::variant<std::vector<std::string>, std::string>> run(
            const InstanceBundle &bundle, const Request &msg) const;

        const std::vector<std::unique_ptr<Command>> &get_commands() const {
          return this->commands;
        };

      private:
        std::vector<std::unique_ptr<Command>> commands;
    };
  }
}