Minor changes on user embed

This commit is contained in:
Natsu Kagami 2020-02-06 14:15:34 -05:00
parent 7c77b7fd61
commit 28ed92eb2f
Signed by: nki
GPG key ID: 73376E117CD20735
3 changed files with 25 additions and 6 deletions

View file

@ -9,4 +9,7 @@ edition = "2018"
serde = { version = "1", features = ["derive"] }
reqwest = "0.10.1"
serenity = "0.8"
Inflector = "0.11"
codeforces = { git = "https://github.com/natsukagami/rust-codeforces-api" }
youmubot-prelude = { path = "../youmubot-prelude" }

View file

@ -1,4 +1,5 @@
use codeforces::{Contest, RatingChange, User};
use inflector::Inflector;
use serenity::{builder::CreateEmbed, utils::MessageBuilder};
use std::borrow::Borrow;
@ -8,8 +9,8 @@ fn unwrap_or_ref<'a, T: ?Sized, B: Borrow<T>>(opt: &'a Option<B>, default: &'a T
/// Create an embed representing the user.
pub fn user_embed<'a>(user: &User, e: &'a mut CreateEmbed) -> &'a mut CreateEmbed {
let rank = unwrap_or_ref(&user.rank, "Unranked");
let max_rank = unwrap_or_ref(&user.max_rank, "Unranked");
let rank = unwrap_or_ref(&user.rank, "Unranked").to_title_case();
let max_rank = unwrap_or_ref(&user.max_rank, "Unranked").to_title_case();
let rating = user.rating.unwrap_or(1500);
let max_rating = user.max_rating.unwrap_or(1500);
let name = &[&user.first_name, &user.last_name]
@ -21,10 +22,12 @@ pub fn user_embed<'a>(user: &User, e: &'a mut CreateEmbed) -> &'a mut CreateEmbe
.iter()
.filter_map(|v| v.as_ref().map(|v| v.as_str()))
.collect::<Vec<_>>()
.join(" ");
.join(", ");
e.color(user.color())
.author(|a| a.name(rank))
.author(|a| a.name(&rank))
.thumbnail(format!("https:{}", user.title_photo))
.title(&user.handle)
.url(user.profile_url())
.description(format!(
"{}\n{}",
if name == "" {
@ -46,7 +49,7 @@ pub fn user_embed<'a>(user: &User, e: &'a mut CreateEmbed) -> &'a mut CreateEmbe
.field("Contribution", format!("**{}**", user.contribution), true)
.field(
"Rank",
format!("**{}** (max **{}**)", rank, max_rank),
format!("**{}** (max **{}**)", &rank, max_rank),
false,
)
}