Move member avatar url into utils

This commit is contained in:
2025-02-02 22:45:53 +00:00
parent e11eb9bd49
commit f4dccd65b2
2 changed files with 18 additions and 14 deletions

View File

@@ -6,7 +6,6 @@ use serenity::all::CreateEmbed;
use crate::app::AppContext; use crate::app::AppContext;
use crate::app::AppError; use crate::app::AppError;
use crate::utils;
mod codes; mod codes;
@@ -57,14 +56,11 @@ async fn show<R: RepositoryProvider + Send + Sync>(
}, },
}; };
let avatar_url = member.avatar_url() let avatar_url = crate::utils::member_avatar_url(&member);
.or_else(|| member.user.avatar_url())
.or_else(|| member.user.static_avatar_url())
.unwrap_or_else(|| member.user.default_avatar_url());
let embed_color = match member.colour(ctx) { let embed_color = match member.colour(ctx) {
Some(color) => color, Some(color) => color,
None => utils::bot_color(&ctx).await, None => crate::utils::bot_color(&ctx).await,
}; };
let mut embed = CreateEmbed::new() let mut embed = CreateEmbed::new()

View File

@@ -1,13 +1,11 @@
use cipher_core::repository::RepositoryProvider; use cipher_core::repository::RepositoryProvider;
use serenity::all::{Color, GuildId}; use serenity::all::Color;
use serenity::all::GuildId;
use serenity::all::Member;
use crate::app::{AppCommand, AppContext, AppError}; use crate::app::{AppCommand, AppContext, AppError};
pub async fn register_in_guilds<R>( pub async fn register_in_guilds<R>(serenity_ctx: &serenity::client::Context, commands: &[AppCommand<R, R::BackendError>], guilds: &[GuildId])
serenity_ctx: &serenity::client::Context,
commands: &[AppCommand<R, R::BackendError>],
guilds: &[GuildId],
)
where where
R: RepositoryProvider, R: RepositoryProvider,
{ {
@@ -34,7 +32,9 @@ where
member.and_then(|m| m.colour(ctx)).unwrap_or(Color::BLURPLE) member.and_then(|m| m.colour(ctx)).unwrap_or(Color::BLURPLE)
} }
pub async fn bot_avatar_url<R>(ctx: &AppContext<'_, R, R::BackendError>) -> Result<String, AppError<R::BackendError>> pub async fn bot_avatar_url<R>(
ctx: &AppContext<'_, R, R::BackendError>,
) -> Result<String, AppError<R::BackendError>>
where where
R: RepositoryProvider + Send + Sync, R: RepositoryProvider + Send + Sync,
{ {
@@ -50,8 +50,16 @@ where
user.avatar_url() user.avatar_url()
.or_else(|| user.static_avatar_url()) .or_else(|| user.static_avatar_url())
.unwrap_or_else(|| user.default_avatar_url()) .unwrap_or_else(|| user.default_avatar_url())
}, }
}; };
Ok(avatar_url) Ok(avatar_url)
} }
pub fn member_avatar_url(member: &Member) -> String {
member
.avatar_url()
.or_else(|| member.user.avatar_url())
.or_else(|| member.user.static_avatar_url())
.unwrap_or_else(|| member.user.default_avatar_url())
}