diff --git a/src/commands/sm_server.rs b/src/commands/sm_server.rs index 38e68e6..eecad4d 100644 --- a/src/commands/sm_server.rs +++ b/src/commands/sm_server.rs @@ -34,6 +34,12 @@ const ROLE_ID_BINGO: u64 = 621128130681110546; const ROLE_ID_MISC: u64 = 313710318486421505; const ROLE_ID_PUZZLE: u64 = 405792833820164102; +// ROLE EMOJIS: +const EMOJI_SM_ID: u64 = 245980377867485184; +const EMOJI_HUNDO_ID: u64 = 1023763860680876132; +const EMOJI_CROCZ_ID: u64 = 243881344910753794; + + pub async fn parse_command(ctx: Context, msg: Message, server_id: GuildId) { @@ -59,7 +65,7 @@ pub async fn parse_command(ctx: Context, msg: Message, server_id: GuildId) command_start == Some(".dorolesmsg") { if let Some(msg) = utils::send_msg(ctx.clone(), - ChannelId::from(SM_TEST_CHANNEL_ID), "Test message!").await + ChannelId::from(SM_TEST_CHANNEL_ID), "Test message! :CrocZ:").await { println!("Test message id is: {:#?}", msg.id) } @@ -110,15 +116,46 @@ 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("👍") + if let ReactionType::Custom{ animated: _, id, name: _ } = reaction.clone().emoji { - let user_name = reaction.user(ctx.clone()).await.unwrap().name; - utils::add_role(ctx.clone(), 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(); + match id + { + EmojiId(EMOJI_SM_ID) => { + utils::add_role(ctx.clone(), 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(); - utils::Logger::log_message(ctx.clone(), &format!("Added any% role for {}", user_name)).await; + let user_name = reaction.user(ctx.clone()).await.unwrap().name; + utils::Logger::log_message(ctx.clone(), &format!("Added any% role for {}", user_name)).await; + }, + + EmojiId(EMOJI_HUNDO_ID) => { + utils::add_role(ctx.clone(), reaction.user_id.expect("UserId was None in handle_reaction_add"), + RoleId::from(ROLE_ID_HUNDO), + reaction.guild_id.expect("GuildId was None in handle_reaction_add")) + .await.unwrap(); + + let user_name = reaction.user(ctx.clone()).await.unwrap().name; + utils::Logger::log_message(ctx.clone(), &format!("Added hundo role for {}", user_name)).await; + }, + + EmojiId(EMOJI_CROCZ_ID) => { + utils::add_role(ctx.clone(), reaction.user_id.expect("UserId was None in handle_reaction_add"), + RoleId::from(ROLE_ID_RANDOMIZER), + reaction.guild_id.expect("GuildId was None in handle_reaction_add")) + .await.unwrap(); + + + let user_name = reaction.user(ctx.clone()).await.unwrap().name; + utils::Logger::log_message(ctx.clone(), &format!("Added randomizer role for {}", user_name)).await; + }, + + // COLORS + + + _ => (), // TODO: Maybe give (or log) an error? + } } // else // { @@ -133,16 +170,48 @@ 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("👍") + if let ReactionType::Custom{ animated: _, id, name: _ } = reaction.clone().emoji { - utils::remove_role(ctx.clone(), 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(); + match id + { + EmojiId(EMOJI_SM_ID) => { + utils::remove_role(ctx.clone(), 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(); + + let user_name = reaction.user(ctx.clone()).await.unwrap().name; + utils::Logger::log_message(ctx.clone(), &format!("Removed any% role for {}", user_name)).await; + }, + + EmojiId(EMOJI_HUNDO_ID) => { + utils::remove_role(ctx.clone(), reaction.user_id.expect("UserId was None in handle_reaction_add"), + RoleId::from(ROLE_ID_HUNDO), + reaction.guild_id.expect("GuildId was None in handle_reaction_add")) + .await.unwrap(); + + let user_name = reaction.user(ctx.clone()).await.unwrap().name; + utils::Logger::log_message(ctx.clone(), &format!("Removed hundo role for {}", user_name)).await; + }, + + EmojiId(EMOJI_CROCZ_ID) => { + utils::remove_role(ctx.clone(), reaction.user_id.expect("UserId was None in handle_reaction_add"), + RoleId::from(ROLE_ID_RANDOMIZER), + reaction.guild_id.expect("GuildId was None in handle_reaction_add")) + .await.unwrap(); + + let user_name = reaction.user(ctx.clone()).await.unwrap().name; + utils::Logger::log_message(ctx.clone(), &format!("Removed randomizer role for {}", user_name)).await; + }, + + + // COLORS + + + _ => (), // TODO: Maybe give (or log) an error? + } + - - let user_name = reaction.user(ctx.clone()).await.unwrap().name; - utils::Logger::log_message(ctx.clone(), &format!("Removed any% role for {}", user_name)).await; } else { diff --git a/src/main.rs b/src/main.rs index 19b2677..21c8860 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.clone(), &format!("reaction add event: {:#?}", add_reaction)).await; + utils::Logger::log_message(ctx.clone(), &format!("reaction add event, emoji: {:#?}", add_reaction.emoji)).await; // todo!() commands::handle_reaction_add(ctx, add_reaction).await;