summaryrefslogtreecommitdiff
path: root/bot
diff options
context:
space:
mode:
authorilotterytea <iltsu@alright.party>2025-04-08 01:07:11 +0400
committerilotterytea <iltsu@alright.party>2025-04-08 01:07:11 +0400
commit112136c184bcb226fa84e9b5a39c2d1dc557c4d3 (patch)
tree0b9ebc6a090b3cad75ac6d5426f3beda173fab24 /bot
parentfbf41a4c737174442717ade79e895321ee8ada36 (diff)
feat: a method for loading a single lua file
Diffstat (limited to 'bot')
-rw-r--r--bot/src/commands/command.cpp30
-rw-r--r--bot/src/commands/command.hpp1
2 files changed, 18 insertions, 13 deletions
diff --git a/bot/src/commands/command.cpp b/bot/src/commands/command.cpp
index 87eecfd..4544810 100644
--- a/bot/src/commands/command.cpp
+++ b/bot/src/commands/command.cpp
@@ -61,22 +61,26 @@ namespace bot {
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';
- }
+ load_lua_file(entry.path());
+ }
+ }
- ifs.close();
+ void CommandLoader::load_lua_file(const std::string &file_path) {
+ std::ifstream ifs(file_path);
+ if (!ifs.is_open()) {
+ throw new std::runtime_error("Failed to open the Lua file at " +
+ file_path);
+ }
+ std::string content, line;
- this->add_command(
- std::make_unique<lua::LuaCommand>(this->luaState, content));
+ 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) {
diff --git a/bot/src/commands/command.hpp b/bot/src/commands/command.hpp
index fcaacdb..507504c 100644
--- a/bot/src/commands/command.hpp
+++ b/bot/src/commands/command.hpp
@@ -44,6 +44,7 @@ namespace bot {
void add_command(std::unique_ptr<Command> cmd);
void load_lua_directory(const std::string &folder_path);
+ void load_lua_file(const std::string &file_path);
std::optional<Response> run(const InstanceBundle &bundle,
const Request &msg);