use std::sync::LazyLock; use twilight_model::application::{ command::{Command, CommandType}, interaction::{Interaction, application_command::CommandData}, }; use twilight_util::builder::command::CommandBuilder; use crate::command::State; const NAME: &str = "join"; const DESCRIPTION: &str = "The bot will join the same VC as you (with intention to record)"; pub static COMMAND: LazyLock = 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 vcs = state.vcs; let guild_id = interaction.guild_id.expect("TODO"); // let user_id = data.user.map(|user| user.id).expect("TODO"); let user_id = interaction .member .and_then(|member| member.user.map(|user| user.id)) .expect("TODO"); let guild_vcs = vcs.get(&guild_id).expect("TODO"); tracing::error!(?guild_vcs, "TODO"); let (&channel_id, user_in_vc_data) = guild_vcs.get_left_and_data_for(&user_id).expect("TODO"); tracing::error!(?user_in_vc_data, "TODO"); let call = tokio::spawn({ let songbird = state.songbird.clone(); async move { songbird.join(guild_id, channel_id).await } }) .await .unwrap() .expect("TODO"); tracing::error!(?call, "TODO"); }