diff --git a/youmubot-cf/src/lib.rs b/youmubot-cf/src/lib.rs index 0b90613..d49da9b 100644 --- a/youmubot-cf/src/lib.rs +++ b/youmubot-cf/src/lib.rs @@ -192,7 +192,7 @@ pub async fn ranks(ctx: &Context, m: &Message) -> CommandResult { } let ranks = &ranks[start..end]; - const HEADERS: [&'static str; 4] = ["Rank", "Rating", "Handle", "Username"]; + const HEADERS: [&str; 4] = ["Rank", "Rating", "Handle", "Username"]; const ALIGNS: [Align; 4] = [Right, Right, Left, Left]; let ranks_arr = ranks @@ -354,11 +354,11 @@ pub(crate) async fn contest_rank_table( if result.points > 0.0 { p_results.push(format!("{}", result.points)); } else if result.best_submission_time_seconds.is_some() { - p_results.push(format!("{}", "?")); + p_results.push("?".to_string()); } else if result.rejected_attempt_count > 0 { p_results.push(format!("-{}", result.rejected_attempt_count)); } else { - p_results.push(format!("{}", "----")); + p_results.push("----".to_string()); } } diff --git a/youmubot-core/src/community/roles.rs b/youmubot-core/src/community/roles.rs index 7ca4d07..37887bd 100644 --- a/youmubot-core/src/community/roles.rs +++ b/youmubot-core/src/community/roles.rs @@ -56,7 +56,7 @@ async fn list(ctx: &Context, m: &Message, _: Args) -> CommandResult { let roles = &roles[start..end]; - const ROLE_HEADERS: [&'static str; 3] = ["Name", "ID", "Description"]; + const ROLE_HEADERS: [&str; 3] = ["Name", "ID", "Description"]; const ROLE_ALIGNS: [Align; 3] = [Right, Right, Right]; let roles_arr = roles diff --git a/youmubot-osu/src/discord/announcer.rs b/youmubot-osu/src/discord/announcer.rs index 4fe9dc1..a1ee10f 100644 --- a/youmubot-osu/src/discord/announcer.rs +++ b/youmubot-osu/src/discord/announcer.rs @@ -203,7 +203,7 @@ impl Announcer { let (user, top_scores) = try_join!(user, top_scores)?; let mut user = user.unwrap(); // if top scores exist, user would too - let events = std::mem::replace(&mut user.events, vec![]) + let events = std::mem::take(&mut user.events) .into_iter() .filter_map(|v| v.to_event_rank()) .filter(|s| Self::is_announceable_date(s.date, last_update, now)) @@ -344,7 +344,7 @@ impl<'a> CollectedScore<'a> { ) .await?; - save_beatmap(&env, channel, bm).await.pls_ok(); + save_beatmap(env, channel, bm).await.pls_ok(); Ok(m) } } diff --git a/youmubot-osu/src/discord/display.rs b/youmubot-osu/src/discord/display.rs index 78dee39..6d306bc 100644 --- a/youmubot-osu/src/discord/display.rs +++ b/youmubot-osu/src/discord/display.rs @@ -298,7 +298,7 @@ mod scores { }) .collect::>(); - const SCORE_HEADERS: [&'static str; 6] = + const SCORE_HEADERS: [&str; 6] = ["#", "PP", "Acc", "Ranks", "Mods", "Beatmap"]; const SCORE_ALIGNS: [Align; 6] = [Right, Right, Right, Right, Right, Left]; @@ -310,7 +310,7 @@ mod scores { .map(|(id, ((play, beatmap), (rank, pp)))| { [ format!("{}", id + start + 1), - format!("{}", pp), + pp.to_string(), format!("{:.2}%", play.accuracy(self.mode)), format!("{}", rank), play.mods.to_string(), diff --git a/youmubot-osu/src/discord/interaction.rs b/youmubot-osu/src/discord/interaction.rs index ef49263..79c69e2 100644 --- a/youmubot-osu/src/discord/interaction.rs +++ b/youmubot-osu/src/discord/interaction.rs @@ -16,9 +16,9 @@ use super::{ BeatmapWithMode, OsuEnv, }; -pub(super) const BTN_CHECK: &'static str = "youmubot_osu_btn_check"; -pub(super) const BTN_LB: &'static str = "youmubot_osu_btn_lb"; -pub(super) const BTN_LAST: &'static str = "youmubot_osu_btn_last"; +pub(super) const BTN_CHECK: &str = "youmubot_osu_btn_check"; +pub(super) const BTN_LB: &str = "youmubot_osu_btn_lb"; +pub(super) const BTN_LAST: &str = "youmubot_osu_btn_last"; /// Create an action row for score pages. pub fn score_components(guild_id: Option) -> CreateActionRow { @@ -208,7 +208,7 @@ pub fn handle_lb_button<'a>( CreateInteractionResponse::Defer(CreateInteractionResponseMessage::new()), ) .await?; - let scores = get_leaderboard(&ctx, &env, &bm, order, guild).await?; + let scores = get_leaderboard(ctx, &env, &bm, order, guild).await?; if scores.is_empty() { comp.create_followup( @@ -230,7 +230,7 @@ pub fn handle_lb_button<'a>( )), ) .await?; - display_rankings_table(&ctx, reply, scores, &bm, order).await?; + display_rankings_table(ctx, reply, scores, &bm, order).await?; Ok(()) }) } diff --git a/youmubot-osu/src/discord/link_parser.rs b/youmubot-osu/src/discord/link_parser.rs index c994b02..6f9df08 100644 --- a/youmubot-osu/src/discord/link_parser.rs +++ b/youmubot-osu/src/discord/link_parser.rs @@ -49,7 +49,7 @@ pub fn parse_old_links<'a>( .name("mode") .map(|v| v.as_str().parse::()) .transpose()? - .map(|v| Mode::from(v)); + .map(Mode::from); let embed = match req_type { "b" => { // collect beatmap info @@ -57,9 +57,9 @@ pub fn parse_old_links<'a>( .name("mods") .and_then(|v| Mods::from_str(v.as_str()).pls_ok()) .unwrap_or(Mods::NOMOD); - EmbedType::from_beatmap_id(&env, capture["id"].parse()?, mode, mods).await + EmbedType::from_beatmap_id(env, capture["id"].parse()?, mode, mods).await } - "s" => EmbedType::from_beatmapset_id(&env, capture["id"].parse()?).await, + "s" => EmbedType::from_beatmapset_id(env, capture["id"].parse()?).await, _ => unreachable!(), }?; Ok(ToPrint { @@ -92,11 +92,11 @@ pub fn parse_new_links<'a>( .name("mods") .and_then(|v| Mods::from_str(v.as_str()).pls_ok()) .unwrap_or(Mods::NOMOD); - EmbedType::from_beatmap_id(&env, beatmap_id, mode, mods).await + EmbedType::from_beatmap_id(env, beatmap_id, mode, mods).await } None => { EmbedType::from_beatmapset_id( - &env, + env, capture.name("set_id").unwrap().as_str().parse()?, ) .await @@ -124,7 +124,7 @@ pub fn parse_short_links<'a>( .name("mods") .and_then(|v| Mods::from_str(v.as_str()).pls_ok()) .unwrap_or(Mods::NOMOD); - let embed = EmbedType::from_beatmap_id(&env, id, mode, mods).await?; + let embed = EmbedType::from_beatmap_id(env, id, mode, mods).await?; Ok(ToPrint { embed, link, mode }) }) .collect::>() diff --git a/youmubot-osu/src/discord/mod.rs b/youmubot-osu/src/discord/mod.rs index 19e9fd9..f5292d2 100644 --- a/youmubot-osu/src/discord/mod.rs +++ b/youmubot-osu/src/discord/mod.rs @@ -386,7 +386,7 @@ async fn add_user(target: serenity::model::id::UserId, user: User, env: &OsuEnv) .user_best(UserID::ID(user.id), |f| f.mode(mode).limit(100)) .await .pls_ok() - .unwrap_or_else(|| vec![]); + .unwrap_or_else(std::vec::Vec::new); ( calculate_weighted_map_length(&scores, &env.beatmaps, mode) @@ -413,7 +413,7 @@ async fn add_user(target: serenity::model::id::UserId, user: User, env: &OsuEnv) }) }) .collect::>() - .filter_map(|v| future::ready(v)) + .filter_map(future::ready) .collect::>() .await; @@ -605,7 +605,7 @@ pub(crate) async fn load_beatmap( } } - let b = cache::get_beatmap(&env, channel_id).await.ok().flatten(); + let b = cache::get_beatmap(env, channel_id).await.ok().flatten(); b.map(|b| (b, None)) } @@ -836,7 +836,7 @@ async fn get_user( mut args: Args, mode: Mode, ) -> CommandResult { - let user = to_user_id_query(args.single::().ok(), &env, msg.author.id).await?; + let user = to_user_id_query(args.single::().ok(), env, msg.author.id).await?; let osu_client = &env.client; let meta_cache = &env.beatmaps; let user = osu_client.user(&user, |f| f.mode(mode)).await?; diff --git a/youmubot-osu/src/discord/oppai_cache.rs b/youmubot-osu/src/discord/oppai_cache.rs index 1f0caf9..de3388b 100644 --- a/youmubot-osu/src/discord/oppai_cache.rs +++ b/youmubot-osu/src/discord/oppai_cache.rs @@ -193,7 +193,7 @@ impl BeatmapCache { }) .collect::>(); for beatmap in &mut osu_files { - if beatmap.metadata.background_file != "" { + if !beatmap.metadata.background_file.is_empty() { let bg = backgrounds .entry(beatmap.metadata.background_file.clone()) .or_insert_with(|| { @@ -205,7 +205,7 @@ impl BeatmapCache { content: content.into_boxed_slice(), })) }); - beatmap.beatmap_background = bg.clone(); + beatmap.beatmap_background.clone_from(bg); } } Ok(osu_files) diff --git a/youmubot-osu/src/discord/server_rank.rs b/youmubot-osu/src/discord/server_rank.rs index 9b8de73..0166cc5 100644 --- a/youmubot-osu/src/discord/server_rank.rs +++ b/youmubot-osu/src/discord/server_rank.rs @@ -225,7 +225,7 @@ pub async fn server_rank(ctx: &Context, m: &Message, mut args: Args) -> CommandR table_formatting(&headers, &ALIGNS, table) } RankQuery::PP => { - const HEADERS: [&'static str; 6] = + const HEADERS: [&str; 6] = ["#", "pp", "Map length", "Map age", "Username", "Member"]; const ALIGNS: [Align; 6] = [Right, Right, Right, Right, Left, Left]; @@ -250,7 +250,7 @@ pub async fn server_rank(ctx: &Context, m: &Message, mut args: Args) -> CommandR table_formatting(&HEADERS, &ALIGNS, table) } RankQuery::TotalPP => { - const HEADERS: [&'static str; 4] = ["#", "Total pp", "Username", "Member"]; + const HEADERS: [&str; 4] = ["#", "Total pp", "Username", "Member"]; const ALIGNS: [Align; 4] = [Right, Right, Left, Left]; let table = users @@ -338,7 +338,7 @@ pub async fn show_leaderboard(ctx: &Context, msg: &Message, mut args: Args) -> C let scores = { let reaction = msg.react(ctx, '⌛').await?; - let s = get_leaderboard(&ctx, &env, &bm, order, guild).await?; + let s = get_leaderboard(ctx, &env, &bm, order, guild).await?; reaction.delete(&ctx).await?; s }; @@ -360,7 +360,7 @@ pub async fn show_leaderboard(ctx: &Context, msg: &Message, mut args: Args) -> C ), ) .await?; - display_rankings_table(&ctx, reply, scores, &bm, order).await?; + display_rankings_table(ctx, reply, scores, &bm, order).await?; } ScoreListStyle::Grid => { let reply = msg @@ -497,9 +497,9 @@ pub async fn display_rankings_table( let scores = scores[start..end].to_vec(); let bm = (bm.0.clone(), bm.1); Box::pin(async move { - const SCORE_HEADERS: [&'static str; 8] = + const SCORE_HEADERS: [&str; 8] = ["#", "Score", "Mods", "Rank", "Acc", "Combo", "Miss", "User"]; - const PP_HEADERS: [&'static str; 8] = + const PP_HEADERS: [&str; 8] = ["#", "PP", "Mods", "Rank", "Acc", "Combo", "Miss", "User"]; const ALIGNS: [Align; 8] = [Right, Right, Right, Right, Right, Right, Right, Left]; diff --git a/youmubot-osu/src/lib.rs b/youmubot-osu/src/lib.rs index 733b380..c37cbed 100644 --- a/youmubot-osu/src/lib.rs +++ b/youmubot-osu/src/lib.rs @@ -123,7 +123,7 @@ impl Client { let s = match self.rosu.score(score_id).await { Ok(v) => v, Err(rosu_v2::error::OsuError::NotFound) => return Ok(None), - e @ _ => e?, + e => e?, }; Ok(Some(s.into())) } diff --git a/youmubot-prelude/src/announcer.rs b/youmubot-prelude/src/announcer.rs index 5c86f83..71377bc 100644 --- a/youmubot-prelude/src/announcer.rs +++ b/youmubot-prelude/src/announcer.rs @@ -77,7 +77,7 @@ impl MemberToChannels { /// Gets the channel list of an user related to that channel. pub async fn channels_of( &self, - http: impl CacheHttp + Clone + Sync, + http: impl CacheHttp + Clone, u: impl Into, ) -> Vec { let u: UserId = u.into(); @@ -105,6 +105,12 @@ pub struct AnnouncerHandler { } /// Announcer-managing related. +impl Default for AnnouncerHandler { + fn default() -> Self { + Self::new() + } +} + impl AnnouncerHandler { /// Create a new instance of the handler. pub fn new() -> Self { @@ -119,7 +125,7 @@ impl AnnouncerHandler { pub fn add( &mut self, key: &'static str, - announcer: impl Announcer + Send + Sync + 'static, + announcer: impl Announcer + Sync + 'static, ) -> &mut Self { if self .announcers @@ -136,12 +142,12 @@ impl AnnouncerHandler { } pub fn run(self, client: &Client) -> AnnouncerRunner { - let runner = AnnouncerRunner { + + AnnouncerRunner { cache_http: CacheAndHttp::from_client(client), data: client.data.clone(), announcers: self.announcers, - }; - runner + } } } diff --git a/youmubot-prelude/src/setup.rs b/youmubot-prelude/src/setup.rs index 62494b9..6624882 100644 --- a/youmubot-prelude/src/setup.rs +++ b/youmubot-prelude/src/setup.rs @@ -39,11 +39,11 @@ pub async fn setup_prelude( // Set up the SQL client. data.insert::(sql_pool.clone()); - let env = Env { + + + Env { http: http_client, sql: sql_pool, members: member_cache, - }; - - env + } } diff --git a/youmubot/src/compose_framework.rs b/youmubot/src/compose_framework.rs index 77228fd..1296cbd 100644 --- a/youmubot/src/compose_framework.rs +++ b/youmubot/src/compose_framework.rs @@ -28,7 +28,7 @@ impl Framework for ComposedFramework { } async fn init(&mut self, client: &Client) { for f in self.frameworks.iter_mut() { - f.init(&client).await + f.init(client).await } } } diff --git a/youmubot/src/main.rs b/youmubot/src/main.rs index 921a1ff..d2f2da6 100644 --- a/youmubot/src/main.rs +++ b/youmubot/src/main.rs @@ -115,7 +115,7 @@ impl EventHandler for Handler { .iter() .map(|hook| { hook.write() - .then(|mut h| async move { h.call(&ctx, &interaction).await }) + .then(|mut h| async move { h.call(ctx, interaction).await }) }) .collect::>() .for_each(|v| async move {