diff --git a/src/commands/play.rs b/src/commands/play.rs index feb170d..acff8ef 100644 --- a/src/commands/play.rs +++ b/src/commands/play.rs @@ -7,7 +7,6 @@ use crate::util::user_util::{self, get_vc_id}; pub async fn run(ctx: &Context, command: &CommandInteraction) -> CreateEmbed { let username = command.user.name.as_str(); - let options = &command.data.options; let query = command.data.options.first().and_then(|option| { if let CommandDataOptionValue::String(query) = &option.value { @@ -27,19 +26,21 @@ pub async fn run(ctx: &Context, command: &CommandInteraction) -> CreateEmbed { return Embed::create(username, "GuildId not found", "Could not find guild id."); } }; - + println!("Guild ID: {:?}", guild_id); - let connect_to = get_vc_id(ctx, &guild_id, &command.user.id).await.expect("Cannot get channel id"); + let connect_to = get_vc_id(ctx, guild_id, &command.user.id) + .await + .expect("Cannot get channel id"); let manager = &songbird::get(ctx) .await .expect("Cannot get Songbird.") .clone(); - if !user_util::is_self_connected_to_vc(ctx, &guild_id).await { + if !user_util::is_self_connected_to_vc(ctx, guild_id).await { // self is connected to vc, check if user is in same vc - let self_channel = user_util::get_self_vc_id(ctx, &guild_id).await; + let self_channel = user_util::get_self_vc_id(ctx, guild_id).await; if self_channel.is_err() { return Embed::create( diff --git a/src/util/user_util.rs b/src/util/user_util.rs index 3f70c58..40ec889 100644 --- a/src/util/user_util.rs +++ b/src/util/user_util.rs @@ -1,4 +1,3 @@ -use futures::future::BoxFuture; use serenity::all::{ChannelId, Context, Guild, GuildId, PartialGuild, UserId}; use serenity::Error; @@ -8,10 +7,10 @@ pub fn get_guild_cached(ctx: &Context, guild_id: &GuildId) -> Option { Some(guild) => guild, None => { println!("Cannot get guild with id {:?}!", guild_id); - return None + return None; } }; - + println!("Got guild: {:?}", guild.name); Some(guild.clone()) @@ -29,24 +28,23 @@ pub async fn request_guild(ctx: &Context, guild_id: &GuildId) -> Result PartialGuild { - let guild = match ctx.http.get_guild(*guild_id).await { + match ctx.http.get_guild(*guild_id).await { Ok(guild) => guild, Err(error) => { panic!("error whilest getting guild from Discord {}", error); } - }; - - guild + } } /// Get the current channel id of the bot pub fn get_vc_id_cached(ctx: &Context, guild_id: &GuildId, user_id: &UserId) -> Option { - let guild = match get_guild_cached(&ctx, guild_id){ + let guild = match get_guild_cached(ctx, guild_id) { Some(guild) => guild, None => { println!("Cannot get guild while getting channel id!"); - return None + return None; } }; @@ -60,8 +58,12 @@ pub fn get_vc_id_cached(ctx: &Context, guild_id: &GuildId, user_id: &UserId) -> Some(channel_id) } -pub async fn get_vc_id(ctx: &Context, guild_id: &GuildId, user_id: &UserId) -> Result { - let guild = request_guild(&ctx, guild_id).await?; +pub async fn get_vc_id( + ctx: &Context, + guild_id: &GuildId, + user_id: &UserId, +) -> Result { + let guild = request_guild(ctx, guild_id).await?; let channel_id = guild .voice_states @@ -76,13 +78,13 @@ pub async fn get_vc_id(ctx: &Context, guild_id: &GuildId, user_id: &UserId) -> R pub fn is_self_connected_to_vc_cached(ctx: &Context, guild_id: &GuildId) -> bool { let channel_id = get_self_vc_id_cached(ctx, guild_id); - !channel_id.is_none() + channel_id.is_some() } pub async fn is_self_connected_to_vc(ctx: &Context, guild_id: &GuildId) -> bool { let channel_id = get_self_vc_id(ctx, guild_id); - !channel_id.await.is_err() + channel_id.await.is_ok() } /// Get the current channel id of the bot