From 0be8f68fe97816fa3b4ffdce425bde46da8b29c8 Mon Sep 17 00:00:00 2001 From: mbn <66748817+mbn-code@users.noreply.github.com> Date: Thu, 30 Jan 2025 17:24:34 +0100 Subject: [PATCH 1/2] Project index reset when at last index --- src/commands/project_cmd.cpp | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/src/commands/project_cmd.cpp b/src/commands/project_cmd.cpp index bfe080a..37f9f33 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,24 @@ 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 + + /* Debugging purposes + std::cout << index << std::endl; + std::cout << data["projects"].size() << std::endl; + */ + + if (index >= data["projects"].size()) + { + index = 0; + } + const auto& project = data["projects"][index]; if (!project.contains("title") || !project.contains("description")) { @@ -43,7 +54,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 +107,6 @@ void cmd::projectCommand(dpp::cluster& bot, const dpp::slashcommand_t& event) dpp::message hintMessage(event.command.channel_id, hintEmbed); event.reply(hintMessage); }); + + index++; } From de796431d3bc351b3d0e743d4274b56aec117762 Mon Sep 17 00:00:00 2001 From: fellalli Date: Tue, 4 Feb 2025 14:57:33 +0100 Subject: [PATCH 2/2] Update project_cmd.cpp --- src/commands/project_cmd.cpp | 6 ------ 1 file changed, 6 deletions(-) diff --git a/src/commands/project_cmd.cpp b/src/commands/project_cmd.cpp index 37f9f33..2b1fce7 100644 --- a/src/commands/project_cmd.cpp +++ b/src/commands/project_cmd.cpp @@ -32,12 +32,6 @@ void cmd::projectCommand(dpp::cluster& bot, const dpp::slashcommand_t& event) } // If index exceeds the number of projects, reset it to 0 - - /* Debugging purposes - std::cout << index << std::endl; - std::cout << data["projects"].size() << std::endl; - */ - if (index >= data["projects"].size()) { index = 0;