diff options
| author | Nathan Perry <np@nathanperry.dev> | 2020-09-25 21:37:29 -0400 |
|---|---|---|
| committer | Nathan Perry <np@nathanperry.dev> | 2020-09-25 21:37:29 -0400 |
| commit | 41e9ba74be6e7389c5aa157bd64987c1549afd57 (patch) | |
| tree | a364fe27af94377b0ffb049b47ada88b9417bfd8 | |
| parent | 87d92a93d8493e0264c381aa005bf9feaef976ed (diff) | |
volume limit to 400%, default at 200%
| -rw-r--r-- | src/commands/sound_levels.rs | 15 | ||||
| -rw-r--r-- | src/main.rs | 1 |
2 files changed, 7 insertions, 9 deletions
diff --git a/src/commands/sound_levels.rs b/src/commands/sound_levels.rs index ab98806..d913d06 100644 --- a/src/commands/sound_levels.rs +++ b/src/commands/sound_levels.rs @@ -20,7 +20,8 @@ use crate::{ util::CtxExt, }; -pub const DEFAULT_VOLUME: f32 = 0.10; +pub const DEFAULT_VOLUME: f32 = 0.20; +const MAX_VOLUME: f32 = 5.0; #[command] pub fn mute(ctx: &mut Context, _: &Message, _: Args) -> Result<()> { @@ -86,15 +87,11 @@ pub fn volume(ctx: &mut Context, msg: &Message, mut args: Args) -> Result<()> { }; let mut vol: f32 = (vol as f32)/100.0; // force aliasing to reasonable values - let adjusted_text = if vol > 3.0 { " (300% max)" } else { "" }; + let adjusted_text = if vol > MAX_VOLUME { + format!(" ({:.0}% max)", MAX_VOLUME * 100.0) + } else { "".to_owned() }; - if vol > 3.0 { - vol = 3.0; - } - - if vol < 0.0 { - vol = 0.0; - } + vol = vol.clamp(0.0, MAX_VOLUME); let queue_lock = ctx.data.write().get::<PlayQueue>().cloned().unwrap(); diff --git a/src/main.rs b/src/main.rs index 55205ba..6888f5f 100644 --- a/src/main.rs +++ b/src/main.rs @@ -2,6 +2,7 @@ #![feature(pattern)] #![feature(concat_idents)] #![feature(associated_type_defaults)] +#![feature(clamp)] #![feature(box_syntax, box_patterns)] |
