This commit is contained in:
2026-03-07 00:50:08 +01:00
parent 41c8303aa4
commit b7a13646ee
3 changed files with 57 additions and 156 deletions
+6 -2
View File
@@ -8,8 +8,12 @@ async-nats = { version = "0.46.0" }
futures = { version = "0.3.32" }
futures-executor = { version = "0.3.32" }
postcard = { version = "1.1.3", features = ["use-std"] }
serenity = { version = "0.12.5" }
songbird = { version = "0.5.0", default-features = true }
serenity = { version = "0.12.5", default-features = false, features = [
"client",
"standard_framework",
"voice",
] }
songbird = { version = "0.5.0" }
tokio = { version = "1.49.0", features = ["macros", "rt-multi-thread"] }
types = { path = "../../libs/types" }
which = { version = "8.0.0" }
+50 -3
View File
@@ -1,6 +1,9 @@
use std::sync::Arc;
use serenity::async_trait;
use songbird::Songbird;
use songbird::events::{Event, EventContext, EventHandler as VoiceEventHandler, TrackEvent};
use songbird::input::File;
use types::jobs::{JobResponse, PlayJob, PlayResponse};
pub async fn play(
@@ -10,11 +13,36 @@ pub async fn play(
println!("job: {:?}", job);
if let Some(voice_manager) = voice_manager {
if let Err(why) = voice_manager.join(job.guild_id, job.channel_id).await {
println!("{why}:?");
return Err(format!("{why}"));
if let Ok(handler_lock) = voice_manager.join(job.guild_id, job.channel_id).await {
// Attach an event handler to see notifications of all track errors.
let mut handler = handler_lock.lock().await;
handler.add_global_event(TrackEvent::Error.into(), TrackErrorNotifier);
}
let handler_lock = match voice_manager.get(job.guild_id) {
Some(handler) => handler,
None => {
return Ok(JobResponse {
content: Some(PlayResponse {}),
error: None,
});
}
};
let mut handler = handler_lock.lock().await;
let src = File::new("output/sQaKWttol58.opus").clone();
let track_handle = handler.play_input(src.into());
println!("before info");
println!("{:?}", track_handle.get_info().await);
println!("after info");
let _ = track_handle.play();
Ok(JobResponse {
content: Some(PlayResponse {}),
error: None,
@@ -23,3 +51,22 @@ pub async fn play(
Err("No voice_manager defined".to_string())
}
}
struct TrackErrorNotifier;
#[async_trait]
impl VoiceEventHandler for TrackErrorNotifier {
async fn act(&self, ctx: &EventContext<'_>) -> Option<Event> {
if let EventContext::Track(track_list) = ctx {
for (state, handle) in *track_list {
println!(
"Track {:?} encountered an error: {:?}",
handle.uuid(),
state.playing
);
}
}
None
}
}