use regex::Regex; use twilight_http::Client; use twilight_gateway::Shard; use twilight_mention::ParseMention; use twilight_model::id::{marker::UserMarker, Id}; use std::sync::Arc; use tokio::sync::Mutex; #[derive(Clone)] pub struct Member { pub name: String, pub discord_token: String, pub user_id: Arc>>>, pub message_pattern: Regex, pub shard: Arc>, pub client: Arc>, } #[derive(Clone)] pub struct System { pub followed_user: Id, pub command_prefix: String, pub members: Vec } #[derive(Clone)] pub enum Response { Proxy {member: Member, content: String}, Noop {delete_source: bool}, } pub enum SystemThreadCommand { Restart, ReloadConfig, ShutdownSystem, ShutdownAll, } impl System { pub async fn resolve_mention<'system>(&'system self, maybe_mention: Option<&str>) -> Option<&'system Member> { if let Some(mention) = maybe_mention { if let Ok(mention) = Id::::parse(mention) { for member in &self.members { let is_member = {member.user_id.lock().await.map(|id| id == mention).unwrap_or(false)}; if is_member { return Some(&member) } } } } None } }