music commands

This commit is contained in:
2024-02-02 21:12:13 +01:00
parent 6ae7ba2233
commit f6961c3b3f
5 changed files with 17 additions and 46 deletions

View File

@@ -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,
);
}

View File

@@ -3,10 +3,10 @@ use serenity::framework::standard::CommandResult;
use serenity::model::prelude::*;
use serenity::prelude::*;
use crate::commands::misc::check_msg;
// use crate::commands::misc::check_msg;
#[command]
#[only_in(guilds)]
async fn queue(ctx: &Context, msg: &Message) -> CommandResult {
async fn queue(_ctx: &Context, _msg: &Message) -> CommandResult {
Ok(())
}

View File

@@ -3,10 +3,10 @@ use serenity::framework::standard::CommandResult;
use serenity::model::prelude::*;
use serenity::prelude::*;
use crate::commands::misc::check_msg;
// use crate::commands::misc::check_msg;
#[command]
#[only_in(guilds)]
async fn skip(ctx: &Context, msg: &Message) -> CommandResult {
async fn skip(_ctx: &Context, _msg: &Message) -> CommandResult {
Ok(())
}

View File

@@ -17,7 +17,7 @@ async fn stop(ctx: &Context, msg: &Message) -> CommandResult {
if let Some(handler_lock) = manager.get(guild_id) {
let mut handler = handler_lock.lock().await;
let queue = handler.queue();
let _queue = handler.queue();
if let Err(e) = handler.deafen(false).await {
check_msg(