MCPcopy Create free account
hub / github.com/Botloader/botloader / merge_command

Function merge_command

components/scheduler/src/command_manager.rs:437–479  ·  view source on GitHub ↗

merges src into dst

(dst: &mut TwilightCommand, src: TwilightCommand)

Source from the content-addressed store, hash-verified

435
436// merges src into dst
437fn merge_command(dst: &mut TwilightCommand, src: TwilightCommand) {
438 if dst.description == GROUP_DESC_PLACEHOLDER && src.description != GROUP_DESC_PLACEHOLDER {
439 dst.description = src.description;
440 }
441
442 for opt in &dst.options {
443 if !matches!(
444 opt.kind,
445 TwilightCommandOptionType::SubCommand | TwilightCommandOptionType::SubCommandGroup
446 ) {
447 // We can only merge sub commands
448 return;
449 }
450 }
451
452 for opt in src.options {
453 if !matches!(
454 opt.kind,
455 TwilightCommandOptionType::SubCommand | TwilightCommandOptionType::SubCommandGroup
456 ) {
457 // We can only merge sub commands
458 return;
459 }
460
461 let src_opt_name = &opt.name;
462 if let Some(dst_opt) = dst.options.iter_mut().find(|v| &v.name == src_opt_name) {
463 // we need to merge these options
464 match (dst_opt.kind, opt.kind) {
465 (
466 TwilightCommandOptionType::SubCommandGroup,
467 TwilightCommandOptionType::SubCommandGroup,
468 ) => merge_subgroups(dst_opt, opt),
469 _ => {
470 // we can only merge subgroups, how would we merge subcommands?
471 continue;
472 }
473 }
474 } else {
475 // no conflict
476 dst.options.push(opt);
477 }
478 }
479}
480
481fn merge_subgroups(dst: &mut TwilightCommandOption, src: TwilightCommandOption) {
482 if dst.description == GROUP_DESC_PLACEHOLDER && src.description != GROUP_DESC_PLACEHOLDER {

Callers 1

merge_script_commandsFunction · 0.85

Calls 1

merge_subgroupsFunction · 0.85

Tested by

no test coverage detected