@@ -245,10 +245,10 @@ fn replay_filepaths(replays_dir: &Path) -> Option<Vec<PathBuf>> {
245245
246246 let file_path = file. path ( ) ;
247247
248- if let Some ( "wowsreplay" ) = file_path. extension ( ) . map ( |s| s. to_str ( ) . expect ( "failed to convert extension to str" ) ) {
249- if file. file_name ( ) != "temp.wowsreplay" {
250- files . push ( file_path ) ;
251- }
248+ if let Some ( "wowsreplay" ) = file_path. extension ( ) . map ( |s| s. to_str ( ) . expect ( "failed to convert extension to str" ) )
249+ && file. file_name ( ) != "temp.wowsreplay"
250+ {
251+ files . push ( file_path ) ;
252252 }
253253 }
254254 }
@@ -309,23 +309,23 @@ pub fn load_wows_files(wows_directory: PathBuf, locale: &str) -> Result<Backgrou
309309 let prefs_file = wows_directory. join ( "preferences.xml" ) ;
310310 if prefs_file. exists ( ) {
311311 // Try getting the version string from the preferences file
312- if let Some ( version_str) = current_build_from_preferences ( & prefs_file) {
313- if version_str. contains ( ',' ) {
314- let full_build_info = wowsunpack :: data :: Version :: from_client_exe ( & version_str ) ;
315- latest_build = Some ( full_build_info . build as usize ) ;
316-
317- // We want to build the version string without the patch component to get the replays dir
318- // that the replay manager mod uses
319- let friendly_build = format ! ( "{}.{}.{}.0" , full_build_info . major , full_build_info . minor , full_build_info . patch ) ;
320-
321- full_version = Some ( full_build_info ) ;
322-
323- for temp_replays_dir in [ replays_dir . join ( & friendly_build ) , replays_dir . join ( friendly_build ) ] {
324- debug ! ( "Looking for build-specific replays dir at {:?}" , temp_replays_dir ) ;
325- if temp_replays_dir . exists ( ) {
326- replays_dir = temp_replays_dir;
327- break ;
328- }
312+ if let Some ( version_str) = current_build_from_preferences ( & prefs_file)
313+ && version_str. contains ( ',' )
314+ {
315+ let full_build_info = wowsunpack :: data :: Version :: from_client_exe ( & version_str ) ;
316+ latest_build = Some ( full_build_info . build as usize ) ;
317+
318+ // We want to build the version string without the patch component to get the replays dir
319+ // that the replay manager mod uses
320+ let friendly_build = format ! ( "{}.{}.{}.0" , full_build_info . major , full_build_info . minor , full_build_info . patch ) ;
321+
322+ full_version = Some ( full_build_info ) ;
323+
324+ for temp_replays_dir in [ replays_dir . join ( & friendly_build ) , replays_dir . join ( friendly_build ) ] {
325+ debug ! ( "Looking for build-specific replays dir at {:?}" , temp_replays_dir ) ;
326+ if temp_replays_dir. exists ( ) {
327+ replays_dir = temp_replays_dir ;
328+ break ;
329329 }
330330 }
331331 }
@@ -343,10 +343,10 @@ pub fn load_wows_files(wows_directory: PathBuf, locale: &str) -> Result<Backgrou
343343 continue ;
344344 }
345345
346- if let Some ( build_num) = file. file_name ( ) . to_str ( ) . and_then ( |name| name. parse :: < usize > ( ) . ok ( ) ) {
347- if latest_build. is_none ( ) || latest_build. map ( |number| number < build_num) . unwrap_or ( false ) {
348- latest_build = Some ( build_num )
349- }
346+ if let Some ( build_num) = file. file_name ( ) . to_str ( ) . and_then ( |name| name. parse :: < usize > ( ) . ok ( ) )
347+ && ( latest_build. is_none ( ) || latest_build. map ( |number| number < build_num) . unwrap_or ( false ) )
348+ {
349+ latest_build = Some ( build_num )
350350 }
351351 }
352352 }
@@ -517,12 +517,11 @@ pub fn start_twitch_task(
517517 ( state. client ( ) . clone ( ) , state. token . clone ( ) )
518518 } ;
519519 let mut monitored_user_id = token. as_ref ( ) . map ( |token| token. user_id . clone ( ) ) ;
520- if !monitored_channel. is_empty ( ) {
521- if let Some ( token) = token {
522- if let Ok ( Some ( user) ) = client. get_user_from_login ( & monitored_channel, & token) . await {
523- monitored_user_id = Some ( user. id )
524- }
525- }
520+ if !monitored_channel. is_empty ( )
521+ && let Some ( token) = token
522+ && let Ok ( Some ( user) ) = client. get_user_from_login ( & monitored_channel, & token) . await
523+ {
524+ monitored_user_id = Some ( user. id )
526525 }
527526
528527 loop {
@@ -532,17 +531,15 @@ pub fn start_twitch_task(
532531 // Every 2 minutes we attempt to get the participants list
533532 _ = interval. tick( ) => {
534533 let ( client, token) = { let state = twitch_state. read( ) ; ( state. client( ) . clone( ) , state. token. clone( ) ) } ;
535- if let Some ( token) = token {
536- if let Some ( monitored_user) = & monitored_user_id {
537- if let Ok ( chatters) = twitch:: fetch_chatters( & client, monitored_user, & token) . await {
534+ if let Some ( token) = token
535+ && let Some ( monitored_user) = & monitored_user_id
536+ && let Ok ( chatters) = twitch:: fetch_chatters( & client, monitored_user, & token) . await {
538537 let now = Timestamp :: now( ) ;
539538 let mut state = twitch_state. write( ) ;
540539 for chatter in chatters {
541540 state. participants. entry( chatter) . or_default( ) . insert( now) ;
542541 }
543542 }
544- }
545- }
546543 }
547544
548545 update = token_receive => {
@@ -553,37 +550,32 @@ pub fn start_twitch_task(
553550 update_twitch_token( & twitch_state, & token) . await ;
554551
555552 let ( client, token) = { let state = twitch_state. read( ) ; ( state. client( ) . clone( ) , state. token. clone( ) ) } ;
556- if let Some ( token) = & token {
557- if let Some ( monitored_user) = & monitored_user_id {
558- if let Ok ( chatters) = twitch:: fetch_chatters( & client, monitored_user, token) . await {
553+ if let Some ( token) = & token
554+ && let Some ( monitored_user) = & monitored_user_id
555+ && let Ok ( chatters) = twitch:: fetch_chatters( & client, monitored_user, token) . await {
559556 let now = Timestamp :: now( ) ;
560557 let mut state = twitch_state. write( ) ;
561558 for chatter in chatters {
562559 state. participants. entry( chatter) . or_default( ) . insert( now) ;
563560 }
564561 }
565- }
566- }
567562
568563 if !had_previous_token {
569564 // If we didn't have a previous token, but we did have a username to watch, update the username
570565 monitored_user_id = token. as_ref( ) . map( |token| token. user_id. clone( ) ) ;
571- if !monitored_channel. is_empty( ) {
572- if let Some ( token) = token {
573- if let Ok ( Some ( user) ) = client. get_user_from_login( & monitored_channel, & token) . await {
566+ if !monitored_channel. is_empty( )
567+ && let Some ( token) = token
568+ && let Ok ( Some ( user) ) = client. get_user_from_login( & monitored_channel, & token) . await {
574569 monitored_user_id = Some ( user. id)
575570 }
576- }
577- }
578571 }
579572 } ,
580573 TwitchUpdate :: User ( user_name) => {
581574 let ( client, token) = { let state = twitch_state. read( ) ; ( state. client( ) . clone( ) , state. token. clone( ) ) } ;
582- if let Some ( token) = token {
583- if let Ok ( Some ( user) ) = client. get_user_from_login( & user_name, & token) . await {
575+ if let Some ( token) = token
576+ && let Ok ( Some ( user) ) = client. get_user_from_login( & user_name, & token) . await {
584577 monitored_user_id = Some ( user. id) ;
585578 }
586- }
587579 } ,
588580 }
589581 }
0 commit comments