From 9cd32f5fa93dc0828d2281c20a54f1b1d641bed1 Mon Sep 17 00:00:00 2001 From: Joey Pollack Date: Tue, 28 May 2024 15:09:50 -0400 Subject: [PATCH] Adds test code for reaction roles --- src/commands/mod.rs | 15 +++++++++++- src/commands/sm_server.rs | 50 +++++++++++++++++++++++++++++++++++---- src/main.rs | 2 +- 3 files changed, 61 insertions(+), 6 deletions(-) diff --git a/src/commands/mod.rs b/src/commands/mod.rs index 0b56f3d..9801d3d 100644 --- a/src/commands/mod.rs +++ b/src/commands/mod.rs @@ -64,5 +64,18 @@ pub async fn handle_reaction_add(ctx: Context, add_reaction: Reaction) pub async fn handle_reaction_remove(ctx: Context, removed_reaction: Reaction) { - + if let Some(server_id) = removed_reaction.guild_id + { + if server_id == utils::ADMIN_SERVER_ID && removed_reaction.channel_id == utils::ADMIN_COMMAND_CHANNEL_ID + { + //test::handle_reaction_remove(ctx, removed_reaction, server_id).await; + return; + } + + if server_id == utils::SM_SERVER_ID + { + sm_server::handle_reaction_remove(ctx, removed_reaction).await; + return; + } + } } \ No newline at end of file diff --git a/src/commands/sm_server.rs b/src/commands/sm_server.rs index 7f7ccba..6a47a75 100644 --- a/src/commands/sm_server.rs +++ b/src/commands/sm_server.rs @@ -5,9 +5,14 @@ use serenity::model::channel::Message; use crate::{utils, Owner}; -const SM_TEST_CHANNEL_ID: u64 = 280548893135994880; + +// AUTHORIZED USER IDS: const BEL_WORK_USER_ID: u64 = 474259726427750420; +// CHANNEL IDS +const SM_TEST_CHANNEL_ID: u64 = 280548893135994880; +const SM_INFO_CHANNEL_ID: u64 = 270628925300801546; + // COLOR ROLE IDS const ROLE_ID_RED: u64 = 279338933748236289; const ROLE_ID_GREEN: u64 = 279338847102566400; @@ -18,8 +23,12 @@ const ROLE_ID_ORANGE: u64 = 279339077382438912; const ROLE_ID_PURPLE: u64 = 284310454908747787; // RACE ROLE IDS - - +const ROLE_ID_ANY_PERCENT: u64 = 313710041641254912; +const ROLE_ID_HUNDO: u64 = 313710205986668546; +const ROLE_ID_RANDOMIZER: u64 = 313710276685856768; +const ROLE_ID_BINGO: u64 = 621128130681110546; +const ROLE_ID_MISC: u64 = 313710318486421505; +const ROLE_ID_PUZZLE: u64 = 405792833820164102; pub async fn parse_command(ctx: Context, msg: Message, server_id: GuildId) { @@ -87,9 +96,42 @@ pub async fn parse_command(ctx: Context, msg: Message, server_id: GuildId) } -pub async fn handle_reaction_add(ctx: Context, reaction_add: Reaction) +pub async fn handle_reaction_add(ctx: Context, reaction: Reaction) { + if reaction.channel_id == ChannelId::from(SM_TEST_CHANNEL_ID) + && reaction.message_id == MessageId::from(1245086205381574790 as u64) + { + if reaction.emoji.unicode_eq("👍") + { + utils::add_role(ctx, reaction.user_id.expect("UserId was None in handle_reaction_add"), + RoleId::from(ROLE_ID_ANY_PERCENT), + reaction.guild_id.expect("GuildId was None in handle_reaction_add")) + .await.unwrap(); + } + else + { + utils::Logger::log_message(ctx, "Reaction was not the thumbs up emoji").await; + } + } +} +pub async fn handle_reaction_remove(ctx: Context, reaction: Reaction) +{ + if reaction.channel_id == ChannelId::from(SM_TEST_CHANNEL_ID) + && reaction.message_id == MessageId::from(1245086205381574790 as u64) + { + if reaction.emoji.unicode_eq("👍") + { + utils::remove_role(ctx, reaction.user_id.expect("UserId was None in handle_reaction_remove"), + RoleId::from(ROLE_ID_ANY_PERCENT), + reaction.guild_id.expect("GuildId was None in handle_reaction_remove")) + .await.unwrap(); + } + else + { + utils::Logger::log_message(ctx, "Reaction was not the thumbs up emoji").await; + } + } } ///////////////////// HELPERS diff --git a/src/main.rs b/src/main.rs index 76735c7..c3f8af5 100644 --- a/src/main.rs +++ b/src/main.rs @@ -47,7 +47,7 @@ impl EventHandler for Handler async fn reaction_add(&self, ctx: Context, add_reaction: Reaction) { // println!("reaction_add event"); - // utils::Logger::log_message(ctx, &format!("reaction add event: {:#?}", add_reaction)).await; + //utils::Logger::log_message(ctx, &format!("reaction add event: {:#?}", add_reaction)).await; // todo!() commands::handle_reaction_add(ctx, add_reaction).await;