diff --git a/src/model/guild/emoji.rs b/src/model/guild/emoji.rs index 3ce0b01abf1..7559b8c5642 100644 --- a/src/model/guild/emoji.rs +++ b/src/model/guild/emoji.rs @@ -1,18 +1,8 @@ use std::fmt; -#[cfg(all(feature = "cache", feature = "model"))] -use crate::cache::Cache; -#[cfg(all(feature = "cache", feature = "model"))] -use crate::http::CacheHttp; -#[cfg(all(feature = "cache", feature = "model"))] -use crate::internal::prelude::*; -#[cfg(all(feature = "cache", feature = "model"))] -use crate::model::id::GuildId; use crate::model::id::{EmojiId, RoleId}; use crate::model::user::User; use crate::model::utils::default_true; -#[cfg(all(feature = "cache", feature = "model"))] -use crate::model::ModelError; /// Represents a custom guild emoji, which can either be created using the API, or via an /// integration. Emojis created using the API only work within the guild it was created in. @@ -54,115 +44,6 @@ pub struct Emoji { #[cfg(feature = "model")] impl Emoji { - /// Deletes the emoji. This method requires the cache to fetch the guild ID. - /// - /// **Note**: If the emoji was created by the current user, requires either the [Create Guild - /// Expressions] or the [Manage Guild Expressions] permission. Otherwise, the [Manage Guild - /// Expressions] permission is required. - /// - /// # Examples - /// - /// Delete a given emoji: - /// - /// ```rust,no_run - /// # use serenity::client::Context; - /// # use serenity::model::prelude::Emoji; - /// # - /// # async fn example(ctx: &Context, emoji: Emoji) -> Result<(), Box> { - /// // assuming emoji has been set already - /// match emoji.delete(&ctx).await { - /// Ok(()) => println!("Emoji deleted."), - /// Err(_) => println!("Could not delete emoji."), - /// } - /// # Ok(()) - /// # } - /// ``` - /// - /// # Errors - /// - /// Returns [`Error::Http`] if the current user lacks permission, or may return - /// [`ModelError::ItemMissing`] if the emoji is not in the cache. - /// - /// [Create Guild Expressions]: crate::model::Permissions::CREATE_GUILD_EXPRESSIONS - /// [Manage Guild Expressions]: crate::model::Permissions::MANAGE_GUILD_EXPRESSIONS - #[deprecated = "Use Guild(Id)::delete_emoji, this performs a loop over all guilds!"] - #[cfg(feature = "cache")] - #[allow(deprecated)] - #[inline] - pub async fn delete(&self, cache_http: impl CacheHttp) -> Result<()> { - let guild_id = self.try_find_guild_id(&cache_http)?; - guild_id.delete_emoji(cache_http.http(), self).await - } - - /// Edits the emoji by updating it with a new name. This method requires the cache to fetch the - /// guild ID. - /// - /// **Note**: If the emoji was created by the current user, requires either the [Create Guild - /// Expressions] or the [Manage Guild Expressions] permission. Otherwise, the [Manage Guild - /// Expressions] permission is required. - /// - /// # Errors - /// - /// Returns [`Error::Http`] if the current user lacks permission, or if an invalid name is - /// given. - /// - /// [Create Guild Expressions]: crate::model::Permissions::CREATE_GUILD_EXPRESSIONS - /// [Manage Guild Expressions]: crate::model::Permissions::MANAGE_GUILD_EXPRESSIONS - #[deprecated = "Use Guild(Id)::edit_emoji, this performs a loop over all guilds!"] - #[cfg(feature = "cache")] - #[allow(deprecated)] - pub async fn edit(&mut self, cache_http: impl CacheHttp, name: &str) -> Result<()> { - let guild_id = self.try_find_guild_id(&cache_http)?; - *self = guild_id.edit_emoji(cache_http.http(), self.id, name).await?; - Ok(()) - } - - /// Finds the [`Guild`] that owns the emoji by looking through the Cache. - /// - /// [`Guild`]: super::Guild - /// - /// # Examples - /// - /// Print the guild id that owns this emoji: - /// - /// ```rust,no_run - /// # use serenity::cache::Cache; - /// # use serenity::model::guild::Emoji; - /// # - /// # fn run(cache: Cache, emoji: Emoji) { - /// // assuming emoji has been set already - /// if let Some(guild_id) = emoji.find_guild_id(&cache) { - /// println!("{} is owned by {}", emoji.name, guild_id); - /// } - /// # } - /// ``` - #[deprecated = "This performs a loop over all guilds and should not be used."] - #[cfg(feature = "cache")] - #[allow(deprecated)] - #[must_use] - pub fn find_guild_id(&self, cache: impl AsRef) -> Option { - for guild_entry in cache.as_ref().guilds.iter() { - let guild = guild_entry.value(); - - if guild.emojis.contains_key(&self.id) { - return Some(guild.id); - } - } - - None - } - - #[deprecated = "This performs a loop over all guilds and should not be used."] - #[cfg(feature = "cache")] - #[allow(deprecated)] - #[inline] - fn try_find_guild_id(&self, cache_http: impl CacheHttp) -> Result { - cache_http - .cache() - .and_then(|c| self.find_guild_id(c)) - .ok_or(Error::Model(ModelError::ItemMissing)) - } - /// Generates a URL to the emoji's image. /// /// # Examples diff --git a/src/model/guild/guild_id.rs b/src/model/guild/guild_id.rs index 9ea1e9d4a4c..e2fa2352c94 100644 --- a/src/model/guild/guild_id.rs +++ b/src/model/guild/guild_id.rs @@ -605,8 +605,6 @@ impl GuildId { /// Edits an [`Emoji`]'s name in the guild. /// - /// Also see [`Emoji::edit`] if you have the `cache` and `methods` features enabled. - /// /// **Note**: If the emoji was created by the current user, requires either the [Create Guild /// Expressions] or the [Manage Guild Expressions] permission. Otherwise, the [Manage Guild /// Expressions] permission is required. diff --git a/src/model/guild/mod.rs b/src/model/guild/mod.rs index 840abf54b2d..112537c6cb5 100644 --- a/src/model/guild/mod.rs +++ b/src/model/guild/mod.rs @@ -1110,8 +1110,6 @@ impl Guild { /// Edits an [`Emoji`]'s name in the guild. /// - /// Also see [`Emoji::edit`] if you have the `cache` and `model` features enabled. - /// /// **Note**: If the emoji was created by the current user, requires either the [Create Guild /// Expressions] or the [Manage Guild Expressions] permission. Otherwise, the [Manage Guild /// Expressions] permission is required. diff --git a/src/model/guild/partial_guild.rs b/src/model/guild/partial_guild.rs index f01067ecb58..6205bb449c7 100644 --- a/src/model/guild/partial_guild.rs +++ b/src/model/guild/partial_guild.rs @@ -793,8 +793,6 @@ impl PartialGuild { /// Edits an [`Emoji`]'s name in the guild. /// - /// Also see [`Emoji::edit`] if you have the `cache` and `methods` features enabled. - /// /// **Note**: If the emoji was created by the current user, requires either the [Create Guild /// Expressions] or the [Manage Guild Expressions] permission. Otherwise, the [Manage Guild /// Expressions] permission is required. diff --git a/src/model/guild/role.rs b/src/model/guild/role.rs index 28ae8ac3162..9203a0d0bdc 100644 --- a/src/model/guild/role.rs +++ b/src/model/guild/role.rs @@ -3,8 +3,6 @@ use std::fmt; #[cfg(feature = "model")] use crate::builder::EditRole; -#[cfg(all(feature = "cache", feature = "model"))] -use crate::cache::Cache; #[cfg(feature = "model")] use crate::http::Http; #[cfg(all(feature = "cache", feature = "model"))] @@ -160,28 +158,6 @@ impl PartialOrd for Role { } } -#[cfg(feature = "model")] -impl RoleId { - /// Tries to find the [`Role`] by its Id in the cache. - #[cfg(feature = "cache")] - #[deprecated = "Use Guild::roles. This performs a loop over the entire cache!"] - pub fn to_role_cached(self, cache: impl AsRef) -> Option { - for guild_entry in cache.as_ref().guilds.iter() { - let guild = guild_entry.value(); - - if !guild.roles.contains_key(&self) { - continue; - } - - if let Some(role) = guild.roles.get(&self) { - return Some(role.clone()); - } - } - - None - } -} - impl From for RoleId { /// Gets the Id of a role. fn from(role: Role) -> RoleId {