init
This commit is contained in:
1
src/commands/mod.rs
Normal file
1
src/commands/mod.rs
Normal file
@@ -0,0 +1 @@
|
||||
pub mod play;
|
||||
46
src/commands/play.rs
Normal file
46
src/commands/play.rs
Normal file
@@ -0,0 +1,46 @@
|
||||
use serenity::all::{Context, GuildId};
|
||||
use serenity::builder::{CreateCommand, CreateCommandOption};
|
||||
use serenity::model::application::{CommandOptionType, ResolvedOption, ResolvedValue};
|
||||
use songbird::Call;
|
||||
use songbird::driver::opus::ffi;
|
||||
use songbird::input::{self, AudioStream, Input};
|
||||
use std::env;
|
||||
use std::process::Command;
|
||||
|
||||
use crate::audio::downloader::get_audio;
|
||||
|
||||
pub async fn run(options: &[ResolvedOption<'_>], ctx: Context) -> String {
|
||||
if let Some(ResolvedOption {
|
||||
value: ResolvedValue::String(url),
|
||||
..
|
||||
}) = options.first()
|
||||
{
|
||||
let path = get_audio(url.to_string());
|
||||
let manager = songbird::get(&ctx).await.unwrap().clone();
|
||||
|
||||
let guild_id = GuildId::new(
|
||||
env::var("GUILD_ID")
|
||||
.expect("Expected GUILD_ID in environment")
|
||||
.parse()
|
||||
.expect("GUILD_ID must be an integer"),
|
||||
);
|
||||
if let Some(handler_lock) = manager.get(guild_id) {
|
||||
let mut handler = handler_lock.lock().await;
|
||||
let src = ffi
|
||||
let _ = handler.play_input();
|
||||
}
|
||||
|
||||
format!("{}", url)
|
||||
} else {
|
||||
"Please provide a valid url".to_string()
|
||||
}
|
||||
}
|
||||
|
||||
pub fn register() -> CreateCommand {
|
||||
CreateCommand::new("play")
|
||||
.description("A play command")
|
||||
.add_option(
|
||||
CreateCommandOption::new(CommandOptionType::String, "url", "song to look for")
|
||||
.required(true),
|
||||
)
|
||||
}
|
||||
Reference in New Issue
Block a user