feat: respect consent to be recorded
This commit is contained in:
@@ -1,8 +1,12 @@
|
|||||||
use crate::{OneToManyUniqueBTreeMap, VCs, command::State};
|
use crate::{
|
||||||
|
OneToManyUniqueBTreeMap, UserDataManager, VCs, command::State, option_ext::OptionExt as _,
|
||||||
|
user_capnp::user::Consent, user_data::RECORD_IF_CONSENT_UNSPECIFIED,
|
||||||
|
};
|
||||||
use async_trait::async_trait;
|
use async_trait::async_trait;
|
||||||
|
use futures::FutureExt;
|
||||||
use hound::{SampleFormat, WavSpec};
|
use hound::{SampleFormat, WavSpec};
|
||||||
use opendal::Operator;
|
use opendal::Operator;
|
||||||
use snafu::{OptionExt, Snafu};
|
use snafu::{OptionExt as _, Snafu};
|
||||||
use songbird::{CoreEvent, Event, EventContext, EventHandler};
|
use songbird::{CoreEvent, Event, EventContext, EventHandler};
|
||||||
use std::{
|
use std::{
|
||||||
io::Cursor,
|
io::Cursor,
|
||||||
@@ -104,6 +108,8 @@ struct Handler {
|
|||||||
|
|
||||||
audio_channels: u16,
|
audio_channels: u16,
|
||||||
audio_sample_rate: u32,
|
audio_sample_rate: u32,
|
||||||
|
|
||||||
|
user_data_manager: UserDataManager,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[async_trait]
|
#[async_trait]
|
||||||
@@ -134,6 +140,26 @@ impl EventHandler for Handler {
|
|||||||
tracing::info!(?user_id);
|
tracing::info!(?user_id);
|
||||||
|
|
||||||
if let Some(pcm) = &voice_data.decoded_voice {
|
if let Some(pcm) = &voice_data.decoded_voice {
|
||||||
|
let may_record = user_id
|
||||||
|
.map_async(|user_id| {
|
||||||
|
self.user_data_manager
|
||||||
|
.with(user_id, |user_data| {
|
||||||
|
user_data.get_voice_recording_consent().unwrap()
|
||||||
|
})
|
||||||
|
.map(|result| result.expect("TODO"))
|
||||||
|
})
|
||||||
|
.await
|
||||||
|
.map_or(RECORD_IF_CONSENT_UNSPECIFIED, |consent| match consent {
|
||||||
|
Consent::Unspecified => RECORD_IF_CONSENT_UNSPECIFIED,
|
||||||
|
Consent::Granted => true,
|
||||||
|
Consent::Withheld => false,
|
||||||
|
});
|
||||||
|
|
||||||
|
if !may_record {
|
||||||
|
tracing::warn!(?user_id, "may not be recorded");
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
let elapsed = self.start_instant.elapsed();
|
let elapsed = self.start_instant.elapsed();
|
||||||
let elapsed = elapsed.try_into().expect("TODO");
|
let elapsed = elapsed.try_into().expect("TODO");
|
||||||
|
|
||||||
@@ -281,6 +307,8 @@ pub async fn handle(state: State, interaction: Interaction) {
|
|||||||
|
|
||||||
audio_channels,
|
audio_channels,
|
||||||
audio_sample_rate,
|
audio_sample_rate,
|
||||||
|
|
||||||
|
user_data_manager: state.user_data_manager,
|
||||||
};
|
};
|
||||||
|
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
use std::str::FromStr;
|
use std::str::FromStr;
|
||||||
|
|
||||||
use async_compression::futures::{bufread::BrotliDecoder, write::BrotliEncoder};
|
use async_compression::futures::{bufread::BrotliDecoder, write::BrotliEncoder};
|
||||||
use capnp::message::{TypedBuilder, TypedReader};
|
use capnp::message::TypedBuilder;
|
||||||
use futures::{AsyncReadExt, AsyncWriteExt, TryStream, TryStreamExt};
|
use futures::{AsyncReadExt, AsyncWriteExt, TryStream, TryStreamExt};
|
||||||
use opendal::Operator;
|
use opendal::Operator;
|
||||||
use snafu::{OptionExt as _, ResultExt as _, Snafu, ensure};
|
use snafu::{OptionExt as _, ResultExt as _, Snafu, ensure};
|
||||||
@@ -9,6 +9,8 @@ use twilight_model::id::{Id, marker::UserMarker};
|
|||||||
|
|
||||||
use crate::{OperatorExt, option_ext::OptionExt as _, user_capnp};
|
use crate::{OperatorExt, option_ext::OptionExt as _, user_capnp};
|
||||||
|
|
||||||
|
pub const RECORD_IF_CONSENT_UNSPECIFIED: bool = true;
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
pub struct UserDataManager {
|
pub struct UserDataManager {
|
||||||
operator: Operator,
|
operator: Operator,
|
||||||
@@ -242,7 +244,10 @@ impl UserDataManager {
|
|||||||
.await
|
.await
|
||||||
.context(update_error::WriteSnafu)?;
|
.context(update_error::WriteSnafu)?;
|
||||||
|
|
||||||
decompressed_writer.close().await.context(update_error::FinalizeSnafu)?;
|
decompressed_writer
|
||||||
|
.close()
|
||||||
|
.await
|
||||||
|
.context(update_error::FinalizeSnafu)?;
|
||||||
|
|
||||||
Ok(ret)
|
Ok(ret)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user