Remove reactions when youmu is no longer handling paginations

This commit is contained in:
Natsu Kagami 2024-02-11 17:34:46 +01:00
parent 30f186c604
commit b5e8a24919
Signed by: nki
GPG key ID: 55A032EB38B49ADB

View file

@ -3,7 +3,7 @@ use futures_util::{future::Future, StreamExt};
use serenity::{
collector::ReactionAction,
model::{
channel::{Message, ReactionType},
channel::{Message, Reaction, ReactionType},
id::ChannelId,
},
};
@ -110,22 +110,32 @@ async fn paginate_with_first_message(
}
// React to the message
let large_count = pager.len().filter(|&p| p > 10).is_some();
let reactions = {
let mut rs = Vec::<Reaction>::with_capacity(4);
if large_count {
// add >> and << buttons
message.react(&ctx, ReactionType::try_from(REWIND)?).await?;
rs.push(message.react(&ctx, ReactionType::try_from(REWIND)?).await?);
}
rs.push(
message
.react(&ctx, ReactionType::try_from(ARROW_LEFT)?)
.await?;
.await?,
);
rs.push(
message
.react(&ctx, ReactionType::try_from(ARROW_RIGHT)?)
.await?;
.await?,
);
if large_count {
// add >> and << buttons
rs.push(
message
.react(&ctx, ReactionType::try_from(FAST_FORWARD)?)
.await?;
.await?,
);
}
rs
};
// Build a reaction collector
let mut reaction_collector = message.await_reactions(ctx).removed(true).build();
let mut page = 0;
@ -148,7 +158,9 @@ async fn paginate_with_first_message(
}
};
message.react(&ctx, '🛑').await?;
for reaction in reactions {
reaction.delete_all(&ctx).await?;
}
res
}