mirror of
https://github.com/natsukagami/youmubot.git
synced 2025-04-16 07:18:54 +00:00
Minor changes on user embed
This commit is contained in:
parent
7c77b7fd61
commit
28ed92eb2f
3 changed files with 25 additions and 6 deletions
15
Cargo.lock
generated
15
Cargo.lock
generated
|
@ -1,5 +1,14 @@
|
|||
# This file is automatically @generated by Cargo.
|
||||
# It is not intended for manual editing.
|
||||
[[package]]
|
||||
name = "Inflector"
|
||||
version = "0.11.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"regex 1.3.3 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "adler32"
|
||||
version = "1.0.4"
|
||||
|
@ -154,7 +163,7 @@ dependencies = [
|
|||
[[package]]
|
||||
name = "codeforces"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/natsukagami/rust-codeforces-api#2eb51a5ee5eb10b725ffbb33a4250a052eb6c60f"
|
||||
source = "git+https://github.com/natsukagami/rust-codeforces-api#093c9fdb40d369a1390918d982d2bff55c984c81"
|
||||
dependencies = [
|
||||
"reqwest 0.10.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"serde 1.0.104 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
|
@ -1688,6 +1697,7 @@ version = "0.1.0"
|
|||
dependencies = [
|
||||
"dotenv 0.15.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"serenity 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"youmubot-cf 0.1.0",
|
||||
"youmubot-core 0.1.0",
|
||||
"youmubot-db 0.1.0",
|
||||
"youmubot-osu 0.1.0",
|
||||
|
@ -1698,10 +1708,12 @@ dependencies = [
|
|||
name = "youmubot-cf"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"Inflector 0.11.4 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"codeforces 0.1.0 (git+https://github.com/natsukagami/rust-codeforces-api)",
|
||||
"reqwest 0.10.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"serde 1.0.104 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"serenity 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"youmubot-prelude 0.1.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
@ -1756,6 +1768,7 @@ dependencies = [
|
|||
]
|
||||
|
||||
[metadata]
|
||||
"checksum Inflector 0.11.4 (registry+https://github.com/rust-lang/crates.io-index)" = "fe438c63458706e03479442743baae6c88256498e6431708f6dfc520a26515d3"
|
||||
"checksum adler32 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)" = "5d2e7343e7fc9de883d1b0341e0b13970f764c14101234857d2ddafa1cb1cac2"
|
||||
"checksum aho-corasick 0.7.6 (registry+https://github.com/rust-lang/crates.io-index)" = "58fb5e95d83b38284460a5fda7d6470aa0b8844d283a0b614b8535e880800d2d"
|
||||
"checksum anyhow 1.0.26 (registry+https://github.com/rust-lang/crates.io-index)" = "7825f6833612eb2414095684fcf6c635becf3ce97fe48cf6421321e93bfbd53c"
|
||||
|
|
|
@ -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" }
|
||||
|
|
|
@ -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,
|
||||
)
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue