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

Method validate

components/validation/src/runtime.rs:19–55  ·  view source on GitHub ↗
(&self, ctx: &mut ValidationContext, _: &())

Source from the content-addressed store, hash-verified

17 type ContextData = ();
18
19 fn validate(&self, ctx: &mut ValidationContext, _: &()) {
20 check_name_field(ctx, "name", &self.name, matches!(self.kind, CommandType::Chat));
21
22 if matches!(self.kind, CommandType::Chat) {
23 check_description_field(ctx, "description", &self.description);
24 } else if !self.description.is_empty() {
25 ctx.push_field_error(
26 "description",
27 "description has to be empty for user and message commands".to_string(),
28 );
29 }
30
31 if let Some(group) = &self.group {
32 check_name_field(ctx, "group", group, true);
33 }
34
35 if let Some(group) = &self.sub_group {
36 check_name_field(ctx, "sub_group", group, true);
37 }
38
39 if self.options.len() > 25 {
40 ctx.push_field_error("options", "max 25 options".to_string());
41 }
42
43 let mut found_optional = false;
44 for option in &self.options {
45 ctx.push_field("options".to_string());
46 option.validate(ctx, &());
47 ctx.pop_field();
48
49 if !option.required {
50 found_optional = true;
51 } else if found_optional {
52 ctx.push_field_error("options", "optional options has to be last".to_string());
53 }
54 }
55 }
56}
57
58impl Validator for CommandOption {

Callers

nothing calls this directly

Calls 10

check_name_fieldFunction · 0.85
check_description_fieldFunction · 0.85
validate_option_nameFunction · 0.85
push_field_errorMethod · 0.80
push_fieldMethod · 0.80
pop_fieldMethod · 0.80
countMethod · 0.80
push_errorMethod · 0.80

Tested by

no test coverage detected