add edit/delete game capabilities
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
use crate::items::{Game, Person};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use std::collections::HashSet;
|
||||
use std::fs::File;
|
||||
use std::io::BufReader;
|
||||
|
||||
@@ -30,6 +31,7 @@ pub struct PersistentState {
|
||||
}
|
||||
|
||||
pub const STATE_FILE: &str = "state.json";
|
||||
pub const ADMINS_FILE: &str = "admins.json";
|
||||
|
||||
pub fn save_state(games: &[Game], users: &[User]) {
|
||||
let mut games = games.to_vec();
|
||||
@@ -57,3 +59,17 @@ pub fn load_state() -> Option<(Vec<Game>, Vec<User>)> {
|
||||
}
|
||||
None
|
||||
}
|
||||
|
||||
pub fn load_admins() -> HashSet<String> {
|
||||
if let Ok(file) = File::open(ADMINS_FILE) {
|
||||
let reader = BufReader::new(file);
|
||||
if let Ok(admins) = serde_json::from_reader::<_, Vec<String>>(reader) {
|
||||
return admins.into_iter().map(|s| s.to_lowercase()).collect();
|
||||
}
|
||||
}
|
||||
HashSet::new()
|
||||
}
|
||||
|
||||
pub fn is_admin(username: &str, admins: &HashSet<String>) -> bool {
|
||||
admins.contains(&username.to_lowercase())
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user