Skip to content

Commit

Permalink
Fix .mute(...) not preventing the bot from sending frames. (serenit…
Browse files Browse the repository at this point in the history
  • Loading branch information
FelixMcFelix committed Jul 20, 2020
1 parent 84b04ba commit 638780e
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 3 deletions.
9 changes: 7 additions & 2 deletions src/voice/connection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -466,7 +466,8 @@ impl Connection {
mut sources: &mut Vec<LockedAudio>,
mut receiver: &mut Option<Box<dyn AudioReceiver>>,
audio_timer: &mut Timer,
bitrate: Bitrate)
bitrate: Bitrate,
muted: bool)
-> Result<()> {
// We need to actually reserve enough space for the desired bitrate.
let size = match bitrate {
Expand Down Expand Up @@ -535,10 +536,14 @@ impl Connection {

// Walk over all the audio files, removing those which have finished.
// For this purpose, we need a while loop in Rust.
let len = self.remove_unfinished_files(&mut sources, &opus_frame, &mut buffer,&mut mix_buffer)?;
let mut len = self.remove_unfinished_files(&mut sources, &opus_frame, &mut buffer, &mut mix_buffer)?;

self.soft_clip.apply(&mut mix_buffer[..])?;

if muted {
len = 0;
}

if len == 0 {
if self.silence_frames > 0 {
self.silence_frames -= 1;
Expand Down
1 change: 1 addition & 0 deletions src/voice/handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,7 @@ impl Handler {

if self.channel_id.is_some() {
self.update();
self.send(VoiceStatus::Mute(mute));
}
}

Expand Down
1 change: 1 addition & 0 deletions src/voice/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,5 @@ pub(crate) enum Status {
SetSender(Option<LockedAudio>),
AddSender(LockedAudio),
SetBitrate(Bitrate),
Mute(bool),
}
6 changes: 5 additions & 1 deletion src/voice/threading.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ fn runner(rx: &MpscReceiver<Status>) {
let mut connection = None;
let mut timer = Timer::new(20);
let mut bitrate = audio::DEFAULT_BITRATE;
let mut mute = false;

'runner: loop {
loop {
Expand Down Expand Up @@ -59,6 +60,9 @@ fn runner(rx: &MpscReceiver<Status>) {
Ok(Status::SetBitrate(b)) => {
bitrate = b;
},
Ok(Status::Mute(m)) => {
mute = m;
},
Err(TryRecvError::Empty) => {
// If we received nothing, then we can perform an update.
break;
Expand All @@ -79,7 +83,7 @@ fn runner(rx: &MpscReceiver<Status>) {
// another event.
let error = match connection.as_mut() {
Some(connection) => {
let cycle = connection.cycle(&mut senders, &mut receiver, &mut timer, bitrate);
let cycle = connection.cycle(&mut senders, &mut receiver, &mut timer, bitrate, mute);

match cycle {
Ok(()) => false,
Expand Down

0 comments on commit 638780e

Please sign in to comment.