From 2a49844a95593ac98e919c18651320e62f276fa7 Mon Sep 17 00:00:00 2001 From: ilotterytea Date: Sun, 6 Apr 2025 17:28:47 +0400 Subject: feat: implementing lua coding --- bot/src/commands/command.cpp | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) (limited to 'bot/src/commands/command.cpp') 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 #include #include +#include #include #include #include +#include +#include +#include #include #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()); this->add_command(std::make_unique()); this->add_command(std::make_unique()); + + this->luaState = std::make_shared(); + 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(this->luaState, content)); + } } void CommandLoader::add_command(std::unique_ptr command) { -- cgit v1.2.3