MCPcopy Create free account
hub / github.com/brainboxdotcc/DPP / from_json

Function from_json

src/dpp/slashcommand.cpp:536–583  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

534}
535
536void 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
585void from_json(const nlohmann::json& j, command_interaction& ci) {
586 ci.id = snowflake_not_null(&j, "id");

Callers

nothing calls this directly

Calls 15

string_not_nullFunction · 0.85
int8_not_nullFunction · 0.85
bool_not_nullFunction · 0.85
snowflake_not_nullFunction · 0.85
int32_not_nullFunction · 0.85
set_snowflake_not_nullFunction · 0.85
containsMethod · 0.80
push_backMethod · 0.80
storeMethod · 0.80
emplaceMethod · 0.80
snowflakeClass · 0.70
messageClass · 0.70

Tested by

no test coverage detected