Skip to content

Commit

Permalink
Fix reaction role wizard errors
Browse files Browse the repository at this point in the history
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 <bdashore3@gmail.com>
  • Loading branch information
bdashore3 committed Oct 7, 2020
1 parent b941cc8 commit f5f8cf6
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions src/commands/reaction_roles.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit f5f8cf6

Please sign in to comment.