add tag all function
This commit is contained in:
parent
3ff112b1cd
commit
6e59919c62
8 changed files with 141 additions and 31 deletions
20
src/state.rs
Normal file
20
src/state.rs
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
use once_cell::sync::Lazy;
|
||||
use std::collections::{HashMap, HashSet};
|
||||
use std::sync::RwLock;
|
||||
|
||||
static SEEN_USERS: Lazy<RwLock<HashMap<i64, HashSet<String>>>> =
|
||||
Lazy::new(|| RwLock::new(HashMap::new()));
|
||||
|
||||
pub fn track_user(chat_id: i64, username: String) {
|
||||
let mut map = SEEN_USERS.write().unwrap();
|
||||
map.entry(chat_id).or_default().insert(username);
|
||||
}
|
||||
|
||||
pub fn get_tracked_users(chat_id: i64) -> Vec<String> {
|
||||
SEEN_USERS
|
||||
.read()
|
||||
.unwrap()
|
||||
.get(&chat_id)
|
||||
.map(|s| s.iter().cloned().collect())
|
||||
.unwrap_or_default()
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue