From e6d48ab0a7f3cc2bb4b3420f26d721564f6810e8 Mon Sep 17 00:00:00 2001 From: kageru Date: Sat, 20 Nov 2021 16:57:31 +0100 Subject: [PATCH] Generify role actions --- src/main.rs | 34 ++++++++++++++++------------------ 1 file changed, 16 insertions(+), 18 deletions(-) diff --git a/src/main.rs b/src/main.rs index 528a8a3..aa5561a 100644 --- a/src/main.rs +++ b/src/main.rs @@ -33,6 +33,20 @@ macro_rules! send_or_log { }; } +macro_rules! role_action { + ($reaction: expr, $ctx: expr, $action: ident) => { + $reaction + .guild_id + .unwrap() + .member(&$ctx, $reaction.user_id.unwrap()) + .await + .unwrap() + .$action(&$ctx, 356421827708321795) + .await + .unwrap() + }; +} + #[group] #[commands(name, message, question, inbox)] struct Fluff; @@ -53,15 +67,7 @@ impl EventHandler for Handler { if reaction.message_id == 911630315376738384 && reaction.emoji == ReactionType::Unicode(String::from("🧪")) { - reaction - .guild_id - .unwrap() - .member(&ctx, reaction.user_id.unwrap()) - .await - .unwrap() - .add_role(&ctx, 356421827708321795) - .await - .unwrap() + role_action!(reaction, ctx, add_role) } } @@ -69,15 +75,7 @@ impl EventHandler for Handler { if reaction.message_id == 911630315376738384 && reaction.emoji == ReactionType::Unicode(String::from("🧪")) { - reaction - .guild_id - .unwrap() - .member(&ctx, reaction.user_id.unwrap()) - .await - .unwrap() - .remove_role(&ctx, 356421827708321795) - .await - .unwrap() + role_action!(reaction, ctx, remove_role) } } }