mirror of
https://github.com/natsukagami/youmubot.git
synced 2025-05-24 01:00:49 +00:00
Change pagination to use interactions instead of reactions
This commit is contained in:
parent
460624c7fe
commit
d1f3aa5fa9
8 changed files with 281 additions and 227 deletions
|
@ -44,14 +44,14 @@ async fn list(ctx: &Context, m: &Message, _: Args) -> CommandResult {
|
|||
let pages = (roles.len() + ROLES_PER_PAGE - 1) / ROLES_PER_PAGE;
|
||||
|
||||
paginate_reply(
|
||||
paginate_from_fn(|page, ctx, msg| {
|
||||
paginate_from_fn(|page, _, _, btns| {
|
||||
let roles = roles.clone();
|
||||
Box::pin(async move {
|
||||
let page = page as usize;
|
||||
let start = page * ROLES_PER_PAGE;
|
||||
let end = roles.len().min(start + ROLES_PER_PAGE);
|
||||
if end <= start {
|
||||
return Ok(false);
|
||||
return Ok(None);
|
||||
}
|
||||
|
||||
let roles = &roles[start..end];
|
||||
|
@ -77,8 +77,9 @@ async fn list(ctx: &Context, m: &Message, _: Args) -> CommandResult {
|
|||
.push_line(format!("Page **{}/{}**", page + 1, pages))
|
||||
.build();
|
||||
|
||||
msg.edit(ctx, EditMessage::new().content(content)).await?;
|
||||
Ok(true)
|
||||
Ok(Some(
|
||||
EditMessage::new().content(content).components(vec![btns]),
|
||||
))
|
||||
})
|
||||
})
|
||||
.with_page_count(pages),
|
||||
|
|
|
@ -66,25 +66,23 @@ async fn message_command(
|
|||
}
|
||||
let images = std::sync::Arc::new(images);
|
||||
paginate_reply(
|
||||
paginate_from_fn(|page, ctx, msg: &mut Message| {
|
||||
paginate_from_fn(|page, _, _, btns| {
|
||||
let images = images.clone();
|
||||
Box::pin(async move {
|
||||
let page = page as usize;
|
||||
if page >= images.len() {
|
||||
Ok(false)
|
||||
Ok(None)
|
||||
} else {
|
||||
msg.edit(
|
||||
ctx,
|
||||
EditMessage::new().content(format!(
|
||||
"[🖼️ **{}/{}**] Here's the image you requested!\n\n{}",
|
||||
page + 1,
|
||||
images.len(),
|
||||
images[page]
|
||||
)),
|
||||
)
|
||||
.await
|
||||
.map(|_| true)
|
||||
.map_err(|e| e.into())
|
||||
Ok(Some(
|
||||
EditMessage::new()
|
||||
.content(format!(
|
||||
"[🖼️ **{}/{}**] Here's the image you requested!\n\n{}",
|
||||
page + 1,
|
||||
images.len(),
|
||||
images[page]
|
||||
))
|
||||
.components(vec![btns]),
|
||||
))
|
||||
}
|
||||
})
|
||||
})
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue