fix: improvements by clippy
This commit is contained in:
parent
af50d54729
commit
d72577c245
2 changed files with 21 additions and 18 deletions
|
@ -7,7 +7,6 @@ use crate::util::user_util::{self, get_vc_id};
|
||||||
|
|
||||||
pub async fn run(ctx: &Context, command: &CommandInteraction) -> CreateEmbed {
|
pub async fn run(ctx: &Context, command: &CommandInteraction) -> CreateEmbed {
|
||||||
let username = command.user.name.as_str();
|
let username = command.user.name.as_str();
|
||||||
let options = &command.data.options;
|
|
||||||
|
|
||||||
let query = command.data.options.first().and_then(|option| {
|
let query = command.data.options.first().and_then(|option| {
|
||||||
if let CommandDataOptionValue::String(query) = &option.value {
|
if let CommandDataOptionValue::String(query) = &option.value {
|
||||||
|
@ -30,16 +29,18 @@ pub async fn run(ctx: &Context, command: &CommandInteraction) -> CreateEmbed {
|
||||||
|
|
||||||
println!("Guild ID: {:?}", 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)
|
let manager = &songbird::get(ctx)
|
||||||
.await
|
.await
|
||||||
.expect("Cannot get Songbird.")
|
.expect("Cannot get Songbird.")
|
||||||
.clone();
|
.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
|
// 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() {
|
if self_channel.is_err() {
|
||||||
return Embed::create(
|
return Embed::create(
|
||||||
|
|
|
@ -1,4 +1,3 @@
|
||||||
use futures::future::BoxFuture;
|
|
||||||
use serenity::all::{ChannelId, Context, Guild, GuildId, PartialGuild, UserId};
|
use serenity::all::{ChannelId, Context, Guild, GuildId, PartialGuild, UserId};
|
||||||
use serenity::Error;
|
use serenity::Error;
|
||||||
|
|
||||||
|
@ -8,7 +7,7 @@ pub fn get_guild_cached(ctx: &Context, guild_id: &GuildId) -> Option<Guild> {
|
||||||
Some(guild) => guild,
|
Some(guild) => guild,
|
||||||
None => {
|
None => {
|
||||||
println!("Cannot get guild with id {:?}!", guild_id);
|
println!("Cannot get guild with id {:?}!", guild_id);
|
||||||
return None
|
return None;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -29,24 +28,23 @@ pub async fn request_guild(ctx: &Context, guild_id: &GuildId) -> Result<Guild, E
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Request a guild by id, get it from Discord, not from cache, this is a partial guild
|
/// Request a guild by id, get it from Discord, not from cache, this is a partial guild
|
||||||
|
#[allow(dead_code)]
|
||||||
pub async fn request_partial_guild(ctx: &Context, guild_id: &GuildId) -> PartialGuild {
|
pub async fn request_partial_guild(ctx: &Context, guild_id: &GuildId) -> PartialGuild {
|
||||||
let guild = match ctx.http.get_guild(*guild_id).await {
|
match ctx.http.get_guild(*guild_id).await {
|
||||||
Ok(guild) => guild,
|
Ok(guild) => guild,
|
||||||
Err(error) => {
|
Err(error) => {
|
||||||
panic!("error whilest getting guild from Discord {}", error);
|
panic!("error whilest getting guild from Discord {}", error);
|
||||||
}
|
}
|
||||||
};
|
}
|
||||||
|
|
||||||
guild
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Get the current channel id of the bot
|
/// Get the current channel id of the bot
|
||||||
pub fn get_vc_id_cached(ctx: &Context, guild_id: &GuildId, user_id: &UserId) -> Option<ChannelId> {
|
pub fn get_vc_id_cached(ctx: &Context, guild_id: &GuildId, user_id: &UserId) -> Option<ChannelId> {
|
||||||
let guild = match get_guild_cached(&ctx, guild_id){
|
let guild = match get_guild_cached(ctx, guild_id) {
|
||||||
Some(guild) => guild,
|
Some(guild) => guild,
|
||||||
None => {
|
None => {
|
||||||
println!("Cannot get guild while getting channel id!");
|
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)
|
Some(channel_id)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn get_vc_id(ctx: &Context, guild_id: &GuildId, user_id: &UserId) -> Result<ChannelId, Error> {
|
pub async fn get_vc_id(
|
||||||
let guild = request_guild(&ctx, guild_id).await?;
|
ctx: &Context,
|
||||||
|
guild_id: &GuildId,
|
||||||
|
user_id: &UserId,
|
||||||
|
) -> Result<ChannelId, Error> {
|
||||||
|
let guild = request_guild(ctx, guild_id).await?;
|
||||||
|
|
||||||
let channel_id = guild
|
let channel_id = guild
|
||||||
.voice_states
|
.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 {
|
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);
|
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 {
|
pub async fn is_self_connected_to_vc(ctx: &Context, guild_id: &GuildId) -> bool {
|
||||||
let channel_id = get_self_vc_id(ctx, guild_id);
|
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
|
/// Get the current channel id of the bot
|
||||||
|
|
Loading…
Reference in a new issue