diff options
Diffstat (limited to 'src/commands/sound_levels.rs')
| -rw-r--r-- | src/commands/sound_levels.rs | 166 |
1 files changed, 61 insertions, 105 deletions
diff --git a/src/commands/sound_levels.rs b/src/commands/sound_levels.rs index db0b6a6..8c75b37 100644 --- a/src/commands/sound_levels.rs +++ b/src/commands/sound_levels.rs @@ -1,132 +1,88 @@ -use log::{ - error, - info, - trace, - warn, -}; use serenity::{ framework::standard::{ macros::command, Args, - CommandError, CommandResult, }, - futures::TryFutureExt, model::channel::Message, prelude::*, }; -use crate::{ - audio::{ - PlayQueue, - VoiceManager, - }, - util, - CONFIG, -}; +use crate::commands::songbird; pub const DEFAULT_VOLUME: f32 = 0.20; const MAX_VOLUME: f32 = 5.0; #[command] -pub async fn mute(ctx: &Context, _: &Message, _: Args) -> CommandResult { - let mgr_lock = ctx.data.write().await.get::<VoiceManager>().cloned().unwrap(); - let mut manager = mgr_lock.lock(); +pub async fn mute(ctx: &Context, msg: &Message, _: Args) -> CommandResult { + let (_sb, call) = songbird(ctx, msg).await?; - manager.get_mut(CONFIG.discord.guild()).map(|handler| { - if handler.self_mute { - trace!("Already muted.") - } else { - handler.mute(true); - trace!("Muted"); - } - }); + let mut call = call.lock().await; + call.mute(true).await?; Ok(()) } #[command] pub async fn unmute(ctx: &Context, msg: &Message, _: Args) -> CommandResult { - let mgr_lock = ctx.data.write().await.get::<VoiceManager>().cloned().unwrap(); - let mut manager = mgr_lock.lock(); + let (_sb, call) = songbird(ctx, msg).await?; - if let Some(handler) = manager.get_mut(CONFIG.discord.guild()) { - if !handler.self_mute { - trace!("Already unmuted.") - } else { - handler.mute(false); - trace!("Unmuted"); - let _ = util::send(ctx, msg.channel_id, "REEEEEEEEEEEEEE", msg.tts) - .map_err(CommandError::from) - .await; - } - } + let mut call = call.lock().await; + call.mute(true).await?; Ok(()) } -#[command] -pub async fn volume(ctx: &Context, msg: &Message, mut args: Args) -> CommandResult { - if args.len() == 0 { - let vol = { - let queue_lock = ctx.data.write().await.get::<PlayQueue>().cloned().unwrap(); - let play_queue = queue_lock.read().unwrap(); - (play_queue.volume / DEFAULT_VOLUME * 100.0) as usize - }; - - trace!("reporting volume {}", vol); - - return util::send(ctx, msg.channel_id, &format!("volume: {}%", vol), msg.tts) - .map_err(CommandError::from) - .await; - } - - let vol: usize = match args.single::<f32>() { - Ok(vol) if vol.is_nan() => { - warn!("reporting NaN volume"); - return util::send(ctx, msg.channel_id, "you're a fuck", msg.tts) - .map_err(CommandError::from) - .await; - }, - Ok(vol) => vol as usize, - Err(e) => { - error!("parsing volume arg: {}", e); - return util::send(ctx, msg.channel_id, "???????", msg.tts) - .map_err(CommandError::from) - .await; - }, - }; - - let mut vol: f32 = (vol as f32) / 100.0; // force aliasing to reasonable values - let adjusted_text = if vol > MAX_VOLUME { - format!(" ({:.0}% max)", MAX_VOLUME * 100.0) - } else { - "".to_owned() - }; - - vol = vol.clamp(0.0, MAX_VOLUME); - - let queue_lock = ctx.data.write().await.get::<PlayQueue>().cloned().unwrap(); - - { - let mut play_queue = queue_lock.write().unwrap(); - play_queue.volume = vol * DEFAULT_VOLUME; - info!("volume updated to {}", vol); - } - - util::send(ctx, msg.channel_id, format!("volume adjusted{}", adjusted_text), msg.tts).await?; - - { - let play_queue = queue_lock.read().unwrap(); - - let current_item = match play_queue.playing { - Some(ref x) => x, - None => return Ok(()), - }; - - let mut audio = current_item.audio.lock(); - audio.volume(play_queue.volume); - } - - Ok(()) -} +// #[command] +// pub async fn volume(ctx: &Context, msg: &Message, mut args: Args) -> CommandResult { +// if args.len() == 0 { +// let vol = { +// let queue_lock = ctx.data.write().await.get::<PlayQueue>().cloned().unwrap(); +// let play_queue = queue_lock.read().unwrap(); +// (play_queue.volume / DEFAULT_VOLUME * 100.0) as usize +// }; +// +// trace!("reporting volume {}", vol); +// +// return util::send(ctx, msg.channel_id, &format!("volume: {}%", vol), msg.tts) +// .map_err(CommandError::from) +// .await; +// } +// +// let vol: usize = match args.single::<f32>() { +// Ok(vol) if vol.is_nan() => { +// warn!("reporting NaN volume"); +// return util::send(ctx, msg.channel_id, "you're a fuck", msg.tts) +// .map_err(CommandError::from) +// .await; +// }, +// Ok(vol) => vol as usize, +// Err(e) => { +// error!("parsing volume arg: {}", e); +// return util::send(ctx, msg.channel_id, "???????", msg.tts) +// .map_err(CommandError::from) +// .await; +// }, +// }; +// +// let mut vol: f32 = (vol as f32) / 100.0; // force aliasing to reasonable values +// let adjusted_text = if vol > MAX_VOLUME { +// format!(" ({:.0}% max)", MAX_VOLUME * 100.0) +// } else { +// "".to_owned() +// }; +// +// vol = vol.clamp(0.0, MAX_VOLUME); +// +// let queue_lock = ctx.data.write().await.get::<PlayQueue>().cloned().unwrap(); +// +// { +// let mut play_queue = queue_lock.write().unwrap(); +// play_queue.volume = vol * DEFAULT_VOLUME; +// info!("volume updated to {}", vol); +// } +// +// util::send(ctx, msg.channel_id, format!("volume adjusted{}", adjusted_text), msg.tts).await?; +// +// Ok(()) +// } |
