From 6285c110e80dde1e44411e5de646044c34831a60 Mon Sep 17 00:00:00 2001 From: CircuitSacul Date: Tue, 24 Jan 2023 18:59:30 -0500 Subject: [PATCH] fetch all reactions for /recount, not first 25 --- src/core/starboard/recount.rs | 99 ++++++++++--------- .../commands/chat/utils/recount.rs | 2 +- 2 files changed, 54 insertions(+), 47 deletions(-) diff --git a/src/core/starboard/recount.rs b/src/core/starboard/recount.rs index 867fb241..546f21bf 100644 --- a/src/core/starboard/recount.rs +++ b/src/core/starboard/recount.rs @@ -101,57 +101,64 @@ async fn recount_votes_reaction( author_is_bot: bool, emoji: SimpleEmoji, ) -> StarboardResult<()> { - let reactions = bot - .http - .reactions(refreshing.0, refreshing.1, &emoji.reactable()) - .await? - .model() - .await?; - - for user in reactions { - let vote = VoteContext { - emoji: &emoji, - reactor_id: user.id, - message_id: orig.message_id.into_id(), - message_author_id: orig.author_id.into_id(), - channel_id: orig.channel_id.into_id(), - message_author_is_bot: author_is_bot, - message_has_image: None, - message_is_frozen: orig.frozen, - }; - let status = VoteStatus::get_vote_status(bot, vote, configs).await?; + let mut last_user = None; + let reactable = emoji.reactable(); + loop { + let mut reactions = bot.http.reactions(refreshing.0, refreshing.1, &reactable); + if let Some(last_user) = last_user { + reactions = reactions.after(last_user); + } + let reactions = reactions.await?.model().await?; - let VoteStatus::Valid((upvotes, downvotes)) = status else { + if reactions.is_empty() { + break; + } + last_user = Some(reactions.last().unwrap().id); + + for user in reactions { + let vote = VoteContext { + emoji: &emoji, + reactor_id: user.id, + message_id: orig.message_id.into_id(), + message_author_id: orig.author_id.into_id(), + channel_id: orig.channel_id.into_id(), + message_author_is_bot: author_is_bot, + message_has_image: None, + message_is_frozen: orig.frozen, + }; + let status = VoteStatus::get_vote_status(bot, vote, configs).await?; + + let VoteStatus::Valid((upvotes, downvotes)) = status else { continue; }; - let user_id = user.id.get_i64(); - DbUser::create(&bot.pool, user_id, user.bot).await?; - DbMember::create(&bot.pool, user_id, guild_id.get_i64()).await?; - - for config in &upvotes { - Vote::create( - &bot.pool, - orig.message_id, - config.starboard.id, - user_id, - orig.author_id, - false, - ) - .await?; - } - for config in &downvotes { - Vote::create( - &bot.pool, - orig.message_id, - config.starboard.id, - user_id, - orig.author_id, - true, - ) - .await?; + let user_id = user.id.get_i64(); + DbUser::create(&bot.pool, user_id, user.bot).await?; + DbMember::create(&bot.pool, user_id, guild_id.get_i64()).await?; + + for config in &upvotes { + Vote::create( + &bot.pool, + orig.message_id, + config.starboard.id, + user_id, + orig.author_id, + false, + ) + .await?; + } + for config in &downvotes { + Vote::create( + &bot.pool, + orig.message_id, + config.starboard.id, + user_id, + orig.author_id, + true, + ) + .await?; + } } } - Ok(()) } diff --git a/src/interactions/commands/chat/utils/recount.rs b/src/interactions/commands/chat/utils/recount.rs index 269cdc10..560a25c5 100644 --- a/src/interactions/commands/chat/utils/recount.rs +++ b/src/interactions/commands/chat/utils/recount.rs @@ -11,7 +11,7 @@ use crate::{ #[derive(CommandModel, CreateCommand)] #[command( name = "recount", - desc = "Recount the first 100 reactions on a message." + desc = "Recount all the reactions on a message." )] pub struct Recount { /// Link to the message to recount reactions on.