From f5f8cf6da02ba890bb21fe255ad0b24c380c40d9 Mon Sep 17 00:00:00 2001 From: kingbri Date: Wed, 7 Oct 2020 13:01:08 -0400 Subject: [PATCH] Fix reaction role wizard errors There was an error where the wizard would do two things 1. Check if anyone reacts to a message within the wizard 2. Check across all servers the bot is in to see if a replied message is provided. These are semantic errors that have been fixed with the addition of a collector filter on every step of the wizard. Resolves #15 Signed-off-by: kingbri --- src/commands/reaction_roles.rs | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/src/commands/reaction_roles.rs b/src/commands/reaction_roles.rs index e136652..9fa2961 100644 --- a/src/commands/reaction_roles.rs +++ b/src/commands/reaction_roles.rs @@ -269,7 +269,12 @@ async fn wizard(ctx: &Context, msg: &Message) -> CommandResult { sent_message.react(ctx, ReactionType::Unicode(String::from("✅"))).await?; sent_message.react(ctx, ReactionType::Unicode(String::from("❌"))).await?; + let channel_id = msg.channel_id; + let author_id = msg.author.id; + let wrapped_action = sent_message.await_reaction(ctx) + .filter(move |reaction| reaction.user_id == Some(author_id) && + reaction.channel_id == channel_id) .timeout(Duration::from_secs(120)).await; match wrapped_action { @@ -296,10 +301,13 @@ async fn wizard(ctx: &Context, msg: &Message) -> CommandResult { } async fn get_message(ctx: &Context, msg: &Message, mut storage: WizardIntermediate) -> CommandResult { - msg.channel_id.say(ctx, "Alright! Please give a channel mention followed by a message id for me to work with!").await?; + let channel_id = msg.channel_id; + + channel_id.say(ctx, "Alright! Please give a channel mention followed by a message id for me to work with!").await?; loop { let id_message = msg.author.await_reply(ctx) + .filter(move |given_msg| given_msg.channel_id == channel_id) .timeout(Duration::from_secs(120)).await; match id_message { @@ -348,13 +356,16 @@ async fn get_message(ctx: &Context, msg: &Message, mut storage: WizardIntermedia } async fn get_emoji(ctx: &Context, msg: &Message, mut storage: WizardIntermediate) -> CommandResult { - msg.channel_id.say(ctx, + let channel_id = msg.channel_id; + + channel_id.say(ctx, concat!("Awesome! Now please give me the emoji you want to use. \n", "Note: The emoji has to be from a server the BOT is in! \n", "The best option would be to use your server's custom emojis or unicode!")).await?; loop { let emoji_message = msg.author.await_reply(ctx) + .filter(move |given_msg| given_msg.channel_id == channel_id) .timeout(Duration::from_secs(120)).await; match emoji_message { @@ -387,10 +398,13 @@ async fn get_emoji(ctx: &Context, msg: &Message, mut storage: WizardIntermediate } async fn get_role(ctx: &Context, msg: &Message, mut storage: WizardIntermediate) -> CommandResult { - msg.channel_id.say(ctx, "Sounds good! Now, please give me a role mention that you want to assign!").await?; + let channel_id = msg.channel_id; + + channel_id.say(ctx, "Sounds good! Now, please give me a role mention that you want to assign!").await?; loop { let role_message = msg.author.await_reply(ctx) + .filter(move |given_msg| given_msg.channel_id == channel_id) .timeout(Duration::from_secs(120)).await; match role_message {