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