feat: user consent setting and retrieving (NOTE: does not affect recording yet)
This commit is contained in:
@@ -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");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user