| 534 | } |
| 535 | |
| 536 | void from_json(const nlohmann::json& j, command_data_option& cdo) { |
| 537 | cdo.name = string_not_null(&j, "name"); |
| 538 | cdo.type = (command_option_type)int8_not_null(&j, "type"); |
| 539 | |
| 540 | if (j.contains("options") && !j.at("options").is_null()) { |
| 541 | j.at("options").get_to(cdo.options); |
| 542 | } |
| 543 | |
| 544 | /* If there's a focused, define it */ |
| 545 | if (j.contains("focused") && !j.at("focused").is_null()) { |
| 546 | cdo.focused = bool_not_null(&j, "focused"); |
| 547 | } |
| 548 | |
| 549 | if (j.contains("value") && !j.at("value").is_null()) { |
| 550 | switch (cdo.type) { |
| 551 | case co_boolean: |
| 552 | if(j.at("value").is_boolean()) { |
| 553 | cdo.value = j.at("value").get<bool>(); |
| 554 | } |
| 555 | break; |
| 556 | case co_channel: |
| 557 | case co_role: |
| 558 | case co_attachment: |
| 559 | case co_user: |
| 560 | case co_mentionable: |
| 561 | cdo.value = dpp::snowflake(snowflake_not_null(&j, "value")); |
| 562 | break; |
| 563 | case co_integer: |
| 564 | if(j.at("value").is_number_integer()) { |
| 565 | cdo.value = j.at("value").get<int64_t>(); |
| 566 | } |
| 567 | break; |
| 568 | case co_string: |
| 569 | if(j.at("value").is_string()) { |
| 570 | cdo.value = j.at("value").get<std::string>(); |
| 571 | } |
| 572 | break; |
| 573 | case co_number: |
| 574 | if(j.at("value").is_number_float()) { |
| 575 | cdo.value = j.at("value").get<double>(); |
| 576 | } |
| 577 | break; |
| 578 | case co_sub_command: |
| 579 | case co_sub_command_group: |
| 580 | break; |
| 581 | } |
| 582 | } |
| 583 | } |
| 584 | |
| 585 | void from_json(const nlohmann::json& j, command_interaction& ci) { |
| 586 | ci.id = snowflake_not_null(&j, "id"); |
nothing calls this directly
no test coverage detected