mirror of
https://github.com/eRgo35/lyra.git
synced 2026-02-04 12:26:10 +01:00
music commands
This commit is contained in:
@@ -1,19 +1,11 @@
|
||||
use serenity::framework::standard::Args;
|
||||
use serenity::framework::standard::{macros::command, CommandResult};
|
||||
|
||||
use reqwest::Client as HttpClient;
|
||||
|
||||
use serenity::client::Context;
|
||||
|
||||
use serenity::prelude::TypeMapKey;
|
||||
|
||||
use serenity::framework::standard::macros::command;
|
||||
use serenity::framework::standard::{Args, CommandResult};
|
||||
use serenity::model::prelude::*;
|
||||
|
||||
use serenity::prelude::*;
|
||||
use reqwest::Client as HttpClient;
|
||||
use songbird::input::YoutubeDl;
|
||||
use songbird::TrackEvent;
|
||||
|
||||
use crate::commands::misc::check_msg;
|
||||
use crate::commands::music::misc::TrackErrorNotifier;
|
||||
|
||||
pub struct HttpKey;
|
||||
|
||||
@@ -22,27 +14,9 @@ impl TypeMapKey for HttpKey {
|
||||
}
|
||||
|
||||
#[command]
|
||||
#[aliases(p)]
|
||||
#[only_in(guilds)]
|
||||
async fn play(ctx: &Context, msg: &Message, mut args: Args) -> CommandResult {
|
||||
let (guild_id, channel_id) = {
|
||||
let guild = msg.guild(&ctx.cache).unwrap();
|
||||
let channel_id = guild
|
||||
.voice_states
|
||||
.get(&msg.author.id)
|
||||
.and_then(|voice_state| voice_state.channel_id);
|
||||
|
||||
(guild.id, channel_id)
|
||||
};
|
||||
|
||||
let connect_to = match channel_id {
|
||||
Some(channel) => channel,
|
||||
None => {
|
||||
check_msg(msg.reply(ctx, "Not in a voice channel").await);
|
||||
|
||||
return Ok(());
|
||||
}
|
||||
};
|
||||
|
||||
let url = match args.single::<String>() {
|
||||
Ok(url) => url,
|
||||
Err(_) => {
|
||||
@@ -58,6 +32,8 @@ async fn play(ctx: &Context, msg: &Message, mut args: Args) -> CommandResult {
|
||||
|
||||
let do_search = !url.starts_with("http");
|
||||
|
||||
let guild_id = msg.guild_id.unwrap();
|
||||
|
||||
let http_client = {
|
||||
let data = ctx.data.read().await;
|
||||
data.get::<HttpKey>()
|
||||
@@ -67,30 +43,25 @@ async fn play(ctx: &Context, msg: &Message, mut args: Args) -> CommandResult {
|
||||
|
||||
let manager = songbird::get(ctx)
|
||||
.await
|
||||
.expect("Client placed at init")
|
||||
.expect("Songbird Voice client placed in at initialisation.")
|
||||
.clone();
|
||||
|
||||
if let Ok(handler_lock) = manager.join(guild_id, connect_to).await {
|
||||
let mut handler = handler_lock.lock().await;
|
||||
handler.add_global_event(TrackEvent::Error.into(), TrackErrorNotifier);
|
||||
}
|
||||
|
||||
if let Some(handler_lock) = manager.get(guild_id) {
|
||||
let mut handler = handler_lock.lock().await;
|
||||
|
||||
let src = if do_search {
|
||||
YoutubeDl::new(http_client, url)
|
||||
// YoutubeDl::new_search(http_client, url)
|
||||
YoutubeDl::new_ytdl_like("yt-dlp", http_client, url)
|
||||
} else {
|
||||
YoutubeDl::new(http_client, url)
|
||||
};
|
||||
|
||||
let _ = handler.play_input(src.clone().into());
|
||||
|
||||
check_msg(msg.channel_id.say(&ctx.http, "Playing song").await);
|
||||
} else {
|
||||
check_msg(
|
||||
msg.channel_id
|
||||
.say(&ctx.http, "Not in a voice channel!")
|
||||
.say(&ctx.http, "Not in a voice channel to play in")
|
||||
.await,
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user