Apply manual clippy

This commit is contained in:
Natsu Kagami 2024-08-04 22:42:44 +02:00
parent b9f6fa7fb8
commit 6458454ba9
Signed by: nki
GPG key ID: 55A032EB38B49ADB
4 changed files with 58 additions and 60 deletions

View file

@ -8,7 +8,7 @@ use serenity::{
}, },
model::channel::{Channel, Message}, model::channel::{Channel, Message},
}; };
use std::string::ToString; use std::fmt::Display;
use youmubot_prelude::*; use youmubot_prelude::*;
#[command] #[command]
@ -108,8 +108,7 @@ async fn get_image(
let req = client let req = client
.get(format!( .get(format!(
"https://danbooru.donmai.us/posts.json?tags=rating:{}+{}", "https://danbooru.donmai.us/posts.json?tags=rating:{}+{}",
rating.to_string(), rating, tags
tags
)) ))
.query(&[("limit", "50"), ("random", "true")]) .query(&[("limit", "50"), ("random", "true")])
.build()?; .build()?;
@ -133,13 +132,12 @@ enum Rating {
Safe, Safe,
} }
impl ToString for Rating { impl Display for Rating {
fn to_string(&self) -> String { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
use Rating::*; use Rating::*;
match self { f.write_str(match self {
Explicit => "explicit", Explicit => "explicit",
Safe => "safe", Safe => "safe",
} })
.to_owned()
} }
} }

View file

@ -34,11 +34,11 @@ mod scores {
} }
impl ScoreListStyle { impl ScoreListStyle {
pub async fn display_scores<'a>( pub async fn display_scores(
self, self,
scores: Vec<Score>, scores: Vec<Score>,
mode: Mode, mode: Mode,
ctx: &'a Context, ctx: &Context,
guild_id: Option<GuildId>, guild_id: Option<GuildId>,
m: Message, m: Message,
) -> Result<()> { ) -> Result<()> {
@ -63,10 +63,10 @@ mod scores {
use crate::discord::{cache::save_beatmap, BeatmapWithMode, OsuEnv}; use crate::discord::{cache::save_beatmap, BeatmapWithMode, OsuEnv};
use crate::models::{Mode, Score}; use crate::models::{Mode, Score};
pub async fn display_scores_grid<'a>( pub async fn display_scores_grid(
scores: Vec<Score>, scores: Vec<Score>,
mode: Mode, mode: Mode,
ctx: &'a Context, ctx: &Context,
guild_id: Option<GuildId>, guild_id: Option<GuildId>,
mut on: Message, mut on: Message,
) -> Result<()> { ) -> Result<()> {
@ -153,10 +153,10 @@ mod scores {
use crate::discord::{Beatmap, BeatmapInfo, OsuEnv}; use crate::discord::{Beatmap, BeatmapInfo, OsuEnv};
use crate::models::{Mode, Score}; use crate::models::{Mode, Score};
pub async fn display_scores_table<'a>( pub async fn display_scores_table(
scores: Vec<Score>, scores: Vec<Score>,
mode: Mode, mode: Mode,
ctx: &'a Context, ctx: &Context,
mut on: Message, mut on: Message,
) -> Result<()> { ) -> Result<()> {
if scores.is_empty() { if scores.is_empty() {
@ -298,8 +298,7 @@ mod scores {
}) })
.collect::<Vec<_>>(); .collect::<Vec<_>>();
const SCORE_HEADERS: [&str; 6] = const SCORE_HEADERS: [&str; 6] = ["#", "PP", "Acc", "Ranks", "Mods", "Beatmap"];
["#", "PP", "Acc", "Ranks", "Mods", "Beatmap"];
const SCORE_ALIGNS: [Align; 6] = [Right, Right, Right, Right, Right, Left]; const SCORE_ALIGNS: [Align; 6] = [Right, Right, Right, Right, Right, Left];
let score_arr = plays let score_arr = plays

View file

@ -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 chrono::DateTime;
use pagination::paginate_with_first_message; use pagination::paginate_with_first_message;
@ -139,8 +139,9 @@ pub async fn server_rank(ctx: &Context, m: &Message, mut args: Args) -> CommandR
} }
}) })
.min(); .min();
let sort_fn: Box<dyn Fn(&(Member, OsuUser), &(Member, OsuUser)) -> std::cmp::Ordering> = type Item = (Member, OsuUser);
match query { #[allow(clippy::type_complexity)]
let sort_fn: Box<dyn Fn(&Item, &Item) -> Ordering> = match query {
RankQuery::PP => Box::new(|(_, a), (_, b)| { RankQuery::PP => Box::new(|(_, a), (_, b)| {
a.modes a.modes
.get(&mode) .get(&mode)
@ -465,7 +466,7 @@ pub async fn get_leaderboard(
OrderBy::PP => scores.sort_by(|a, b| { OrderBy::PP => scores.sort_by(|a, b| {
(b.official, b.pp) (b.official, b.pp)
.partial_cmp(&(a.official, a.pp)) .partial_cmp(&(a.official, a.pp))
.unwrap_or(std::cmp::Ordering::Equal) .unwrap_or(Ordering::Equal)
}), }),
OrderBy::Score => { OrderBy::Score => {
scores.sort_by(|a, b| b.score.normalized_score.cmp(&a.score.normalized_score)) scores.sort_by(|a, b| b.score.normalized_score.cmp(&a.score.normalized_score))

View file

@ -241,7 +241,7 @@ pub async fn paginate_with_first_message(
}; };
for reaction in reactions { 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. // probably no permission to delete all reactions, fall back to delete my own.
reaction.delete(&ctx).await.pls_ok(); reaction.delete(&ctx).await.pls_ok();
} }