Generify role actions

This commit is contained in:
kageru 2021-11-20 16:57:31 +01:00
parent 1ee9233e05
commit e6d48ab0a7
Signed by: kageru
GPG Key ID: 8282A2BEA4ADA3D2

View File

@ -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)
}
}
}