Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 11 additions & 5 deletions src/commands/project_cmd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand All @@ -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"))
{
Expand All @@ -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)
Expand Down Expand Up @@ -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++;
}