Files
siren/src/bot/commands/audio/resume.rs

55 lines
1.4 KiB
Rust

use serenity::{
all::{CommandInteraction, CreateCommand},
prelude::*,
};
use crate::bot::chat::{edit_response, process_message};
use super::get_songbird;
pub async fn run(ctx: &Context, command: &CommandInteraction) {
// Create the initial response
process_message(&ctx, &command, false).await;
// Get the songbird manager
let manager = get_songbird(ctx).await;
// Extract the guild ID
let guild_id = match &command.guild_id {
Some(guild_id) => guild_id,
None => {
edit_response(
&ctx,
&command,
"Unable to find the current server ID".to_string(),
)
.await;
return;
}
};
// Resume the track
if let Some(handler_lock) = manager.get(guild_id.to_owned()) {
let handler = handler_lock.lock().await;
match handler.queue().current() {
Some(track) => match track.play() {
Ok(_) => {
log::debug!("<{guild_id}> Resumed the track");
edit_response(&ctx, &command, "Resuming the track".to_string()).await;
}
Err(err) => {
edit_response(&ctx, &command, format!("Failed to resume: {}", err)).await;
}
},
None => {
edit_response(&ctx, &command, "No track is currently playing".to_string()).await;
return;
}
}
}
}
pub fn register() -> CreateCommand {
CreateCommand::new("resume").description("Resume the current track")
}