summaryrefslogtreecommitdiff
path: root/bot/src/commands/command.cpp
diff options
context:
space:
mode:
authorilotterytea <iltsu@alright.party>2025-04-06 17:28:47 +0400
committerilotterytea <iltsu@alright.party>2025-04-06 17:28:47 +0400
commit2a49844a95593ac98e919c18651320e62f276fa7 (patch)
tree01b7e2ebb1dc7a9ac92e7c3105edfd098271f29a /bot/src/commands/command.cpp
parenta1a36cf4d4999b5ce89dce95364c9fd839b54b5d (diff)
feat: implementing lua coding
Diffstat (limited to 'bot/src/commands/command.cpp')
-rw-r--r--bot/src/commands/command.cpp30
1 files changed, 30 insertions, 0 deletions
diff --git a/bot/src/commands/command.cpp b/bot/src/commands/command.cpp
index bd33c68..97dd88b 100644
--- a/bot/src/commands/command.cpp
+++ b/bot/src/commands/command.cpp
@@ -3,9 +3,13 @@
#include <algorithm>
#include <chrono>
#include <ctime>
+#include <fstream>
#include <memory>
#include <optional>
#include <pqxx/pqxx>
+#include <sol/state.hpp>
+#include <sol/types.hpp>
+#include <stdexcept>
#include <string>
#include "../bundle.hpp"
@@ -23,6 +27,8 @@
#include "../modules/timer.hpp"
#include "../modules/user.hpp"
#include "../utils/chrono.hpp"
+#include "commands/lua.hpp"
+#include "logger.hpp"
#include "request.hpp"
#include "response.hpp"
@@ -42,6 +48,30 @@ namespace bot {
this->add_command(std::make_unique<mod::Settings>());
this->add_command(std::make_unique<mod::User>());
this->add_command(std::make_unique<mod::MinecraftServerCheck>());
+
+ this->luaState = std::make_shared<sol::state>();
+ this->luaState->open_libraries(sol::lib::base, sol::lib::string);
+ }
+
+ void CommandLoader::load_lua_directory(const std::string &folder_path) {
+ for (const auto &entry :
+ std::filesystem::directory_iterator(folder_path)) {
+ std::ifstream ifs(entry.path());
+ if (!ifs.is_open()) {
+ throw new std::runtime_error("Failed to open the Lua file at " +
+ entry.path().string());
+ }
+ std::string content, line;
+
+ while (std::getline(ifs, line)) {
+ content += line + '\n';
+ }
+
+ ifs.close();
+
+ this->add_command(
+ std::make_unique<lua::LuaCommand>(this->luaState, content));
+ }
}
void CommandLoader::add_command(std::unique_ptr<Command> command) {