This commit is contained in:
2024-02-03 21:56:12 +01:00
parent 85287f1284
commit 29816860a1
4 changed files with 30 additions and 7 deletions

View File

@@ -7,7 +7,7 @@ edition = "2021"
dotenv = "0.15.0"
regex = "1.10.3"
reqwest = "0.11.23"
serenity = "0.12.0"
serenity = { version = "0.12.0", features = ["cache", "framework", "standard_framework", "voice"] }
songbird = { version = "0.4.0", features = ["builtin-queue", "serenity"] }
symphonia = "0.5.3"
tokio = { version = "1.35.1", features = ["macros", "rt-multi-thread", "signal"] }

BIN
assets/lyra.pdn Executable file

Binary file not shown.

View File

@@ -6,6 +6,7 @@ use serenity::prelude::*;
use crate::commands::misc::check_msg;
#[command]
#[aliases(q)]
#[only_in(guilds)]
async fn leave(ctx: &Context, msg: &Message) -> CommandResult {
let guild_id = msg.guild_id.unwrap();

View File

@@ -4,8 +4,9 @@ use serenity::model::prelude::*;
use serenity::prelude::*;
use reqwest::Client as HttpClient;
use songbird::input::YoutubeDl;
use songbird::events::TrackEvent;
use crate::commands::misc::check_msg;
use crate::commands::{misc::check_msg, music::misc::TrackErrorNotifier};
pub struct HttpKey;
@@ -32,7 +33,24 @@ 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 (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 http_client = {
let data = ctx.data.read().await;
@@ -43,19 +61,23 @@ async fn play(ctx: &Context, msg: &Message, mut args: Args) -> CommandResult {
let manager = songbird::get(ctx)
.await
.expect("Songbird Voice client placed in at initialisation.")
.expect("Songbird Voice placed at init")
.clone();
if let Some(handler_lock) = manager.get(guild_id) {
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);
let src = if do_search {
// 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());
let _ = handler.enqueue_input(src.clone().into()).await;
// let _ = handler.play_input(src.clone().into());
check_msg(msg.channel_id.say(&ctx.http, "Playing song").await);
} else {