diff --git a/Cargo.toml b/Cargo.toml index 62e16c3..d1a2b8c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -12,4 +12,6 @@ tokio = { version = "1.37.0", features = ["full", "rt-multi-thread"] } env_logger = "0.11.3" anyhow = "1.0.82" regex = "1.10.4" -lavalink-rs = "0.11.0" \ No newline at end of file +songbird = "0.4.1" +youtube_dl = "0.10.0" +ffmpeg-the-third = "1.2.2+ffmpeg-6.0" \ No newline at end of file diff --git a/README.md b/README.md index 877e845..32cafbb 100644 --- a/README.md +++ b/README.md @@ -8,6 +8,10 @@ Welcome to the repository for **EvilBunny**, a robust and versatile Discord bot - **Built with Serenity:** EvilBunny is constructed using the widely-used and well-documented Serenity library in Rust, ensuring reliability and user-friendly operation. - **Versioning:** There are two versions of EvilBunny available. The stable version is named "EvilBunny", and the development version is named "Red". This distinction allows users to select the version that best fits their requirements. +## 📦 System Dependencies + +This package depends on `libavutil`. Make sure to install it on your system before building the project. In Fedora, you can install it by installing the `ffmpeg-devel` package from the RPMFusion repository. + ## 🚀 Usage To use EvilBunny, clone this repository and install the necessary Rust packages. Set your bot token in the `.env` file. Start the bot and use the `help` command to view the list of available commands. For detailed information about a specific command, use the `help [command]` command. diff --git a/src/commands/youtube/ytplay.rs b/src/commands/youtube/ytplay.rs index 32a0473..2eea1fd 100644 --- a/src/commands/youtube/ytplay.rs +++ b/src/commands/youtube/ytplay.rs @@ -1,16 +1,28 @@ use crate::Context; +use poise::serenity_prelude::client::Context as SerenityContext; +use poise::serenity_prelude::model::id::GuildId; +use songbird::input::ffmpeg; +use songbird::SerenityInit; +use youtube_dl::YoutubeDl; -/// Description of the new function -/// -/// This command allows you to play a YouTube video in VC. -/// ``` -/// ~ytplay -/// ``` #[poise::command(prefix_command, slash_command)] -pub async fn ytplay(ctx: Context<'_>) -> Result<(), Box> { +pub async fn ytplay( + ctx: Context<'_>, + url: String, +) -> Result<(), Box> { ctx.defer().await?; - // ... + // Fetch audio stream from YouTube video + let video = YoutubeDl::new(&url).run().await?; + let audio = video.get_best_audio().ok_or("No audio found")?; + + // Connect to voice channel and play audio + let manager = songbird::get(&ctx.discord).await.expect("Songbird Voice client placed in at initialisation."); + let handler_lock = manager.get(ctx.guild_id).ok_or("Not in a voice channel")?; + let mut handler = handler_lock.lock().await; + + let source = ffmpeg(audio.url).await?; + handler.play_source(source); Ok(()) } \ No newline at end of file