diff --git a/src/commands/project_cmd.cpp b/src/commands/project_cmd.cpp index bfe080a..2b1fce7 100644 --- a/src/commands/project_cmd.cpp +++ b/src/commands/project_cmd.cpp @@ -5,8 +5,7 @@ using json = nlohmann::json; void cmd::projectCommand(dpp::cluster& bot, const dpp::slashcommand_t& event) { - static int index = -1; - index++; + static int index = 0; std::ifstream projectFile("res/project.json"); if (!projectFile.is_open()) @@ -26,12 +25,18 @@ void cmd::projectCommand(dpp::cluster& bot, const dpp::slashcommand_t& event) return; } - if (!data.contains("projects") || !data["projects"].is_array() || index >= data["projects"].size()) + if (!data.contains("projects") || !data["projects"].is_array()) { - event.reply("Invalid project data or index out of bounds."); + event.reply("Invalid project data."); return; } + // If index exceeds the number of projects, reset it to 0 + if (index >= data["projects"].size()) + { + index = 0; + } + const auto& project = data["projects"][index]; if (!project.contains("title") || !project.contains("description")) { @@ -43,7 +48,6 @@ void cmd::projectCommand(dpp::cluster& bot, const dpp::slashcommand_t& event) const std::string projectDescription = project["description"]; const std::string projectHint = project.contains("hint") ? project["hint"] : "No hint available."; - dpp::embed embed = dpp::embed() .set_color(globals::color::defaultColor) .add_field("Project Idea", projectTitle) @@ -97,4 +101,6 @@ void cmd::projectCommand(dpp::cluster& bot, const dpp::slashcommand_t& event) dpp::message hintMessage(event.command.channel_id, hintEmbed); event.reply(hintMessage); }); + + index++; }