1 Commits
0.1.0 ... 0.2.0

Author SHA1 Message Date
70c249787c 0.2.0 player update 2024-02-07 23:36:46 +01:00
16 changed files with 112 additions and 122 deletions

2
Cargo.lock generated
View File

@@ -892,7 +892,7 @@ dependencies = [
[[package]] [[package]]
name = "lyra" name = "lyra"
version = "0.1.0" version = "0.2.0"
dependencies = [ dependencies = [
"dotenv", "dotenv",
"openssl", "openssl",

View File

@@ -1,6 +1,6 @@
[package] [package]
name = "lyra" name = "lyra"
version = "0.1.0" version = "0.2.0"
edition = "2021" edition = "2021"
[dependencies] [dependencies]

View File

@@ -27,7 +27,15 @@ async fn deafen(ctx: &Context, msg: &Message) -> CommandResult {
let mut handler = handler_lock.lock().await; let mut handler = handler_lock.lock().await;
if handler.is_deaf() { if handler.is_deaf() {
check_msg(msg.channel_id.say(&ctx.http, "Already deafened").await); if let Err(err) = handler.deafen(false).await {
check_msg(
msg.channel_id
.say(&ctx.http, format!("Failed: {:?}", err))
.await,
);
}
check_msg(msg.channel_id.say(&ctx.http, "Undeafened").await);
} else { } else {
if let Err(err) = handler.deafen(true).await { if let Err(err) = handler.deafen(true).await {
check_msg( check_msg(

View File

@@ -9,15 +9,8 @@ use crate::commands::{misc::check_msg, music::misc::TrackErrorNotifier};
#[command] #[command]
#[only_in(guilds)] #[only_in(guilds)]
async fn join(ctx: &Context, msg: &Message) -> CommandResult { async fn join(ctx: &Context, msg: &Message) -> CommandResult {
let (guild_id, channel_id) = { let guild_id = msg.guild_id.unwrap();
let guild = msg.guild(&ctx.cache).unwrap(); let channel_id = msg.guild(&ctx.cache).unwrap().voice_states.get(&msg.author.id).and_then(|voice_state| voice_state.channel_id);
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 { let connect_to = match channel_id {
Some(channel) => channel, Some(channel) => channel,

View File

View File

@@ -7,5 +7,3 @@ pub mod play;
pub mod queue; pub mod queue;
pub mod skip; pub mod skip;
pub mod stop; pub mod stop;
pub mod undeafen;
pub mod unmute;

View File

@@ -27,7 +27,15 @@ async fn mute(ctx: &Context, msg: &Message) -> CommandResult {
let mut handler = handler_lock.lock().await; let mut handler = handler_lock.lock().await;
if handler.is_mute() { if handler.is_mute() {
check_msg(msg.channel_id.say(&ctx.http, "Already muted").await); if let Err(e) = handler.mute(false).await {
check_msg(
msg.channel_id
.say(&ctx.http, format!("failed: {:?}", e))
.await,
);
}
check_msg(msg.channel_id.say(&ctx.http, "Unmuted").await);
} else { } else {
if let Err(err) = handler.mute(true).await { if let Err(err) = handler.mute(true).await {
check_msg( check_msg(

View File

View File

@@ -3,7 +3,7 @@ use serenity::framework::standard::{Args, CommandResult};
use serenity::model::prelude::*; use serenity::model::prelude::*;
use serenity::prelude::*; use serenity::prelude::*;
use reqwest::Client as HttpClient; use reqwest::Client as HttpClient;
use songbird::input::YoutubeDl; use songbird::input::{Compose, YoutubeDl};
use songbird::events::TrackEvent; use songbird::events::TrackEvent;
use crate::commands::{misc::check_msg, music::misc::TrackErrorNotifier}; use crate::commands::{misc::check_msg, music::misc::TrackErrorNotifier};
@@ -31,17 +31,10 @@ async fn play(ctx: &Context, msg: &Message, mut args: Args) -> CommandResult {
} }
}; };
let do_search = !url.starts_with("http"); let is_search = !url.starts_with("http");
let (guild_id, channel_id) = { let guild_id = msg.guild_id.unwrap();
let guild = msg.guild(&ctx.cache).unwrap(); let channel_id = msg.guild(&ctx.cache).unwrap().voice_states.get(&msg.author.id).and_then(|voice_state| voice_state.channel_id);
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 { let connect_to = match channel_id {
Some(channel) => channel, Some(channel) => channel,
@@ -67,19 +60,22 @@ async fn play(ctx: &Context, msg: &Message, mut args: Args) -> CommandResult {
if let Ok(handler_lock) = manager.join(guild_id, connect_to).await { if let Ok(handler_lock) = manager.join(guild_id, connect_to).await {
let mut handler = handler_lock.lock().await; let mut handler = handler_lock.lock().await;
if let Err(err) = handler.deafen(true).await {println!("Failed to deafen: {:?}", err)};
handler.add_global_event(TrackEvent::Error.into(), TrackErrorNotifier); handler.add_global_event(TrackEvent::Error.into(), TrackErrorNotifier);
let src = if do_search { let mut src = if is_search {
YoutubeDl::new_ytdl_like("yt-dlp", http_client, url) println!("ytsearch:{}", url);
YoutubeDl::new_ytdl_like("yt-dlp", http_client, format!("ytsearch:{}", args.clone().message()))
} else { } else {
YoutubeDl::new(http_client, url) YoutubeDl::new_ytdl_like("yt-dlp", http_client, url)
}; };
let _ = handler.enqueue_input(src.clone().into()).await; let _ = handler.enqueue_input(src.clone().into()).await;
let metadata = src.aux_metadata().await.unwrap();
// let _ = handler.play_input(src.clone().into()); // let _ = handler.play_input(src.clone().into());
check_msg(msg.channel_id.say(&ctx.http, "Playing song").await); check_msg(msg.channel_id.say(&ctx.http, format!("Playing song: {}", metadata.title.unwrap())).await);
} else { } else {
check_msg( check_msg(
msg.channel_id msg.channel_id

View File

@@ -3,10 +3,46 @@ use serenity::framework::standard::CommandResult;
use serenity::model::prelude::*; use serenity::model::prelude::*;
use serenity::prelude::*; use serenity::prelude::*;
// use crate::commands::misc::check_msg; use crate::commands::misc::check_msg;
#[command] #[command]
#[only_in(guilds)] #[only_in(guilds)]
async fn queue(_ctx: &Context, _msg: &Message) -> CommandResult { async fn queue(ctx: &Context, msg: &Message) -> CommandResult {
let guild_id = msg.guild_id.unwrap();
let manager = songbird::get(ctx)
.await
.expect("Client placed at init")
.clone();
if let Some(handler_lock) = manager.get(guild_id) {
let handler = handler_lock.lock().await;
let queue = handler.queue();
let mut queue_res = String::from("Queue: \n");
for (i, song) in queue.current_queue().iter().enumerate() {
queue_res.push_str(&format!(
"{}. {} - {}\n",
i + 1,
song.uuid(),
"Artist"
// song.metadata().artist.clone().unwrap_or_else(|| String::from("Unknown"))
));
}
check_msg(
msg.channel_id
.say(&ctx.http, queue_res)
.await,
);
} else {
check_msg(
msg.channel_id
.say(&ctx.http, "Not in a voice channel!")
.await,
);
}
Ok(()) Ok(())
} }

View File

View File

@@ -3,10 +3,38 @@ use serenity::framework::standard::CommandResult;
use serenity::model::prelude::*; use serenity::model::prelude::*;
use serenity::prelude::*; use serenity::prelude::*;
// use crate::commands::misc::check_msg; use crate::commands::misc::check_msg;
#[command] #[command]
#[only_in(guilds)] #[only_in(guilds)]
async fn skip(_ctx: &Context, _msg: &Message) -> CommandResult { async fn skip(ctx: &Context, msg: &Message) -> CommandResult {
let guild_id = msg.guild_id.unwrap();
let manager = songbird::get(ctx)
.await
.expect("Client placed at init")
.clone();
if let Some(handler_lock) = manager.get(guild_id) {
let handler = handler_lock.lock().await;
let queue = handler.queue();
let _ = queue.skip();
check_msg(
msg.channel_id
.say(
&ctx.http,
format!("Song skipped: {} in queue.", queue.len()),
)
.await,
);
} else {
check_msg(
msg.channel_id
.say(&ctx.http, "Not in a voice channel to play in")
.await,
);
}
Ok(()) Ok(())
} }

View File

@@ -17,7 +17,8 @@ async fn stop(ctx: &Context, msg: &Message) -> CommandResult {
if let Some(handler_lock) = manager.get(guild_id) { if let Some(handler_lock) = manager.get(guild_id) {
let mut handler = handler_lock.lock().await; let mut handler = handler_lock.lock().await;
let _queue = handler.queue(); let queue = handler.queue();
queue.stop();
if let Err(e) = handler.deafen(false).await { if let Err(e) = handler.deafen(false).await {
check_msg( check_msg(
@@ -31,7 +32,7 @@ async fn stop(ctx: &Context, msg: &Message) -> CommandResult {
} else { } else {
check_msg( check_msg(
msg.channel_id msg.channel_id
.say(&ctx.http, "Not in a voice channel to undeafen in") .say(&ctx.http, "Not in a voice channel!")
.await, .await,
); );
} }

View File

@@ -1,38 +0,0 @@
use serenity::framework::standard::macros::command;
use serenity::framework::standard::CommandResult;
use serenity::model::prelude::*;
use serenity::prelude::*;
use crate::commands::misc::check_msg;
#[command]
#[only_in(guilds)]
async fn undeafen(ctx: &Context, msg: &Message) -> CommandResult {
let guild_id = msg.guild_id.unwrap();
let manager = songbird::get(ctx)
.await
.expect("Client placed at init")
.clone();
if let Some(handler_lock) = manager.get(guild_id) {
let mut handler = handler_lock.lock().await;
if let Err(e) = handler.deafen(false).await {
check_msg(
msg.channel_id
.say(&ctx.http, format!("Failed: {:?}", e))
.await,
);
}
check_msg(msg.channel_id.say(&ctx.http, "Undeafened").await);
} else {
check_msg(
msg.channel_id
.say(&ctx.http, "Not in a voice channel to undeafen in")
.await,
);
}
Ok(())
}

View File

@@ -1,38 +0,0 @@
use serenity::framework::standard::macros::command;
use serenity::framework::standard::CommandResult;
use serenity::model::prelude::*;
use serenity::prelude::*;
use crate::commands::misc::check_msg;
#[command]
#[only_in(guilds)]
async fn unmute(ctx: &Context, msg: &Message) -> CommandResult {
let guild_id = msg.guild_id.unwrap();
let manager = songbird::get(ctx)
.await
.expect("Client placed at init")
.clone();
if let Some(handler_lock) = manager.get(guild_id) {
let mut handler = handler_lock.lock().await;
if let Err(e) = handler.mute(false).await {
check_msg(
msg.channel_id
.say(&ctx.http, format!("Failed: {:?}", e))
.await,
);
}
check_msg(msg.channel_id.say(&ctx.http, "Unmuted").await);
} else {
check_msg(
msg.channel_id
.say(&ctx.http, "Not in a voice channel to unmute in")
.await,
);
}
Ok(())
}

View File

@@ -30,8 +30,6 @@ use crate::commands::music::play::*;
use crate::commands::music::queue::*; use crate::commands::music::queue::*;
use crate::commands::music::skip::*; use crate::commands::music::skip::*;
use crate::commands::music::stop::*; use crate::commands::music::stop::*;
use crate::commands::music::undeafen::*;
use crate::commands::music::unmute::*;
// tools // tools
use crate::commands::tools::ping::*; use crate::commands::tools::ping::*;
@@ -61,7 +59,7 @@ async fn before(_: &Context, msg: &Message, command_name: &str) -> bool {
#[group] #[group]
#[commands( #[commands(
join, deafen, leave, mute, play, unmute, undeafen, ping, kashi, queue, stop, skip join, deafen, leave, mute, play, ping, kashi, queue, stop, skip
)] )]
struct General; struct General;