Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove more deprecated items #2651

Merged
merged 1 commit into from
Dec 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
119 changes: 0 additions & 119 deletions src/model/guild/emoji.rs
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -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<dyn std::error::Error>> {
/// // 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<Cache>) -> Option<GuildId> {
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<GuildId> {
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
Expand Down
2 changes: 0 additions & 2 deletions src/model/guild/guild_id.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 0 additions & 2 deletions src/model/guild/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 0 additions & 2 deletions src/model/guild/partial_guild.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
24 changes: 0 additions & 24 deletions src/model/guild/role.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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"))]
Expand Down Expand Up @@ -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<Cache>) -> Option<Role> {
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<Role> for RoleId {
/// Gets the Id of a role.
fn from(role: Role) -> RoleId {
Expand Down