From 7eb339285775d8dfdb24a05d4eec20a7424a1f6b Mon Sep 17 00:00:00 2001 From: Ash <spook123@gmail.com> Date: Sat, 28 Mar 2020 15:31:42 +0800 Subject: [PATCH] cleanup --- src/config.rs | 12 ++++++------ src/ldap.rs | 2 +- src/main.rs | 6 +++--- src/reaction_roles.rs | 2 +- src/token_management.rs | 4 ++-- src/user_management.rs | 14 +++++++------- src/voting.rs | 14 ++++++-------- 7 files changed, 26 insertions(+), 28 deletions(-) diff --git a/src/config.rs b/src/config.rs index 9320830..a854a72 100644 --- a/src/config.rs +++ b/src/config.rs @@ -36,12 +36,6 @@ pub struct UccbotConfig { pub bind_address: String, } -#[derive(Debug, Deserialize)] -pub struct UccbotSecrets { - pub ldap_pass: String, - pub discord_token: String, -} - pub fn ldap_bind_address() -> String { "ldaps://samson.ucc.asn.au:636".to_string() } @@ -59,6 +53,12 @@ impl UccbotConfig { } } +#[derive(Debug, Deserialize)] +pub struct UccbotSecrets { + pub ldap_pass: String, + pub discord_token: String, +} + pub type ReactRoleMap = IndexMap<String, id::RoleId>; #[derive(Debug, Deserialize, Clone)] diff --git a/src/ldap.rs b/src/ldap.rs index 1346ffc..ee0deee 100644 --- a/src/ldap.rs +++ b/src/ldap.rs @@ -30,7 +30,7 @@ pub fn ldap_search(username: &str) -> Option<LDAPUser> { .success() .expect("LDAP search error"); if rs.is_empty() { - return None; + return None } let result = SearchEntry::construct(rs[0].clone()).attrs; Some(LDAPUser { diff --git a/src/main.rs b/src/main.rs index 2486c3e..e4ded92 100644 --- a/src/main.rs +++ b/src/main.rs @@ -130,7 +130,7 @@ impl EventHandler for Handler { Ok(message) => match get_message_type(&message) { MessageType::RoleReactMessage if add_reaction.user_id.0 != CONFIG.bot_id => { add_role_by_reaction(&ctx, message, add_reaction); - return; + return } _ if message.author.id.0 != CONFIG.bot_id || add_reaction.user_id == CONFIG.bot_id => @@ -146,7 +146,7 @@ impl EventHandler for Handler { "The logreact message {} just tried to use is too old", react_user.name ); - return; + return } info!( "The react {} just added is {:?}. In full: {:?}", @@ -172,7 +172,7 @@ impl EventHandler for Handler { Ok(message) => match get_message_type(&message) { MessageType::RoleReactMessage if removed_reaction.user_id != CONFIG.bot_id => { remove_role_by_reaction(&ctx, message, removed_reaction); - return; + return } _ if message.author.id.0 != CONFIG.bot_id || removed_reaction.user_id == CONFIG.bot_id => diff --git a/src/reaction_roles.rs b/src/reaction_roles.rs index f0f1b38..fbc188d 100644 --- a/src/reaction_roles.rs +++ b/src/reaction_roles.rs @@ -97,7 +97,7 @@ pub fn sync_all_role_reactions(ctx: &Context) { for react in &message.reactions { let react_as_string = get_string_from_react(&react.reaction_type); if mapping.contains_key(&react_as_string) { - continue; + continue } info!( " message #{}: Removing non-role react '{}'", diff --git a/src/token_management.rs b/src/token_management.rs index ff11f94..f6d21f6 100644 --- a/src/token_management.rs +++ b/src/token_management.rs @@ -75,7 +75,7 @@ pub fn parse_token(discord_user: &User, encrypted_token: &str) -> Result<String, let token_username = token_components[2]; if token_discord_user != discord_user.id.0.to_string() { warn!("... attempt failed : DiscordID mismatch"); - return Err(TokenError::DiscordIdMismatch); + return Err(TokenError::DiscordIdMismatch) } let time_delta_seconds = Utc::now().timestamp() - token_timestamp.timestamp(); if time_delta_seconds > TOKEN_LIFETIME { @@ -83,7 +83,7 @@ pub fn parse_token(discord_user: &User, encrypted_token: &str) -> Result<String, "... attempt failed : token expired ({} seconds old)", time_delta_seconds ); - return Err(TokenError::TokenExpired); + return Err(TokenError::TokenExpired) } info!( "... verification successful (token {} seconds old)", diff --git a/src/user_management.rs b/src/user_management.rs index 5e3c1f2..2b09045 100644 --- a/src/user_management.rs +++ b/src/user_management.rs @@ -78,7 +78,7 @@ impl Commands { &ctx.http, format!("Usage: {}register <username>", CONFIG.command_prefix) ); - return; + return } if RESERVED_NAMES.contains(&account_name) || database::username_exists(account_name) { send_message!( @@ -88,7 +88,7 @@ impl Commands { .choose(&mut rand::thread_rng()) .expect("We couldn't get any sass") ); - return; + return } if !ldap_exists(account_name) { send_message!( @@ -99,7 +99,7 @@ impl Commands { account_name ) ); - return; + return } send_message!( msg.channel_id, @@ -200,7 +200,7 @@ impl Commands { &ctx.http, "Sorry, I couldn't find that profile (you need to !register for a profile)" ); - return; + return } let member = possible_member.unwrap(); let result = msg.channel_id.send_message(&ctx.http, |m| { @@ -272,7 +272,7 @@ impl Commands { m }) .expect("Failed to send usage help embed"); - return; + return } let info_content: Vec<_> = info.splitn(2, ' ').collect(); let mut property = String::from(info_content[0]); @@ -316,7 +316,7 @@ impl Commands { m }) .expect("Failed to send usage embed"); - return; + return } let mut value = info_content[1].to_string(); @@ -333,7 +333,7 @@ impl Commands { &ctx.http, "That ain't a URL where I come from..." ); - return; + return } } } diff --git a/src/voting.rs b/src/voting.rs index 6d67961..5f2e05f 100644 --- a/src/voting.rs +++ b/src/voting.rs @@ -15,7 +15,7 @@ impl Commands { let motion = content; if !motion.is_empty() { create_motion(&ctx, &msg, motion); - return; + return } send_message!( msg.channel_id, @@ -34,7 +34,7 @@ impl Commands { let topic = content; if !topic.is_empty() { create_poll(&ctx, &msg, topic); - return; + return } send_message!( msg.channel_id, @@ -193,7 +193,7 @@ fn get_cached_motion(ctx: &Context, msg: &Message) -> MotionInfo { fn set_cached_motion(id: serenity::model::id::MessageId, motion_info: MotionInfo) { if let Some(motion) = MOTIONS_CACHE.lock().unwrap().get_mut(&id) { *motion = motion_info; - return; + return } warn!("{}", "Couldn't find motion in cache to set"); } @@ -208,7 +208,7 @@ macro_rules! tiebreaker { } else { 0.0 } - }; + } } fn update_motion( @@ -225,10 +225,8 @@ fn update_motion( let abstain_votes = motion_info.votes.get(&CONFIG.abstain_vote).unwrap().len() as isize - 1; let for_strength = for_votes as f32 + tiebreaker!(ctx, &CONFIG.for_vote, motion_info); - let against_strength = - against_votes as f32 + tiebreaker!(ctx, &CONFIG.against_vote, motion_info); - let abstain_strength = - abstain_votes as f32 + tiebreaker!(ctx, &CONFIG.abstain_vote, motion_info); + let against_strength = against_votes as f32 + tiebreaker!(ctx, &CONFIG.against_vote, motion_info); + let abstain_strength = abstain_votes as f32 + tiebreaker!(ctx, &CONFIG.abstain_vote, motion_info); let old_embed = msg.embeds[0].clone(); let topic = old_embed.clone().title.unwrap(); -- GitLab