diff --git a/discord-frontend/hartex-discord-entitycache-entities/src/member.rs b/discord-frontend/hartex-discord-entitycache-entities/src/member.rs index 8218b19f2..bce314925 100644 --- a/discord-frontend/hartex-discord-entitycache-entities/src/member.rs +++ b/discord-frontend/hartex-discord-entitycache-entities/src/member.rs @@ -22,6 +22,7 @@ use hartex_discord_core::discord::model::guild::Member; use hartex_discord_core::discord::model::id::marker::GuildMarker; +use hartex_discord_core::discord::model::id::marker::RoleMarker; use hartex_discord_core::discord::model::id::marker::UserMarker; use hartex_discord_core::discord::model::id::Id; use hartex_discord_entitycache_core::Entity; @@ -31,6 +32,7 @@ use hartex_discord_entitycache_core::Entity; pub struct MemberEntity { #[entity(id)] pub guild_id: Id, + pub roles: Vec>, #[entity(id)] pub user_id: Id, } @@ -39,6 +41,7 @@ impl From<(Member, Id)> for MemberEntity { fn from((member, guild_id): (Member, Id)) -> Self { Self { guild_id, + roles: member.roles, user_id: member.user.id, } } diff --git a/discord-frontend/hartex-discord-entitycache-repositories/src/member.rs b/discord-frontend/hartex-discord-entitycache-repositories/src/member.rs index a4a8bc6c7..137b161ba 100644 --- a/discord-frontend/hartex-discord-entitycache-repositories/src/member.rs +++ b/discord-frontend/hartex-discord-entitycache-repositories/src/member.rs @@ -21,8 +21,10 @@ */ use std::env; +use std::str::FromStr; use hartex_discord_core::discord::model::id::marker::GuildMarker; +use hartex_discord_core::discord::model::id::marker::RoleMarker; use hartex_discord_core::discord::model::id::marker::UserMarker; use hartex_discord_core::discord::model::id::Id; use hartex_discord_entitycache_core::error::CacheResult; @@ -72,7 +74,18 @@ impl Repository for CachedMemberRepository { &self, (guild_id, user_id): ::Id, ) -> CacheResult { - Ok(MemberEntity { guild_id, user_id }) + let pass = env::var("DOCKER_REDIS_REQUIREPASS")?; + let client = Client::open(format!("redis://:{pass}@127.0.0.1/"))?; + let mut connection = client.get_tokio_connection().await?; + + let roles = connection + .get::(format!("guild:{guild_id}:member:{user_id}:roles")) + .await? + .split(',') + .map(|str| Id::::from_str(str).unwrap()) + .collect::>(); + + Ok(MemberEntity { guild_id, roles, user_id }) } async fn upsert(&self, entity: MemberEntity) -> CacheResult<()> { @@ -88,6 +101,20 @@ impl Repository for CachedMemberRepository { entity.user_id.get(), ) .await?; + connection + .set( + format!( + "guild:{}:member:{}:roles", + entity.guild_id, entity.user_id + ), + entity + .roles + .into_iter() + .map(|id| id.to_string()) + .collect::>() + .join(",") + ) + .await?; Ok(()) }