Initial code upload

This commit is contained in:
2025-04-20 00:49:17 +08:00
parent fe4f0aec41
commit 44170c8ae7
11 changed files with 827 additions and 0 deletions

49
src/commands/leave.rs Normal file
View File

@@ -0,0 +1,49 @@
// src/commands/leave.rs
use super::{CommandHandler, SlashCommand};
use anyhow::{Context as _, Result};
use lavalink_rs::LavalinkClient;
use serenity::{
builder::{CreateApplicationCommandOption, EditInteractionResponse},
client::Context,
model::prelude::interaction::application_command::ApplicationCommandInteraction,
};
use tracing::instrument;
use futures::future::BoxFuture;
inventory::submit! {
SlashCommand {
name: "leave",
description: "Makes the bot leave the current voice channel.",
options: || Vec::new(), // No options
handler: handle_leave,
}
}
#[instrument(skip(ctx, interaction, lavalink))]
fn handle_leave<'a>(
ctx: &'a Context,
interaction: &'a ApplicationCommandInteraction,
lavalink: &'a LavalinkClient,
) -> BoxFuture<'a, Result<()>> {
Box::pin(async move {
let guild_id = interaction.guild_id.context("Command must be used in a guild")?;
// Check if connected before trying to leave
if lavalink.get_player(guild_id).is_none() {
interaction.edit_original_response(&ctx.http,
EditInteractionResponse::new().content("Bot is not in a voice channel.")
).await?;
return Ok(()); // Not an error, just inform user
}
// Destroy the Lavalink session for this guild
lavalink.destroy_session(guild_id).await?;
interaction.edit_original_response(&ctx.http,
EditInteractionResponse::new().content("Left the voice channel.")
).await?;
Ok(())
})
}