Skip to content

Commit

Permalink
fix: integer autocompletes no longer cause crash (#992)
Browse files Browse the repository at this point in the history
  • Loading branch information
Jaskowicz1 authored Nov 2, 2023
1 parent 223e0a1 commit cb17478
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 9 deletions.
18 changes: 13 additions & 5 deletions src/dpp/events/interaction_create.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,23 +37,31 @@ void fill_options(dpp::json option_json, std::vector<dpp::command_option>& optio
opt.type = (dpp::command_option_type)int8_not_null(&o, "type");
switch (opt.type) {
case co_boolean:
opt.value = o.at("value").get<bool>();
if(o.at("value").is_boolean()) {
opt.value = o.at("value").get<bool>();
}
break;
case co_channel:
case co_role:
case co_user:
case co_attachment:
case co_user:
case co_mentionable:
opt.value = dpp::snowflake(snowflake_not_null(&o, "value"));
break;
case co_integer:
opt.value = o.at("value").get<int64_t>();
if(o.at("value").is_number_integer()) {
opt.value = o.at("value").get<int64_t>();
}
break;
case co_string:
opt.value = o.at("value").get<std::string>();
if(o.at("value").is_string()) {
opt.value = o.at("value").get<std::string>();
}
break;
case co_number:
opt.value = o.at("value").get<double>();
if(o.at("value").is_number_float()) {
opt.value = o.at("value").get<double>();
}
break;
case co_sub_command:
case co_sub_command_group:
Expand Down
16 changes: 12 additions & 4 deletions src/dpp/slashcommand.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -521,7 +521,9 @@ void from_json(const nlohmann::json& j, command_data_option& cdo) {
if (j.contains("value") && !j.at("value").is_null()) {
switch (cdo.type) {
case co_boolean:
cdo.value = j.at("value").get<bool>();
if(j.at("value").is_boolean()) {
cdo.value = j.at("value").get<bool>();
}
break;
case co_channel:
case co_role:
Expand All @@ -531,13 +533,19 @@ void from_json(const nlohmann::json& j, command_data_option& cdo) {
cdo.value = dpp::snowflake(snowflake_not_null(&j, "value"));
break;
case co_integer:
cdo.value = j.at("value").get<int64_t>();
if(j.at("value").is_number_integer()) {
cdo.value = j.at("value").get<int64_t>();
}
break;
case co_string:
cdo.value = j.at("value").get<std::string>();
if(j.at("value").is_string()) {
cdo.value = j.at("value").get<std::string>();
}
break;
case co_number:
cdo.value = j.at("value").get<double>();
if(j.at("value").is_number_float()) {
cdo.value = j.at("value").get<double>();
}
break;
case co_sub_command:
case co_sub_command_group:
Expand Down

0 comments on commit cb17478

Please sign in to comment.