mirror of
https://github.com/natsukagami/youmubot.git
synced 2025-04-16 07:18:54 +00:00
Apply manual clippy
This commit is contained in:
parent
b9f6fa7fb8
commit
6458454ba9
4 changed files with 58 additions and 60 deletions
|
@ -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()
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
|
@ -34,11 +34,11 @@ mod scores {
|
|||
}
|
||||
|
||||
impl ScoreListStyle {
|
||||
pub async fn display_scores<'a>(
|
||||
pub async fn display_scores(
|
||||
self,
|
||||
scores: Vec<Score>,
|
||||
mode: Mode,
|
||||
ctx: &'a Context,
|
||||
ctx: &Context,
|
||||
guild_id: Option<GuildId>,
|
||||
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<Score>,
|
||||
mode: Mode,
|
||||
ctx: &'a Context,
|
||||
ctx: &Context,
|
||||
guild_id: Option<GuildId>,
|
||||
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<Score>,
|
||||
mode: Mode,
|
||||
ctx: &'a Context,
|
||||
ctx: &Context,
|
||||
mut on: Message,
|
||||
) -> Result<()> {
|
||||
if scores.is_empty() {
|
||||
|
@ -298,8 +298,7 @@ mod scores {
|
|||
})
|
||||
.collect::<Vec<_>>();
|
||||
|
||||
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
|
||||
|
|
|
@ -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<dyn Fn(&(Member, OsuUser), &(Member, OsuUser)) -> 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::<f64>()
|
||||
.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<dyn Fn(&Item, &Item) -> 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::<f64>()
|
||||
.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))
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue