music commands migrated

This commit is contained in:
2024-02-10 22:22:45 +01:00
parent 6946ddc9f1
commit a27e95a88d
23 changed files with 182 additions and 352 deletions

View File

@@ -1,58 +1,35 @@
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 crate::{Context, Error};
use songbird::input::{Compose, YoutubeDl};
use songbird::events::TrackEvent;
use crate::commands::{misc::check_msg, music::misc::TrackErrorNotifier};
pub struct HttpKey;
impl TypeMapKey for HttpKey {
type Value = HttpClient;
}
#[command]
#[aliases(p)]
#[only_in(guilds)]
async fn play(ctx: &Context, msg: &Message, mut args: Args) -> CommandResult {
let url = match args.single::<String>() {
Ok(url) => url,
Err(_) => {
check_msg(
msg.channel_id
.say(&ctx.http, "Must provide a URL to a video or audio")
.await,
);
return Ok(());
}
};
use crate::commands::music::misc::TrackErrorNotifier;
use crate::http::HttpKey;
#[poise::command(prefix_command, slash_command)]
pub async fn play(ctx: Context<'_>, url: String) -> Result<(), Error> {
let is_search = !url.starts_with("http");
let guild_id = msg.guild_id.unwrap();
let channel_id = msg.guild(&ctx.cache).unwrap().voice_states.get(&msg.author.id).and_then(|voice_state| voice_state.channel_id);
let guild_id = ctx.guild_id().unwrap();
let channel_id = ctx.guild().unwrap().voice_states.get(&ctx.author().id).and_then(|voice_state| voice_state.channel_id);
let connect_to = match channel_id {
Some(channel) => channel,
None => {
check_msg(msg.reply(ctx, "Not in a voice channel").await);
ctx.say("Not in a voice channel").await?;
return Ok(());
}
};
let http_client = {
let data = ctx.data.read().await;
let data = ctx.serenity_context().data.read().await;
data.get::<HttpKey>()
.cloned()
.expect("Guaranteed to exist in the typemap.")
};
let manager = songbird::get(ctx)
let manager = songbird::get(&ctx.serenity_context())
.await
.expect("Songbird Voice placed at init")
.clone();
@@ -65,22 +42,18 @@ async fn play(ctx: &Context, msg: &Message, mut args: Args) -> CommandResult {
let mut src = if is_search {
println!("ytsearch:{}", url);
YoutubeDl::new_ytdl_like("yt-dlp", http_client, format!("ytsearch:{}", args.clone().message()))
YoutubeDl::new_ytdl_like("yt-dlp", http_client, format!("ytsearch:{}", url))
} else {
YoutubeDl::new_ytdl_like("yt-dlp", http_client, url)
};
let _ = handler.enqueue_input(src.clone().into()).await;
let metadata = src.aux_metadata().await.unwrap();
let _metadata = src.aux_metadata().await.unwrap();
check_msg(msg.channel_id.say(&ctx.http, format!("Playing song: {}", metadata.title.unwrap())).await);
// ctx.say(format!("Playing song: {}", metadata.title.unwrap())).await?;
} else {
check_msg(
msg.channel_id
.say(&ctx.http, "Not in a voice channel to play in")
.await,
);
ctx.say("Not in a voice channel to play in").await?;
}
Ok(())