| 425 | } |
| 426 | |
| 427 | fn add_hook_to_groups( |
| 428 | groups: &mut Vec<Value>, |
| 429 | command: &str, |
| 430 | status_message: Option<&str>, |
| 431 | ) -> bool { |
| 432 | if groups.iter().any(|group| group_has_command(group, command)) { |
| 433 | return false; |
| 434 | } |
| 435 | |
| 436 | let mut entry = Map::new(); |
| 437 | entry.insert("type".to_string(), Value::String("command".to_string())); |
| 438 | entry.insert("command".to_string(), Value::String(command.to_string())); |
| 439 | if let Some(message) = status_message { |
| 440 | entry.insert( |
| 441 | "statusMessage".to_string(), |
| 442 | Value::String(message.to_string()), |
| 443 | ); |
| 444 | } |
| 445 | |
| 446 | let mut group = Map::new(); |
| 447 | group.insert( |
| 448 | "hooks".to_string(), |
| 449 | Value::Array(vec![Value::Object(entry)]), |
| 450 | ); |
| 451 | groups.push(Value::Object(group)); |
| 452 | true |
| 453 | } |
| 454 | |
| 455 | fn group_has_command(group: &Value, command: &str) -> bool { |
| 456 | group |