From 29bafbecc1ee6d092acfe7f402b0e576fbbc8f7f Mon Sep 17 00:00:00 2001 From: Joey Pollack Date: Tue, 28 May 2024 16:05:16 -0400 Subject: [PATCH] Completes testing for reaction roles, just need to setup the real thing --- src/commands/mod.rs | 2 +- src/commands/sm_server.rs | 21 ++++++++++++++++----- src/main.rs | 6 ++++-- 3 files changed, 21 insertions(+), 8 deletions(-) diff --git a/src/commands/mod.rs b/src/commands/mod.rs index 9801d3d..12d7deb 100644 --- a/src/commands/mod.rs +++ b/src/commands/mod.rs @@ -10,7 +10,7 @@ pub mod sm_server; use crate::utils; -pub async fn initialize(ctx: Context) -> Result<(), String> +pub async fn initialize(_ctx: Context) -> Result<(), String> { Ok(()) diff --git a/src/commands/sm_server.rs b/src/commands/sm_server.rs index 67bad3c..431fd3b 100644 --- a/src/commands/sm_server.rs +++ b/src/commands/sm_server.rs @@ -1,10 +1,14 @@ + +#![allow(dead_code)] + use serenity::prelude::*; use serenity::model::prelude::*; use serenity::model::channel::Message; use crate::{utils, Owner}; +// TODO: ADD REACTION ROLE MESSAGE IDS HERE // AUTHORIZED USER IDS: const BEL_WORK_USER_ID: u64 = 474259726427750420; @@ -49,6 +53,7 @@ pub async fn parse_command(ctx: Context, msg: Message, server_id: GuildId) None => { utils::Logger::log_error(ctx.clone(), &format!("Couldn't get bot owner id")).await; return; } }; + // TODO: Modify this to post the real Reaction Roles message if (UserId::from(owner_id) == msg.author.id || UserId::from(BEL_WORK_USER_ID) == msg.author.id) && command_start == Some(".dotestmsg") { if let Some(msg) = utils::send_msg(ctx.clone(), ChannelId::from(SM_TEST_CHANNEL_ID), "Test message!").await @@ -98,6 +103,7 @@ pub async fn parse_command(ctx: Context, msg: Message, server_id: GuildId) pub async fn handle_reaction_add(ctx: Context, reaction: Reaction) { + // TODO: Modify to handle the real reaction roles message for all race roles if reaction.channel_id == ChannelId::from(SM_TEST_CHANNEL_ID) && reaction.message_id == MessageId::from(1245086205381574790 as u64) { @@ -111,24 +117,29 @@ pub async fn handle_reaction_add(ctx: Context, reaction: Reaction) utils::Logger::log_message(ctx.clone(), &format!("Added any% role for {}", user_name)).await; } - else - { - utils::Logger::log_message(ctx.clone(), "Reaction was not the thumbs up emoji").await; - } + // else + // { + // utils::Logger::log_message(ctx.clone(), "Reaction was not the thumbs up emoji").await; + // } } } pub async fn handle_reaction_remove(ctx: Context, reaction: Reaction) { + // TODO: Modify to handle the real reaction roles message for all race roles 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"), + 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(); + + + 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 3176ffc..1759f14 100644 --- a/src/main.rs +++ b/src/main.rs @@ -4,7 +4,7 @@ mod data_loader; mod utils; mod racetime; -use racetime::{race::Races}; +use racetime::race::Races; use std::collections::HashMap; use std::sync::Arc; @@ -15,7 +15,7 @@ use std::time::Duration; use serenity::async_trait; use serenity::prelude::*; use serenity::model::channel::{Message, Reaction}; -use serenity::model::gateway::{Gateway, Ready}; +use serenity::model::gateway::Ready; use serenity::model::id::GuildId; use serenity::http::Http; @@ -57,6 +57,8 @@ impl EventHandler for Handler { println!("reaction_remove event"); //utils::Logger::log_message(ctx, &format!("reaction removed event: {:#?}", removed_reaction)).await; + + commands::handle_reaction_remove(ctx, removed_reaction).await; } // Set a handler to be called on the `ready` event. This is called when a