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