From 63d28c1751b429016577c902f95599f7e7bcd688 Mon Sep 17 00:00:00 2001 From: Prince Date: Sat, 9 Mar 2024 18:22:29 +0000 Subject: [PATCH 1/5] allow only active memebers to transfer money --- bin/bot/src/discord/slash/bank.rs | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/bin/bot/src/discord/slash/bank.rs b/bin/bot/src/discord/slash/bank.rs index 5048bb5..9d7f4ed 100644 --- a/bin/bot/src/discord/slash/bank.rs +++ b/bin/bot/src/discord/slash/bank.rs @@ -4,7 +4,7 @@ use serenity::{ client::Context, }; use synixe_events::gear::db::Response; -use synixe_meta::discord::{channel::LOG, role::STAFF, BRODSKY, GUILD}; +use synixe_meta::discord::{channel::LOG, role::{ACTIVE, JUNIOR, MEMBER, STAFF}, BRODSKY, GUILD}; use synixe_proc::events_request_2; use crate::{discord::interaction::Interaction, get_option, get_option_user}; @@ -128,7 +128,7 @@ async fn balance( .await } -#[allow(clippy::cast_possible_truncation)] +#[allow(clippy::cast_possible_truncation, clippy::too_many_lines)] async fn transfer( ctx: &Context, command: &CommandInteraction, @@ -139,6 +139,20 @@ async fn transfer( let Some(user) = get_option_user!(options, "member") else { return interaction.reply("Invalid member").await; }; + + super::requires_roles( + command.user.id, + &[JUNIOR, MEMBER, ACTIVE], + &command + .member + .as_ref() + .expect("member should always exist on guild commands") + .roles, + ShouldAsk::Deny, + &mut interaction, + ) + .await?; + if user != &synixe_meta::discord::BRODSKY && GUILD.member(&ctx, user).await?.user.bot { return interaction.reply("You can't transfer money to a bot").await; } From 9ea9b23c52c76a6bb7d0cde346c3c1dcfc81059b Mon Sep 17 00:00:00 2001 From: Prince Date: Sat, 9 Mar 2024 18:23:45 +0000 Subject: [PATCH 2/5] cargo fmt --- bin/bot/src/discord/slash/bank.rs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/bin/bot/src/discord/slash/bank.rs b/bin/bot/src/discord/slash/bank.rs index 9d7f4ed..52344b2 100644 --- a/bin/bot/src/discord/slash/bank.rs +++ b/bin/bot/src/discord/slash/bank.rs @@ -4,7 +4,11 @@ use serenity::{ client::Context, }; use synixe_events::gear::db::Response; -use synixe_meta::discord::{channel::LOG, role::{ACTIVE, JUNIOR, MEMBER, STAFF}, BRODSKY, GUILD}; +use synixe_meta::discord::{ + channel::LOG, + role::{ACTIVE, JUNIOR, MEMBER, STAFF}, + BRODSKY, GUILD, +}; use synixe_proc::events_request_2; use crate::{discord::interaction::Interaction, get_option, get_option_user}; From edce877b08097d5e34e785c46d5f2a5fdde09453 Mon Sep 17 00:00:00 2001 From: Prince Date: Sat, 9 Mar 2024 18:51:41 +0000 Subject: [PATCH 3/5] make sure the user is active --- bin/bot/src/discord/slash/bank.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/bot/src/discord/slash/bank.rs b/bin/bot/src/discord/slash/bank.rs index 52344b2..a53b643 100644 --- a/bin/bot/src/discord/slash/bank.rs +++ b/bin/bot/src/discord/slash/bank.rs @@ -146,7 +146,7 @@ async fn transfer( super::requires_roles( command.user.id, - &[JUNIOR, MEMBER, ACTIVE], + &[ACTIVE], &command .member .as_ref() From d874d0ff2013cdb69b715b07b4caf9bd86b9c8b7 Mon Sep 17 00:00:00 2001 From: Prince Date: Sat, 9 Mar 2024 18:53:59 +0000 Subject: [PATCH 4/5] remove unused imports --- bin/bot/src/discord/slash/bank.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/bot/src/discord/slash/bank.rs b/bin/bot/src/discord/slash/bank.rs index a53b643..a9aa40e 100644 --- a/bin/bot/src/discord/slash/bank.rs +++ b/bin/bot/src/discord/slash/bank.rs @@ -6,7 +6,7 @@ use serenity::{ use synixe_events::gear::db::Response; use synixe_meta::discord::{ channel::LOG, - role::{ACTIVE, JUNIOR, MEMBER, STAFF}, + role::{ACTIVE, STAFF}, BRODSKY, GUILD, }; use synixe_proc::events_request_2; From e7680c902cde0d44cb48bc6b6f87b74a5a8d3ab4 Mon Sep 17 00:00:00 2001 From: Prince Date: Sat, 9 Mar 2024 21:35:17 +0000 Subject: [PATCH 5/5] allow confirm to transfer --- bin/bot/src/discord/slash/bank.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/bot/src/discord/slash/bank.rs b/bin/bot/src/discord/slash/bank.rs index a9aa40e..127e0df 100644 --- a/bin/bot/src/discord/slash/bank.rs +++ b/bin/bot/src/discord/slash/bank.rs @@ -152,7 +152,7 @@ async fn transfer( .as_ref() .expect("member should always exist on guild commands") .roles, - ShouldAsk::Deny, + ShouldAsk::Yes(("bank transfer", options)), &mut interaction, ) .await?;