feat: user consent setting and retrieving (NOTE: does not affect recording yet)
This commit is contained in:
@@ -3,7 +3,10 @@ use std::{fmt::Debug, sync::Arc};
|
||||
use futures::future::BoxFuture;
|
||||
use opendal::Operator;
|
||||
use patricia_tree::StringPatriciaMap;
|
||||
use songbird::{Songbird, driver::{Channels, SampleRate}};
|
||||
use songbird::{
|
||||
Songbird,
|
||||
driver::{Channels, SampleRate},
|
||||
};
|
||||
use tokio_util::sync::CancellationToken;
|
||||
use twilight_model::{
|
||||
application::{command::Command, interaction::Interaction},
|
||||
@@ -13,7 +16,7 @@ use twilight_model::{
|
||||
},
|
||||
};
|
||||
|
||||
use crate::{VCs, track_vcs::GuildVoiceChannelToTextChannel};
|
||||
use crate::{GuildVoiceChannelToTextChannel, UserDataManager, VCs};
|
||||
|
||||
mod debug;
|
||||
mod join;
|
||||
@@ -34,7 +37,7 @@ pub struct State {
|
||||
pub discord_voice_channel_corresponding_text_channel: Arc<GuildVoiceChannelToTextChannel>,
|
||||
pub recording_data: Operator,
|
||||
pub songbird: Arc<Songbird>,
|
||||
pub user_data: Operator,
|
||||
pub user_data_manager: UserDataManager,
|
||||
pub vcs: Arc<VCs>,
|
||||
}
|
||||
|
||||
|
||||
@@ -1,12 +1,15 @@
|
||||
use std::sync::LazyLock;
|
||||
|
||||
use twilight_model::application::{
|
||||
command::{Command, CommandType},
|
||||
interaction::Interaction,
|
||||
use twilight_model::{
|
||||
application::{
|
||||
command::{Command, CommandType},
|
||||
interaction::Interaction,
|
||||
},
|
||||
http::interaction::{InteractionResponse, InteractionResponseType},
|
||||
};
|
||||
use twilight_util::builder::command::CommandBuilder;
|
||||
use twilight_util::builder::{InteractionResponseDataBuilder, command::CommandBuilder};
|
||||
|
||||
use crate::command::State;
|
||||
use crate::{command::State, user_capnp::user::Consent};
|
||||
|
||||
const NAME: &str = "opt-in";
|
||||
const DESCRIPTION: &str = "Opt in to being recorded";
|
||||
@@ -20,5 +23,66 @@ pub static COMMAND: LazyLock<Command> = LazyLock::new(|| {
|
||||
|
||||
#[tracing::instrument]
|
||||
pub async fn handle(state: State, interaction: Interaction) {
|
||||
todo!();
|
||||
let user_id = interaction
|
||||
.member
|
||||
.as_ref()
|
||||
.and_then(|member| member.user.as_ref().map(|user| user.id));
|
||||
|
||||
let user_id = match user_id {
|
||||
Some(user_id) => user_id,
|
||||
None => {
|
||||
state
|
||||
.discord_client
|
||||
.interaction(state.discord_application_id)
|
||||
.create_response(
|
||||
interaction.id,
|
||||
&interaction.token,
|
||||
&InteractionResponse {
|
||||
kind: InteractionResponseType::ChannelMessageWithSource,
|
||||
data: Some(
|
||||
InteractionResponseDataBuilder::new()
|
||||
.content("TODO")
|
||||
.build(),
|
||||
),
|
||||
},
|
||||
)
|
||||
.await
|
||||
.expect("TODO");
|
||||
return;
|
||||
}
|
||||
};
|
||||
|
||||
let previous_consent = state
|
||||
.user_data_manager
|
||||
.update(user_id, |mut user_data| {
|
||||
let previous_consent = user_data
|
||||
.reborrow()
|
||||
.get_voice_recording_consent()
|
||||
.expect("TODO");
|
||||
user_data.set_voice_recording_consent(Consent::Granted);
|
||||
|
||||
previous_consent
|
||||
})
|
||||
.await
|
||||
.expect("TODO");
|
||||
|
||||
state
|
||||
.discord_client
|
||||
.interaction(state.discord_application_id)
|
||||
.create_response(
|
||||
interaction.id,
|
||||
&interaction.token,
|
||||
&InteractionResponse {
|
||||
kind: InteractionResponseType::ChannelMessageWithSource,
|
||||
data: Some(
|
||||
InteractionResponseDataBuilder::new()
|
||||
.content(format!(
|
||||
"opted you in, your previous consent was {previous_consent:?}"
|
||||
))
|
||||
.build(),
|
||||
),
|
||||
},
|
||||
)
|
||||
.await
|
||||
.expect("TODO");
|
||||
}
|
||||
|
||||
@@ -1,24 +1,88 @@
|
||||
use std::sync::LazyLock;
|
||||
|
||||
use twilight_model::application::{
|
||||
command::{Command, CommandType},
|
||||
interaction::Interaction,
|
||||
};
|
||||
use twilight_util::builder::command::CommandBuilder;
|
||||
|
||||
use crate::command::State;
|
||||
|
||||
const NAME: &str = "opt-out";
|
||||
const DESCRIPTION: &str = "Opt out of being recorded";
|
||||
|
||||
pub static COMMAND: LazyLock<Command> = LazyLock::new(|| {
|
||||
CommandBuilder::new(NAME, DESCRIPTION, CommandType::ChatInput)
|
||||
.validate()
|
||||
.expect("command wasn't correct")
|
||||
.build()
|
||||
});
|
||||
|
||||
#[tracing::instrument]
|
||||
pub async fn handle(state: State, interaction: Interaction) {
|
||||
todo!();
|
||||
}
|
||||
use std::sync::LazyLock;
|
||||
|
||||
use twilight_model::{
|
||||
application::{
|
||||
command::{Command, CommandType},
|
||||
interaction::Interaction,
|
||||
},
|
||||
http::interaction::{InteractionResponse, InteractionResponseType},
|
||||
};
|
||||
use twilight_util::builder::{InteractionResponseDataBuilder, command::CommandBuilder};
|
||||
|
||||
use crate::{command::State, user_capnp::user::Consent};
|
||||
|
||||
const NAME: &str = "opt-out";
|
||||
const DESCRIPTION: &str = "Opt out of being recorded";
|
||||
|
||||
pub static COMMAND: LazyLock<Command> = LazyLock::new(|| {
|
||||
CommandBuilder::new(NAME, DESCRIPTION, CommandType::ChatInput)
|
||||
.validate()
|
||||
.expect("command wasn't correct")
|
||||
.build()
|
||||
});
|
||||
|
||||
#[tracing::instrument]
|
||||
pub async fn handle(state: State, interaction: Interaction) {
|
||||
let user_id = interaction
|
||||
.member
|
||||
.as_ref()
|
||||
.and_then(|member| member.user.as_ref().map(|user| user.id));
|
||||
|
||||
let user_id = match user_id {
|
||||
Some(user_id) => user_id,
|
||||
None => {
|
||||
state
|
||||
.discord_client
|
||||
.interaction(state.discord_application_id)
|
||||
.create_response(
|
||||
interaction.id,
|
||||
&interaction.token,
|
||||
&InteractionResponse {
|
||||
kind: InteractionResponseType::ChannelMessageWithSource,
|
||||
data: Some(
|
||||
InteractionResponseDataBuilder::new()
|
||||
.content("TODO")
|
||||
.build(),
|
||||
),
|
||||
},
|
||||
)
|
||||
.await
|
||||
.expect("TODO");
|
||||
return;
|
||||
}
|
||||
};
|
||||
|
||||
let previous_consent = state
|
||||
.user_data_manager
|
||||
.update(user_id, |mut user_data| {
|
||||
let previous_consent = user_data
|
||||
.reborrow()
|
||||
.get_voice_recording_consent()
|
||||
.expect("TODO");
|
||||
user_data.set_voice_recording_consent(Consent::Withheld);
|
||||
|
||||
previous_consent
|
||||
})
|
||||
.await
|
||||
.expect("TODO");
|
||||
|
||||
state
|
||||
.discord_client
|
||||
.interaction(state.discord_application_id)
|
||||
.create_response(
|
||||
interaction.id,
|
||||
&interaction.token,
|
||||
&InteractionResponse {
|
||||
kind: InteractionResponseType::ChannelMessageWithSource,
|
||||
data: Some(
|
||||
InteractionResponseDataBuilder::new()
|
||||
.content(format!(
|
||||
"opted you out, your previous consent was {previous_consent:?}"
|
||||
))
|
||||
.build(),
|
||||
),
|
||||
},
|
||||
)
|
||||
.await
|
||||
.expect("TODO");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user