summaryrefslogtreecommitdiff
path: root/bot/src/commands/command.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'bot/src/commands/command.cpp')
-rw-r--r--bot/src/commands/command.cpp30
1 files changed, 17 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) {