summaryrefslogtreecommitdiff
path: root/bot/src/commands
diff options
context:
space:
mode:
Diffstat (limited to 'bot/src/commands')
-rw-r--r--bot/src/commands/command.cpp6
-rw-r--r--bot/src/commands/command.hpp10
-rw-r--r--bot/src/commands/response.cpp40
-rw-r--r--bot/src/commands/response.hpp25
4 files changed, 73 insertions, 8 deletions
diff --git a/bot/src/commands/command.cpp b/bot/src/commands/command.cpp
index b656254..8d75999 100644
--- a/bot/src/commands/command.cpp
+++ b/bot/src/commands/command.cpp
@@ -20,6 +20,7 @@
#include "../modules/timer.hpp"
#include "../utils/chrono.hpp"
#include "request.hpp"
+#include "response.hpp"
namespace bot {
namespace command {
@@ -39,9 +40,8 @@ namespace bot {
this->commands.push_back(std::move(command));
}
- std::optional<std::variant<std::vector<std::string>, std::string>>
- CommandLoader::run(const InstanceBundle &bundle,
- const Request &request) const {
+ std::optional<Response> CommandLoader::run(const InstanceBundle &bundle,
+ const Request &request) const {
auto command = std::find_if(
this->commands.begin(), this->commands.end(),
[&](const auto &x) { return x->get_name() == request.command_id; });
diff --git a/bot/src/commands/command.hpp b/bot/src/commands/command.hpp
index 40ec114..793446e 100644
--- a/bot/src/commands/command.hpp
+++ b/bot/src/commands/command.hpp
@@ -3,11 +3,11 @@
#include <memory>
#include <optional>
#include <string>
-#include <variant>
#include <vector>
#include "../bundle.hpp"
#include "request.hpp"
+#include "response.hpp"
namespace bot {
namespace command {
@@ -24,8 +24,8 @@ namespace bot {
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;
+ virtual Response run(const InstanceBundle &bundle,
+ const Request &request) const = 0;
virtual schemas::PermissionLevel get_permission_level() const {
return schemas::PermissionLevel::USER;
}
@@ -41,8 +41,8 @@ namespace bot {
~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;
+ std::optional<Response> run(const InstanceBundle &bundle,
+ const Request &msg) const;
const std::vector<std::unique_ptr<Command>> &get_commands() const {
return this->commands;
diff --git a/bot/src/commands/response.cpp b/bot/src/commands/response.cpp
new file mode 100644
index 0000000..cf13009
--- /dev/null
+++ b/bot/src/commands/response.cpp
@@ -0,0 +1,40 @@
+#include "response.hpp"
+
+#include <optional>
+#include <string>
+#include <vector>
+
+namespace bot::command {
+ Response::Response() {
+ this->single = std::nullopt;
+ this->multiple = std::nullopt;
+ }
+
+ Response::Response(std::string single) {
+ this->single = single;
+ this->multiple = std::nullopt;
+ }
+
+ Response::Response(std::vector<std::string> multiple) {
+ this->single = std::nullopt;
+ this->multiple = multiple;
+ }
+
+ const std::string Response::get_single() const {
+ return this->single.value();
+ }
+
+ const std::vector<std::string> Response::get_multiple() const {
+ return this->multiple.value();
+ }
+
+ const bool Response::is_single() const { return this->single.has_value(); }
+
+ const bool Response::is_multiple() const {
+ return this->multiple.has_value();
+ }
+
+ const bool Response::is_empty() const {
+ return !this->single.has_value() && !this->multiple.has_value();
+ }
+} \ No newline at end of file
diff --git a/bot/src/commands/response.hpp b/bot/src/commands/response.hpp
new file mode 100644
index 0000000..2f05fd8
--- /dev/null
+++ b/bot/src/commands/response.hpp
@@ -0,0 +1,25 @@
+#pragma once
+
+#include <optional>
+#include <string>
+#include <vector>
+
+namespace bot::command {
+ class Response {
+ public:
+ Response();
+ Response(std::string single);
+ Response(std::vector<std::string> multiple);
+
+ const std::string get_single() const;
+ const std::vector<std::string> get_multiple() const;
+
+ const bool is_single() const;
+ const bool is_multiple() const;
+ const bool is_empty() const;
+
+ private:
+ std::optional<std::string> single;
+ std::optional<std::vector<std::string>> multiple;
+ };
+} \ No newline at end of file