-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathproject_cmd.cpp
More file actions
73 lines (59 loc) · 1.88 KB
/
project_cmd.cpp
File metadata and controls
73 lines (59 loc) · 1.88 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#include "commands.h"
#include "../globals/globals.h"
using json = nlohmann::json;
void cmd::projectCommand(dpp::cluster& bot, const dpp::slashcommand_t& event)
{
static int index = 0;
std::ifstream projectFile("res/project.json");
if (!projectFile.is_open())
{
event.reply("Failed to open project file.");
return;
}
json data;
try
{
projectFile >> data;
}
catch (const json::parse_error& e)
{
event.reply("Failed to parse project file.");
return;
}
if (!data.contains("projects") || !data["projects"].is_array())
{
event.reply("Invalid project data.");
return;
}
if (data["projects"].empty())
{
event.reply("No projects available.");
return;
}
index = index % data["projects"].size();
const auto& project = data["projects"][index];
if (!project.contains("title") || !project.contains("description"))
{
event.reply("Project data is missing required fields.");
return;
}
const std::string projectTitle = project["title"];
const std::string projectDescription = project["description"];
const std::string projectHint = project.contains("hint") ? project["hint"] : "No hint available.";
const dpp::embed embed = dpp::embed()
.set_color(globals::color::defaultColor)
.add_field("Project Idea", projectTitle)
.add_field("Description", projectDescription);
dpp::message message(event.command.channel_id, embed);
message.add_component(
dpp::component().add_component(
dpp::component()
.set_label("Hint")
.set_type(dpp::cot_button)
.set_style(dpp::cos_primary)
.set_id("hint_button_" + std::to_string(index))
)
);
event.reply(message);
index = (index + 1) % data["projects"].size();
}