mirror of
https://github.com/natsukagami/youmubot.git
synced 2025-05-24 01:00:49 +00:00
display should take a lazy score future
This commit is contained in:
parent
11e34e0c78
commit
fcf3ed60d2
5 changed files with 30 additions and 18 deletions
|
@ -307,7 +307,7 @@ async fn handle_listing<U: HasOsuEnv>(
|
||||||
let reply = ctx.clone().reply(&header).await?;
|
let reply = ctx.clone().reply(&header).await?;
|
||||||
style
|
style
|
||||||
.display_scores(
|
.display_scores(
|
||||||
plays.try_collect::<Vec<_>>().await?,
|
plays.try_collect::<Vec<_>>(),
|
||||||
ctx.clone().serenity_context(),
|
ctx.clone().serenity_context(),
|
||||||
ctx.guild_id(),
|
ctx.guild_id(),
|
||||||
(reply, ctx).with_header(header),
|
(reply, ctx).with_header(header),
|
||||||
|
@ -489,7 +489,7 @@ async fn check<U: HasOsuEnv>(
|
||||||
|
|
||||||
style
|
style
|
||||||
.display_scores(
|
.display_scores(
|
||||||
scores,
|
future::ok(scores),
|
||||||
ctx.clone().serenity_context(),
|
ctx.clone().serenity_context(),
|
||||||
ctx.guild_id(),
|
ctx.guild_id(),
|
||||||
(msg, ctx).with_header(header),
|
(msg, ctx).with_header(header),
|
||||||
|
@ -612,7 +612,7 @@ async fn leaderboard<U: HasOsuEnv>(
|
||||||
let reply = ctx.reply(header).await?;
|
let reply = ctx.reply(header).await?;
|
||||||
style
|
style
|
||||||
.display_scores(
|
.display_scores(
|
||||||
scores.into_iter().map(|s| s.score).collect(),
|
future::ok(scores.into_iter().map(|s| s.score).collect()),
|
||||||
ctx.serenity_context(),
|
ctx.serenity_context(),
|
||||||
Some(guild.id),
|
Some(guild.id),
|
||||||
(reply, ctx),
|
(reply, ctx),
|
||||||
|
|
|
@ -76,6 +76,7 @@ mod scores {
|
||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
let env = ctx.data.read().await.get::<OsuEnv>().unwrap().clone();
|
let env = ctx.data.read().await.get::<OsuEnv>().unwrap().clone();
|
||||||
let channel_id = on.get_message().await?.channel_id;
|
let channel_id = on.get_message().await?.channel_id;
|
||||||
|
let scores = scores.await?;
|
||||||
if scores.is_empty() {
|
if scores.is_empty() {
|
||||||
on.apply_edit(CreateReply::default().content("No plays found"))
|
on.apply_edit(CreateReply::default().content("No plays found"))
|
||||||
.await?;
|
.await?;
|
||||||
|
@ -85,7 +86,7 @@ mod scores {
|
||||||
paginate_with_first_message(
|
paginate_with_first_message(
|
||||||
Paginate {
|
Paginate {
|
||||||
env,
|
env,
|
||||||
scores: scores.await?,
|
scores,
|
||||||
guild_id,
|
guild_id,
|
||||||
channel_id,
|
channel_id,
|
||||||
},
|
},
|
||||||
|
@ -157,6 +158,7 @@ mod scores {
|
||||||
|
|
||||||
pub mod table {
|
pub mod table {
|
||||||
use std::borrow::Cow;
|
use std::borrow::Cow;
|
||||||
|
use std::future::Future;
|
||||||
|
|
||||||
use pagination::paginate_with_first_message;
|
use pagination::paginate_with_first_message;
|
||||||
use serenity::all::{CreateActionRow, CreateAttachment};
|
use serenity::all::{CreateActionRow, CreateAttachment};
|
||||||
|
@ -170,27 +172,26 @@ mod scores {
|
||||||
use crate::models::Score;
|
use crate::models::Score;
|
||||||
|
|
||||||
pub async fn display_scores_as_file(
|
pub async fn display_scores_as_file(
|
||||||
scores: Vec<Score>,
|
scores: impl Future<Output = Result<Vec<Score>>>,
|
||||||
ctx: &Context,
|
ctx: &Context,
|
||||||
mut on: impl CanEdit,
|
mut on: impl CanEdit,
|
||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
|
let header = on.headers().unwrap_or("").to_owned();
|
||||||
|
let content = format!("{}\n\nPreparing file...", header);
|
||||||
|
let preparing = on.apply_edit(CreateReply::default().content(content));
|
||||||
|
let (_, scores) = future::try_join(preparing, scores).await?;
|
||||||
if scores.is_empty() {
|
if scores.is_empty() {
|
||||||
on.apply_edit(CreateReply::default().content("No plays found"))
|
on.apply_edit(CreateReply::default().content("No plays found"))
|
||||||
.await?;
|
.await?;
|
||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
let header = on.headers().unwrap_or("").to_owned();
|
|
||||||
let content = format!("{}\n\nPreparing file...", header);
|
|
||||||
let first_edit = on
|
|
||||||
.apply_edit(CreateReply::default().content(content))
|
|
||||||
.map(|v| v.pls_ok());
|
|
||||||
|
|
||||||
let p = Paginate {
|
let p = Paginate {
|
||||||
env: ctx.data.read().await.get::<OsuEnv>().unwrap().clone(),
|
env: ctx.data.read().await.get::<OsuEnv>().unwrap().clone(),
|
||||||
header: header.clone(),
|
header: header.clone(),
|
||||||
scores,
|
scores,
|
||||||
};
|
};
|
||||||
let (_, content) = future::join(first_edit, p.to_table(0, p.scores.len())).await;
|
let content = p.to_table(0, p.scores.len()).await;
|
||||||
on.apply_edit(
|
on.apply_edit(
|
||||||
CreateReply::default()
|
CreateReply::default()
|
||||||
.content(header)
|
.content(header)
|
||||||
|
@ -201,10 +202,11 @@ mod scores {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn display_scores_table(
|
pub async fn display_scores_table(
|
||||||
scores: Vec<Score>,
|
scores: impl Future<Output = Result<Vec<Score>>>,
|
||||||
ctx: &Context,
|
ctx: &Context,
|
||||||
mut on: impl CanEdit,
|
mut on: impl CanEdit,
|
||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
|
let scores = scores.await?;
|
||||||
if scores.is_empty() {
|
if scores.is_empty() {
|
||||||
on.apply_edit(CreateReply::default().content("No plays found"))
|
on.apply_edit(CreateReply::default().content("No plays found"))
|
||||||
.await?;
|
.await?;
|
||||||
|
|
|
@ -109,7 +109,12 @@ 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(
|
||||||
|
future::ok(scores),
|
||||||
|
&ctx,
|
||||||
|
guild_id,
|
||||||
|
(comp, ctx).with_header(header),
|
||||||
|
)
|
||||||
.await
|
.await
|
||||||
.pls_ok();
|
.pls_ok();
|
||||||
Ok(())
|
Ok(())
|
||||||
|
|
|
@ -685,7 +685,7 @@ pub async fn recent(ctx: &Context, msg: &Message, mut args: Args) -> CommandResu
|
||||||
let reply = msg.reply(ctx, &header).await?;
|
let reply = msg.reply(ctx, &header).await?;
|
||||||
style
|
style
|
||||||
.display_scores(
|
.display_scores(
|
||||||
plays.try_collect::<Vec<_>>().await?,
|
plays.try_collect::<Vec<_>>(),
|
||||||
ctx,
|
ctx,
|
||||||
reply.guild_id,
|
reply.guild_id,
|
||||||
(reply, ctx).with_header(header),
|
(reply, ctx).with_header(header),
|
||||||
|
@ -758,7 +758,7 @@ pub async fn pins(ctx: &Context, msg: &Message, mut args: Args) -> CommandResult
|
||||||
let reply = msg.reply(ctx, &header).await?;
|
let reply = msg.reply(ctx, &header).await?;
|
||||||
style
|
style
|
||||||
.display_scores(
|
.display_scores(
|
||||||
plays.try_collect::<Vec<_>>().await?,
|
plays.try_collect::<Vec<_>>(),
|
||||||
ctx,
|
ctx,
|
||||||
reply.guild_id,
|
reply.guild_id,
|
||||||
(reply, ctx).with_header(header),
|
(reply, ctx).with_header(header),
|
||||||
|
@ -1016,7 +1016,12 @@ pub async fn check(ctx: &Context, msg: &Message, mut args: Args) -> CommandResul
|
||||||
);
|
);
|
||||||
let reply = msg.reply(&ctx, &header).await?;
|
let reply = msg.reply(&ctx, &header).await?;
|
||||||
style
|
style
|
||||||
.display_scores(scores, ctx, msg.guild_id, (reply, ctx).with_header(header))
|
.display_scores(
|
||||||
|
future::ok(scores),
|
||||||
|
ctx,
|
||||||
|
msg.guild_id,
|
||||||
|
(reply, ctx).with_header(header),
|
||||||
|
)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
|
@ -1122,7 +1127,7 @@ pub async fn top(ctx: &Context, msg: &Message, mut args: Args) -> CommandResult
|
||||||
let reply = msg.reply(&ctx, &header).await?;
|
let reply = msg.reply(&ctx, &header).await?;
|
||||||
style
|
style
|
||||||
.display_scores(
|
.display_scores(
|
||||||
plays.try_collect::<Vec<_>>().await?,
|
plays.try_collect::<Vec<_>>(),
|
||||||
ctx,
|
ctx,
|
||||||
msg.guild_id,
|
msg.guild_id,
|
||||||
(reply, ctx).with_header(header),
|
(reply, ctx).with_header(header),
|
||||||
|
|
|
@ -438,7 +438,7 @@ pub async fn show_leaderboard(ctx: &Context, msg: &Message, mut args: Args) -> C
|
||||||
let reply = msg.reply(&ctx, header).await?;
|
let reply = msg.reply(&ctx, header).await?;
|
||||||
style
|
style
|
||||||
.display_scores(
|
.display_scores(
|
||||||
scores.into_iter().map(|s| s.score).collect(),
|
future::ok(scores.into_iter().map(|s| s.score).collect()),
|
||||||
ctx,
|
ctx,
|
||||||
Some(guild),
|
Some(guild),
|
||||||
(reply, ctx),
|
(reply, ctx),
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue