mirror of
https://github.com/natsukagami/youmubot.git
synced 2025-05-23 16:50:49 +00:00
Cargo clippy & format
This commit is contained in:
parent
cdd85dae71
commit
c5f46dd7fe
22 changed files with 79 additions and 87 deletions
|
@ -176,7 +176,7 @@ pub async fn ranks(ctx: &Context, m: &Message) -> CommandResult {
|
|||
let ranks = Arc::new(ranks);
|
||||
|
||||
const ITEMS_PER_PAGE: usize = 10;
|
||||
let total_pages = (ranks.len() + ITEMS_PER_PAGE - 1) / ITEMS_PER_PAGE;
|
||||
let total_pages = ranks.len().div_ceil(ITEMS_PER_PAGE);
|
||||
let last_updated = ranks.iter().map(|(_, cfu)| cfu.last_update).min().unwrap();
|
||||
|
||||
paginate_reply(
|
||||
|
@ -308,7 +308,7 @@ pub(crate) async fn contest_rank_table(
|
|||
ranks: Vec<(Member, String, codeforces::RanklistRow)>,
|
||||
) -> Result<()> {
|
||||
const ITEMS_PER_PAGE: usize = 10;
|
||||
let total_pages = (ranks.len() + ITEMS_PER_PAGE - 1) / ITEMS_PER_PAGE;
|
||||
let total_pages = ranks.len().div_ceil(ITEMS_PER_PAGE);
|
||||
|
||||
if ranks.is_empty() {
|
||||
reply_to
|
||||
|
|
|
@ -82,7 +82,7 @@ async fn list<U: HasCoreEnv>(ctx: CmdContext<'_, U>) -> Result<()> {
|
|||
})
|
||||
.collect::<Vec<_>>()
|
||||
.join("\n");
|
||||
let users = if users == "" {
|
||||
let users = if users.is_empty() {
|
||||
"No one is being ignored!"
|
||||
} else {
|
||||
&users[..]
|
||||
|
@ -118,10 +118,7 @@ impl IgnoredUsers {
|
|||
Ok(Self { list: Arc::new(mp) })
|
||||
}
|
||||
|
||||
pub fn query<'a>(
|
||||
&'a self,
|
||||
id: UserId,
|
||||
) -> Option<impl std::ops::Deref<Target = IgnoredUser> + 'a> {
|
||||
pub fn query(&self, id: UserId) -> Option<impl std::ops::Deref<Target = IgnoredUser> + '_> {
|
||||
self.list.get(&id)
|
||||
}
|
||||
|
||||
|
|
|
@ -40,7 +40,7 @@ async fn list(ctx: &Context, m: &Message, _: Args) -> CommandResult {
|
|||
.filter_map(|(_, role)| roles.get(&role.id).cloned().map(|r| (r, role.description)))
|
||||
.collect();
|
||||
const ROLES_PER_PAGE: usize = 8;
|
||||
let pages = (roles.len() + ROLES_PER_PAGE - 1) / ROLES_PER_PAGE;
|
||||
let pages = roles.len().div_ceil(ROLES_PER_PAGE);
|
||||
|
||||
paginate_reply(
|
||||
paginate_from_fn(|page, btns| {
|
||||
|
|
|
@ -473,7 +473,7 @@ const FIRST_NAMES: [&str; 440] = [
|
|||
"Yusuke",
|
||||
];
|
||||
|
||||
const LAST_NAMES: [&str; 1051] = [
|
||||
static LAST_NAMES: [&str; 1051] = [
|
||||
// A Surnames
|
||||
"Abe",
|
||||
"Abukara",
|
||||
|
|
|
@ -45,8 +45,8 @@ impl<T: AsRef<CoreEnv> + Send + Sync> HasCoreEnv for T {
|
|||
pub async fn setup(path: &std::path::Path, data: &mut TypeMap, prelude: Env) -> Result<CoreEnv> {
|
||||
db::load_role_list(
|
||||
&mut *data,
|
||||
&path.join("roles_v2.yaml"),
|
||||
&path.join("roles.yaml"),
|
||||
path.join("roles_v2.yaml"),
|
||||
path.join("roles.yaml"),
|
||||
)?;
|
||||
|
||||
// Start reaction handlers
|
||||
|
|
|
@ -64,7 +64,7 @@ where
|
|||
}
|
||||
}
|
||||
|
||||
impl<'a, T> DBWriteGuard<'a, T>
|
||||
impl<T> DBWriteGuard<'_, T>
|
||||
where
|
||||
T: Send + Sync + Clone + std::fmt::Debug + Serialize + DeserializeOwned,
|
||||
{
|
||||
|
@ -79,7 +79,7 @@ where
|
|||
}
|
||||
}
|
||||
|
||||
impl<'a, T> Drop for DBWriteGuard<'a, T>
|
||||
impl<T> Drop for DBWriteGuard<'_, T>
|
||||
where
|
||||
T: Send + Sync + Clone + std::fmt::Debug + Serialize + DeserializeOwned,
|
||||
{
|
||||
|
|
|
@ -291,7 +291,7 @@ impl<'a> CollectedScore<'a> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<'a> CollectedScore<'a> {
|
||||
impl CollectedScore<'_> {
|
||||
async fn send_message(
|
||||
self,
|
||||
ctx: impl CacheHttp,
|
||||
|
|
|
@ -186,7 +186,6 @@ pub async fn save<U: HasOsuEnv>(
|
|||
ctx.defer().await?;
|
||||
let (u, mode, score, beatmap, info) = find_save_requirements(env, username).await?;
|
||||
let reply = ctx
|
||||
.clone()
|
||||
.send(
|
||||
CreateReply::default()
|
||||
.content(save_request_message(&u.username, score.beatmap_id, mode))
|
||||
|
@ -197,10 +196,10 @@ pub async fn save<U: HasOsuEnv>(
|
|||
]),
|
||||
)
|
||||
.await?;
|
||||
let mut p = (reply, ctx.clone());
|
||||
let mut p = (reply, ctx);
|
||||
match handle_save_respond(
|
||||
ctx.serenity_context(),
|
||||
&env,
|
||||
env,
|
||||
ctx.author().id,
|
||||
&mut p,
|
||||
&beatmap,
|
||||
|
@ -212,7 +211,7 @@ pub async fn save<U: HasOsuEnv>(
|
|||
Ok(_) => (),
|
||||
Err(e) => {
|
||||
p.0.delete(ctx).await?;
|
||||
return Err(e.into());
|
||||
return Err(e);
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -235,8 +234,8 @@ pub async fn forcesave<U: HasOsuEnv>(
|
|||
else {
|
||||
return Err(Error::msg("osu! user not found"));
|
||||
};
|
||||
add_user(discord_name.id, &u, &env).await?;
|
||||
let ex = UserExtras::from_user(&env, &u, u.preferred_mode).await?;
|
||||
add_user(discord_name.id, &u, env).await?;
|
||||
let ex = UserExtras::from_user(env, &u, u.preferred_mode).await?;
|
||||
ctx.send(
|
||||
CreateReply::default()
|
||||
.content(
|
||||
|
@ -289,8 +288,7 @@ async fn handle_listing<U: HasOsuEnv>(
|
|||
user.mention()
|
||||
))
|
||||
.embed({
|
||||
let mut b =
|
||||
transform(nth + 1, score_embed(&play, &beatmap, &content, user));
|
||||
let mut b = transform(nth + 1, score_embed(play, &beatmap, &content, user));
|
||||
if let Some(rank) = play.global_rank {
|
||||
b = b.world_record(rank as u16);
|
||||
}
|
||||
|
@ -301,15 +299,15 @@ async fn handle_listing<U: HasOsuEnv>(
|
|||
.await?;
|
||||
|
||||
// Save the beatmap...
|
||||
cache::save_beatmap(&env, ctx.channel_id(), &beatmap).await?;
|
||||
cache::save_beatmap(env, ctx.channel_id(), &beatmap).await?;
|
||||
}
|
||||
Nth::All => {
|
||||
let header = format!("Here are the {} plays by {}!", listing_kind, user.mention());
|
||||
let reply = ctx.clone().reply(&header).await?;
|
||||
let reply = ctx.reply(&header).await?;
|
||||
style
|
||||
.display_scores(
|
||||
plays,
|
||||
ctx.clone().serenity_context(),
|
||||
ctx.serenity_context(),
|
||||
ctx.guild_id(),
|
||||
(reply, ctx).with_header(header),
|
||||
)
|
||||
|
@ -380,11 +378,10 @@ async fn beatmap<U: HasOsuEnv>(
|
|||
EmbedType::Beatmapset(vec, _) => {
|
||||
let b0 = &vec[0];
|
||||
let msg = ctx
|
||||
.clone()
|
||||
.reply(format!("Information for {}", b0.beatmapset_mention()))
|
||||
.await?;
|
||||
display_beatmapset(
|
||||
ctx.clone().serenity_context(),
|
||||
ctx.serenity_context(),
|
||||
vec,
|
||||
mode,
|
||||
mods,
|
||||
|
@ -480,7 +477,7 @@ async fn check<U: HasOsuEnv>(
|
|||
args.user.mention(),
|
||||
display
|
||||
);
|
||||
let msg = ctx.clone().reply(&header).await?;
|
||||
let msg = ctx.reply(&header).await?;
|
||||
|
||||
let style = style.unwrap_or(if scores.len() <= 5 {
|
||||
ScoreListStyle::Grid
|
||||
|
@ -491,7 +488,7 @@ async fn check<U: HasOsuEnv>(
|
|||
style
|
||||
.display_scores(
|
||||
scores,
|
||||
ctx.clone().serenity_context(),
|
||||
ctx.serenity_context(),
|
||||
ctx.guild_id(),
|
||||
(msg, ctx).with_header(header),
|
||||
)
|
||||
|
@ -512,7 +509,7 @@ async fn ranks<U: HasOsuEnv>(
|
|||
let guild = ctx.partial_guild().await.unwrap();
|
||||
ctx.defer().await?;
|
||||
server_rank::do_server_ranks(
|
||||
ctx.clone().serenity_context(),
|
||||
ctx.serenity_context(),
|
||||
env,
|
||||
&guild,
|
||||
mode,
|
||||
|
@ -551,7 +548,7 @@ async fn leaderboard<U: HasOsuEnv>(
|
|||
let scoreboard_msg = embed.mention();
|
||||
let (mut scores, show_diff) = get_leaderboard_from_embed(
|
||||
ctx.serenity_context(),
|
||||
&env,
|
||||
env,
|
||||
embed,
|
||||
None,
|
||||
unranked.unwrap_or(true),
|
||||
|
|
|
@ -176,7 +176,7 @@ impl From<model::OsuUser> for OsuUser {
|
|||
impl From<OsuUser> for crate::models::UserHeader {
|
||||
fn from(value: OsuUser) -> Self {
|
||||
Self {
|
||||
id: value.id as u64,
|
||||
id: value.id,
|
||||
username: value.username.to_string(),
|
||||
}
|
||||
}
|
||||
|
|
|
@ -138,7 +138,7 @@ mod scores {
|
|||
.await?
|
||||
.ok_or_else(|| Error::msg("user not found"))?;
|
||||
|
||||
save_beatmap(&env, self.channel_id, &bm).await?;
|
||||
save_beatmap(env, self.channel_id, &bm).await?;
|
||||
Ok(Some(
|
||||
CreateReply::default()
|
||||
.embed({
|
||||
|
@ -479,7 +479,7 @@ mod beatmapset {
|
|||
.oppai
|
||||
.get_beatmap(b.beatmap_id)
|
||||
.await
|
||||
.map(move |v| v.get_possible_pp_with(b.mode.with_override(self.mode), &mods))
|
||||
.map(move |v| v.get_possible_pp_with(b.mode.with_override(self.mode), mods))
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -269,7 +269,7 @@ pub(crate) struct ScoreEmbedBuilder<'a> {
|
|||
footer: Option<String>,
|
||||
}
|
||||
|
||||
impl<'a> ScoreEmbedBuilder<'a> {
|
||||
impl ScoreEmbedBuilder<'_> {
|
||||
pub fn top_record(mut self, rank: u8) -> Self {
|
||||
self.top_record = Some(rank);
|
||||
self
|
||||
|
@ -304,7 +304,7 @@ pub(crate) fn score_embed<'a>(
|
|||
}
|
||||
}
|
||||
|
||||
impl<'a> ScoreEmbedBuilder<'a> {
|
||||
impl ScoreEmbedBuilder<'_> {
|
||||
#[allow(clippy::many_single_char_names)]
|
||||
pub fn build(mut self) -> CreateEmbed {
|
||||
let mode = self.bm.mode();
|
||||
|
@ -471,7 +471,7 @@ pub(crate) struct FakeScore<'a> {
|
|||
pub max_combo: Option<u32>,
|
||||
}
|
||||
|
||||
impl<'a> FakeScore<'a> {
|
||||
impl FakeScore<'_> {
|
||||
fn score_origin(&self, attrs: &OsuPerformanceAttributes) -> OsuScoreOrigin {
|
||||
if !self.mods.is_lazer {
|
||||
OsuScoreOrigin::Stable
|
||||
|
|
|
@ -135,7 +135,7 @@ pub fn dot_osu_hook<'a>(
|
|||
.collect::<Vec<_>>()
|
||||
.await;
|
||||
|
||||
const ARCHIVE_EXTS: [&'static str; 2] = [".osz", ".olz"];
|
||||
const ARCHIVE_EXTS: [&str; 2] = [".osz", ".olz"];
|
||||
let osz_embeds = msg
|
||||
.attachments
|
||||
.iter()
|
||||
|
|
|
@ -109,7 +109,7 @@ pub fn handle_check_button<'a>(
|
|||
|
||||
let guild_id = comp.guild_id;
|
||||
ScoreListStyle::Grid
|
||||
.display_scores(scores, &ctx, guild_id, (comp, ctx).with_header(header))
|
||||
.display_scores(scores, ctx, guild_id, (comp, ctx).with_header(header))
|
||||
.await
|
||||
.pls_ok();
|
||||
Ok(())
|
||||
|
@ -209,7 +209,7 @@ pub fn handle_simulate_button<'a>(
|
|||
|
||||
let Some(query) = comp
|
||||
.quick_modal(
|
||||
&ctx,
|
||||
ctx,
|
||||
CreateQuickModal::new(format!(
|
||||
"Simulate Score on beatmap `{}`",
|
||||
b.short_link(None, Mods::NOMOD)
|
||||
|
@ -263,7 +263,7 @@ async fn handle_simluate_query(
|
|||
let (mods, max_combo, c100, c50, cmiss) =
|
||||
(&inputs[0], &inputs[1], &inputs[2], &inputs[3], &inputs[4]);
|
||||
let mods = UnparsedMods::from_str(mods)
|
||||
.map_err(|v| Error::msg(v))?
|
||||
.map_err(Error::msg)?
|
||||
.to_mods(mode)?;
|
||||
let info = content.get_info_with(mode, &mods);
|
||||
let max_combo = max_combo.parse::<u32>().ok();
|
||||
|
@ -351,7 +351,7 @@ async fn handle_last_req(
|
|||
&ctx,
|
||||
serenity::all::CreateInteractionResponseFollowup::new()
|
||||
.content(content_type)
|
||||
.embed(beatmap_embed(&*b, m.unwrap_or(b.mode), &mods, &info))
|
||||
.embed(beatmap_embed(&b, m.unwrap_or(b.mode), &mods, &info))
|
||||
.components(vec![beatmap_components(m.unwrap_or(b.mode), comp.guild_id)]),
|
||||
)
|
||||
.await?;
|
||||
|
|
|
@ -361,7 +361,7 @@ pub(crate) async fn handle_save_respond(
|
|||
.is_some_and(|s| s.beatmap_id == map_id))
|
||||
}
|
||||
let msg_id = reply.get_message().await?.id;
|
||||
let recv = InteractionCollector::create(&ctx, msg_id).await?;
|
||||
let recv = InteractionCollector::create(ctx, msg_id).await?;
|
||||
let timeout = std::time::Duration::from_secs(300) + beatmap.difficulty.total_length;
|
||||
let completed = loop {
|
||||
let Some(reaction) = recv.next(timeout).await else {
|
||||
|
@ -385,7 +385,7 @@ pub(crate) async fn handle_save_respond(
|
|||
return Ok(());
|
||||
}
|
||||
|
||||
add_user(sender, &user, &env).await?;
|
||||
add_user(sender, &user, env).await?;
|
||||
let ex = UserExtras::from_user(env, &user, mode).await?;
|
||||
reply
|
||||
.apply_edit(
|
||||
|
@ -450,7 +450,7 @@ async fn add_user(target: serenity::model::id::UserId, user: &User, env: &OsuEnv
|
|||
let modes = [Mode::Std, Mode::Taiko, Mode::Catch, Mode::Mania]
|
||||
.into_iter()
|
||||
.map(|mode| {
|
||||
let mode = mode.clone();
|
||||
let mode = mode;
|
||||
async move {
|
||||
let pp = async {
|
||||
env.client
|
||||
|
@ -790,7 +790,7 @@ pub async fn pins(ctx: &Context, msg: &Message, mut args: Args) -> CommandResult
|
|||
&ctx,
|
||||
CreateMessage::new()
|
||||
.content("Here is the play that you requested".to_string())
|
||||
.embed(score_embed(&play, &beatmap_mode, &content, user).build())
|
||||
.embed(score_embed(play, &beatmap_mode, &content, user).build())
|
||||
.components(vec![score_components(msg.guild_id)])
|
||||
.reference_message(msg),
|
||||
)
|
||||
|
@ -908,15 +908,13 @@ pub(crate) async fn load_beatmap(
|
|||
None => load_beatmap_from_channel(env, channel_id).await,
|
||||
};
|
||||
|
||||
if req == LoadRequest::Beatmapset {
|
||||
if embed.is_none() {
|
||||
if req == LoadRequest::Beatmapset && embed.is_none() {
|
||||
if let Some(EmbedType::Beatmap(b, mode, _, _)) = fallback {
|
||||
return EmbedType::from_beatmapset_id(env, b.beatmapset_id, mode)
|
||||
.await
|
||||
.ok();
|
||||
}
|
||||
}
|
||||
}
|
||||
embed
|
||||
}
|
||||
|
||||
|
@ -1052,7 +1050,7 @@ pub(crate) async fn do_check(
|
|||
.scores(b.beatmap_id, |f| f.user(UserID::ID(user.id)).mode(m))
|
||||
.and_then(|v| v.get_all())
|
||||
.map_ok(move |mut v| {
|
||||
v.retain(|s| mods.as_ref().is_none_or(|m| s.mods.contains(&m)));
|
||||
v.retain(|s| mods.as_ref().is_none_or(|m| s.mods.contains(m)));
|
||||
v
|
||||
})
|
||||
.await
|
||||
|
@ -1060,7 +1058,7 @@ pub(crate) async fn do_check(
|
|||
|
||||
let mut scores = match embed {
|
||||
EmbedType::Beatmap(beatmap, mode, _, _) => {
|
||||
fetch_for_beatmap(env, &**beatmap, *mode, &mods, user).await?
|
||||
fetch_for_beatmap(env, beatmap, *mode, &mods, user).await?
|
||||
}
|
||||
EmbedType::Beatmapset(vec, mode) => vec
|
||||
.iter()
|
||||
|
@ -1118,7 +1116,7 @@ pub async fn top(ctx: &Context, msg: &Message, mut args: Args) -> CommandResult
|
|||
user.mention()
|
||||
))
|
||||
.embed(
|
||||
score_embed(&play, &beatmap, &content, user)
|
||||
score_embed(play, &beatmap, &content, user)
|
||||
.top_record(nth + 1)
|
||||
.build(),
|
||||
)
|
||||
|
|
|
@ -234,7 +234,7 @@ where
|
|||
let users = Arc::new(users);
|
||||
let last_update = last_update.unwrap();
|
||||
let total_len = users.len();
|
||||
let total_pages = (total_len + ITEMS_PER_PAGE - 1) / ITEMS_PER_PAGE;
|
||||
let total_pages = total_len.div_ceil(ITEMS_PER_PAGE);
|
||||
paginate_with_first_message(
|
||||
paginate_from_fn(move |page: u8, btns| {
|
||||
let header = header.clone();
|
||||
|
@ -404,7 +404,7 @@ pub async fn show_leaderboard(ctx: &Context, msg: &Message, mut args: Args) -> C
|
|||
|
||||
let header = format!(
|
||||
"Here are the top scores of **{}** on {}",
|
||||
guild.name(&ctx).unwrap(),
|
||||
guild.name(ctx).unwrap(),
|
||||
scoreboard_msg,
|
||||
);
|
||||
let has_lazer_score = scores.iter().any(|v| v.score.mods.is_lazer);
|
||||
|
@ -587,7 +587,7 @@ pub async fn get_leaderboard_from_embed(
|
|||
let iter = std::iter::once(*map);
|
||||
let scores = get_leaderboard(
|
||||
ctx,
|
||||
&env,
|
||||
env,
|
||||
iter,
|
||||
mode_override.or(mode),
|
||||
show_unranked,
|
||||
|
@ -603,7 +603,7 @@ pub async fn get_leaderboard_from_embed(
|
|||
(
|
||||
get_leaderboard(
|
||||
ctx,
|
||||
&env,
|
||||
env,
|
||||
maps,
|
||||
mode_override.or(mode),
|
||||
show_unranked,
|
||||
|
@ -689,7 +689,7 @@ pub(crate) fn rankings_to_table(
|
|||
} else {
|
||||
beatmap.difficulty_name.clone()
|
||||
};
|
||||
format!("[{:.2}*] {} {}", star, trimmed_diff, score.mods.to_string())
|
||||
format!("[{:.2}*] {} {}", star, trimmed_diff, score.mods)
|
||||
} else {
|
||||
score.mods.to_string()
|
||||
},
|
||||
|
@ -716,7 +716,7 @@ pub async fn display_rankings_table(
|
|||
) -> Result<()> {
|
||||
const ITEMS_PER_PAGE: usize = 5;
|
||||
let total_len = scores.len();
|
||||
let total_pages = (total_len + ITEMS_PER_PAGE - 1) / ITEMS_PER_PAGE;
|
||||
let total_pages = total_len.div_ceil(ITEMS_PER_PAGE);
|
||||
let header = to.content.clone();
|
||||
|
||||
paginate_with_first_message(
|
||||
|
|
|
@ -125,9 +125,9 @@ impl Difficulty {
|
|||
|
||||
if let Some(ratio) = mods.inner.clock_rate() {
|
||||
if ratio != 1.0 {
|
||||
diff.apply_length_by_ratio(1.0 / ratio as f64);
|
||||
diff.apply_ar_by_time_ratio(1.0 / ratio as f64);
|
||||
diff.apply_od_by_time_ratio(1.0 / ratio as f64);
|
||||
diff.apply_length_by_ratio(1.0 / ratio);
|
||||
diff.apply_ar_by_time_ratio(1.0 / ratio);
|
||||
diff.apply_od_by_time_ratio(1.0 / ratio);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -587,7 +587,7 @@ pub struct User {
|
|||
}
|
||||
|
||||
impl User {
|
||||
pub fn mention<'a>(&'a self) -> impl Display + 'a {
|
||||
pub fn mention(&self) -> impl Display + '_ {
|
||||
UserHeaderLink(&self.username, self.id)
|
||||
}
|
||||
|
||||
|
@ -603,14 +603,14 @@ impl User {
|
|||
#[derive(Debug, Clone)]
|
||||
struct UserHeaderLink<'a>(&'a String, u64);
|
||||
|
||||
impl<'a> Display for UserHeaderLink<'a> {
|
||||
impl Display for UserHeaderLink<'_> {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
write!(f, "[{}](<https://osu.ppy.sh/users/{}>)", self.0, self.1)
|
||||
}
|
||||
}
|
||||
|
||||
impl UserHeader {
|
||||
pub fn mention<'a>(&'a self) -> impl Display + 'a {
|
||||
pub fn mention(&self) -> impl Display + '_ {
|
||||
UserHeaderLink(&self.username, self.id)
|
||||
}
|
||||
|
||||
|
|
|
@ -116,7 +116,7 @@ impl From<rosu::score::Score> for Score {
|
|||
s.score as u64
|
||||
} else {
|
||||
s.classic_score
|
||||
} as u64;
|
||||
};
|
||||
Self {
|
||||
id: Some(s.id),
|
||||
user_id: s.user_id as u64,
|
||||
|
|
|
@ -215,7 +215,7 @@ pub mod builders {
|
|||
match &self.mods {
|
||||
Some(mods) => r.await.map(|mut ss| {
|
||||
ss.retain(|s| {
|
||||
Mods::from_gamemods(s.mods.clone(), s.set_on_lazer).contains(&mods)
|
||||
Mods::from_gamemods(s.mods.clone(), s.set_on_lazer).contains(mods)
|
||||
});
|
||||
ss
|
||||
}),
|
||||
|
@ -225,7 +225,7 @@ pub mod builders {
|
|||
None => {
|
||||
let mut r = osu.rosu.beatmap_scores(self.beatmap_id as u32).global();
|
||||
if let Some(mode) = &self.mode {
|
||||
r = r.mode(mode.clone().into());
|
||||
r = r.mode((*mode).into());
|
||||
}
|
||||
if let Some(mods) = &self.mods {
|
||||
r = r.mods(GameModsIntermode::from(mods.inner.clone()));
|
||||
|
@ -241,7 +241,7 @@ pub mod builders {
|
|||
pub(crate) async fn build(self, osu: &OsuClient) -> Result<impl Scores> {
|
||||
// user queries always return all scores, so no need to consider offset.
|
||||
// otherwise, it's not working anyway...
|
||||
Ok(self.fetch_scores(osu, 0).await?)
|
||||
self.fetch_scores(osu, 0).await
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -106,7 +106,7 @@ impl Scores for Vec<Score> {
|
|||
}
|
||||
|
||||
async fn find<F: FnMut(&Score) -> bool + Send>(&mut self, mut f: F) -> Result<Option<&Score>> {
|
||||
Ok(self.iter().find(|v| f(*v)))
|
||||
Ok(self.iter().find(|v| f(v)))
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -155,7 +155,7 @@ impl<T: FetchScores> Scores for ScoresFetcher<T> {
|
|||
|
||||
/// Get the index-th score.
|
||||
async fn get(&mut self, index: usize) -> Result<Option<&Score>> {
|
||||
Ok(self.get_range(index..(index + 1)).await?.get(0))
|
||||
Ok(self.get_range(index..(index + 1)).await?.first())
|
||||
}
|
||||
|
||||
/// Get all scores.
|
||||
|
|
|
@ -42,6 +42,12 @@ impl Drop for InteractionCollectorGuard {
|
|||
}
|
||||
}
|
||||
|
||||
impl Default for InteractionCollector {
|
||||
fn default() -> Self {
|
||||
Self::new()
|
||||
}
|
||||
}
|
||||
|
||||
impl InteractionCollector {
|
||||
pub fn new() -> Self {
|
||||
Self {
|
||||
|
@ -51,7 +57,7 @@ impl InteractionCollector {
|
|||
/// Create a new collector, returning a receiver.
|
||||
pub fn create_collector(&self, msg: MessageId) -> InteractionCollectorGuard {
|
||||
let (send, recv) = flume::unbounded();
|
||||
self.channels.insert(msg.clone(), send);
|
||||
self.channels.insert(msg, send);
|
||||
InteractionCollectorGuard {
|
||||
msg_id: msg,
|
||||
ch: recv,
|
||||
|
|
|
@ -43,7 +43,7 @@ impl<T: CanEdit> CanEdit for WithHeaders<T> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<'a> CanEdit for (Message, &'a Context) {
|
||||
impl CanEdit for (Message, &Context) {
|
||||
async fn get_message(&self) -> Result<Message> {
|
||||
Ok(self.0.clone())
|
||||
}
|
||||
|
@ -56,7 +56,7 @@ impl<'a> CanEdit for (Message, &'a Context) {
|
|||
}
|
||||
}
|
||||
|
||||
impl<'a, 'b> CanEdit for (&'a ComponentInteraction, &'b Context) {
|
||||
impl CanEdit for (&ComponentInteraction, &Context) {
|
||||
async fn get_message(&self) -> Result<Message> {
|
||||
Ok(self.0.get_response(&self.1.http).await?)
|
||||
}
|
||||
|
@ -72,7 +72,7 @@ impl<'a, 'b> CanEdit for (&'a ComponentInteraction, &'b Context) {
|
|||
}
|
||||
}
|
||||
|
||||
impl<'a, 'e, Env: Send + Sync> CanEdit for (ReplyHandle<'a>, CmdContext<'e, Env>) {
|
||||
impl<Env: Send + Sync> CanEdit for (ReplyHandle<'_>, CmdContext<'_, Env>) {
|
||||
async fn get_message(&self) -> Result<Message> {
|
||||
Ok(self.0.message().await?.into_owned())
|
||||
}
|
||||
|
@ -326,13 +326,7 @@ pub async fn handle_pagination_reaction(
|
|||
let new_page = match reaction {
|
||||
PREV | FAST_PREV if page == 0 => return Ok(page),
|
||||
PREV => page - 1,
|
||||
FAST_PREV => {
|
||||
if page < fast {
|
||||
0
|
||||
} else {
|
||||
page - fast
|
||||
}
|
||||
}
|
||||
FAST_PREV => page.saturating_sub(fast),
|
||||
NEXT if pages.filter(|&pages| page as usize + 1 >= pages).is_some() => return Ok(page),
|
||||
NEXT => page + 1,
|
||||
FAST_NEXT => (pages.unwrap() as u8 - 1).min(page + fast),
|
||||
|
|
|
@ -50,14 +50,14 @@ impl<T> Ratelimit<T> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<'a, T> Deref for RatelimitGuard<'a, T> {
|
||||
impl<T> Deref for RatelimitGuard<'_, T> {
|
||||
type Target = T;
|
||||
fn deref(&self) -> &Self::Target {
|
||||
self.inner
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, T> Drop for RatelimitGuard<'a, T> {
|
||||
impl<T> Drop for RatelimitGuard<'_, T> {
|
||||
fn drop(&mut self) {
|
||||
let send = self.send.clone();
|
||||
let wait_time = *self.wait_time;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue