summaryrefslogtreecommitdiff
path: root/bot/src/modules/lua.hpp
blob: b60850abf3f807d46bcc71beeeb0cd014a8cf67c (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
#pragma once

#include <string>

#include "bundle.hpp"
#include "commands/command.hpp"
#include "commands/lua.hpp"
#include "commands/response_error.hpp"

namespace bot::mod {
  class LuaExecution : public command::Command {
      std::string get_name() const override { return "lua"; }

      int get_delay_seconds() const override { return 1; }

      command::Response run(const InstanceBundle &bundle,
                            const command::Request &request) const override {
        if (!request.message.has_value()) {
          throw ResponseException<ResponseError::NOT_ENOUGH_ARGUMENTS>(
              request, bundle.localization, command::CommandArgument::VALUE);
        }

        std::string script = request.message.value();

        return command::lua::run_safe_lua_script(request, bundle, script);
      }
  };
}