wip
This commit is contained in:
@@ -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
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user