From b5e8a2491930e7917e06fb7620845ee4beefe908 Mon Sep 17 00:00:00 2001 From: Natsu Kagami Date: Sun, 11 Feb 2024 17:34:46 +0100 Subject: [PATCH] Remove reactions when youmu is no longer handling paginations --- youmubot-prelude/src/pagination.rs | 48 +++++++++++++++++++----------- 1 file changed, 30 insertions(+), 18 deletions(-) diff --git a/youmubot-prelude/src/pagination.rs b/youmubot-prelude/src/pagination.rs index d37381c..9b6a9bf 100644 --- a/youmubot-prelude/src/pagination.rs +++ b/youmubot-prelude/src/pagination.rs @@ -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(); - if large_count { - // add >> and << buttons - message.react(&ctx, ReactionType::try_from(REWIND)?).await?; - } - message - .react(&ctx, ReactionType::try_from(ARROW_LEFT)?) - .await?; - message - .react(&ctx, ReactionType::try_from(ARROW_RIGHT)?) - .await?; - if large_count { - // add >> and << buttons - message - .react(&ctx, ReactionType::try_from(FAST_FORWARD)?) - .await?; - } + let reactions = { + let mut rs = Vec::::with_capacity(4); + if large_count { + // add >> and << buttons + rs.push(message.react(&ctx, ReactionType::try_from(REWIND)?).await?); + } + rs.push( + message + .react(&ctx, ReactionType::try_from(ARROW_LEFT)?) + .await?, + ); + rs.push( + message + .react(&ctx, ReactionType::try_from(ARROW_RIGHT)?) + .await?, + ); + if large_count { + // add >> and << buttons + rs.push( + message + .react(&ctx, ReactionType::try_from(FAST_FORWARD)?) + .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 }