feat: advertise opt in and opt out commands
This commit is contained in:
@@ -1,354 +1,362 @@
|
|||||||
use crate::{
|
use crate::{
|
||||||
OneToManyUniqueBTreeMap, UserDataManager, VCs, command::State, option_ext::OptionExt as _,
|
OneToManyUniqueBTreeMap, UserDataManager, VCs, command::State, option_ext::OptionExt as _,
|
||||||
user_capnp::user::Consent, user_data::RECORD_IF_CONSENT_UNSPECIFIED,
|
user_capnp::user::Consent, user_data::RECORD_IF_CONSENT_UNSPECIFIED,
|
||||||
};
|
};
|
||||||
use async_trait::async_trait;
|
use async_trait::async_trait;
|
||||||
use futures::FutureExt;
|
use futures::FutureExt;
|
||||||
use hound::{SampleFormat, WavSpec};
|
use hound::{SampleFormat, WavSpec};
|
||||||
use opendal::Operator;
|
use opendal::Operator;
|
||||||
use snafu::{OptionExt as _, 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,
|
||||||
sync::{Arc, LazyLock, Mutex},
|
sync::{Arc, LazyLock, Mutex},
|
||||||
time::Instant,
|
time::Instant,
|
||||||
};
|
};
|
||||||
use time::UtcDateTime;
|
use time::UtcDateTime;
|
||||||
use twilight_model::{
|
use twilight_model::{
|
||||||
application::{
|
application::{
|
||||||
command::{Command, CommandType},
|
command::{Command, CommandType},
|
||||||
interaction::Interaction,
|
interaction::Interaction,
|
||||||
},
|
},
|
||||||
channel::message::{Embed, MessageFlags},
|
channel::message::{Embed, MessageFlags},
|
||||||
http::interaction::{InteractionResponse, InteractionResponseType},
|
http::interaction::{InteractionResponse, InteractionResponseType},
|
||||||
id::{
|
id::{
|
||||||
Id,
|
Id,
|
||||||
marker::{ChannelMarker, GuildMarker, UserMarker},
|
marker::{ChannelMarker, GuildMarker, UserMarker},
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
use twilight_util::builder::{
|
use twilight_util::builder::{
|
||||||
InteractionResponseDataBuilder,
|
InteractionResponseDataBuilder,
|
||||||
command::CommandBuilder,
|
command::CommandBuilder,
|
||||||
embed::{EmbedBuilder, EmbedFieldBuilder, EmbedFooterBuilder},
|
embed::{EmbedBuilder, EmbedFieldBuilder, EmbedFooterBuilder},
|
||||||
};
|
};
|
||||||
|
|
||||||
const NAME: &str = "join";
|
const NAME: &str = "join";
|
||||||
const DESCRIPTION: &str = "The bot will join the same VC as you (with intention to record)";
|
const DESCRIPTION: &str = "The bot will join the same VC as you (with intention to record)";
|
||||||
|
|
||||||
pub static COMMAND: LazyLock<Command> = LazyLock::new(|| {
|
pub static COMMAND: LazyLock<Command> = LazyLock::new(|| {
|
||||||
CommandBuilder::new(NAME, DESCRIPTION, CommandType::ChatInput)
|
CommandBuilder::new(NAME, DESCRIPTION, CommandType::ChatInput)
|
||||||
.validate()
|
.validate()
|
||||||
.expect("command wasn't correct")
|
.expect("command wasn't correct")
|
||||||
.build()
|
.build()
|
||||||
});
|
});
|
||||||
|
|
||||||
#[derive(Debug, Snafu)]
|
#[derive(Debug, Snafu)]
|
||||||
enum GetGuildAndVoiceChannelIdError {
|
enum GetGuildAndVoiceChannelIdError {
|
||||||
/// this command was not used inside a guild (Discord server)
|
/// this command was not used inside a guild (Discord server)
|
||||||
NotInGuild,
|
NotInGuild,
|
||||||
|
|
||||||
/// there is no user who invoked this command
|
/// there is no user who invoked this command
|
||||||
NoUser,
|
NoUser,
|
||||||
|
|
||||||
/// there are no voice chats in this guild
|
/// there are no voice chats in this guild
|
||||||
NoVCsInGuild,
|
NoVCsInGuild,
|
||||||
|
|
||||||
/// the user is not in a voice chat in this guild
|
/// the user is not in a voice chat in this guild
|
||||||
UserNotInVC,
|
UserNotInVC,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[tracing::instrument]
|
#[tracing::instrument]
|
||||||
fn get_guild_and_voice_channel_id(
|
fn get_guild_and_voice_channel_id(
|
||||||
interaction: &Interaction,
|
interaction: &Interaction,
|
||||||
vcs: &VCs,
|
vcs: &VCs,
|
||||||
) -> Result<(Id<GuildMarker>, Id<ChannelMarker>), GetGuildAndVoiceChannelIdError> {
|
) -> Result<(Id<GuildMarker>, Id<ChannelMarker>), GetGuildAndVoiceChannelIdError> {
|
||||||
let guild_id = interaction.guild_id.context(NotInGuildSnafu)?;
|
let guild_id = interaction.guild_id.context(NotInGuildSnafu)?;
|
||||||
|
|
||||||
let user_id = interaction
|
let user_id = interaction
|
||||||
.member
|
.member
|
||||||
.as_ref()
|
.as_ref()
|
||||||
.and_then(|member| member.user.as_ref().map(|user| user.id))
|
.and_then(|member| member.user.as_ref().map(|user| user.id))
|
||||||
.context(NoUserSnafu)?;
|
.context(NoUserSnafu)?;
|
||||||
|
|
||||||
let guild_vcs = vcs.get(&guild_id).context(NoVCsInGuildSnafu)?;
|
let guild_vcs = vcs.get(&guild_id).context(NoVCsInGuildSnafu)?;
|
||||||
|
|
||||||
let &voice_channel_id = guild_vcs.get_left_for(&user_id).context(UserNotInVCSnafu)?;
|
let &voice_channel_id = guild_vcs.get_left_for(&user_id).context(UserNotInVCSnafu)?;
|
||||||
|
|
||||||
Ok((guild_id, voice_channel_id))
|
Ok((guild_id, voice_channel_id))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_guild_and_vc_error_to_embed(error: GetGuildAndVoiceChannelIdError) -> Embed {
|
fn get_guild_and_vc_error_to_embed(error: GetGuildAndVoiceChannelIdError) -> Embed {
|
||||||
match error {
|
match error {
|
||||||
GetGuildAndVoiceChannelIdError::NotInGuild => {
|
GetGuildAndVoiceChannelIdError::NotInGuild => {
|
||||||
EmbedBuilder::new().title("Use this in a server").description("This bot can't find a VC to join if the command is used outside of a server (you might've used it in a DM?).").validate().unwrap().build()
|
EmbedBuilder::new().title("Use this in a server").description("This bot can't find a VC to join if the command is used outside of a server (you might've used it in a DM?).").validate().unwrap().build()
|
||||||
},
|
},
|
||||||
GetGuildAndVoiceChannelIdError::NoUser => {
|
GetGuildAndVoiceChannelIdError::NoUser => {
|
||||||
EmbedBuilder::new().title("Not invoked by a user").description("This command works by joining the same VC as the user, but this bot didn't receive any user data. So did no user invoke it?! (This error should be impossible!)").validate().unwrap().build()
|
EmbedBuilder::new().title("Not invoked by a user").description("This command works by joining the same VC as the user, but this bot didn't receive any user data. So did no user invoke it?! (This error should be impossible!)").validate().unwrap().build()
|
||||||
},
|
},
|
||||||
GetGuildAndVoiceChannelIdError::NoVCsInGuild => {
|
GetGuildAndVoiceChannelIdError::NoVCsInGuild => {
|
||||||
EmbedBuilder::new().title("No VCs in this server").description("This bot can't find a VC to join because there aren't any in this server right now.").validate().unwrap().build()
|
EmbedBuilder::new().title("No VCs in this server").description("This bot can't find a VC to join because there aren't any in this server right now.").validate().unwrap().build()
|
||||||
},
|
},
|
||||||
GetGuildAndVoiceChannelIdError::UserNotInVC => {
|
GetGuildAndVoiceChannelIdError::UserNotInVC => {
|
||||||
EmbedBuilder::new().title("You're not in a VC").description("This bot can't follow you into VC if you aren't in one in this server.").validate().unwrap().build()
|
EmbedBuilder::new().title("You're not in a VC").description("This bot can't follow you into VC if you aren't in one in this server.").validate().unwrap().build()
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
struct Handler {
|
struct Handler {
|
||||||
start_instant: Instant,
|
start_instant: Instant,
|
||||||
start_utc: UtcDateTime,
|
start_utc: UtcDateTime,
|
||||||
|
|
||||||
recordings: Operator,
|
recordings: Operator,
|
||||||
|
|
||||||
guild_id: Id<GuildMarker>,
|
guild_id: Id<GuildMarker>,
|
||||||
channel_id: Id<ChannelMarker>,
|
channel_id: Id<ChannelMarker>,
|
||||||
|
|
||||||
known_ssrcs: Arc<Mutex<OneToManyUniqueBTreeMap<Id<UserMarker>, u32>>>,
|
known_ssrcs: Arc<Mutex<OneToManyUniqueBTreeMap<Id<UserMarker>, u32>>>,
|
||||||
|
|
||||||
audio_channels: u16,
|
audio_channels: u16,
|
||||||
audio_sample_rate: u32,
|
audio_sample_rate: u32,
|
||||||
|
|
||||||
user_data_manager: UserDataManager,
|
user_data_manager: UserDataManager,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[async_trait]
|
#[async_trait]
|
||||||
impl EventHandler for Handler {
|
impl EventHandler for Handler {
|
||||||
async fn act(&self, ctx: &EventContext<'_>) -> Option<Event> {
|
async fn act(&self, ctx: &EventContext<'_>) -> Option<Event> {
|
||||||
match ctx {
|
match ctx {
|
||||||
EventContext::Track(_items) => {
|
EventContext::Track(_items) => {
|
||||||
// Not expected to fire
|
// Not expected to fire
|
||||||
}
|
}
|
||||||
EventContext::SpeakingStateUpdate(speaking) => {
|
EventContext::SpeakingStateUpdate(speaking) => {
|
||||||
tracing::error!(?speaking);
|
tracing::error!(?speaking);
|
||||||
|
|
||||||
if let Some(user_id) = speaking.user_id {
|
if let Some(user_id) = speaking.user_id {
|
||||||
let user_id = Id::new(user_id.0);
|
let user_id = Id::new(user_id.0);
|
||||||
|
|
||||||
self.known_ssrcs
|
self.known_ssrcs
|
||||||
.lock()
|
.lock()
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.insert(user_id, speaking.ssrc);
|
.insert(user_id, speaking.ssrc);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
EventContext::VoiceTick(voice_tick) => {
|
EventContext::VoiceTick(voice_tick) => {
|
||||||
tracing::error!(?voice_tick);
|
tracing::error!(?voice_tick);
|
||||||
|
|
||||||
for (ssrc, voice_data) in &voice_tick.speaking {
|
for (ssrc, voice_data) in &voice_tick.speaking {
|
||||||
let user_id = self.known_ssrcs.lock().unwrap().get_left_for(ssrc).cloned();
|
let user_id = self.known_ssrcs.lock().unwrap().get_left_for(ssrc).cloned();
|
||||||
|
|
||||||
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
|
let may_record = user_id
|
||||||
.map_async(|user_id| {
|
.map_async(|user_id| {
|
||||||
self.user_data_manager
|
self.user_data_manager
|
||||||
.with(user_id, |user_data| {
|
.with(user_id, |user_data| {
|
||||||
user_data.get_voice_recording_consent().unwrap()
|
user_data.get_voice_recording_consent().unwrap()
|
||||||
})
|
})
|
||||||
.map(|result| result.expect("TODO"))
|
.map(|result| result.expect("TODO"))
|
||||||
})
|
})
|
||||||
.await
|
.await
|
||||||
.map_or(RECORD_IF_CONSENT_UNSPECIFIED, |consent| match consent {
|
.map_or(RECORD_IF_CONSENT_UNSPECIFIED, |consent| match consent {
|
||||||
Consent::Unspecified => RECORD_IF_CONSENT_UNSPECIFIED,
|
Consent::Unspecified => RECORD_IF_CONSENT_UNSPECIFIED,
|
||||||
Consent::Granted => true,
|
Consent::Granted => true,
|
||||||
Consent::Withheld => false,
|
Consent::Withheld => false,
|
||||||
});
|
});
|
||||||
|
|
||||||
if !may_record {
|
if !may_record {
|
||||||
tracing::warn!(?user_id, "may not be recorded");
|
tracing::warn!(?user_id, "may not be recorded");
|
||||||
continue;
|
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");
|
||||||
|
|
||||||
let now_utc = self.start_utc.checked_add(elapsed).expect("TODO");
|
let now_utc = self.start_utc.checked_add(elapsed).expect("TODO");
|
||||||
tracing::error!(?now_utc, "TODO");
|
tracing::error!(?now_utc, "TODO");
|
||||||
|
|
||||||
let year = now_utc.year();
|
let year = now_utc.year();
|
||||||
let month = now_utc.month();
|
let month = now_utc.month();
|
||||||
let day = now_utc.day();
|
let day = now_utc.day();
|
||||||
|
|
||||||
let hour = now_utc.hour();
|
let hour = now_utc.hour();
|
||||||
let minute = now_utc.minute();
|
let minute = now_utc.minute();
|
||||||
let second = now_utc.second();
|
let second = now_utc.second();
|
||||||
|
|
||||||
let microseconds = now_utc.microsecond();
|
let microseconds = now_utc.microsecond();
|
||||||
|
|
||||||
let guild_id = self.guild_id;
|
let guild_id = self.guild_id;
|
||||||
let channel_id = self.channel_id;
|
let channel_id = self.channel_id;
|
||||||
|
|
||||||
let user = user_id
|
let user = user_id
|
||||||
.as_ref()
|
.as_ref()
|
||||||
.map_or_else(|| "UNKNOWN".into(), ToString::to_string);
|
.map_or_else(|| "UNKNOWN".into(), ToString::to_string);
|
||||||
|
|
||||||
let path = format!(
|
let path = format!(
|
||||||
"{year}/{month}/{day}/{hour}/{minute}/audio-{second}.{microseconds}-{guild_id}-{channel_id}-{user}.wav"
|
"{year}/{month}/{day}/{hour}/{minute}/audio-{second}.{microseconds}-{guild_id}-{channel_id}-{user}.wav"
|
||||||
);
|
);
|
||||||
|
|
||||||
let channels = self.audio_channels;
|
let channels = self.audio_channels;
|
||||||
let sample_rate = self.audio_sample_rate;
|
let sample_rate = self.audio_sample_rate;
|
||||||
|
|
||||||
let wav_spec = WavSpec {
|
let wav_spec = WavSpec {
|
||||||
channels,
|
channels,
|
||||||
sample_rate,
|
sample_rate,
|
||||||
bits_per_sample: 16,
|
bits_per_sample: 16,
|
||||||
sample_format: SampleFormat::Int,
|
sample_format: SampleFormat::Int,
|
||||||
};
|
};
|
||||||
|
|
||||||
let mut buffer = Vec::new();
|
let mut buffer = Vec::new();
|
||||||
let writer = Cursor::new(&mut buffer);
|
let writer = Cursor::new(&mut buffer);
|
||||||
|
|
||||||
let mut wav_writer = hound::WavWriter::new(writer, wav_spec).expect("TODO");
|
let mut wav_writer = hound::WavWriter::new(writer, wav_spec).expect("TODO");
|
||||||
|
|
||||||
let mut sample_writer = wav_writer.get_i16_writer(pcm.len() as u32);
|
let mut sample_writer = wav_writer.get_i16_writer(pcm.len() as u32);
|
||||||
|
|
||||||
for sample in pcm {
|
for sample in pcm {
|
||||||
sample_writer.write_sample(*sample);
|
sample_writer.write_sample(*sample);
|
||||||
}
|
}
|
||||||
sample_writer.flush().expect("TODO");
|
sample_writer.flush().expect("TODO");
|
||||||
|
|
||||||
wav_writer.finalize().expect("TODO");
|
wav_writer.finalize().expect("TODO");
|
||||||
|
|
||||||
tracing::info!("going to write the audio shortly");
|
tracing::info!("going to write the audio shortly");
|
||||||
|
|
||||||
let recordings = self.recordings.clone();
|
let recordings = self.recordings.clone();
|
||||||
tokio::spawn(async move {
|
tokio::spawn(async move {
|
||||||
recordings.write(&path, buffer).await.expect("TODO");
|
recordings.write(&path, buffer).await.expect("TODO");
|
||||||
tracing::info!("successfully wrote the audio!");
|
tracing::info!("successfully wrote the audio!");
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
EventContext::RtpPacket(_rtp_data) => {}
|
EventContext::RtpPacket(_rtp_data) => {}
|
||||||
EventContext::RtcpPacket(_rtcp_data) => {}
|
EventContext::RtcpPacket(_rtcp_data) => {}
|
||||||
EventContext::ClientDisconnect(_client_disconnect) => {
|
EventContext::ClientDisconnect(_client_disconnect) => {
|
||||||
// This is already taken care of elsewhere
|
// This is already taken care of elsewhere
|
||||||
}
|
}
|
||||||
EventContext::DriverConnect(_connect_data) => {}
|
EventContext::DriverConnect(_connect_data) => {}
|
||||||
EventContext::DriverReconnect(_connect_data) => {}
|
EventContext::DriverReconnect(_connect_data) => {}
|
||||||
EventContext::DriverDisconnect(_disconnect_data) => {}
|
EventContext::DriverDisconnect(_disconnect_data) => {}
|
||||||
other => {
|
other => {
|
||||||
tracing::warn!(?other, "cannot be handled yet");
|
tracing::warn!(?other, "cannot be handled yet");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[tracing::instrument(skip(state))]
|
#[tracing::instrument(skip(state))]
|
||||||
pub async fn handle(state: State, interaction: Interaction) {
|
pub async fn handle(state: State, interaction: Interaction) {
|
||||||
let vcs = state.vcs;
|
let vcs = state.vcs;
|
||||||
|
|
||||||
let (guild_id, voice_channel_id) = match get_guild_and_voice_channel_id(&interaction, &vcs) {
|
let (guild_id, voice_channel_id) = match get_guild_and_voice_channel_id(&interaction, &vcs) {
|
||||||
Ok((guild_id, voice_channel_id)) => (guild_id, voice_channel_id),
|
Ok((guild_id, voice_channel_id)) => (guild_id, voice_channel_id),
|
||||||
Err(error) => {
|
Err(error) => {
|
||||||
state
|
state
|
||||||
.discord_client
|
.discord_client
|
||||||
.interaction(state.discord_application_id)
|
.interaction(state.discord_application_id)
|
||||||
.create_response(
|
.create_response(
|
||||||
interaction.id,
|
interaction.id,
|
||||||
&interaction.token,
|
&interaction.token,
|
||||||
&InteractionResponse {
|
&InteractionResponse {
|
||||||
kind: InteractionResponseType::ChannelMessageWithSource,
|
kind: InteractionResponseType::ChannelMessageWithSource,
|
||||||
data: Some(
|
data: Some(
|
||||||
InteractionResponseDataBuilder::new()
|
InteractionResponseDataBuilder::new()
|
||||||
.embeds([get_guild_and_vc_error_to_embed(error)])
|
.embeds([get_guild_and_vc_error_to_embed(error)])
|
||||||
.flags(MessageFlags::EPHEMERAL)
|
.flags(MessageFlags::EPHEMERAL)
|
||||||
.build(),
|
.build(),
|
||||||
),
|
),
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
.await
|
.await
|
||||||
.expect("TODO");
|
.expect("TODO");
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
state
|
state
|
||||||
.discord_client
|
.discord_client
|
||||||
.interaction(state.discord_application_id)
|
.interaction(state.discord_application_id)
|
||||||
.create_response(
|
.create_response(
|
||||||
interaction.id,
|
interaction.id,
|
||||||
&interaction.token,
|
&interaction.token,
|
||||||
&InteractionResponse {
|
&InteractionResponse {
|
||||||
kind: InteractionResponseType::DeferredChannelMessageWithSource,
|
kind: InteractionResponseType::DeferredChannelMessageWithSource,
|
||||||
data: None,
|
data: None,
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
.await
|
.await
|
||||||
.expect("TODO");
|
.expect("TODO");
|
||||||
|
|
||||||
let call = state
|
let call = state
|
||||||
.songbird
|
.songbird
|
||||||
.join(guild_id, voice_channel_id)
|
.join(guild_id, voice_channel_id)
|
||||||
.await
|
.await
|
||||||
.expect("TODO");
|
.expect("TODO");
|
||||||
|
|
||||||
tracing::error!(?call, "successfully joined");
|
tracing::error!(?call, "successfully joined");
|
||||||
|
|
||||||
let start_instant = Instant::now();
|
let start_instant = Instant::now();
|
||||||
let start_utc = UtcDateTime::now();
|
let start_utc = UtcDateTime::now();
|
||||||
|
|
||||||
let audio_channels = opus2::Channels::from(state.audio_channels) as u16;
|
let audio_channels = opus2::Channels::from(state.audio_channels) as u16;
|
||||||
|
|
||||||
let audio_sample_rate = u32::from(state.audio_sample_rate);
|
let audio_sample_rate = u32::from(state.audio_sample_rate);
|
||||||
|
|
||||||
let handler = Handler {
|
let handler = Handler {
|
||||||
start_instant,
|
start_instant,
|
||||||
start_utc,
|
start_utc,
|
||||||
recordings: state.recording_data,
|
recordings: state.recording_data,
|
||||||
guild_id,
|
guild_id,
|
||||||
channel_id: voice_channel_id,
|
channel_id: voice_channel_id,
|
||||||
known_ssrcs: Default::default(),
|
known_ssrcs: Default::default(),
|
||||||
|
|
||||||
audio_channels,
|
audio_channels,
|
||||||
audio_sample_rate,
|
audio_sample_rate,
|
||||||
|
|
||||||
user_data_manager: state.user_data_manager,
|
user_data_manager: state.user_data_manager,
|
||||||
};
|
};
|
||||||
|
|
||||||
{
|
{
|
||||||
let mut call = call.lock().await;
|
let mut call = call.lock().await;
|
||||||
|
|
||||||
call.add_global_event(CoreEvent::SpeakingStateUpdate.into(), handler.clone());
|
call.add_global_event(CoreEvent::SpeakingStateUpdate.into(), handler.clone());
|
||||||
call.add_global_event(CoreEvent::VoiceTick.into(), handler);
|
call.add_global_event(CoreEvent::VoiceTick.into(), handler);
|
||||||
|
|
||||||
call.mute(true).await.expect("TODO");
|
call.mute(true).await.expect("TODO");
|
||||||
}
|
}
|
||||||
|
|
||||||
let channel_mention = format!("<#{voice_channel_id}>");
|
let channel_mention = format!("<#{voice_channel_id}>");
|
||||||
|
let bot_owner_mention = format!("<@{}>", state.discord_bot_owner_user_id);
|
||||||
let bot_owner_mention = format!("<@{}>", state.discord_bot_owner_user_id);
|
|
||||||
|
let opt_in_mention = format!(
|
||||||
state
|
"</{}:{}>",
|
||||||
.discord_client
|
state.discord_opt_in_command_name, state.discord_opt_in_command_id
|
||||||
.interaction(state.discord_application_id)
|
);
|
||||||
.update_response(
|
let opt_out_mention = format!(
|
||||||
&interaction.token,
|
"</{}:{}>",
|
||||||
).embeds(Some(&[
|
state.discord_opt_out_command_name, state.discord_opt_out_command_id
|
||||||
EmbedBuilder::new()
|
);
|
||||||
.title("Joined VC to record")
|
|
||||||
.description(format!("This bot joined {channel_mention} and intends to record. Here are some pledges backed by faith (because there is no way to verify them yourself) in {bot_owner_mention}:"))
|
state
|
||||||
.field(
|
.discord_client
|
||||||
EmbedFieldBuilder::new("Recordings are never shared", "Audio recordings are only stored on my home server and desktop computer and will never be uploaded to services or hardware that is owned by another person: not even curated clips, and not even to people who were in the recording. When transcription to text is implemented, this will only be run on my personally owned devices and not on any internet or cloud offering.").build()
|
.interaction(state.discord_application_id)
|
||||||
)
|
.update_response(
|
||||||
.field(
|
&interaction.token,
|
||||||
EmbedFieldBuilder::new("You won't be \"audited\"", "I will not reference things said in past recordings with the goal of \"making a point\", nor pull them up on the spot (even by the request of the person who said it). Ideally, these are just peace of mind for me that I'm not missing out by not being in a Discord call all the time and can take my life back, so using them in an unhealthy way isn't in my interest.").build()
|
).embeds(Some(&[
|
||||||
)
|
EmbedBuilder::new()
|
||||||
.field(
|
.title("Joined VC to record")
|
||||||
EmbedFieldBuilder::new("Code is publicly available", "The latest source code is at https://gitea.katniss.top/jacob/fomo-reducer so that I don't have to write guarantees about the technology here (e.g. what data is acquired, how it's used or stored) and you can just check it yourself.").build()
|
.description(format!("This bot joined {channel_mention} and intends to record. You can opt out with {opt_out_mention} or explicitly opt in with {opt_in_mention} (I'd appreciate this one). Here are some pledges backed by faith (because there is no way to verify them yourself) in {bot_owner_mention}:"))
|
||||||
)
|
.field(
|
||||||
.footer(
|
EmbedFieldBuilder::new("Recordings are never shared", "Audio recordings are only stored on my home server and desktop computer and will never be uploaded to services or hardware that is owned by another person: not even curated clips, and not even to people who were in the recording. When transcription to text is implemented, this will only be run on my personally owned devices and not on any internet or cloud offering.").build()
|
||||||
EmbedFooterBuilder::new("Thanks for your patience and understanding as I have bad and unusual mental health and it's crazy that I need this. This - especially if I learn if I can record streams or webcams so I don't miss out on those experiences either - should be the end of abrasion and force about how we spend our time. Again, thank you, I appreciate it.")
|
)
|
||||||
)
|
.field(
|
||||||
.validate()
|
EmbedFieldBuilder::new("You won't be \"audited\"", "I will not reference things said in past recordings with the goal of \"making a point\", nor pull them up on the spot (even by the request of the person who said it). Ideally, these are just peace of mind for me that I'm not missing out by not being in a Discord call all the time and can take my life back, so using them in an unhealthy way isn't in my interest.").build()
|
||||||
.unwrap()
|
)
|
||||||
.build()
|
.field(
|
||||||
]))
|
EmbedFieldBuilder::new("Code is publicly available", "The latest source code is at https://gitea.katniss.top/jacob/fomo-reducer so that I don't have to write guarantees about the technology here (e.g. what data is acquired, how it's used or stored) and you can just check it yourself.").build()
|
||||||
.await
|
)
|
||||||
.expect("TODO");
|
.footer(
|
||||||
}
|
EmbedFooterBuilder::new("Thanks for your patience and understanding as I have bad and unusual mental health and it's crazy that I need this. This - especially if I learn if I can record streams or webcams so I don't miss out on those experiences either - should be the end of abrasion and force about how we spend our time. Again, thank you, I appreciate it.")
|
||||||
|
)
|
||||||
|
.validate()
|
||||||
|
.unwrap()
|
||||||
|
.build()
|
||||||
|
]))
|
||||||
|
.await
|
||||||
|
.expect("TODO");
|
||||||
|
}
|
||||||
|
|||||||
@@ -12,17 +12,17 @@ use twilight_model::{
|
|||||||
application::{command::Command, interaction::Interaction},
|
application::{command::Command, interaction::Interaction},
|
||||||
id::{
|
id::{
|
||||||
Id,
|
Id,
|
||||||
marker::{ApplicationMarker, UserMarker},
|
marker::{ApplicationMarker, CommandMarker, UserMarker},
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
use crate::{GuildVoiceChannelToTextChannel, UserDataManager, VCs};
|
use crate::{GuildVoiceChannelToTextChannel, UserDataManager, VCs};
|
||||||
|
|
||||||
mod debug;
|
pub mod debug;
|
||||||
mod join;
|
pub mod join;
|
||||||
mod leave;
|
pub mod leave;
|
||||||
mod opt_in;
|
pub mod opt_in;
|
||||||
mod opt_out;
|
pub mod opt_out;
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
pub struct State {
|
pub struct State {
|
||||||
@@ -33,6 +33,10 @@ pub struct State {
|
|||||||
pub discord_application_id: Id<ApplicationMarker>,
|
pub discord_application_id: Id<ApplicationMarker>,
|
||||||
pub discord_bot_owner_user_id: Id<UserMarker>,
|
pub discord_bot_owner_user_id: Id<UserMarker>,
|
||||||
pub discord_client: Arc<twilight_http::Client>,
|
pub discord_client: Arc<twilight_http::Client>,
|
||||||
|
pub discord_opt_in_command_id: Id<CommandMarker>,
|
||||||
|
pub discord_opt_in_command_name: Arc<str>,
|
||||||
|
pub discord_opt_out_command_id: Id<CommandMarker>,
|
||||||
|
pub discord_opt_out_command_name: Arc<str>,
|
||||||
pub discord_user_id: Id<UserMarker>,
|
pub discord_user_id: Id<UserMarker>,
|
||||||
pub discord_voice_channel_corresponding_text_channel: Arc<GuildVoiceChannelToTextChannel>,
|
pub discord_voice_channel_corresponding_text_channel: Arc<GuildVoiceChannelToTextChannel>,
|
||||||
pub recording_data: Operator,
|
pub recording_data: Operator,
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
mod command;
|
pub mod command;
|
||||||
mod one_to_many;
|
mod one_to_many;
|
||||||
mod one_to_many_with_data;
|
mod one_to_many_with_data;
|
||||||
mod one_to_one;
|
mod one_to_one;
|
||||||
|
|||||||
29
src/main.rs
29
src/main.rs
@@ -1,7 +1,7 @@
|
|||||||
use clap::Parser;
|
use clap::Parser;
|
||||||
use fomo_reducer::{
|
use fomo_reducer::{
|
||||||
CommandRouter, GuildVoiceChannelToTextChannel, State, Storage, UserDataManager, all_commands,
|
CommandRouter, GuildVoiceChannelToTextChannel, State, Storage, UserDataManager, all_commands,
|
||||||
initialize_vcs, update_vcs,
|
command, initialize_vcs, update_vcs,
|
||||||
};
|
};
|
||||||
use secrecy::{ExposeSecret, SecretString};
|
use secrecy::{ExposeSecret, SecretString};
|
||||||
use snafu::{OptionExt, ResultExt, Snafu};
|
use snafu::{OptionExt, ResultExt, Snafu};
|
||||||
@@ -10,7 +10,7 @@ use songbird::{
|
|||||||
driver::{Channels, DecodeConfig, SampleRate},
|
driver::{Channels, DecodeConfig, SampleRate},
|
||||||
shards::TwilightMap,
|
shards::TwilightMap,
|
||||||
};
|
};
|
||||||
use std::{fmt::Debug, str::FromStr, sync::Arc};
|
use std::{collections::BTreeMap, fmt::Debug, str::FromStr, sync::Arc};
|
||||||
use strum::EnumString;
|
use strum::EnumString;
|
||||||
use tokio::{select, signal::ctrl_c, task::JoinSet};
|
use tokio::{select, signal::ctrl_c, task::JoinSet};
|
||||||
use tokio_util::{sync::CancellationToken, time::FutureExt as _};
|
use tokio_util::{sync::CancellationToken, time::FutureExt as _};
|
||||||
@@ -275,7 +275,7 @@ async fn main() -> Result<(), MainError> {
|
|||||||
|
|
||||||
let commands = all_commands();
|
let commands = all_commands();
|
||||||
|
|
||||||
let _returned_commands = interaction_client
|
let returned_commands = interaction_client
|
||||||
.set_global_commands(
|
.set_global_commands(
|
||||||
Vec::from_iter(
|
Vec::from_iter(
|
||||||
commands
|
commands
|
||||||
@@ -290,6 +290,25 @@ async fn main() -> Result<(), MainError> {
|
|||||||
.await
|
.await
|
||||||
.expect("failed to deserialize set commands"); // TODO
|
.expect("failed to deserialize set commands"); // TODO
|
||||||
|
|
||||||
|
let mut discord_command_name_to_returned_command = BTreeMap::from_iter(
|
||||||
|
returned_commands
|
||||||
|
.into_iter()
|
||||||
|
.map(|command| (command.name.clone(), command)),
|
||||||
|
);
|
||||||
|
|
||||||
|
let discord_opt_in_command = discord_command_name_to_returned_command
|
||||||
|
.remove(&command::opt_in::COMMAND.name)
|
||||||
|
.expect("TODO");
|
||||||
|
let discord_opt_out_command = discord_command_name_to_returned_command
|
||||||
|
.remove(&command::opt_out::COMMAND.name)
|
||||||
|
.expect("TODO");
|
||||||
|
|
||||||
|
let discord_opt_in_command_id = discord_opt_in_command.id.expect("TODO");
|
||||||
|
let discord_opt_out_command_id = discord_opt_out_command.id.expect("TODO");
|
||||||
|
|
||||||
|
let discord_opt_in_command_name = discord_opt_in_command.name.into();
|
||||||
|
let discord_opt_out_command_name = discord_opt_out_command.name.into();
|
||||||
|
|
||||||
let vcs = initialize_vcs(&discord_client).await;
|
let vcs = initialize_vcs(&discord_client).await;
|
||||||
|
|
||||||
let command_router = CommandRouter::from_iter(commands);
|
let command_router = CommandRouter::from_iter(commands);
|
||||||
@@ -329,6 +348,10 @@ async fn main() -> Result<(), MainError> {
|
|||||||
discord_application_id,
|
discord_application_id,
|
||||||
discord_bot_owner_user_id,
|
discord_bot_owner_user_id,
|
||||||
discord_client,
|
discord_client,
|
||||||
|
discord_opt_in_command_id,
|
||||||
|
discord_opt_in_command_name,
|
||||||
|
discord_opt_out_command_id,
|
||||||
|
discord_opt_out_command_name,
|
||||||
discord_user_id,
|
discord_user_id,
|
||||||
discord_voice_channel_corresponding_text_channel,
|
discord_voice_channel_corresponding_text_channel,
|
||||||
recording_data,
|
recording_data,
|
||||||
|
|||||||
Reference in New Issue
Block a user