Commit 54b61a30 authored by Ash's avatar Ash

Merge branch 'morefix2' into 'master'

cleanup

See merge request !10
parents bc3a4f18 7eb33928
Pipeline #207 failed with stages
in 4 seconds
...@@ -36,12 +36,6 @@ pub struct UccbotConfig { ...@@ -36,12 +36,6 @@ pub struct UccbotConfig {
pub bind_address: String, pub bind_address: String,
} }
#[derive(Debug, Deserialize)]
pub struct UccbotSecrets {
pub ldap_pass: String,
pub discord_token: String,
}
pub fn ldap_bind_address() -> String { pub fn ldap_bind_address() -> String {
"ldaps://samson.ucc.asn.au:636".to_string() "ldaps://samson.ucc.asn.au:636".to_string()
} }
...@@ -59,6 +53,12 @@ impl UccbotConfig { ...@@ -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>; pub type ReactRoleMap = IndexMap<String, id::RoleId>;
#[derive(Debug, Deserialize, Clone)] #[derive(Debug, Deserialize, Clone)]
......
...@@ -30,7 +30,7 @@ pub fn ldap_search(username: &str) -> Option<LDAPUser> { ...@@ -30,7 +30,7 @@ pub fn ldap_search(username: &str) -> Option<LDAPUser> {
.success() .success()
.expect("LDAP search error"); .expect("LDAP search error");
if rs.is_empty() { if rs.is_empty() {
return None; return None
} }
let result = SearchEntry::construct(rs[0].clone()).attrs; let result = SearchEntry::construct(rs[0].clone()).attrs;
Some(LDAPUser { Some(LDAPUser {
......
...@@ -130,7 +130,7 @@ impl EventHandler for Handler { ...@@ -130,7 +130,7 @@ impl EventHandler for Handler {
Ok(message) => match get_message_type(&message) { Ok(message) => match get_message_type(&message) {
MessageType::RoleReactMessage if add_reaction.user_id.0 != CONFIG.bot_id => { MessageType::RoleReactMessage if add_reaction.user_id.0 != CONFIG.bot_id => {
add_role_by_reaction(&ctx, message, add_reaction); add_role_by_reaction(&ctx, message, add_reaction);
return; return
} }
_ if message.author.id.0 != CONFIG.bot_id _ if message.author.id.0 != CONFIG.bot_id
|| add_reaction.user_id == CONFIG.bot_id => || add_reaction.user_id == CONFIG.bot_id =>
...@@ -146,7 +146,7 @@ impl EventHandler for Handler { ...@@ -146,7 +146,7 @@ impl EventHandler for Handler {
"The logreact message {} just tried to use is too old", "The logreact message {} just tried to use is too old",
react_user.name react_user.name
); );
return; return
} }
info!( info!(
"The react {} just added is {:?}. In full: {:?}", "The react {} just added is {:?}. In full: {:?}",
...@@ -172,7 +172,7 @@ impl EventHandler for Handler { ...@@ -172,7 +172,7 @@ impl EventHandler for Handler {
Ok(message) => match get_message_type(&message) { Ok(message) => match get_message_type(&message) {
MessageType::RoleReactMessage if removed_reaction.user_id != CONFIG.bot_id => { MessageType::RoleReactMessage if removed_reaction.user_id != CONFIG.bot_id => {
remove_role_by_reaction(&ctx, message, removed_reaction); remove_role_by_reaction(&ctx, message, removed_reaction);
return; return
} }
_ if message.author.id.0 != CONFIG.bot_id _ if message.author.id.0 != CONFIG.bot_id
|| removed_reaction.user_id == CONFIG.bot_id => || removed_reaction.user_id == CONFIG.bot_id =>
......
...@@ -97,7 +97,7 @@ pub fn sync_all_role_reactions(ctx: &Context) { ...@@ -97,7 +97,7 @@ pub fn sync_all_role_reactions(ctx: &Context) {
for react in &message.reactions { for react in &message.reactions {
let react_as_string = get_string_from_react(&react.reaction_type); let react_as_string = get_string_from_react(&react.reaction_type);
if mapping.contains_key(&react_as_string) { if mapping.contains_key(&react_as_string) {
continue; continue
} }
info!( info!(
" message #{}: Removing non-role react '{}'", " message #{}: Removing non-role react '{}'",
......
...@@ -75,7 +75,7 @@ pub fn parse_token(discord_user: &User, encrypted_token: &str) -> Result<String, ...@@ -75,7 +75,7 @@ pub fn parse_token(discord_user: &User, encrypted_token: &str) -> Result<String,
let token_username = token_components[2]; let token_username = token_components[2];
if token_discord_user != discord_user.id.0.to_string() { if token_discord_user != discord_user.id.0.to_string() {
warn!("... attempt failed : DiscordID mismatch"); warn!("... attempt failed : DiscordID mismatch");
return Err(TokenError::DiscordIdMismatch); return Err(TokenError::DiscordIdMismatch)
} }
let time_delta_seconds = Utc::now().timestamp() - token_timestamp.timestamp(); let time_delta_seconds = Utc::now().timestamp() - token_timestamp.timestamp();
if time_delta_seconds > TOKEN_LIFETIME { if time_delta_seconds > TOKEN_LIFETIME {
...@@ -83,7 +83,7 @@ pub fn parse_token(discord_user: &User, encrypted_token: &str) -> Result<String, ...@@ -83,7 +83,7 @@ pub fn parse_token(discord_user: &User, encrypted_token: &str) -> Result<String,
"... attempt failed : token expired ({} seconds old)", "... attempt failed : token expired ({} seconds old)",
time_delta_seconds time_delta_seconds
); );
return Err(TokenError::TokenExpired); return Err(TokenError::TokenExpired)
} }
info!( info!(
"... verification successful (token {} seconds old)", "... verification successful (token {} seconds old)",
......
...@@ -78,7 +78,7 @@ impl Commands { ...@@ -78,7 +78,7 @@ impl Commands {
&ctx.http, &ctx.http,
format!("Usage: {}register <username>", CONFIG.command_prefix) format!("Usage: {}register <username>", CONFIG.command_prefix)
); );
return; return
} }
if RESERVED_NAMES.contains(&account_name) || database::username_exists(account_name) { if RESERVED_NAMES.contains(&account_name) || database::username_exists(account_name) {
send_message!( send_message!(
...@@ -88,7 +88,7 @@ impl Commands { ...@@ -88,7 +88,7 @@ impl Commands {
.choose(&mut rand::thread_rng()) .choose(&mut rand::thread_rng())
.expect("We couldn't get any sass") .expect("We couldn't get any sass")
); );
return; return
} }
if !ldap_exists(account_name) { if !ldap_exists(account_name) {
send_message!( send_message!(
...@@ -99,7 +99,7 @@ impl Commands { ...@@ -99,7 +99,7 @@ impl Commands {
account_name account_name
) )
); );
return; return
} }
send_message!( send_message!(
msg.channel_id, msg.channel_id,
...@@ -200,7 +200,7 @@ impl Commands { ...@@ -200,7 +200,7 @@ impl Commands {
&ctx.http, &ctx.http,
"Sorry, I couldn't find that profile (you need to !register for a profile)" "Sorry, I couldn't find that profile (you need to !register for a profile)"
); );
return; return
} }
let member = possible_member.unwrap(); let member = possible_member.unwrap();
let result = msg.channel_id.send_message(&ctx.http, |m| { let result = msg.channel_id.send_message(&ctx.http, |m| {
...@@ -272,7 +272,7 @@ impl Commands { ...@@ -272,7 +272,7 @@ impl Commands {
m m
}) })
.expect("Failed to send usage help embed"); .expect("Failed to send usage help embed");
return; return
} }
let info_content: Vec<_> = info.splitn(2, ' ').collect(); let info_content: Vec<_> = info.splitn(2, ' ').collect();
let mut property = String::from(info_content[0]); let mut property = String::from(info_content[0]);
...@@ -316,7 +316,7 @@ impl Commands { ...@@ -316,7 +316,7 @@ impl Commands {
m m
}) })
.expect("Failed to send usage embed"); .expect("Failed to send usage embed");
return; return
} }
let mut value = info_content[1].to_string(); let mut value = info_content[1].to_string();
...@@ -333,7 +333,7 @@ impl Commands { ...@@ -333,7 +333,7 @@ impl Commands {
&ctx.http, &ctx.http,
"That ain't a URL where I come from..." "That ain't a URL where I come from..."
); );
return; return
} }
} }
} }
......
...@@ -15,7 +15,7 @@ impl Commands { ...@@ -15,7 +15,7 @@ impl Commands {
let motion = content; let motion = content;
if !motion.is_empty() { if !motion.is_empty() {
create_motion(&ctx, &msg, motion); create_motion(&ctx, &msg, motion);
return; return
} }
send_message!( send_message!(
msg.channel_id, msg.channel_id,
...@@ -34,7 +34,7 @@ impl Commands { ...@@ -34,7 +34,7 @@ impl Commands {
let topic = content; let topic = content;
if !topic.is_empty() { if !topic.is_empty() {
create_poll(&ctx, &msg, topic); create_poll(&ctx, &msg, topic);
return; return
} }
send_message!( send_message!(
msg.channel_id, msg.channel_id,
...@@ -193,7 +193,7 @@ fn get_cached_motion(ctx: &Context, msg: &Message) -> MotionInfo { ...@@ -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) { fn set_cached_motion(id: serenity::model::id::MessageId, motion_info: MotionInfo) {
if let Some(motion) = MOTIONS_CACHE.lock().unwrap().get_mut(&id) { if let Some(motion) = MOTIONS_CACHE.lock().unwrap().get_mut(&id) {
*motion = motion_info; *motion = motion_info;
return; return
} }
warn!("{}", "Couldn't find motion in cache to set"); warn!("{}", "Couldn't find motion in cache to set");
} }
...@@ -208,7 +208,7 @@ macro_rules! tiebreaker { ...@@ -208,7 +208,7 @@ macro_rules! tiebreaker {
} else { } else {
0.0 0.0
} }
}; }
} }
fn update_motion( fn update_motion(
...@@ -225,10 +225,8 @@ 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 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 for_strength = for_votes as f32 + tiebreaker!(ctx, &CONFIG.for_vote, motion_info);
let against_strength = let against_strength = against_votes as f32 + tiebreaker!(ctx, &CONFIG.against_vote, motion_info);
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 abstain_strength =
abstain_votes as f32 + tiebreaker!(ctx, &CONFIG.abstain_vote, motion_info);
let old_embed = msg.embeds[0].clone(); let old_embed = msg.embeds[0].clone();
let topic = old_embed.clone().title.unwrap(); let topic = old_embed.clone().title.unwrap();
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment