tulpje_cache/models/
role.rs1use twilight_model::{
2 guild::Role,
3 id::{
4 Id,
5 marker::{GuildMarker, RoleMarker},
6 },
7};
8
9use crate::{Cache, Error, GuildResource};
10
11pub use twilight_model::guild::Role as CachedRole;
12
13impl Cache {
14 pub(crate) async fn cache_roles(
15 &self,
16 guild_id: Id<GuildMarker>,
17 roles: impl IntoIterator<Item = Role>,
18 ) -> Result<(), Error> {
19 for role in roles {
20 self.cache_role(guild_id, role).await?;
21 }
22
23 Ok(())
24 }
25
26 pub(crate) async fn cache_role(
27 &self,
28 guild_id: Id<GuildMarker>,
29 role: Role,
30 ) -> Result<(), Error> {
31 self.guild_roles.insert(&guild_id, &role.id).await?;
32 self.roles
33 .insert(
34 &role.id.clone(),
35 &GuildResource {
36 guild_id,
37 value: role,
38 },
39 )
40 .await?;
41
42 Ok(())
43 }
44
45 pub(crate) async fn delete_role(
46 &self,
47 guild_id: Id<GuildMarker>,
48 role_id: Id<RoleMarker>,
49 ) -> Result<(), Error> {
50 self.roles.remove(&role_id).await?;
51 self.guild_roles.remove(&guild_id, &role_id).await?;
52
53 Ok(())
54 }
55}