diff --git a/youmubot-core/src/fun/images.rs b/youmubot-core/src/fun/images.rs index 0bc9a2f..4257fe2 100644 --- a/youmubot-core/src/fun/images.rs +++ b/youmubot-core/src/fun/images.rs @@ -8,7 +8,7 @@ use serenity::{ }, model::channel::{Channel, Message}, }; -use std::string::ToString; +use std::fmt::Display; use youmubot_prelude::*; #[command] @@ -108,8 +108,7 @@ async fn get_image( let req = client .get(format!( "https://danbooru.donmai.us/posts.json?tags=rating:{}+{}", - rating.to_string(), - tags + rating, tags )) .query(&[("limit", "50"), ("random", "true")]) .build()?; @@ -133,13 +132,12 @@ enum Rating { Safe, } -impl ToString for Rating { - fn to_string(&self) -> String { +impl Display for Rating { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { use Rating::*; - match self { + f.write_str(match self { Explicit => "explicit", Safe => "safe", - } - .to_owned() + }) } } diff --git a/youmubot-osu/src/discord/display.rs b/youmubot-osu/src/discord/display.rs index 6d306bc..9d78b95 100644 --- a/youmubot-osu/src/discord/display.rs +++ b/youmubot-osu/src/discord/display.rs @@ -34,11 +34,11 @@ mod scores { } impl ScoreListStyle { - pub async fn display_scores<'a>( + pub async fn display_scores( self, scores: Vec, mode: Mode, - ctx: &'a Context, + ctx: &Context, guild_id: Option, m: Message, ) -> Result<()> { @@ -63,10 +63,10 @@ mod scores { use crate::discord::{cache::save_beatmap, BeatmapWithMode, OsuEnv}; use crate::models::{Mode, Score}; - pub async fn display_scores_grid<'a>( + pub async fn display_scores_grid( scores: Vec, mode: Mode, - ctx: &'a Context, + ctx: &Context, guild_id: Option, mut on: Message, ) -> Result<()> { @@ -153,10 +153,10 @@ mod scores { use crate::discord::{Beatmap, BeatmapInfo, OsuEnv}; use crate::models::{Mode, Score}; - pub async fn display_scores_table<'a>( + pub async fn display_scores_table( scores: Vec, mode: Mode, - ctx: &'a Context, + ctx: &Context, mut on: Message, ) -> Result<()> { if scores.is_empty() { @@ -298,8 +298,7 @@ mod scores { }) .collect::>(); - const SCORE_HEADERS: [&str; 6] = - ["#", "PP", "Acc", "Ranks", "Mods", "Beatmap"]; + const SCORE_HEADERS: [&str; 6] = ["#", "PP", "Acc", "Ranks", "Mods", "Beatmap"]; const SCORE_ALIGNS: [Align; 6] = [Right, Right, Right, Right, Right, Left]; let score_arr = plays diff --git a/youmubot-osu/src/discord/server_rank.rs b/youmubot-osu/src/discord/server_rank.rs index 0166cc5..75fca05 100644 --- a/youmubot-osu/src/discord/server_rank.rs +++ b/youmubot-osu/src/discord/server_rank.rs @@ -1,4 +1,4 @@ -use std::{borrow::Cow, collections::HashMap, str::FromStr, sync::Arc}; +use std::{borrow::Cow, cmp::Ordering, collections::HashMap, str::FromStr, sync::Arc}; use chrono::DateTime; use pagination::paginate_with_first_message; @@ -139,47 +139,48 @@ pub async fn server_rank(ctx: &Context, m: &Message, mut args: Args) -> CommandR } }) .min(); - let sort_fn: Box std::cmp::Ordering> = - match query { - RankQuery::PP => Box::new(|(_, a), (_, b)| { - a.modes - .get(&mode) - .map(|v| v.pp) - .partial_cmp(&b.modes.get(&mode).map(|v| v.pp)) - .unwrap() - .reverse() - }), - RankQuery::TotalPP => Box::new(|(_, a), (_, b)| { - a.modes - .values() - .map(|v| v.pp) - .sum::() - .partial_cmp(&b.modes.values().map(|v| v.pp).sum()) - .unwrap() - .reverse() - }), - RankQuery::MapLength => Box::new(|(_, a), (_, b)| { - a.modes - .get(&mode) - .map(|v| v.map_length) - .partial_cmp(&b.modes.get(&mode).map(|v| v.map_length)) - .unwrap() - .reverse() - }), - RankQuery::MapAge { newest_first } => Box::new(move |(_, a), (_, b)| { - let r = a - .modes - .get(&mode) - .map(|v| v.map_age) - .partial_cmp(&b.modes.get(&mode).map(|v| v.map_age)) - .unwrap(); - if newest_first { - r.reverse() - } else { - r - } - }), - }; + type Item = (Member, OsuUser); + #[allow(clippy::type_complexity)] + let sort_fn: Box Ordering> = match query { + RankQuery::PP => Box::new(|(_, a), (_, b)| { + a.modes + .get(&mode) + .map(|v| v.pp) + .partial_cmp(&b.modes.get(&mode).map(|v| v.pp)) + .unwrap() + .reverse() + }), + RankQuery::TotalPP => Box::new(|(_, a), (_, b)| { + a.modes + .values() + .map(|v| v.pp) + .sum::() + .partial_cmp(&b.modes.values().map(|v| v.pp).sum()) + .unwrap() + .reverse() + }), + RankQuery::MapLength => Box::new(|(_, a), (_, b)| { + a.modes + .get(&mode) + .map(|v| v.map_length) + .partial_cmp(&b.modes.get(&mode).map(|v| v.map_length)) + .unwrap() + .reverse() + }), + RankQuery::MapAge { newest_first } => Box::new(move |(_, a), (_, b)| { + let r = a + .modes + .get(&mode) + .map(|v| v.map_age) + .partial_cmp(&b.modes.get(&mode).map(|v| v.map_age)) + .unwrap(); + if newest_first { + r.reverse() + } else { + r + } + }), + }; users.sort_unstable_by(sort_fn); if users.is_empty() { @@ -465,7 +466,7 @@ pub async fn get_leaderboard( OrderBy::PP => scores.sort_by(|a, b| { (b.official, b.pp) .partial_cmp(&(a.official, a.pp)) - .unwrap_or(std::cmp::Ordering::Equal) + .unwrap_or(Ordering::Equal) }), OrderBy::Score => { scores.sort_by(|a, b| b.score.normalized_score.cmp(&a.score.normalized_score)) diff --git a/youmubot-prelude/src/pagination.rs b/youmubot-prelude/src/pagination.rs index c10cf63..ec6cd3f 100644 --- a/youmubot-prelude/src/pagination.rs +++ b/youmubot-prelude/src/pagination.rs @@ -241,7 +241,7 @@ pub async fn paginate_with_first_message( }; for reaction in reactions { - if let None = reaction.delete_all(&ctx).await.pls_ok() { + if reaction.delete_all(&ctx).await.pls_ok().is_none() { // probably no permission to delete all reactions, fall back to delete my own. reaction.delete(&ctx).await.pls_ok(); }