feat: playing from URL works now
This commit is contained in:
parent
daf21fad90
commit
49f09082e9
10 changed files with 369 additions and 382 deletions
2
.TODO
Normal file
2
.TODO
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
handle disconnect by someone, other than command
|
||||||
|
disconnect after some time when not playing
|
199
Cargo.lock
generated
199
Cargo.lock
generated
|
@ -753,6 +753,12 @@ dependencies = [
|
||||||
"pin-project-lite",
|
"pin-project-lite",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "extended"
|
||||||
|
version = "0.1.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "af9673d8203fcb076b19dfd17e38b3d4ae9f44959416ea532ce72415a6020365"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "fastrand"
|
name = "fastrand"
|
||||||
version = "2.1.0"
|
version = "2.1.0"
|
||||||
|
@ -1268,6 +1274,19 @@ dependencies = [
|
||||||
"tower-service",
|
"tower-service",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "hyper-tls"
|
||||||
|
version = "0.5.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "d6183ddfa99b85da61a140bea0efc93fdf56ceaa041b37d553518030827f9905"
|
||||||
|
dependencies = [
|
||||||
|
"bytes",
|
||||||
|
"hyper 0.14.30",
|
||||||
|
"native-tls",
|
||||||
|
"tokio",
|
||||||
|
"tokio-native-tls",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "hyper-tls"
|
name = "hyper-tls"
|
||||||
version = "0.6.0"
|
version = "0.6.0"
|
||||||
|
@ -1286,9 +1305,9 @@ dependencies = [
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "hyper-util"
|
name = "hyper-util"
|
||||||
version = "0.1.6"
|
version = "0.1.10"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "3ab92f4f49ee4fb4f997c784b7a2e0fa70050211e0b6a287f898c3c9785ca956"
|
checksum = "df2dcfbe0677734ab2f3ffa7fa7bfd4706bfdc1ef393f2ee30184aed67e631b4"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"bytes",
|
"bytes",
|
||||||
"futures-channel",
|
"futures-channel",
|
||||||
|
@ -1299,7 +1318,6 @@ dependencies = [
|
||||||
"pin-project-lite",
|
"pin-project-lite",
|
||||||
"socket2",
|
"socket2",
|
||||||
"tokio",
|
"tokio",
|
||||||
"tower",
|
|
||||||
"tower-service",
|
"tower-service",
|
||||||
"tracing",
|
"tracing",
|
||||||
]
|
]
|
||||||
|
@ -1552,9 +1570,11 @@ dependencies = [
|
||||||
"poise",
|
"poise",
|
||||||
"rand",
|
"rand",
|
||||||
"regex",
|
"regex",
|
||||||
|
"reqwest 0.11.27",
|
||||||
"serenity",
|
"serenity",
|
||||||
"songbird",
|
"songbird",
|
||||||
"sqlx",
|
"sqlx",
|
||||||
|
"symphonia",
|
||||||
"tenorv2",
|
"tenorv2",
|
||||||
"tokio",
|
"tokio",
|
||||||
"tokio-cron-scheduler",
|
"tokio-cron-scheduler",
|
||||||
|
@ -2163,11 +2183,13 @@ dependencies = [
|
||||||
"http-body 0.4.6",
|
"http-body 0.4.6",
|
||||||
"hyper 0.14.30",
|
"hyper 0.14.30",
|
||||||
"hyper-rustls 0.24.2",
|
"hyper-rustls 0.24.2",
|
||||||
|
"hyper-tls 0.5.0",
|
||||||
"ipnet",
|
"ipnet",
|
||||||
"js-sys",
|
"js-sys",
|
||||||
"log",
|
"log",
|
||||||
"mime",
|
"mime",
|
||||||
"mime_guess",
|
"mime_guess",
|
||||||
|
"native-tls",
|
||||||
"once_cell",
|
"once_cell",
|
||||||
"percent-encoding",
|
"percent-encoding",
|
||||||
"pin-project-lite",
|
"pin-project-lite",
|
||||||
|
@ -2179,6 +2201,7 @@ dependencies = [
|
||||||
"sync_wrapper 0.1.2",
|
"sync_wrapper 0.1.2",
|
||||||
"system-configuration 0.5.1",
|
"system-configuration 0.5.1",
|
||||||
"tokio",
|
"tokio",
|
||||||
|
"tokio-native-tls",
|
||||||
"tokio-rustls 0.24.1",
|
"tokio-rustls 0.24.1",
|
||||||
"tokio-util",
|
"tokio-util",
|
||||||
"tower-service",
|
"tower-service",
|
||||||
|
@ -2193,9 +2216,9 @@ dependencies = [
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "reqwest"
|
name = "reqwest"
|
||||||
version = "0.12.8"
|
version = "0.12.12"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "f713147fbe92361e52392c73b8c9e48c04c6625bce969ef54dc901e58e042a7b"
|
checksum = "43e734407157c3c2034e0258f5e4473ddb361b1e85f95a66690d67264d7cd1da"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"base64 0.22.1",
|
"base64 0.22.1",
|
||||||
"bytes",
|
"bytes",
|
||||||
|
@ -2208,7 +2231,7 @@ dependencies = [
|
||||||
"http-body-util",
|
"http-body-util",
|
||||||
"hyper 1.4.1",
|
"hyper 1.4.1",
|
||||||
"hyper-rustls 0.27.2",
|
"hyper-rustls 0.27.2",
|
||||||
"hyper-tls",
|
"hyper-tls 0.6.0",
|
||||||
"hyper-util",
|
"hyper-util",
|
||||||
"ipnet",
|
"ipnet",
|
||||||
"js-sys",
|
"js-sys",
|
||||||
|
@ -2226,6 +2249,7 @@ dependencies = [
|
||||||
"system-configuration 0.6.1",
|
"system-configuration 0.6.1",
|
||||||
"tokio",
|
"tokio",
|
||||||
"tokio-native-tls",
|
"tokio-native-tls",
|
||||||
|
"tower",
|
||||||
"tower-service",
|
"tower-service",
|
||||||
"url",
|
"url",
|
||||||
"wasm-bindgen",
|
"wasm-bindgen",
|
||||||
|
@ -3189,8 +3213,95 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "815c942ae7ee74737bb00f965fa5b5a2ac2ce7b6c01c0cc169bbeaf7abd5f5a9"
|
checksum = "815c942ae7ee74737bb00f965fa5b5a2ac2ce7b6c01c0cc169bbeaf7abd5f5a9"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"lazy_static",
|
"lazy_static",
|
||||||
|
"symphonia-bundle-flac",
|
||||||
|
"symphonia-bundle-mp3",
|
||||||
|
"symphonia-codec-aac",
|
||||||
|
"symphonia-codec-adpcm",
|
||||||
|
"symphonia-codec-alac",
|
||||||
|
"symphonia-codec-pcm",
|
||||||
|
"symphonia-codec-vorbis",
|
||||||
|
"symphonia-core",
|
||||||
|
"symphonia-format-isomp4",
|
||||||
|
"symphonia-format-mkv",
|
||||||
|
"symphonia-format-ogg",
|
||||||
|
"symphonia-format-riff",
|
||||||
|
"symphonia-metadata",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "symphonia-bundle-flac"
|
||||||
|
version = "0.5.4"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "72e34f34298a7308d4397a6c7fbf5b84c5d491231ce3dd379707ba673ab3bd97"
|
||||||
|
dependencies = [
|
||||||
|
"log",
|
||||||
"symphonia-core",
|
"symphonia-core",
|
||||||
"symphonia-metadata",
|
"symphonia-metadata",
|
||||||
|
"symphonia-utils-xiph",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "symphonia-bundle-mp3"
|
||||||
|
version = "0.5.4"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "c01c2aae70f0f1fb096b6f0ff112a930b1fb3626178fba3ae68b09dce71706d4"
|
||||||
|
dependencies = [
|
||||||
|
"lazy_static",
|
||||||
|
"log",
|
||||||
|
"symphonia-core",
|
||||||
|
"symphonia-metadata",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "symphonia-codec-aac"
|
||||||
|
version = "0.5.4"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "cdbf25b545ad0d3ee3e891ea643ad115aff4ca92f6aec472086b957a58522f70"
|
||||||
|
dependencies = [
|
||||||
|
"lazy_static",
|
||||||
|
"log",
|
||||||
|
"symphonia-core",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "symphonia-codec-adpcm"
|
||||||
|
version = "0.5.4"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "c94e1feac3327cd616e973d5be69ad36b3945f16b06f19c6773fc3ac0b426a0f"
|
||||||
|
dependencies = [
|
||||||
|
"log",
|
||||||
|
"symphonia-core",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "symphonia-codec-alac"
|
||||||
|
version = "0.5.4"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "2d8a6666649a08412906476a8b0efd9b9733e241180189e9f92b09c08d0e38f3"
|
||||||
|
dependencies = [
|
||||||
|
"log",
|
||||||
|
"symphonia-core",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "symphonia-codec-pcm"
|
||||||
|
version = "0.5.4"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "f395a67057c2ebc5e84d7bb1be71cce1a7ba99f64e0f0f0e303a03f79116f89b"
|
||||||
|
dependencies = [
|
||||||
|
"log",
|
||||||
|
"symphonia-core",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "symphonia-codec-vorbis"
|
||||||
|
version = "0.5.4"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "5a98765fb46a0a6732b007f7e2870c2129b6f78d87db7987e6533c8f164a9f30"
|
||||||
|
dependencies = [
|
||||||
|
"log",
|
||||||
|
"symphonia-core",
|
||||||
|
"symphonia-utils-xiph",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
|
@ -3206,6 +3317,56 @@ dependencies = [
|
||||||
"log",
|
"log",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "symphonia-format-isomp4"
|
||||||
|
version = "0.5.4"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "abfdf178d697e50ce1e5d9b982ba1b94c47218e03ec35022d9f0e071a16dc844"
|
||||||
|
dependencies = [
|
||||||
|
"encoding_rs",
|
||||||
|
"log",
|
||||||
|
"symphonia-core",
|
||||||
|
"symphonia-metadata",
|
||||||
|
"symphonia-utils-xiph",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "symphonia-format-mkv"
|
||||||
|
version = "0.5.4"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "1bb43471a100f7882dc9937395bd5ebee8329298e766250b15b3875652fe3d6f"
|
||||||
|
dependencies = [
|
||||||
|
"lazy_static",
|
||||||
|
"log",
|
||||||
|
"symphonia-core",
|
||||||
|
"symphonia-metadata",
|
||||||
|
"symphonia-utils-xiph",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "symphonia-format-ogg"
|
||||||
|
version = "0.5.4"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "ada3505789516bcf00fc1157c67729eded428b455c27ca370e41f4d785bfa931"
|
||||||
|
dependencies = [
|
||||||
|
"log",
|
||||||
|
"symphonia-core",
|
||||||
|
"symphonia-metadata",
|
||||||
|
"symphonia-utils-xiph",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "symphonia-format-riff"
|
||||||
|
version = "0.5.4"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "05f7be232f962f937f4b7115cbe62c330929345434c834359425e043bfd15f50"
|
||||||
|
dependencies = [
|
||||||
|
"extended",
|
||||||
|
"log",
|
||||||
|
"symphonia-core",
|
||||||
|
"symphonia-metadata",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "symphonia-metadata"
|
name = "symphonia-metadata"
|
||||||
version = "0.5.4"
|
version = "0.5.4"
|
||||||
|
@ -3218,6 +3379,16 @@ dependencies = [
|
||||||
"symphonia-core",
|
"symphonia-core",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "symphonia-utils-xiph"
|
||||||
|
version = "0.5.4"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "484472580fa49991afda5f6550ece662237b00c6f562c7d9638d1b086ed010fe"
|
||||||
|
dependencies = [
|
||||||
|
"symphonia-core",
|
||||||
|
"symphonia-metadata",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "syn"
|
name = "syn"
|
||||||
version = "1.0.109"
|
version = "1.0.109"
|
||||||
|
@ -3323,7 +3494,7 @@ dependencies = [
|
||||||
"form_urlencoded",
|
"form_urlencoded",
|
||||||
"json",
|
"json",
|
||||||
"regex",
|
"regex",
|
||||||
"reqwest 0.12.8",
|
"reqwest 0.12.12",
|
||||||
"thiserror",
|
"thiserror",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
@ -3557,14 +3728,14 @@ dependencies = [
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "tower"
|
name = "tower"
|
||||||
version = "0.4.13"
|
version = "0.5.2"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "b8fa9be0de6cf49e536ce1851f987bd21a43b771b09473c3549a6c853db37c1c"
|
checksum = "d039ad9159c98b70ecfd540b2573b97f7f52c3e8d9f8ad57a24b916a536975f9"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"futures-core",
|
"futures-core",
|
||||||
"futures-util",
|
"futures-util",
|
||||||
"pin-project",
|
|
||||||
"pin-project-lite",
|
"pin-project-lite",
|
||||||
|
"sync_wrapper 1.0.1",
|
||||||
"tokio",
|
"tokio",
|
||||||
"tower-layer",
|
"tower-layer",
|
||||||
"tower-service",
|
"tower-service",
|
||||||
|
@ -3572,15 +3743,15 @@ dependencies = [
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "tower-layer"
|
name = "tower-layer"
|
||||||
version = "0.3.2"
|
version = "0.3.3"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "c20c8dbed6283a09604c3e69b4b7eeb54e298b8a600d4d5ecb5ad39de609f1d0"
|
checksum = "121c2a6cda46980bb0fcd1647ffaf6cd3fc79a013de288782836f6df9c48780e"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "tower-service"
|
name = "tower-service"
|
||||||
version = "0.3.2"
|
version = "0.3.3"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "b6bc1c9ce2b5135ac7f93c72918fc37feb872bdc6a5533a8b85eb4b86bfdae52"
|
checksum = "8df9b6e13f2d32c91b9bd719c00d1958837bc7dec474d94952798cc8e69eeec3"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "tracing"
|
name = "tracing"
|
||||||
|
|
|
@ -20,7 +20,12 @@ sqlx = {version="0.8.2", features=["runtime-tokio", "sqlite"]}
|
||||||
form_urlencoded = "1.2.1"
|
form_urlencoded = "1.2.1"
|
||||||
tenorv2 = { path = "./tenor-v2/tenorv2" }
|
tenorv2 = { path = "./tenor-v2/tenorv2" }
|
||||||
# librespot = { version = "0.6.0", default-features = false, features = ["rodio-backend"] }
|
# librespot = { version = "0.6.0", default-features = false, features = ["rodio-backend"] }
|
||||||
songbird = { version = "0.4.6", features = ["driver"] }
|
songbird = { version = "0.4.6", features = ["driver", "builtin-queue"] }
|
||||||
|
reqwest = "0.11.27" # songbird depends on ^0.11
|
||||||
|
|
||||||
|
[dependencies.symphonia]
|
||||||
|
version = "0.5.2"
|
||||||
|
features = ["aac", "mp3", "isomp4", "alac"]
|
||||||
|
|
||||||
[features]
|
[features]
|
||||||
DEBUG = []
|
DEBUG = []
|
||||||
|
|
|
@ -1 +1,5 @@
|
||||||
|
pub mod util;
|
||||||
pub mod player;
|
pub mod player;
|
||||||
|
pub mod radio;
|
||||||
|
// pub mod spotify;
|
||||||
|
// pub mod yt;
|
|
@ -1,122 +1,26 @@
|
||||||
use std::vec;
|
use std::vec;
|
||||||
|
|
||||||
use serenity::{all::ChannelId, async_trait};
|
|
||||||
use songbird::events::{Event, EventContext, EventHandler as VoiceEventHandler};
|
|
||||||
use songbird::input::{File, Input};
|
use songbird::input::{File, Input};
|
||||||
use songbird::TrackEvent;
|
|
||||||
|
|
||||||
use crate::util::debug::send_error;
|
use crate::util::debug::send_error;
|
||||||
use crate::util::poise_context_extension::ContextExt;
|
use crate::util::poise_context_extension::ContextExt;
|
||||||
use crate::util::utilities::get_local_songs;
|
use crate::util::utilities::get_local_songs;
|
||||||
use crate::{types::{Context, Error}, util::utilities::get_channel_by_name};
|
use crate::types::{Context, Error};
|
||||||
|
|
||||||
#[poise::command(
|
use super::util::{connect, autocomplete_channel};
|
||||||
slash_command,
|
|
||||||
description_localized("en-US", "Play song")
|
|
||||||
)]
|
|
||||||
pub async fn play(ctx: Context<'_>,
|
|
||||||
#[description = "Song: "]
|
|
||||||
_url: String
|
|
||||||
) -> Result<(), Error> {
|
|
||||||
|
|
||||||
ctx.reply("Done!").await?;
|
// #[poise::command(
|
||||||
Ok(())
|
// slash_command,
|
||||||
}
|
// description_localized("en-US", "Play song")
|
||||||
|
// )]
|
||||||
|
// pub async fn play(ctx: Context<'_>,
|
||||||
|
// #[description = "Song: "]
|
||||||
|
// _url: String
|
||||||
|
// ) -> Result<(), Error> {
|
||||||
|
|
||||||
/// Returns either voice channel to which the user is currently connected to or the one passed via name
|
// ctx.reply("Done!").await?;
|
||||||
async fn get_voice_channel(ctx: &Context<'_>, name: Option<String>) -> Result<ChannelId, String> {
|
// Ok(())
|
||||||
if name.is_none() || name.as_ref().is_some_and(|n| n.is_empty()) {
|
// }
|
||||||
match ctx.guild().and_then(|guild|
|
|
||||||
guild.voice_states.get(&ctx.author().id).and_then(|voice_state|
|
|
||||||
voice_state.channel_id
|
|
||||||
)
|
|
||||||
) {
|
|
||||||
Some(c) => Ok(c),
|
|
||||||
None => Err("You must be in a voice channel or specify explicit voice channel by name".to_string())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
match ctx.guild().and_then(|guild|
|
|
||||||
get_channel_by_name(guild, name.unwrap())
|
|
||||||
) {
|
|
||||||
Some(c) => Ok(c),
|
|
||||||
None => Err("Channel with this name does not exist".to_string())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[poise::command(
|
|
||||||
slash_command,
|
|
||||||
description_localized("en-US", "Connect to channel")
|
|
||||||
)]
|
|
||||||
pub async fn connect(ctx: Context<'_>,
|
|
||||||
#[autocomplete = "autocomplete_channel"]
|
|
||||||
#[description = "Voice channel name: "]
|
|
||||||
name: Option<String>
|
|
||||||
) -> Result<(), Error> {
|
|
||||||
|
|
||||||
if ctx.guild().is_none() {
|
|
||||||
ctx.reply_ephemeral("Can't use this outside of guild").await?;
|
|
||||||
return Ok(());
|
|
||||||
}
|
|
||||||
|
|
||||||
let voice_channel = match get_voice_channel(&ctx, name).await {
|
|
||||||
Ok(c) => c,
|
|
||||||
Err(e) => {
|
|
||||||
ctx.reply_ephemeral(e.as_str()).await?;
|
|
||||||
return Ok(())
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
let manager = songbird::get(ctx.serenity_context())
|
|
||||||
.await
|
|
||||||
.expect("Songbird Voice client placed in at initialisation.")
|
|
||||||
.clone();
|
|
||||||
|
|
||||||
let Some(guild_id) = ctx.guild_id() else {
|
|
||||||
ctx.reply_ephemeral("Guild id not found").await?;
|
|
||||||
return Ok(())
|
|
||||||
};
|
|
||||||
|
|
||||||
if let Ok(handler_lock) = manager.join(guild_id, voice_channel).await {
|
|
||||||
let mut handler = handler_lock.lock().await;
|
|
||||||
handler.add_global_event(TrackEvent::Error.into(), TrackErrorNotifier);
|
|
||||||
}
|
|
||||||
|
|
||||||
ctx.reply_ephemeral("Done!").await?;
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
|
|
||||||
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
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
async fn autocomplete_channel(
|
|
||||||
ctx: Context<'_>,
|
|
||||||
_partial: &str,
|
|
||||||
) -> Vec<String> {
|
|
||||||
|
|
||||||
use crate::util::utilities::get_vc_names;
|
|
||||||
match ctx.guild() {
|
|
||||||
Some(guild) => get_vc_names(guild),
|
|
||||||
None => [].to_vec()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[poise::command(
|
#[poise::command(
|
||||||
slash_command,
|
slash_command,
|
||||||
|
@ -168,12 +72,12 @@ async fn autocomplete_song(
|
||||||
|
|
||||||
#[poise::command(
|
#[poise::command(
|
||||||
slash_command,
|
slash_command,
|
||||||
description_localized("en-US", "Connect to channel")
|
description_localized("en-US", "Play song from server storage")
|
||||||
)]
|
)]
|
||||||
pub async fn play_local(ctx: Context<'_>,
|
pub async fn play_local(ctx: Context<'_>,
|
||||||
#[autocomplete = "autocomplete_channel"]
|
#[autocomplete = "autocomplete_channel"]
|
||||||
#[description = "Voice channel name: "]
|
#[description = "Voice channel name: "]
|
||||||
_channel: Option<String>,
|
channel: Option<String>,
|
||||||
#[autocomplete = "autocomplete_song"]
|
#[autocomplete = "autocomplete_song"]
|
||||||
#[description = "Filename of local song: "]
|
#[description = "Filename of local song: "]
|
||||||
file_name: String
|
file_name: String
|
||||||
|
@ -194,17 +98,24 @@ pub async fn play_local(ctx: Context<'_>,
|
||||||
return Ok(())
|
return Ok(())
|
||||||
};
|
};
|
||||||
|
|
||||||
|
if manager.get(guild_id).is_none() {
|
||||||
|
match connect(&ctx, guild_id, channel).await {
|
||||||
|
Ok(_) => (),
|
||||||
|
Err(e) => {
|
||||||
|
ctx.reply_ephemeral(&e.to_string()).await?;
|
||||||
|
return Ok(())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if let Some(handler_lock) = manager.get(guild_id) {
|
if let Some(handler_lock) = manager.get(guild_id) {
|
||||||
let mut handler = handler_lock.lock().await;
|
let mut handler = handler_lock.lock().await;
|
||||||
|
|
||||||
let input_file = File::new(format!("/home/emil/Music/{file_name}"));
|
let input_file = File::new(format!("/home/emil/Music/{file_name}"));
|
||||||
let input = Input::Lazy(Box::new(input_file));
|
let input = Input::Lazy(Box::new(input_file));
|
||||||
let _ = handler.play_input(input);
|
let _ = handler.play_only_input(input);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
|
||||||
ctx.reply_ephemeral("Not in a voice channel").await?;
|
ctx.reply_ephemeral("Not in a voice channel").await?;
|
||||||
return Ok(())
|
return Ok(())
|
||||||
}
|
}
|
||||||
|
@ -212,44 +123,3 @@ pub async fn play_local(ctx: Context<'_>,
|
||||||
ctx.reply_ephemeral("Done!").await?;
|
ctx.reply_ephemeral("Done!").await?;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
// #[poise::command(
|
|
||||||
// slash_command,
|
|
||||||
// description_localized("en-US", "Connect to channel")
|
|
||||||
// )]
|
|
||||||
// pub async fn play_local(ctx: Context<'_>,
|
|
||||||
// #[autocomplete = "autocomplete_song"]
|
|
||||||
// #[description = "Voice channel name: "]
|
|
||||||
// file_name: String
|
|
||||||
// ) -> Result<(), Error> {
|
|
||||||
|
|
||||||
// if ctx.guild().is_none() {
|
|
||||||
// ctx.reply_ephemeral("Can't use this outside of guild").await?;
|
|
||||||
// return Ok(());
|
|
||||||
// }
|
|
||||||
|
|
||||||
// let manager = songbird::get(ctx.serenity_context())
|
|
||||||
// .await
|
|
||||||
// .expect("Songbird Voice client placed in at initialisation.")
|
|
||||||
// .clone();
|
|
||||||
|
|
||||||
// let Some(guild_id) = ctx.guild_id() else {
|
|
||||||
// ctx.reply_ephemeral("Guild id not found").await?;
|
|
||||||
// return Ok(())
|
|
||||||
// };
|
|
||||||
|
|
||||||
// if let Some(handler_lock) = manager.get(guild_id) {
|
|
||||||
// let mut handler = handler_lock.lock().await;
|
|
||||||
|
|
||||||
// let input_file = File::new(format!("/home/emil/Music/{file_name}"));
|
|
||||||
// let input = Input::Lazy(Box::new(input_file));
|
|
||||||
// let _ = handler.play_input(input);
|
|
||||||
// }
|
|
||||||
// else {
|
|
||||||
// ctx.reply_ephemeral("Not in a voice channel").await?;
|
|
||||||
// return Ok(())
|
|
||||||
// }
|
|
||||||
|
|
||||||
// ctx.reply_ephemeral("Done!").await?;
|
|
||||||
// Ok(())
|
|
||||||
// }
|
|
||||||
|
|
3
src/commands/voice/radio/mod.rs
Normal file
3
src/commands/voice/radio/mod.rs
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
pub use radio_player::*;
|
||||||
|
|
||||||
|
pub mod radio_player;
|
66
src/commands/voice/radio/radio_player.rs
Normal file
66
src/commands/voice/radio/radio_player.rs
Normal file
|
@ -0,0 +1,66 @@
|
||||||
|
use std::vec;
|
||||||
|
|
||||||
|
use reqwest::Client;
|
||||||
|
|
||||||
|
use songbird::input::Input;
|
||||||
|
use songbird::input::HttpRequest;
|
||||||
|
|
||||||
|
use crate::commands::util::connect;
|
||||||
|
use crate::util::poise_context_extension::ContextExt;
|
||||||
|
use crate::types::{Context, Error};
|
||||||
|
use crate::commands::voice::util::autocomplete_channel;
|
||||||
|
|
||||||
|
// TODO: autocomplete radio stream URLs
|
||||||
|
#[poise::command(
|
||||||
|
slash_command,
|
||||||
|
description_localized("en-US", "Plays music from URL source")
|
||||||
|
)]
|
||||||
|
pub async fn radio(ctx: Context<'_>,
|
||||||
|
#[autocomplete = "autocomplete_channel"]
|
||||||
|
#[description = "Voice channel name: "]
|
||||||
|
channel: Option<String>,
|
||||||
|
#[description = "Source URL: "]
|
||||||
|
url: String,
|
||||||
|
) -> Result<(), Error> {
|
||||||
|
|
||||||
|
if ctx.guild().is_none() {
|
||||||
|
ctx.reply_ephemeral("Can't use this outside of guild").await?;
|
||||||
|
return Ok(());
|
||||||
|
}
|
||||||
|
|
||||||
|
let manager = songbird::get(ctx.serenity_context())
|
||||||
|
.await
|
||||||
|
.expect("Songbird Voice client placed in at initialisation.")
|
||||||
|
.clone();
|
||||||
|
|
||||||
|
let Some(guild_id) = ctx.guild_id() else {
|
||||||
|
ctx.reply_ephemeral("Guild id not found").await?;
|
||||||
|
return Ok(())
|
||||||
|
};
|
||||||
|
|
||||||
|
if manager.get(guild_id).is_none() {
|
||||||
|
match connect(&ctx, guild_id, channel).await {
|
||||||
|
Ok(_) => (),
|
||||||
|
Err(e) => {
|
||||||
|
ctx.reply_ephemeral(&e.to_string()).await?;
|
||||||
|
return Ok(())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if let Some(handler_lock) = manager.get(guild_id) {
|
||||||
|
let mut handler = handler_lock.lock().await;
|
||||||
|
|
||||||
|
let client = Client::new();
|
||||||
|
let request = HttpRequest::new(client, url);
|
||||||
|
let input = Input::from(request);
|
||||||
|
handler.play_only_input(input);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
ctx.reply_ephemeral("Not in a voice channel").await?;
|
||||||
|
return Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
ctx.reply_ephemeral("Done!").await?;
|
||||||
|
Ok(())
|
||||||
|
}
|
|
@ -1,211 +0,0 @@
|
||||||
use std::vec;
|
|
||||||
|
|
||||||
use poise::{self, CreateReply};
|
|
||||||
use serenity::all::{CacheHttp, Guild, PartialGuild, UserId};
|
|
||||||
use serenity::{all::ChannelId, async_trait};
|
|
||||||
use songbird::events::{Event, EventContext, EventHandler as VoiceEventHandler};
|
|
||||||
use songbird::input::{File, Input};
|
|
||||||
use songbird::tracks::Track;
|
|
||||||
use songbird::TrackEvent;
|
|
||||||
|
|
||||||
use crate::util::debug::send_error;
|
|
||||||
use crate::util::poise_context_extension::ContextExt;
|
|
||||||
use crate::util::utilities::get_local_songs;
|
|
||||||
use crate::{types::{Context, Error}, util::utilities::get_channel_by_name};
|
|
||||||
|
|
||||||
#[poise::command(
|
|
||||||
slash_command,
|
|
||||||
description_localized("en-US", "Play song")
|
|
||||||
)]
|
|
||||||
pub async fn play(ctx: Context<'_>,
|
|
||||||
#[description = "Song: "]
|
|
||||||
_url: String
|
|
||||||
) -> Result<(), Error> {
|
|
||||||
|
|
||||||
ctx.reply("Done!").await?;
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Returns either voice channel to which the user is currently connected to or the one passed via name
|
|
||||||
async fn get_voice_channel(ctx: &Context<'_>, name: Option<String>) -> Result<ChannelId, String> {
|
|
||||||
if name.is_none() || name.as_ref().is_some_and(|n| n.is_empty()) {
|
|
||||||
match ctx.guild().and_then(|guild|
|
|
||||||
guild.voice_states.get(&ctx.author().id).and_then(|voice_state|
|
|
||||||
voice_state.channel_id
|
|
||||||
)
|
|
||||||
) {
|
|
||||||
Some(c) => Ok(c),
|
|
||||||
None => Err("You must be in a voice channel or specify explicit voice channel by name".to_string())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
match ctx.guild().and_then(|guild|
|
|
||||||
get_channel_by_name(guild, name.unwrap())
|
|
||||||
) {
|
|
||||||
Some(c) => Ok(c),
|
|
||||||
None => Err("Channel with this name does not exist".to_string())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[poise::command(
|
|
||||||
slash_command,
|
|
||||||
description_localized("en-US", "Connect to channel")
|
|
||||||
)]
|
|
||||||
pub async fn connect(ctx: Context<'_>,
|
|
||||||
#[autocomplete = "autocomplete_channel"]
|
|
||||||
#[description = "Voice channel name: "]
|
|
||||||
name: Option<String>
|
|
||||||
) -> Result<(), Error> {
|
|
||||||
|
|
||||||
if ctx.guild().is_none() {
|
|
||||||
ctx.reply_ephemeral("Can't use this outside of guild").await?;
|
|
||||||
return Ok(());
|
|
||||||
}
|
|
||||||
|
|
||||||
let voice_channel = match get_voice_channel(&ctx, name).await {
|
|
||||||
Ok(c) => c,
|
|
||||||
Err(e) => {
|
|
||||||
ctx.reply_ephemeral(e.as_str()).await?;
|
|
||||||
return Ok(())
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
let manager = songbird::get(ctx.serenity_context())
|
|
||||||
.await
|
|
||||||
.expect("Songbird Voice client placed in at initialisation.")
|
|
||||||
.clone();
|
|
||||||
|
|
||||||
let Some(guild_id) = ctx.guild_id() else {
|
|
||||||
ctx.reply_ephemeral("Guild id not found").await?;
|
|
||||||
return Ok(())
|
|
||||||
};
|
|
||||||
|
|
||||||
if let Ok(handler_lock) = manager.join(guild_id, voice_channel).await {
|
|
||||||
let mut handler = handler_lock.lock().await;
|
|
||||||
handler.add_global_event(TrackEvent::Error.into(), TrackErrorNotifier);
|
|
||||||
}
|
|
||||||
|
|
||||||
ctx.reply_ephemeral("Done!").await?;
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
|
|
||||||
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
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
async fn autocomplete_channel(
|
|
||||||
ctx: Context<'_>,
|
|
||||||
_partial: &str,
|
|
||||||
) -> Vec<String> {
|
|
||||||
|
|
||||||
use crate::util::utilities::get_vc_names;
|
|
||||||
match ctx.guild() {
|
|
||||||
Some(guild) => get_vc_names(guild),
|
|
||||||
None => [].to_vec()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[poise::command(
|
|
||||||
slash_command,
|
|
||||||
description_localized("en-US", "Disconnect from voice channel")
|
|
||||||
)]
|
|
||||||
pub async fn disconnect(
|
|
||||||
ctx: Context<'_>
|
|
||||||
) -> Result<(), Error> {
|
|
||||||
|
|
||||||
let Some(guild_id) = ctx.guild_id() else {
|
|
||||||
ctx.reply("Can't use this outside of guild").await?;
|
|
||||||
return Ok(());
|
|
||||||
};
|
|
||||||
|
|
||||||
let manager = songbird::get(ctx.serenity_context())
|
|
||||||
.await
|
|
||||||
.expect("Songbird Voice client placed in at initialisation.")
|
|
||||||
.clone();
|
|
||||||
|
|
||||||
let has_handler = manager.get(guild_id).is_some();
|
|
||||||
|
|
||||||
if ! has_handler {
|
|
||||||
ctx.reply("I am not connected to a channel!").await?;
|
|
||||||
return Ok(())
|
|
||||||
}
|
|
||||||
|
|
||||||
match manager.remove(guild_id).await {
|
|
||||||
Ok(()) => {
|
|
||||||
ctx.reply("Disconnected").await?;
|
|
||||||
return Ok(())
|
|
||||||
}
|
|
||||||
Err(e) => {
|
|
||||||
let _ = send_error(ctx.serenity_context().http.clone(), e.to_string()).await;
|
|
||||||
return Ok(())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
async fn autocomplete_song(
|
|
||||||
_ctx: Context<'_>,
|
|
||||||
partial: &str,
|
|
||||||
) -> Vec<String> {
|
|
||||||
|
|
||||||
match get_local_songs(partial) {
|
|
||||||
Ok(names) => names,
|
|
||||||
Err(_) => vec![]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[poise::command(
|
|
||||||
slash_command,
|
|
||||||
description_localized("en-US", "Connect to channel")
|
|
||||||
)]
|
|
||||||
pub async fn play_local(ctx: Context<'_>,
|
|
||||||
#[autocomplete = "autocomplete_song"]
|
|
||||||
#[description = "Voice channel name: "]
|
|
||||||
file_name: String
|
|
||||||
) -> Result<(), Error> {
|
|
||||||
|
|
||||||
if ctx.guild().is_none() {
|
|
||||||
ctx.reply_ephemeral("Can't use this outside of guild").await?;
|
|
||||||
return Ok(());
|
|
||||||
}
|
|
||||||
|
|
||||||
let manager = songbird::get(ctx.serenity_context())
|
|
||||||
.await
|
|
||||||
.expect("Songbird Voice client placed in at initialisation.")
|
|
||||||
.clone();
|
|
||||||
|
|
||||||
let Some(guild_id) = ctx.guild_id() else {
|
|
||||||
ctx.reply_ephemeral("Guild id not found").await?;
|
|
||||||
return Ok(())
|
|
||||||
};
|
|
||||||
|
|
||||||
if let Some(handler_lock) = manager.get(guild_id) {
|
|
||||||
let mut handler = handler_lock.lock().await;
|
|
||||||
|
|
||||||
let input_file = File::new(format!("/home/emil/Music/{file_name}"));
|
|
||||||
let input = Input::Lazy(Box::new(input_file));
|
|
||||||
let _ = handler.play_input(input);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
ctx.reply_ephemeral("Not in a voice channel").await?;
|
|
||||||
return Ok(())
|
|
||||||
}
|
|
||||||
|
|
||||||
ctx.reply_ephemeral("Done!").await?;
|
|
||||||
Ok(())
|
|
||||||
}
|
|
76
src/commands/voice/util.rs
Normal file
76
src/commands/voice/util.rs
Normal file
|
@ -0,0 +1,76 @@
|
||||||
|
use serenity::all::{ChannelId, GuildId};
|
||||||
|
use serenity::async_trait;
|
||||||
|
|
||||||
|
use songbird::events::{Event, EventContext, EventHandler as VoiceEventHandler};
|
||||||
|
use songbird::TrackEvent;
|
||||||
|
|
||||||
|
use crate::{types::{Context, Error}, util::utilities::get_channel_by_name};
|
||||||
|
|
||||||
|
/// Returns either voice channel to which the user is currently connected to or the one passed via name
|
||||||
|
async fn get_voice_channel(ctx: &Context<'_>, name: Option<String>) -> Result<ChannelId, String> {
|
||||||
|
if name.is_none() || name.as_ref().is_some_and(|n| n.is_empty()) {
|
||||||
|
match ctx.guild().and_then(|guild|
|
||||||
|
guild.voice_states.get(&ctx.author().id).and_then(|voice_state|
|
||||||
|
voice_state.channel_id
|
||||||
|
)
|
||||||
|
) {
|
||||||
|
Some(c) => Ok(c),
|
||||||
|
None => Err("You must be in a voice channel or specify explicit voice channel by name".to_string())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
match ctx.guild().and_then(|guild|
|
||||||
|
get_channel_by_name(guild, name.unwrap())
|
||||||
|
) {
|
||||||
|
Some(c) => Ok(c),
|
||||||
|
None => Err("Channel with this name does not exist".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
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub async fn connect(ctx: &Context<'_>, guild_id: GuildId, channel: Option<String>) -> Result<(), Error> {
|
||||||
|
let voice_channel = get_voice_channel(&ctx, channel).await?;
|
||||||
|
|
||||||
|
let manager = songbird::get(ctx.serenity_context())
|
||||||
|
.await
|
||||||
|
.expect("Songbird Voice client placed in at initialisation.")
|
||||||
|
.clone();
|
||||||
|
|
||||||
|
if let Ok(handler_lock) = manager.join(guild_id, voice_channel).await {
|
||||||
|
let mut handler = handler_lock.lock().await;
|
||||||
|
handler.add_global_event(TrackEvent::Error.into(), TrackErrorNotifier);
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
pub async fn autocomplete_channel(
|
||||||
|
ctx: Context<'_>,
|
||||||
|
_partial: &str,
|
||||||
|
) -> Vec<String> {
|
||||||
|
|
||||||
|
use crate::util::utilities::get_vc_names;
|
||||||
|
match ctx.guild() {
|
||||||
|
Some(guild) => get_vc_names(guild),
|
||||||
|
None => [].to_vec()
|
||||||
|
}
|
||||||
|
}
|
|
@ -86,6 +86,7 @@ async fn main() -> anyhow::Result<()> {
|
||||||
commands::hug(),
|
commands::hug(),
|
||||||
commands::player::play_local(),
|
commands::player::play_local(),
|
||||||
commands::player::disconnect(),
|
commands::player::disconnect(),
|
||||||
|
commands::radio::radio()
|
||||||
],
|
],
|
||||||
prefix_options: poise::PrefixFrameworkOptions {
|
prefix_options: poise::PrefixFrameworkOptions {
|
||||||
prefix: Some("/".into()),
|
prefix: Some("/".into()),
|
||||||
|
|
Loading…
Reference in a new issue