playing works
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
mod workers;
|
||||
|
||||
use std::{env, num::NonZeroU64, path::PathBuf, str::FromStr};
|
||||
use std::env;
|
||||
|
||||
use futures::StreamExt;
|
||||
use postcard::{from_bytes, to_stdvec};
|
||||
@@ -10,7 +10,7 @@ use serenity::{
|
||||
async_trait,
|
||||
};
|
||||
use songbird::SerenityInit;
|
||||
use types::{jobs::{JobResponse, Jobs, PlayJob}, misc::new_uuid_v4};
|
||||
use types::jobs::{JobResponse, Jobs};
|
||||
use which::which;
|
||||
use yt_dlp::{Downloader, client::Libraries};
|
||||
|
||||
@@ -49,12 +49,7 @@ impl EventHandler for Handler {
|
||||
error: res.error,
|
||||
}),
|
||||
"play" => {
|
||||
workers::play::play(&voice_manager, PlayJob {
|
||||
uuid: new_uuid_v4(),
|
||||
path: PathBuf::new(),
|
||||
guild_id: NonZeroU64::from_str("302837320250294283").unwrap(),
|
||||
channel_id: NonZeroU64::from_str("863014198703423499").unwrap()
|
||||
})
|
||||
workers::play::play(&voice_manager, from_bytes(&message.payload).unwrap())
|
||||
.await
|
||||
.map(|res| JobResponse {
|
||||
content: res.content.map(Jobs::Play),
|
||||
@@ -86,6 +81,10 @@ impl EventHandler for Handler {
|
||||
|
||||
#[tokio::main]
|
||||
async fn main() {
|
||||
rustls::crypto::ring::default_provider()
|
||||
.install_default()
|
||||
.expect("Failed to install rustls crypto provider");
|
||||
|
||||
let discord_token = env::var("DISCORD_TOKEN").expect("Expected a token in the environment");
|
||||
|
||||
let nats_client = async_nats::connect("nats://localhost:4222")
|
||||
@@ -105,7 +104,7 @@ async fn main() {
|
||||
yt_downloader,
|
||||
};
|
||||
|
||||
let mut discord_client = Client::builder(&discord_token, GatewayIntents::empty())
|
||||
let mut discord_client = Client::builder(&discord_token, GatewayIntents::non_privileged())
|
||||
.event_handler(handler)
|
||||
.register_songbird()
|
||||
.await
|
||||
|
||||
@@ -15,7 +15,7 @@ pub async fn download(
|
||||
let audio_path = match downloader
|
||||
.download_audio_stream_with_quality(
|
||||
&video,
|
||||
format!("{}.opus", video.id),
|
||||
format!("{}.ogg", video.id),
|
||||
yt_dlp::model::AudioQuality::Best,
|
||||
yt_dlp::model::AudioCodecPreference::Opus,
|
||||
)
|
||||
|
||||
@@ -1,9 +1,11 @@
|
||||
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 songbird::{
|
||||
Songbird,
|
||||
events::{Event, EventContext, EventHandler as VoiceEventHandler, TrackEvent},
|
||||
input::File,
|
||||
};
|
||||
use types::jobs::{JobResponse, PlayJob, PlayResponse};
|
||||
|
||||
pub async fn play(
|
||||
@@ -31,18 +33,16 @@ pub async fn play(
|
||||
|
||||
let mut handler = handler_lock.lock().await;
|
||||
|
||||
let src = File::new("output/sQaKWttol58.opus").clone();
|
||||
let src = File::new(job.path).clone();
|
||||
|
||||
let track_handle = handler.play_input(src.into());
|
||||
|
||||
println!("before info");
|
||||
println!("before info {:?}", track_handle);
|
||||
|
||||
println!("{:?}", track_handle.get_info().await);
|
||||
|
||||
println!("after info");
|
||||
|
||||
let _ = track_handle.play();
|
||||
|
||||
Ok(JobResponse {
|
||||
content: Some(PlayResponse {}),
|
||||
error: None,
|
||||
|
||||
Reference in New Issue
Block a user