Compare commits
4 Commits
906ddec843
...
a752838a46
| Author | SHA1 | Date | |
|---|---|---|---|
| a752838a46 | |||
| fcd856b61a | |||
| fa88bd495f | |||
| bb51f1cc63 |
92
Cargo.lock
generated
92
Cargo.lock
generated
@@ -843,6 +843,27 @@ dependencies = [
|
||||
"tiny-keccak",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "const_format"
|
||||
version = "0.2.36"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "4481a617ad9a412be3b97c5d403fef8ed023103368908b9c50af598ff467cc1e"
|
||||
dependencies = [
|
||||
"const_format_proc_macros",
|
||||
"konst",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "const_format_proc_macros"
|
||||
version = "0.2.34"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "1d57c2eccfb16dbac1f4e61e206105db5820c9d26c3c472bc17c774259ef7744"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"unicode-xid",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "convert_case"
|
||||
version = "0.4.0"
|
||||
@@ -1738,6 +1759,7 @@ dependencies = [
|
||||
"rhai",
|
||||
"rustls 0.23.35",
|
||||
"secrecy 0.10.3",
|
||||
"shadow-rs",
|
||||
"snafu",
|
||||
"songbird",
|
||||
"strum 0.28.0",
|
||||
@@ -2040,6 +2062,19 @@ dependencies = [
|
||||
"polyval",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "git2"
|
||||
version = "0.20.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "7b88256088d75a56f8ecfa070513a775dd9107f6530ef14919dac831af9cfe2b"
|
||||
dependencies = [
|
||||
"bitflags 2.10.0",
|
||||
"libc",
|
||||
"libgit2-sys",
|
||||
"log",
|
||||
"url",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "glob"
|
||||
version = "0.3.3"
|
||||
@@ -2738,6 +2773,12 @@ dependencies = [
|
||||
"serde",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "is_debug"
|
||||
version = "1.1.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "1fe266d2e243c931d8190177f20bf7f24eed45e96f39e87dc49a27b32d12d407"
|
||||
|
||||
[[package]]
|
||||
name = "is_terminal_polyfill"
|
||||
version = "1.70.2"
|
||||
@@ -2851,6 +2892,21 @@ dependencies = [
|
||||
"elliptic-curve",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "konst"
|
||||
version = "0.2.20"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "128133ed7824fcd73d6e7b17957c5eb7bacb885649bd8c69708b2331a10bcefb"
|
||||
dependencies = [
|
||||
"konst_macro_rules",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "konst_macro_rules"
|
||||
version = "0.2.19"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a4933f3f57a8e9d9da04db23fb153356ecaf00cbd14aee46279c33dc80925c37"
|
||||
|
||||
[[package]]
|
||||
name = "kv-log-macro"
|
||||
version = "1.0.7"
|
||||
@@ -3120,6 +3176,18 @@ dependencies = [
|
||||
"rand 0.9.2",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "libgit2-sys"
|
||||
version = "0.18.3+1.9.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "c9b3acc4b91781bb0b3386669d325163746af5f6e4f73e6d2d630e09a35f3487"
|
||||
dependencies = [
|
||||
"cc",
|
||||
"libc",
|
||||
"libz-sys",
|
||||
"pkg-config",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "libloading"
|
||||
version = "0.9.0"
|
||||
@@ -3168,6 +3236,18 @@ dependencies = [
|
||||
"vcpkg",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "libz-sys"
|
||||
version = "1.1.28"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "fc3a226e576f50782b3305c5ccf458698f92798987f551c6a02efe8276721e22"
|
||||
dependencies = [
|
||||
"cc",
|
||||
"libc",
|
||||
"pkg-config",
|
||||
"vcpkg",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "linked-hash-map"
|
||||
version = "0.5.6"
|
||||
@@ -5925,6 +6005,18 @@ dependencies = [
|
||||
"digest",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "shadow-rs"
|
||||
version = "2.0.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "1dd39b4b2077bd36e60ca28c31d494046e747759cb9b507a7d177bb64787c39e"
|
||||
dependencies = [
|
||||
"const_format",
|
||||
"git2",
|
||||
"is_debug",
|
||||
"jiff",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "sharded-slab"
|
||||
version = "0.1.7"
|
||||
|
||||
@@ -56,6 +56,7 @@ patricia_tree = "0.10.1"
|
||||
rhai = "1.23.6"
|
||||
rustls = "0.23"
|
||||
secrecy = { version = "0.10.3", features = ["serde"] }
|
||||
shadow-rs = { version = "2.0.0", default-features = false }
|
||||
snafu = { version = "0.8.9", features = ["futures"] }
|
||||
songbird = { version = "0.6.0", default-features = false, features = [
|
||||
"driver",
|
||||
@@ -97,3 +98,4 @@ yoke = "0.8.2"
|
||||
|
||||
[build-dependencies]
|
||||
capnpc = "0.25.3"
|
||||
shadow-rs = "2.0.0"
|
||||
|
||||
7
build.rs
7
build.rs
@@ -1,7 +1,14 @@
|
||||
use shadow_rs::{BuildPattern, ShadowBuilder};
|
||||
|
||||
fn main() {
|
||||
capnpc::CompilerCommand::new()
|
||||
.file("bot.capnp")
|
||||
.file("user.capnp")
|
||||
.run()
|
||||
.expect("couldn't compile capnproto schemas");
|
||||
|
||||
ShadowBuilder::builder()
|
||||
.build_pattern(BuildPattern::RealTime)
|
||||
.build()
|
||||
.expect("couldn't embed build time information");
|
||||
}
|
||||
|
||||
@@ -1,22 +1,20 @@
|
||||
use futures::TryStreamExt;
|
||||
use snafu::{OptionExt, Snafu};
|
||||
use std::sync::LazyLock;
|
||||
use twilight_model::{
|
||||
application::{
|
||||
command::{Command, CommandType},
|
||||
interaction::Interaction,
|
||||
},
|
||||
channel::message::{Embed, MessageFlags},
|
||||
channel::message::MessageFlags,
|
||||
http::interaction::{InteractionResponse, InteractionResponseType},
|
||||
id::{Id, marker::UserMarker},
|
||||
};
|
||||
use twilight_util::builder::{
|
||||
InteractionResponseDataBuilder,
|
||||
command::CommandBuilder,
|
||||
embed::{EmbedAuthorBuilder, EmbedBuilder, EmbedFieldBuilder},
|
||||
embed::{EmbedAuthorBuilder, EmbedBuilder, EmbedFieldBuilder, EmbedFooterBuilder},
|
||||
};
|
||||
|
||||
use crate::command::State;
|
||||
use crate::{build_info, command::State};
|
||||
|
||||
const NAME: &str = "info";
|
||||
const DESCRIPTION: &str = "Show various information";
|
||||
@@ -28,67 +26,31 @@ pub static COMMAND: LazyLock<Command> = LazyLock::new(|| {
|
||||
.build()
|
||||
});
|
||||
|
||||
#[derive(Debug, Snafu)]
|
||||
enum NoPermission {
|
||||
/// there isn't a user who invoked this command
|
||||
NoUser,
|
||||
|
||||
/// the user isn't allowed to use this command because they're not the bot owner
|
||||
NotInvokedByBotOwner,
|
||||
}
|
||||
|
||||
fn no_permission_to_embed(error: NoPermission) -> Embed {
|
||||
match error {
|
||||
NoPermission::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()
|
||||
},
|
||||
NoPermission::NotInvokedByBotOwner => {
|
||||
EmbedBuilder::new().title("No permission to see debug info").description("Only the owner of this bot is allowed to see its information for debugging purposes.").validate().unwrap().build()
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
fn check_permission(
|
||||
interaction: &Interaction,
|
||||
bot_owner_user_id: Id<UserMarker>,
|
||||
) -> Result<(), NoPermission> {
|
||||
let user_id = interaction
|
||||
.member
|
||||
.as_ref()
|
||||
.and_then(|member| member.user.as_ref().map(|user| user.id))
|
||||
.context(NoUserSnafu)?;
|
||||
|
||||
if user_id != bot_owner_user_id {
|
||||
return Err(NoPermission::NotInvokedByBotOwner);
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[tracing::instrument]
|
||||
pub async fn handle(state: State, interaction: Interaction) {
|
||||
if let Err(no_permission) = check_permission(&interaction, state.discord_bot_owner_user_id) {
|
||||
state
|
||||
.discord_client
|
||||
.interaction(state.discord_application_id)
|
||||
.create_response(
|
||||
interaction.id,
|
||||
&interaction.token,
|
||||
&InteractionResponse {
|
||||
kind: InteractionResponseType::ChannelMessageWithSource,
|
||||
data: Some(
|
||||
InteractionResponseDataBuilder::new()
|
||||
.embeds([no_permission_to_embed(no_permission)])
|
||||
.flags(MessageFlags::EPHEMERAL)
|
||||
.build(),
|
||||
),
|
||||
},
|
||||
)
|
||||
.await
|
||||
.expect("TODO");
|
||||
let revision = build_info::COMMIT_HASH;
|
||||
|
||||
return;
|
||||
}
|
||||
let bot_owner_user_id = state.discord_bot_owner_user_id;
|
||||
|
||||
let is_bot_owner =
|
||||
interaction
|
||||
.member
|
||||
.as_ref()
|
||||
.and_then(|member| member.user.as_ref().map(|user| user.id))
|
||||
.map(|user_id| user_id == bot_owner_user_id)
|
||||
.unwrap_or(false);
|
||||
|
||||
let bot_owner_mention = format!("<@{}>", bot_owner_user_id);
|
||||
|
||||
let opt_in_mention = format!(
|
||||
"</{}:{}>",
|
||||
state.discord_opt_in_command_name, state.discord_opt_in_command_id
|
||||
);
|
||||
let opt_out_mention = format!(
|
||||
"</{}:{}>",
|
||||
state.discord_opt_out_command_name, state.discord_opt_out_command_id
|
||||
);
|
||||
|
||||
state
|
||||
.discord_client
|
||||
@@ -96,90 +58,110 @@ pub async fn handle(state: State, interaction: Interaction) {
|
||||
.create_response(
|
||||
interaction.id,
|
||||
&interaction.token,
|
||||
&InteractionResponse {
|
||||
&InteractionResponse {
|
||||
kind: InteractionResponseType::ChannelMessageWithSource,
|
||||
data: Some(
|
||||
InteractionResponseDataBuilder::new()
|
||||
.flags(MessageFlags::EPHEMERAL)
|
||||
.content("some debug info is coming your way!")
|
||||
.build(),
|
||||
),
|
||||
},
|
||||
)
|
||||
.await
|
||||
.expect("TODO");
|
||||
|
||||
let heat_script_description = state
|
||||
.bot_data_manager
|
||||
.with(|bot_data| {
|
||||
let heat_script_option = bot_data.has_heat_script().then(|| {
|
||||
bot_data
|
||||
.get_heat_script()
|
||||
.expect("TODO")
|
||||
.to_string()
|
||||
.expect("TODO")
|
||||
});
|
||||
heat_script_option.map_or("none set yet".into(), |heat_script| {
|
||||
format!("```\n{heat_script}\n```")
|
||||
})
|
||||
InteractionResponseDataBuilder::new().embeds([
|
||||
EmbedBuilder::new()
|
||||
.title("About This Bot")
|
||||
.description(format!("This bot intends to record VCs it's in. 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(
|
||||
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()
|
||||
)
|
||||
.field(
|
||||
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()
|
||||
)
|
||||
.field(
|
||||
EmbedFieldBuilder::new("Code is publicly available", format!("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. To that end: this bot is running revision `{revision}` at the time of this message.")).build()
|
||||
)
|
||||
.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()
|
||||
])
|
||||
.flags(MessageFlags::EPHEMERAL)
|
||||
.build()
|
||||
)
|
||||
})
|
||||
.await
|
||||
.expect("TODO");
|
||||
|
||||
state
|
||||
.discord_client
|
||||
.interaction(state.discord_application_id)
|
||||
.create_followup(&interaction.token)
|
||||
.embeds(&[EmbedBuilder::new()
|
||||
.field(EmbedFieldBuilder::new("Heat Script", heat_script_description).build())
|
||||
.validate()
|
||||
.unwrap()
|
||||
.build()])
|
||||
.flags(MessageFlags::EPHEMERAL)
|
||||
.await
|
||||
.expect("TODO");
|
||||
|
||||
let mut user_id_stream = state.user_data_manager.list().await.expect("TODO");
|
||||
|
||||
while let Some(user_id) = user_id_stream.try_next().await.expect("TODO") {
|
||||
let (consent, notification_script) = state
|
||||
.user_data_manager
|
||||
.with(user_id, |user_data| {
|
||||
let consent = user_data.get_voice_recording_consent().unwrap();
|
||||
let notification_script = user_data.has_notification_script().then_some(
|
||||
user_data
|
||||
.get_notification_script()
|
||||
|
||||
if is_bot_owner {
|
||||
let heat_script_description = state
|
||||
.bot_data_manager
|
||||
.with(|bot_data| {
|
||||
let heat_script_option = bot_data.has_heat_script().then(|| {
|
||||
bot_data
|
||||
.get_heat_script()
|
||||
.expect("TODO")
|
||||
.to_string()
|
||||
.expect("TODO"),
|
||||
);
|
||||
|
||||
(consent, notification_script)
|
||||
.to_str()
|
||||
.expect("TODO")
|
||||
});
|
||||
heat_script_option.map_or("none set yet".into(), |heat_script| {
|
||||
format!("```\n{heat_script}\n```")
|
||||
})
|
||||
})
|
||||
.await
|
||||
.expect("TODO");
|
||||
|
||||
let user_mention = format!("<@{user_id}>");
|
||||
|
||||
state
|
||||
.discord_client
|
||||
.interaction(state.discord_application_id)
|
||||
.create_followup(&interaction.token)
|
||||
.embeds(&[EmbedBuilder::new()
|
||||
.author(EmbedAuthorBuilder::new(user_mention))
|
||||
.field(EmbedFieldBuilder::new("Consent", format!("{consent:?}")).build())
|
||||
.field(
|
||||
EmbedFieldBuilder::new(
|
||||
"Notification Script",
|
||||
format!("{notification_script:?}"),
|
||||
)
|
||||
.build(),
|
||||
)
|
||||
.title("Bot Data")
|
||||
.field(EmbedFieldBuilder::new("Heat Script", heat_script_description).build())
|
||||
.validate()
|
||||
.unwrap()
|
||||
.build()])
|
||||
.flags(MessageFlags::EPHEMERAL)
|
||||
.await
|
||||
.expect("TODO");
|
||||
|
||||
let mut user_id_stream = state.user_data_manager.list().await.expect("TODO");
|
||||
|
||||
while let Some(user_id) = user_id_stream.try_next().await.expect("TODO") {
|
||||
let (consent, notification_script) = state
|
||||
.user_data_manager
|
||||
.with(user_id, |user_data| {
|
||||
let consent = user_data.get_voice_recording_consent().unwrap();
|
||||
let notification_script = user_data.has_notification_script().then_some(
|
||||
user_data
|
||||
.get_notification_script()
|
||||
.expect("TODO")
|
||||
.to_string()
|
||||
.expect("TODO"),
|
||||
);
|
||||
|
||||
(consent, notification_script)
|
||||
})
|
||||
.await
|
||||
.expect("TODO");
|
||||
|
||||
let user_mention = format!("<@{user_id}>");
|
||||
|
||||
state
|
||||
.discord_client
|
||||
.interaction(state.discord_application_id)
|
||||
.create_followup(&interaction.token)
|
||||
.embeds(&[EmbedBuilder::new()
|
||||
.author(EmbedAuthorBuilder::new(user_mention))
|
||||
.field(EmbedFieldBuilder::new("Consent", format!("{consent:?}")).build())
|
||||
.field(
|
||||
EmbedFieldBuilder::new(
|
||||
"Notification Script",
|
||||
format!("{notification_script:?}"),
|
||||
)
|
||||
.build(),
|
||||
)
|
||||
.validate()
|
||||
.unwrap()
|
||||
.build()])
|
||||
.flags(MessageFlags::EPHEMERAL)
|
||||
.await
|
||||
.expect("TODO");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -27,9 +27,7 @@ use twilight_model::{
|
||||
},
|
||||
};
|
||||
use twilight_util::builder::{
|
||||
InteractionResponseDataBuilder,
|
||||
command::CommandBuilder,
|
||||
embed::{EmbedBuilder, EmbedFieldBuilder, EmbedFooterBuilder},
|
||||
InteractionResponseDataBuilder, command::CommandBuilder, embed::EmbedBuilder,
|
||||
};
|
||||
|
||||
const NAME: &str = "join";
|
||||
@@ -50,9 +48,6 @@ enum GetGuildAndVoiceChannelIdError {
|
||||
/// there is no user who invoked this command
|
||||
NoUser,
|
||||
|
||||
/// there are no voice chats in this guild
|
||||
NoVCsInGuild,
|
||||
|
||||
/// the user is not in a voice chat in this guild
|
||||
UserNotInVC,
|
||||
}
|
||||
@@ -70,9 +65,11 @@ fn get_guild_and_voice_channel_id(
|
||||
.and_then(|member| member.user.as_ref().map(|user| user.id))
|
||||
.context(NoUserSnafu)?;
|
||||
|
||||
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 = vcs
|
||||
.get(&guild_id)
|
||||
.context(UserNotInVCSnafu)?
|
||||
.get_left_for(&user_id)
|
||||
.context(UserNotInVCSnafu)?;
|
||||
|
||||
Ok((guild_id, voice_channel_id))
|
||||
}
|
||||
@@ -85,9 +82,6 @@ fn get_guild_and_vc_error_to_embed(error: GetGuildAndVoiceChannelIdError) -> Emb
|
||||
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()
|
||||
},
|
||||
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()
|
||||
},
|
||||
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()
|
||||
},
|
||||
@@ -240,9 +234,9 @@ impl EventHandler for Handler {
|
||||
|
||||
#[tracing::instrument(skip(state))]
|
||||
pub async fn handle(state: State, interaction: Interaction) {
|
||||
let vcs = state.vcs;
|
||||
|
||||
let (guild_id, voice_channel_id) = match get_guild_and_voice_channel_id(&interaction, &vcs) {
|
||||
let guild_and_voice_channel_id_res =
|
||||
get_guild_and_voice_channel_id(&interaction, &state.vcs_watcher.borrow());
|
||||
let (guild_id, voice_channel_id) = match guild_and_voice_channel_id_res {
|
||||
Ok((guild_id, voice_channel_id)) => (guild_id, voice_channel_id),
|
||||
Err(error) => {
|
||||
state
|
||||
@@ -321,8 +315,11 @@ pub async fn handle(state: State, interaction: Interaction) {
|
||||
}
|
||||
|
||||
let channel_mention = format!("<#{voice_channel_id}>");
|
||||
let bot_owner_mention = format!("<@{}>", state.discord_bot_owner_user_id);
|
||||
|
||||
let info_mention = format!(
|
||||
"</{}:{}>",
|
||||
state.discord_info_command_name, state.discord_info_command_id
|
||||
);
|
||||
let opt_in_mention = format!(
|
||||
"</{}:{}>",
|
||||
state.discord_opt_in_command_name, state.discord_opt_in_command_id
|
||||
@@ -340,19 +337,7 @@ pub async fn handle(state: State, interaction: Interaction) {
|
||||
).embeds(Some(&[
|
||||
EmbedBuilder::new()
|
||||
.title("Joined VC to record")
|
||||
.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(
|
||||
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()
|
||||
)
|
||||
.field(
|
||||
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()
|
||||
)
|
||||
.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()
|
||||
)
|
||||
.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.")
|
||||
)
|
||||
.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). Please use {info_mention} for more information about this bot."))
|
||||
.validate()
|
||||
.unwrap()
|
||||
.build()
|
||||
|
||||
@@ -37,9 +37,6 @@ pub enum GetGuildAndVoiceChannelIdError {
|
||||
/// there is no user who invoked this command
|
||||
NoUser,
|
||||
|
||||
/// there are no voice chats in this guild
|
||||
NoVCsInGuild,
|
||||
|
||||
/// the bot is not in a voice chat in this guild
|
||||
BotNotInVC,
|
||||
}
|
||||
@@ -58,9 +55,9 @@ pub fn get_user_and_guild_and_voice_channel_id(
|
||||
|
||||
let guild_id = interaction.guild_id.context(NotInGuildSnafu)?;
|
||||
|
||||
let guild_vcs = vcs.get(&guild_id).context(NoVCsInGuildSnafu)?;
|
||||
|
||||
let &voice_channel_id = guild_vcs
|
||||
let &voice_channel_id = vcs
|
||||
.get(&guild_id)
|
||||
.context(BotNotInVCSnafu)?
|
||||
.get_left_for(&bot_user_id)
|
||||
.context(BotNotInVCSnafu)?;
|
||||
|
||||
@@ -75,9 +72,6 @@ fn get_guild_and_vc_error_to_embed(error: GetGuildAndVoiceChannelIdError) -> Emb
|
||||
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()
|
||||
},
|
||||
GetGuildAndVoiceChannelIdError::NoVCsInGuild => {
|
||||
EmbedBuilder::new().title("No VCs in this server").description("This bot can't leave VC because there aren't any in this server right now (therefore the bot must not be in any).").validate().unwrap().build()
|
||||
},
|
||||
GetGuildAndVoiceChannelIdError::BotNotInVC => {
|
||||
EmbedBuilder::new().title("Not in a VC").description("This bot can't leave VC if it isn't in one in this server.").validate().unwrap().build()
|
||||
},
|
||||
@@ -86,11 +80,12 @@ fn get_guild_and_vc_error_to_embed(error: GetGuildAndVoiceChannelIdError) -> Emb
|
||||
|
||||
#[tracing::instrument]
|
||||
pub async fn handle(state: State, interaction: Interaction) {
|
||||
let (user_id, guild_id, voice_channel_id) = match get_user_and_guild_and_voice_channel_id(
|
||||
let user_and_guild_and_voice_channel_id_res = get_user_and_guild_and_voice_channel_id(
|
||||
state.discord_user_id,
|
||||
&interaction,
|
||||
&state.vcs,
|
||||
) {
|
||||
&state.vcs_watcher.borrow(),
|
||||
);
|
||||
let (user_id, guild_id, voice_channel_id) = match user_and_guild_and_voice_channel_id_res {
|
||||
Ok((user_id, guild_id, voice_channel_id)) => (user_id, guild_id, voice_channel_id),
|
||||
Err(error) => {
|
||||
state
|
||||
|
||||
@@ -16,7 +16,7 @@ use twilight_model::{
|
||||
},
|
||||
};
|
||||
|
||||
use crate::{BotDataManager, GuildVoiceChannelToTextChannel, UserDataManager, VCs};
|
||||
use crate::{BotDataManager, GuildVoiceChannelToTextChannel, UserDataManager, VCsWatcher};
|
||||
|
||||
pub mod info;
|
||||
pub mod join;
|
||||
@@ -33,6 +33,8 @@ pub struct State {
|
||||
pub discord_application_id: Id<ApplicationMarker>,
|
||||
pub discord_bot_owner_user_id: Id<UserMarker>,
|
||||
pub discord_client: Arc<twilight_http::Client>,
|
||||
pub discord_info_command_id: Id<CommandMarker>,
|
||||
pub discord_info_command_name: Arc<str>,
|
||||
pub discord_opt_in_command_id: Id<CommandMarker>,
|
||||
pub discord_opt_in_command_name: Arc<str>,
|
||||
pub discord_opt_out_command_id: Id<CommandMarker>,
|
||||
@@ -42,7 +44,7 @@ pub struct State {
|
||||
pub recording_data: Operator,
|
||||
pub songbird: Arc<Songbird>,
|
||||
pub user_data_manager: UserDataManager,
|
||||
pub vcs: Arc<VCs>,
|
||||
pub vcs_watcher: VCsWatcher,
|
||||
}
|
||||
|
||||
type Return = ();
|
||||
|
||||
@@ -11,6 +11,7 @@ mod user_data;
|
||||
mod vc_user;
|
||||
capnp::generated_code!(mod bot_capnp);
|
||||
capnp::generated_code!(mod user_capnp);
|
||||
shadow_rs::shadow!(build_info);
|
||||
|
||||
pub use bot_data::BotDataManager;
|
||||
pub use command::{Router as CommandRouter, State, all as all_commands};
|
||||
@@ -19,6 +20,6 @@ pub use one_to_many_with_data::OneToManyUniqueBTreeMapWithData;
|
||||
pub use one_to_one::OneToOneBTreeMap;
|
||||
pub use operator_ext::OperatorExt;
|
||||
pub use storage::Storage;
|
||||
pub use track_vcs::{GuildVoiceChannelToTextChannel, VCs, initialize_vcs, update_vcs};
|
||||
pub use track_vcs::{GuildVoiceChannelToTextChannel, VCs, VCsWatcher, initialize_vcs, update_vcs};
|
||||
pub use user_data::UserDataManager;
|
||||
pub use vc_user::{UserInVCData, VoiceStatus};
|
||||
|
||||
16
src/main.rs
16
src/main.rs
@@ -1,7 +1,6 @@
|
||||
use clap::Parser;
|
||||
use fomo_reducer::{
|
||||
BotDataManager, CommandRouter, GuildVoiceChannelToTextChannel, State, Storage, UserDataManager,
|
||||
all_commands, command, initialize_vcs, update_vcs,
|
||||
BotDataManager, CommandRouter, GuildVoiceChannelToTextChannel, State, Storage, UserDataManager, VCsWatcher, all_commands, command, initialize_vcs, update_vcs
|
||||
};
|
||||
use secrecy::{ExposeSecret, SecretString};
|
||||
use snafu::{OptionExt, ResultExt, Snafu};
|
||||
@@ -296,6 +295,9 @@ async fn main() -> Result<(), MainError> {
|
||||
.map(|command| (command.name.clone(), command)),
|
||||
);
|
||||
|
||||
let discord_info_command = discord_command_name_to_returned_command
|
||||
.remove(&command::info::COMMAND.name)
|
||||
.expect("TODO");
|
||||
let discord_opt_in_command = discord_command_name_to_returned_command
|
||||
.remove(&command::opt_in::COMMAND.name)
|
||||
.expect("TODO");
|
||||
@@ -303,9 +305,11 @@ async fn main() -> Result<(), MainError> {
|
||||
.remove(&command::opt_out::COMMAND.name)
|
||||
.expect("TODO");
|
||||
|
||||
let discord_info_command_id = discord_info_command.id.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_info_command_name = discord_info_command.name.into();
|
||||
let discord_opt_in_command_name = discord_opt_in_command.name.into();
|
||||
let discord_opt_out_command_name = discord_opt_out_command.name.into();
|
||||
|
||||
@@ -316,7 +320,7 @@ async fn main() -> Result<(), MainError> {
|
||||
|
||||
let discord_client = Arc::new(discord_client);
|
||||
let songbird = Arc::new(songbird);
|
||||
let vcs = Arc::new(vcs);
|
||||
let vcs_watcher = VCsWatcher::new(vcs);
|
||||
|
||||
let bot_data = bot_data.into_inner();
|
||||
let recording_data = recording_data.into_inner();
|
||||
@@ -349,6 +353,8 @@ async fn main() -> Result<(), MainError> {
|
||||
discord_application_id,
|
||||
discord_bot_owner_user_id,
|
||||
discord_client,
|
||||
discord_info_command_id,
|
||||
discord_info_command_name,
|
||||
discord_opt_in_command_id,
|
||||
discord_opt_in_command_name,
|
||||
discord_opt_out_command_id,
|
||||
@@ -358,7 +364,7 @@ async fn main() -> Result<(), MainError> {
|
||||
recording_data,
|
||||
songbird,
|
||||
user_data_manager,
|
||||
vcs,
|
||||
vcs_watcher,
|
||||
};
|
||||
|
||||
if let Some(discord_status) = discord_status {
|
||||
@@ -455,7 +461,7 @@ async fn handle_event(command_router: Arc<CommandRouter>, state: State, event: E
|
||||
|
||||
match event {
|
||||
Event::VoiceStateUpdate(voice_state_update) => {
|
||||
update_vcs(&voice_state_update, &state.vcs);
|
||||
state.vcs_watcher.send_modify(|vcs| update_vcs(&voice_state_update, vcs));
|
||||
}
|
||||
Event::InteractionCreate(interaction_create) => {
|
||||
let InteractionCreate(interaction) = *interaction_create;
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
use std::collections::BTreeMap;
|
||||
|
||||
use dashmap::DashMap;
|
||||
use futures::{StreamExt, stream::FuturesUnordered};
|
||||
use tokio::sync::watch;
|
||||
use twilight_model::{
|
||||
gateway::payload::incoming::VoiceStateUpdate,
|
||||
id::{
|
||||
@@ -15,8 +15,9 @@ use crate::{OneToManyUniqueBTreeMapWithData, OneToOneBTreeMap, UserInVCData, Voi
|
||||
pub type GuildVoiceChannelToTextChannel =
|
||||
BTreeMap<Id<GuildMarker>, OneToOneBTreeMap<Id<ChannelMarker>, Id<ChannelMarker>>>;
|
||||
|
||||
type VCsInGuild = OneToManyUniqueBTreeMapWithData<Id<ChannelMarker>, Id<UserMarker>, UserInVCData>;
|
||||
pub type VCs = DashMap<Id<GuildMarker>, VCsInGuild>;
|
||||
pub type VCsInGuild = OneToManyUniqueBTreeMapWithData<Id<ChannelMarker>, Id<UserMarker>, UserInVCData>;
|
||||
pub type VCs = BTreeMap<Id<GuildMarker>, VCsInGuild>;
|
||||
pub type VCsWatcher = watch::Sender<VCs>;
|
||||
|
||||
#[tracing::instrument(skip(discord_client), ret)]
|
||||
async fn initialize_user_in_vc(
|
||||
@@ -92,7 +93,7 @@ pub async fn initialize_vcs(discord_client: &twilight_http::Client) -> VCs {
|
||||
}
|
||||
|
||||
#[tracing::instrument(skip(vcs))]
|
||||
pub fn update_vcs(voice_state_update: &VoiceStateUpdate, vcs: &VCs) {
|
||||
pub fn update_vcs(voice_state_update: &VoiceStateUpdate, vcs: &mut VCs) {
|
||||
let user_id = voice_state_update.user_id;
|
||||
match voice_state_update.guild_id {
|
||||
Some(guild_id) => match voice_state_update.channel_id {
|
||||
@@ -107,9 +108,7 @@ pub fn update_vcs(voice_state_update: &VoiceStateUpdate, vcs: &VCs) {
|
||||
.build();
|
||||
let user_in_vc_data = voice_status.into();
|
||||
|
||||
vcs.entry(guild_id)
|
||||
.or_default()
|
||||
.insert(channel_id, user_id, user_in_vc_data);
|
||||
vcs.entry(guild_id).or_default().insert(channel_id, user_id, user_in_vc_data);
|
||||
|
||||
tracing::info!(
|
||||
?guild_id,
|
||||
@@ -120,9 +119,7 @@ pub fn update_vcs(voice_state_update: &VoiceStateUpdate, vcs: &VCs) {
|
||||
}
|
||||
|
||||
None => {
|
||||
if let Some(mut channel_vcers) = vcs.get_mut(&guild_id) {
|
||||
channel_vcers.remove_right(&user_id);
|
||||
}
|
||||
vcs.entry(guild_id).or_default().remove_right(&user_id);
|
||||
|
||||
tracing::info!(?guild_id, ?user_id, "disconnected");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user