mirror of
https://github.com/eRgo35/lyra.git
synced 2026-02-04 12:26:10 +01:00
0.2.0 player update
This commit is contained in:
2
Cargo.lock
generated
2
Cargo.lock
generated
@@ -892,7 +892,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "lyra"
|
||||
version = "0.1.0"
|
||||
version = "0.2.0"
|
||||
dependencies = [
|
||||
"dotenv",
|
||||
"openssl",
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "lyra"
|
||||
version = "0.1.0"
|
||||
version = "0.2.0"
|
||||
edition = "2021"
|
||||
|
||||
[dependencies]
|
||||
|
||||
@@ -27,7 +27,15 @@ async fn deafen(ctx: &Context, msg: &Message) -> CommandResult {
|
||||
let mut handler = handler_lock.lock().await;
|
||||
|
||||
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 {
|
||||
if let Err(err) = handler.deafen(true).await {
|
||||
check_msg(
|
||||
|
||||
@@ -9,15 +9,8 @@ use crate::commands::{misc::check_msg, music::misc::TrackErrorNotifier};
|
||||
#[command]
|
||||
#[only_in(guilds)]
|
||||
async fn join(ctx: &Context, msg: &Message) -> 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 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 connect_to = match channel_id {
|
||||
Some(channel) => channel,
|
||||
@@ -39,4 +32,4 @@ async fn join(ctx: &Context, msg: &Message) -> CommandResult {
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
0
src/commands/music/loop.rs
Normal file
0
src/commands/music/loop.rs
Normal file
@@ -7,5 +7,3 @@ pub mod play;
|
||||
pub mod queue;
|
||||
pub mod skip;
|
||||
pub mod stop;
|
||||
pub mod undeafen;
|
||||
pub mod unmute;
|
||||
|
||||
@@ -26,8 +26,16 @@ async fn mute(ctx: &Context, msg: &Message) -> CommandResult {
|
||||
|
||||
let mut handler = handler_lock.lock().await;
|
||||
|
||||
if handler.is_mute() {
|
||||
check_msg(msg.channel_id.say(&ctx.http, "Already muted").await);
|
||||
if handler.is_mute() {
|
||||
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 {
|
||||
if let Err(err) = handler.mute(true).await {
|
||||
check_msg(
|
||||
|
||||
0
src/commands/music/pause.rs
Normal file
0
src/commands/music/pause.rs
Normal file
@@ -3,7 +3,7 @@ use serenity::framework::standard::{Args, CommandResult};
|
||||
use serenity::model::prelude::*;
|
||||
use serenity::prelude::*;
|
||||
use reqwest::Client as HttpClient;
|
||||
use songbird::input::YoutubeDl;
|
||||
use songbird::input::{Compose, YoutubeDl};
|
||||
use songbird::events::TrackEvent;
|
||||
|
||||
use crate::commands::{misc::check_msg, music::misc::TrackErrorNotifier};
|
||||
@@ -31,18 +31,11 @@ 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 = msg.guild(&ctx.cache).unwrap();
|
||||
let channel_id = guild
|
||||
.voice_states
|
||||
.get(&msg.author.id)
|
||||
.and_then(|voice_state| voice_state.channel_id);
|
||||
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);
|
||||
|
||||
(guild.id, channel_id)
|
||||
};
|
||||
|
||||
let connect_to = match channel_id {
|
||||
Some(channel) => channel,
|
||||
None => {
|
||||
@@ -66,20 +59,23 @@ async fn play(ctx: &Context, msg: &Message, mut args: Args) -> CommandResult {
|
||||
|
||||
if let Ok(handler_lock) = manager.join(guild_id, connect_to).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);
|
||||
|
||||
let src = if do_search {
|
||||
YoutubeDl::new_ytdl_like("yt-dlp", http_client, url)
|
||||
let mut src = if is_search {
|
||||
println!("ytsearch:{}", url);
|
||||
YoutubeDl::new_ytdl_like("yt-dlp", http_client, format!("ytsearch:{}", args.clone().message()))
|
||||
} else {
|
||||
YoutubeDl::new(http_client, url)
|
||||
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 _ = 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 {
|
||||
check_msg(
|
||||
msg.channel_id
|
||||
|
||||
@@ -3,10 +3,46 @@ 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 {
|
||||
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(())
|
||||
}
|
||||
}
|
||||
|
||||
0
src/commands/music/resume.rs
Normal file
0
src/commands/music/resume.rs
Normal file
@@ -3,10 +3,38 @@ 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 {
|
||||
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(())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,7 +17,8 @@ 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();
|
||||
queue.stop();
|
||||
|
||||
if let Err(e) = handler.deafen(false).await {
|
||||
check_msg(
|
||||
@@ -31,10 +32,10 @@ async fn stop(ctx: &Context, msg: &Message) -> CommandResult {
|
||||
} else {
|
||||
check_msg(
|
||||
msg.channel_id
|
||||
.say(&ctx.http, "Not in a voice channel to undeafen in")
|
||||
.say(&ctx.http, "Not in a voice channel!")
|
||||
.await,
|
||||
);
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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(())
|
||||
}
|
||||
@@ -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(())
|
||||
}
|
||||
@@ -30,8 +30,6 @@ use crate::commands::music::play::*;
|
||||
use crate::commands::music::queue::*;
|
||||
use crate::commands::music::skip::*;
|
||||
use crate::commands::music::stop::*;
|
||||
use crate::commands::music::undeafen::*;
|
||||
use crate::commands::music::unmute::*;
|
||||
|
||||
// tools
|
||||
use crate::commands::tools::ping::*;
|
||||
@@ -61,7 +59,7 @@ async fn before(_: &Context, msg: &Message, command_name: &str) -> bool {
|
||||
|
||||
#[group]
|
||||
#[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;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user