restarting project
This commit is contained in:
66
src/check_permissions/mod.rs
Normal file
66
src/check_permissions/mod.rs
Normal file
@@ -0,0 +1,66 @@
|
||||
use std::fs;
|
||||
use std::collections::LinkedList;
|
||||
use std::sync::Mutex;
|
||||
use std::sync::RwLock;
|
||||
use once_cell::sync::Lazy;
|
||||
|
||||
#[cfg(not(debug_assertions))]
|
||||
const ALLOW_PATH : &str ="/opt/mini_admin_bot/allow_users";
|
||||
#[cfg(not(debug_assertions))]
|
||||
const POLE_PATH : &str ="/opt/mini_admin_bot/allow_pole";
|
||||
|
||||
#[cfg(debug_assertions)]
|
||||
const ALLOW_PATH : &str ="allow_users";
|
||||
#[cfg(debug_assertions)]
|
||||
const POLE_PATH : &str ="allow_pole";
|
||||
|
||||
static mut LIST_IDS: Lazy<Mutex<LinkedList<String>>> = Lazy::new(|| Mutex::new(read_ids(ALLOW_PATH)));
|
||||
|
||||
static mut LIST_POLE_IDS: Lazy<Mutex<LinkedList<String>>> = Lazy::new(|| Mutex::new(read_ids(POLE_PATH)));
|
||||
|
||||
fn read_ids<'a>(path: &str)-> LinkedList<String> {
|
||||
let content = fs::read_to_string(path).expect("Something went wrong reading the file");
|
||||
content.split('\n').into_iter().map(|item| format!("{}", item)).collect::<LinkedList<String>>()
|
||||
}
|
||||
|
||||
pub struct group_permissions {
|
||||
aproved_groups: RwLock<LinkedList<String>>,
|
||||
party_groups: RwLock<LinkedList<String>>,
|
||||
}
|
||||
|
||||
impl group_permissions {
|
||||
pub fn new() -> Self {
|
||||
Self{
|
||||
aproved_groups: RwLock::new(read_ids(ALLOW_PATH)),
|
||||
party_groups: RwLock::new(read_ids(POLE_PATH)),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn compare(&self, id: &String) -> bool {
|
||||
self.aproved_groups.read().unwrap().contains(id)
|
||||
}
|
||||
|
||||
pub fn compar_party(&self, id: &String) -> bool {
|
||||
self.party_groups.read().unwrap().contains(id)
|
||||
}
|
||||
}
|
||||
|
||||
pub fn compare(id: &String) -> bool{
|
||||
let ret: bool;
|
||||
unsafe {
|
||||
ret=LIST_IDS.lock().unwrap().contains(id);
|
||||
log::info!("{}",id);
|
||||
|
||||
}
|
||||
ret
|
||||
}
|
||||
|
||||
pub fn compare_pole(id: &String) -> bool{
|
||||
let ret: bool;
|
||||
unsafe {
|
||||
ret=LIST_POLE_IDS.lock().unwrap().contains(id);
|
||||
log::info!("{}",id);
|
||||
|
||||
}
|
||||
ret
|
||||
}
|
||||
Reference in New Issue
Block a user