1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54
use twilight_model::{ gateway::presence::{Activity, ClientStatus, Presence, Status, UserOrId}, id::{GuildId, UserId}, }; #[derive(Clone, Debug, Eq, PartialEq)] pub struct CachedPresence { pub activities: Vec<Activity>, pub client_status: ClientStatus, pub game: Option<Activity>, pub guild_id: Option<GuildId>, pub status: Status, pub user_id: UserId, } impl PartialEq<Presence> for CachedPresence { fn eq(&self, other: &Presence) -> bool { ( &self.activities, &self.client_status, &self.game, self.guild_id, self.status, self.user_id, ) == ( &other.activities, &other.client_status, &other.game, other.guild_id, other.status, presence_user_id(&other.user), ) } } impl From<&'_ Presence> for CachedPresence { fn from(presence: &'_ Presence) -> Self { Self { activities: presence.activities.clone(), client_status: presence.client_status.clone(), game: presence.game.clone(), guild_id: presence.guild_id, status: presence.status, user_id: presence_user_id(&presence.user), } } } fn presence_user_id(user: &UserOrId) -> UserId { match user { UserOrId::User(ref u) => u.id, UserOrId::UserId { id } => *id, } }