Explorar o código

cleaning up code with clippy

Zhizhou Ma %!s(int64=3) %!d(string=hai) anos
pai
achega
752657200c

+ 1 - 1
.spotify_token_cache.json

@@ -1 +1 @@
-{"access_token":"BQBJjw-UD_aNwnXEveJ7v3inISHrPFQXdxM2msuhRqzOje5ZOV_KpkR8jIyIyhk3jH1pV3E8waQ7dTGvSe4","expires_in":3600,"expires_at":"2021-06-11T07:05:31.838345500Z","refresh_token":null,"scope":""}
+{"access_token":"BQAlb4fCcG9jZm7Rh87q_BChrYjDFTaDiCwsRnjbUI86jVhEk7bGwpBluwLJojOTJbvZEunezyFHzbaQh6s","expires_in":3600,"expires_at":"2021-06-11T07:35:03.229668200Z","refresh_token":null,"scope":""}

+ 1 - 1
src/audio/audio.rs

@@ -92,7 +92,7 @@ async fn remove_audio_state(ctx: &Context, msg: &Message) -> Result<(), String>
 #[command]
 async fn join(ctx: &Context, msg: &Message) -> CommandResult{
     let audio_state = get_audio_state(ctx, msg).await;
-    if let Some(_) = audio_state{
+    if audio_state.is_some(){
         message_react(ctx, msg, "🥳").await;
     }
 

+ 1 - 1
src/audio/audio_state.rs

@@ -40,7 +40,7 @@ impl AudioState{
     pub fn new(handler: Arc<SerenityMutex<Call>>) -> Arc<AudioState>{
         let audio_state = AudioState{
             queue: SongQueue::new(),
-            handler: handler.clone(),
+            handler,
             current_song: Mutex::new(None),
             track_handle: Mutex::new(None),
         };

+ 2 - 6
src/audio/loader.rs

@@ -18,11 +18,7 @@ impl Loader{
         };
     }
     async fn loader_loop(mut work: mpsc::Receiver<Work>,){
-        loop{
-            let work = match work.recv().await{
-                Some(work)=>work,
-                None=>break,
-            };
+        while let Some(work) = work.recv().await {
             println!("hi2");
             // update this
             let url = ytdl(&work.query).await;
@@ -33,7 +29,7 @@ impl Loader{
 
             {
                 let mut is_loaded = work.is_loaded.lock().await;
-                assert!(*is_loaded == false);
+                assert!(!*is_loaded);
                 *is_loaded = true;
             }
         }

+ 3 - 4
src/audio/query.rs

@@ -11,16 +11,15 @@ pub async fn process_query(query: &str) -> Result<Vec<(Song, Option<Work>)>, Str
     if query.contains("spotify") && query.contains("/playlist/"){
         let split: Vec<&str> = query
             .split("/playlist/")
-            .filter(|s| s.len() > 0)
+            .filter(|s| !s.is_empty())
             .collect();
         if split.len() != 2 {
             return Err("invalid spotify playlist URL".to_string());
         }
         let playlist_id = split[1];
         let playlist_id = playlist_id
-            .split("?")
-            .filter(|s| s.len() > 0)
-            .next()
+            .split('?')
+            .find(|s| !s.is_empty())
             .expect("Logical error: process_query's playlist_id contains items?");
         let songs = match get_playlist(playlist_id).await{
             Ok(songs) => songs,

+ 2 - 2
src/audio/song.rs

@@ -40,10 +40,10 @@ impl Song{
         let work = Work{
             sender: tx,
             is_loaded: is_loaded.clone(),
-            query: query.clone(),
+            query: query,
         };
         let url_state = SongUrlState::Proc{
-            is_loaded: is_loaded.clone(),
+            is_loaded: is_loaded,
             receiver: rx,
             work: work.clone(),
         };

+ 2 - 3
src/audio/song_queue.rs

@@ -33,9 +33,8 @@ impl SongQueue{
         let loader = self.loader.lock().await;
         for item in songs.into_iter(){
             queue.push_back(item.0);
-            match item.1{
-                Some(work) => loader.add_work(work).await,
-                None =>{},
+            if let Some(work) = item.1{
+                loader.add_work(work).await;
             };
             //self.loader.add_work(item.1).await;
         }