tulpje_cache/models/
stage_instance.rs

1use twilight_model::{
2    channel::StageInstance,
3    id::{
4        Id,
5        marker::{GuildMarker, StageMarker},
6    },
7};
8
9use crate::{Cache, Error, GuildResource};
10
11pub use twilight_model::channel::StageInstance as CachedStageInstance;
12
13impl Cache {
14    pub(crate) async fn cache_stage_instances(
15        &self,
16        guild_id: Id<GuildMarker>,
17        stage_instances: impl IntoIterator<Item = StageInstance>,
18    ) -> Result<(), Error> {
19        for stage_instance in stage_instances {
20            self.cache_stage_instance(guild_id, stage_instance).await?;
21        }
22
23        Ok(())
24    }
25
26    pub(crate) async fn cache_stage_instance(
27        &self,
28        guild_id: Id<GuildMarker>,
29        stage_instance: StageInstance,
30    ) -> Result<(), Error> {
31        self.guild_stage_instances
32            .insert(&guild_id, &stage_instance.id)
33            .await?;
34
35        self.stage_instances
36            .insert(
37                &stage_instance.id.clone(),
38                &GuildResource {
39                    guild_id,
40                    value: stage_instance,
41                },
42            )
43            .await?;
44
45        Ok(())
46    }
47
48    pub(crate) async fn delete_stage_instance(
49        &self,
50        guild_id: Id<GuildMarker>,
51        stage_id: Id<StageMarker>,
52    ) -> Result<(), Error> {
53        self.stage_instances.remove(&stage_id).await?;
54        self.guild_stage_instances
55            .remove(&guild_id, &stage_id)
56            .await?;
57
58        Ok(())
59    }
60}