chore: improve checks

This commit is contained in:
Miguel da Mota 2024-03-10 17:46:35 +01:00
parent fc32017a10
commit 29392dc72d
7 changed files with 20 additions and 29 deletions

View file

@ -3,9 +3,7 @@ use serenity::builder::{CreateCommand, CreateEmbed};
use crate::util::embed::Embed;
pub async fn run(_ctx: &Context, command: &CommandInteraction) -> CreateEmbed {
let username = command.user.name.as_str();
pub async fn run(_ctx: &Context, _command: &CommandInteraction) -> CreateEmbed {
Embed::create(
"",
"Botendo v7",

View file

@ -1,3 +1,3 @@
pub mod info;
pub mod play;
pub mod stop;
pub mod stop;

View file

@ -6,7 +6,7 @@ use serenity::model::application::CommandOptionType;
use crate::util::embed::Embed;
pub async unsafe fn run(ctx: &Context, command: &CommandInteraction) -> CreateEmbed {
pub async fn run(ctx: &Context, command: &CommandInteraction) -> CreateEmbed {
let username = command.user.name.as_str();
let options = &command.data.options;

View file

@ -3,7 +3,7 @@ use crate::util::embed::Embed;
use serenity::all::{CommandInteraction, Context};
use serenity::builder::{CreateCommand, CreateEmbed};
pub async unsafe fn run(ctx: &Context, command: &CommandInteraction) -> CreateEmbed {
pub async fn run(ctx: &Context, command: &CommandInteraction) -> CreateEmbed {
let username = command.user.name.as_str();
let guild_id = match &command.guild_id {

View file

@ -63,22 +63,20 @@ struct Handler;
#[async_trait]
impl EventHandler for Handler {
async fn interaction_create(&self, ctx: Context, interaction: Interaction) {
unsafe {
if let Interaction::Command(command) = interaction {
let _ = &command.defer(&ctx.http()).await.expect("Cannot defer");
if let Interaction::Command(command) = interaction {
let _ = &command.defer(&ctx.http()).await.expect("Cannot defer");
let content = Some(match command.data.name.as_str() {
"info" => commands::info::run(&ctx, &command).await,
"play" => commands::play::run(&ctx, &command).await,
"stop" => commands::stop::run(&ctx, &command).await,
_ => respond_with_error(&ctx, &command).await,
});
let content = Some(match command.data.name.as_str() {
"info" => commands::info::run(&ctx, &command).await,
"play" => commands::play::run(&ctx, &command).await,
"stop" => commands::stop::run(&ctx, &command).await,
_ => respond_with_error(&ctx, &command).await,
});
if let Some(embed) = content {
let followup = CreateInteractionResponseFollowup::new().embed(embed);
if let Err(why) = command.create_followup(&ctx.http, followup).await {
println!("Cannot followup to slash command: {why}")
}
if let Some(embed) = content {
let followup = CreateInteractionResponseFollowup::new().embed(embed);
if let Err(why) = command.create_followup(&ctx.http, followup).await {
println!("Cannot followup to slash command: {why}")
}
}
}

View file

@ -224,9 +224,7 @@ pub async fn stop(ctx: &Context, guild_id: &GuildId) -> Result<bool, JoinError>
.expect("Cannot get Songbird")
.clone();
let has_handler = manager.get(*guild_id).is_some();
if has_handler {
if manager.get(*guild_id).is_some() {
manager.remove(*guild_id).await?;
return Ok(true); // Handler removed
}

View file

@ -12,6 +12,7 @@ pub fn request_guild(ctx: &Context, guild_id: &GuildId) -> 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 {
match ctx.http.get_guild(*guild_id).await {
Ok(guild) => guild,
@ -32,16 +33,12 @@ pub async fn get_vc_id(ctx: &Context, guild_id: &GuildId, user_id: &UserId) -> O
/// Check if the bot is connected to a voice channel
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_some()
get_self_vc_id(ctx, guild_id).await.is_some()
}
/// Check if a user is connected to a voice channel
pub async fn is_user_connected_to_vc(ctx: &Context, guild_id: &GuildId, user_id: &UserId) -> bool {
let channel_id = get_vc_id(ctx, guild_id, user_id).await;
channel_id.is_some()
get_vc_id(ctx, guild_id, user_id).await.is_some()
}
/// Get the voice channel id of the bot