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

Function check_name_field

components/validation/src/runtime.rs:91–117  ·  view source on GitHub ↗
(ctx: &mut ValidationContext, field: &str, value: &str, chat_command: bool)

Source from the content-addressed store, hash-verified

89}
90
91fn check_name_field(ctx: &mut ValidationContext, field: &str, value: &str, chat_command: bool) {
92 if value.chars().count() < 1 {
93 ctx.push_field_error(field, "has to be atleast 1 character".to_string());
94 }
95 if value.chars().count() > 32 {
96 ctx.push_field_error(field, "can be max 32 characters long".to_string());
97 }
98
99 lazy_static! {
100 static ref RE: Regex = Regex::new(r#"^[\w-]+$"#).unwrap();
101 static ref RERelaxed: Regex = Regex::new(r#"^[\w -]+$"#).unwrap();
102 }
103
104 if chat_command {
105 if !RE.is_match(value) {
106 ctx.push_field_error(field, "can only contain 'word' characters".to_string());
107 }
108
109 if value.to_lowercase() != value {
110 ctx.push_field_error(field, "has to be lower-case".to_string());
111 }
112 } else {
113 if !RERelaxed.is_match(value) {
114 ctx.push_field_error(field, "can only contain 'word or space' characters".to_string());
115 }
116 }
117}
118
119fn check_description_field(ctx: &mut ValidationContext, field: &str, value: &str) {
120 if value.chars().count() < 1 {

Callers 1

validateMethod · 0.85

Calls 2

countMethod · 0.80
push_field_errorMethod · 0.80

Tested by

no test coverage detected