aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/audio_player.rs24
-rw-r--r--src/bot/master.rs8
-rw-r--r--src/bot/music.rs5
-rw-r--r--src/main.rs2
-rw-r--r--src/teamspeak/mod.rs10
-rw-r--r--src/web_server.rs4
-rw-r--r--src/youtube_dl.rs8
7 files changed, 27 insertions, 34 deletions
diff --git a/src/audio_player.rs b/src/audio_player.rs
index 5f9c625..79c54ef 100644
--- a/src/audio_player.rs
+++ b/src/audio_player.rs
@@ -13,8 +13,8 @@ use log::{debug, error, info, warn};
use std::sync::{Arc, RwLock};
use tokio02::sync::mpsc::UnboundedSender;
-use crate::youtube_dl::AudioMetadata;
use crate::command::{Seek, VolumeChange};
+use crate::youtube_dl::AudioMetadata;
static GST_INIT: Once = Once::new();
@@ -63,18 +63,15 @@ fn add_decode_bin_new_pad_callback(
None
};
- match name.as_deref() {
- Some("audio/x-raw") => {
- if let Some(peer) = ghost_pad.get_peer() {
- peer.unlink(&ghost_pad).unwrap();
- }
+ if let Some("audio/x-raw") = name.as_deref() {
+ if let Some(peer) = ghost_pad.get_peer() {
+ peer.unlink(&ghost_pad).unwrap();
+ }
- info!("Found raw audio, linking audio bin");
- new_pad.link(&ghost_pad).unwrap();
+ info!("Found raw audio, linking audio bin");
+ new_pad.link(&ghost_pad).unwrap();
- audio_bin.sync_state_with_parent().unwrap();
- }
- _ => {}
+ audio_bin.sync_state_with_parent().unwrap();
}
});
}
@@ -233,7 +230,7 @@ impl AudioPlayer {
pub fn position(&self) -> Option<Duration> {
self.pipeline
.query_position::<gst::ClockTime>()
- .and_then(|t| t.0.map(|v| Duration::from_nanos(v)))
+ .and_then(|t| t.0.map(Duration::from_nanos))
}
pub fn currently_playing(&self) -> Option<AudioMetadata> {
@@ -313,9 +310,10 @@ impl AudioPlayer {
pub fn quit(&self, reason: String) {
info!("Quitting audio player");
- if let Err(_) = self
+ if self
.bus
.post(&gst::Message::new_application(gst::Structure::new_empty("quit")).build())
+ .is_err()
{
warn!("Tried to send \"quit\" app event on flushing bus.");
}
diff --git a/src/bot/master.rs b/src/bot/master.rs
index 4cdb490..7612c68 100644
--- a/src/bot/master.rs
+++ b/src/bot/master.rs
@@ -119,7 +119,7 @@ impl MasterBot {
ref connected_bots,
} = &mut *self.music_bots.write().expect("RwLock was not poisoned");
- for (_, bot) in connected_bots {
+ for bot in connected_bots.values() {
if bot.my_channel() == channel {
return Err(BotCreationError::MultipleBots(bot.name().to_owned()));
}
@@ -209,7 +209,7 @@ impl MasterBot {
let bot = music_bots.connected_bots.get(&name)?;
Some(crate::web_server::BotData {
- name: name,
+ name,
state: bot.state(),
volume: bot.volume(),
position: bot.position(),
@@ -244,7 +244,7 @@ impl MasterBot {
let len = music_bots.connected_bots.len();
let mut result = Vec::with_capacity(len);
- for (name, _) in &music_bots.connected_bots {
+ for name in music_bots.connected_bots.keys() {
result.push(name.clone());
}
@@ -253,7 +253,7 @@ impl MasterBot {
pub fn quit(&self, reason: String) {
let music_bots = self.music_bots.read().unwrap();
- for (_, bot) in &music_bots.connected_bots {
+ for bot in music_bots.connected_bots.values() {
bot.quit(reason.clone())
}
let sender = self.sender.read().unwrap();
diff --git a/src/bot/music.rs b/src/bot/music.rs
index 14a73f9..71e7b58 100644
--- a/src/bot/music.rs
+++ b/src/bot/music.rs
@@ -4,7 +4,6 @@ use std::sync::{Arc, RwLock};
use std::thread;
use std::time::Duration;
-use humantime;
use log::{debug, info};
use serde::Serialize;
use structopt::StructOpt;
@@ -56,7 +55,7 @@ pub enum MusicBotMessage {
ChannelCreated(ChannelId),
ClientDisconnected {
id: ClientId,
- client: data::Client,
+ client: Box<data::Client>,
},
StateChange(State),
Quit(String),
@@ -284,7 +283,7 @@ impl MusicBot {
async fn on_text(&self, message: Message) -> Result<(), AudioPlayerError> {
let msg = message.text;
- if msg.starts_with("!") {
+ if msg.starts_with('!') {
let tokens = msg[1..].split_whitespace().collect::<Vec<_>>();
match Command::from_iter_safe(&tokens) {
diff --git a/src/main.rs b/src/main.rs
index 4fd2b0c..c8c93a4 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -147,7 +147,7 @@ fn run() -> Result<(), Box<dyn std::error::Error>> {
let disconnect_cb = Box::new(move |_, _, _| {});
let bot_args = MusicBotArgs {
- name: name,
+ name,
name_index: 0,
id_index: 0,
local: true,
diff --git a/src/teamspeak/mod.rs b/src/teamspeak/mod.rs
index b53d1d0..66d973c 100644
--- a/src/teamspeak/mod.rs
+++ b/src/teamspeak/mod.rs
@@ -22,7 +22,7 @@ pub struct TeamSpeakConnection {
conn: Connection,
}
-fn get_message<'a>(event: &Event) -> Option<MusicBotMessage> {
+fn get_message(event: &Event) -> Option<MusicBotMessage> {
use tsclientlib::events::{PropertyId, PropertyValue};
match event {
@@ -39,9 +39,7 @@ fn get_message<'a>(event: &Event) -> Option<MusicBotMessage> {
id: property,
invoker: _,
} => match property {
- PropertyId::Channel(id) => {
- Some(MusicBotMessage::ChannelCreated(*id))
- }
+ PropertyId::Channel(id) => Some(MusicBotMessage::ChannelCreated(*id)),
_ => None,
},
Event::PropertyChanged {
@@ -70,7 +68,7 @@ fn get_message<'a>(event: &Event) -> Option<MusicBotMessage> {
if let PropertyValue::Client(client) = client {
Some(MusicBotMessage::ClientDisconnected {
id: *id,
- client: client.clone(),
+ client: Box::new(client.clone()),
})
} else {
None
@@ -172,7 +170,7 @@ impl TeamSpeakConnection {
pub fn user_count(&self, channel: ChannelId) -> u32 {
let conn = self.conn.lock();
let mut count = 0;
- for (_, client) in &conn.clients {
+ for client in conn.clients.values() {
if client.channel == channel {
count += 1;
}
diff --git a/src/web_server.rs b/src/web_server.rs
index 8ee740c..be373e4 100644
--- a/src/web_server.rs
+++ b/src/web_server.rs
@@ -2,9 +2,7 @@ use std::sync::Arc;
use std::time::Duration;
use actix::{Addr, SyncArbiter};
-use actix_web::{
- get, middleware::Logger, post, web, App, HttpServer, Responder,
-};
+use actix_web::{get, middleware::Logger, post, web, App, HttpServer, Responder};
use askama::actix_web::TemplateIntoResponse;
use askama::Template;
use serde::{Deserialize, Serialize};
diff --git a/src/youtube_dl.rs b/src/youtube_dl.rs
index 89b1477..1b77303 100644
--- a/src/youtube_dl.rs
+++ b/src/youtube_dl.rs
@@ -26,7 +26,7 @@ where
{
let dur: Option<f64> = Deserialize::deserialize(deserializer)?;
- Ok(dur.map(|v| Duration::from_secs_f64(v)))
+ Ok(dur.map(Duration::from_secs_f64))
}
pub async fn get_audio_download_url(uri: String) -> Result<AudioMetadata, String> {
@@ -40,11 +40,11 @@ pub async fn get_audio_download_url(uri: String) -> Result<AudioMetadata, String
let ytdl_output = cmd.output_async().compat().await.unwrap();
- if ytdl_output.status.success() == false {
- return Err(String::from_utf8(ytdl_output.stderr.clone()).unwrap());
+ if !ytdl_output.status.success() {
+ return Err(String::from_utf8(ytdl_output.stderr).unwrap());
}
- let output_str = String::from_utf8(ytdl_output.stdout.clone()).unwrap();
+ let output_str = String::from_utf8(ytdl_output.stdout).unwrap();
let output = serde_json::from_str(&output_str).map_err(|e| e.to_string())?;
Ok(output)