Add colors update

This commit is contained in:
2025-08-24 20:03:52 -03:00
parent 39120a65fa
commit 3f5ec4f258
13 changed files with 1304 additions and 50 deletions
+19 -2
View File
@@ -13,10 +13,17 @@ use twilight_model::util::ImageHash;
///
/// Returns:
/// [`String`] - The URL of the user's avatar.
pub fn get_avatar_url(hash: Option<ImageHash>, user_id: u64, discriminator: u64, guild_id: Option<u64>) -> String {
pub fn get_avatar_url(
hash: Option<ImageHash>,
user_id: u64,
discriminator: u64,
guild_id: Option<u64>,
) -> String {
if let Some(hash) = hash {
if let Some(guild_id) = guild_id {
return format!("https://cdn.discordapp.com/guilds/{guild_id}/users/{user_id}/avatars/{hash}.webp?size=256");
return format!(
"https://cdn.discordapp.com/guilds/{guild_id}/users/{user_id}/avatars/{hash}.webp?size=256"
);
}
format!("https://cdn.discordapp.com/avatars/{user_id}/{hash}.webp?size=256")
@@ -30,3 +37,13 @@ pub fn get_avatar_url(hash: Option<ImageHash>, user_id: u64, discriminator: u64,
)
}
}
/// Returns the user's avatar URL only if it's custom (i.e. not the default avatar). It doesn't
/// take into account custom per-server avatars, i.e. only the global avatar is returned if any.
///
/// Arguments:
/// * `user_id` - The user's ID.
/// * `hash` - The hex-encoded hash string, if any.
pub fn get_user_custom_avatar_url_or_none(user_id: u64, hash: String) -> String {
format!("https://cdn.discordapp.com/avatars/{user_id}/{hash}.webp?size=256")
}