3 Commits
0.1.0 ... 0.2.1

Author SHA1 Message Date
21fe190921 handy scripts 2024-02-08 23:11:23 +01:00
4a0184811e loop plus fixes 2024-02-08 22:57:59 +01:00
70c249787c 0.2.0 player update 2024-02-07 23:36:46 +01:00
16 changed files with 236 additions and 80 deletions

2
Cargo.lock generated
View File

@@ -892,7 +892,7 @@ dependencies = [
[[package]] [[package]]
name = "lyra" name = "lyra"
version = "0.1.0" version = "0.3.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.3.0"
edition = "2021" edition = "2021"
[dependencies] [dependencies]

3
scripts/cross-build.sh Normal file
View File

@@ -0,0 +1,3 @@
#!/bin/bash
cross build -r --target aarch64-unknown-linux-gnu

3
scripts/launch.sh Normal file
View File

@@ -0,0 +1,3 @@
#!/bin/bash
nohup ./lyra > lyra.log 2> lyra.err < /dev/null &

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,
@@ -39,4 +32,4 @@ async fn join(ctx: &Context, msg: &Message) -> CommandResult {
} }
Ok(()) Ok(())
} }

View File

@@ -0,0 +1,83 @@
use serenity::framework::standard::macros::command;
use serenity::framework::standard::{Args, CommandResult};
use serenity::model::prelude::*;
use serenity::prelude::*;
use songbird::tracks::LoopState;
use crate::commands::misc::check_msg;
#[command]
#[aliases(loop)]
#[only_in(guilds)]
async fn loopcurrent(ctx: &Context, msg: &Message, mut args: Args) -> 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 track = queue.current().unwrap().get_info().await;
let is_looped = track.unwrap().loops;
let count = match args.single::<usize>() {
Ok(count) => count,
Err(_) => 100,
};
match is_looped {
LoopState::Infinite => {
let _ = queue.current().unwrap().disable_loop();
check_msg(
msg.channel_id
.say(
&ctx.http,
format!("Song unlooped."),
)
.await,
);
}
LoopState::Finite(_) => {
if count < 100 {
let _ = queue.current().unwrap().loop_for(count);
check_msg(
msg.channel_id
.say(
&ctx.http,
format!("Song looped forever (a very long time)."),
)
.await,
)
}
else {
let _ = queue.current().unwrap().enable_loop();
check_msg(
msg.channel_id
.say(
&ctx.http,
format!("Song looped {} times.", count),
)
.await,
)
}
}
}
} else {
check_msg(
msg.channel_id
.say(&ctx.http, "Not in a voice channel to play in")
.await,
);
}
Ok(())
}

View File

@@ -7,5 +7,6 @@ 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 loopcurrent;
pub mod unmute; pub mod pause;
pub mod resume;

View File

@@ -26,8 +26,16 @@ 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

@@ -7,7 +7,7 @@ use crate::commands::misc::check_msg;
#[command] #[command]
#[only_in(guilds)] #[only_in(guilds)]
async fn undeafen(ctx: &Context, msg: &Message) -> CommandResult { async fn pause(ctx: &Context, msg: &Message) -> CommandResult {
let guild_id = msg.guild_id.unwrap(); let guild_id = msg.guild_id.unwrap();
let manager = songbird::get(ctx) let manager = songbird::get(ctx)
@@ -16,23 +16,25 @@ async fn undeafen(ctx: &Context, msg: &Message) -> CommandResult {
.clone(); .clone();
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 handler = handler_lock.lock().await;
if let Err(e) = handler.deafen(false).await { let queue = handler.queue();
check_msg( let _ = queue.pause();
msg.channel_id
.say(&ctx.http, format!("Failed: {:?}", e))
.await,
);
}
check_msg(msg.channel_id.say(&ctx.http, "Undeafened").await); check_msg(
msg.channel_id
.say(
&ctx.http,
format!("Song paused."),
)
.await,
);
} 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 to play in")
.await, .await,
); );
} }
Ok(()) Ok(())
} }

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,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_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,
None => { None => {
@@ -66,20 +59,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()); check_msg(msg.channel_id.say(&ctx.http, format!("Playing song: {}", metadata.title.unwrap())).await);
check_msg(msg.channel_id.say(&ctx.http, "Playing song").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

@@ -7,7 +7,7 @@ use crate::commands::misc::check_msg;
#[command] #[command]
#[only_in(guilds)] #[only_in(guilds)]
async fn unmute(ctx: &Context, msg: &Message) -> CommandResult { async fn resume(ctx: &Context, msg: &Message) -> CommandResult {
let guild_id = msg.guild_id.unwrap(); let guild_id = msg.guild_id.unwrap();
let manager = songbird::get(ctx) let manager = songbird::get(ctx)
@@ -16,23 +16,25 @@ async fn unmute(ctx: &Context, msg: &Message) -> CommandResult {
.clone(); .clone();
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 handler = handler_lock.lock().await;
if let Err(e) = handler.mute(false).await { let queue = handler.queue();
check_msg( let _ = queue.resume();
msg.channel_id
.say(&ctx.http, format!("Failed: {:?}", e))
.await,
);
}
check_msg(msg.channel_id.say(&ctx.http, "Unmuted").await); check_msg(
msg.channel_id
.say(
&ctx.http,
format!("Song resumed."),
)
.await,
);
} else { } else {
check_msg( check_msg(
msg.channel_id msg.channel_id
.say(&ctx.http, "Not in a voice channel to unmute in") .say(&ctx.http, "Not in a voice channel to play in")
.await, .await,
); );
} }
Ok(()) Ok(())
} }

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

@@ -16,25 +16,18 @@ async fn stop(ctx: &Context, msg: &Message) -> CommandResult {
.clone(); .clone();
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 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(
msg.channel_id
.say(&ctx.http, format!("Failed: {:?}", e))
.await,
);
}
check_msg(msg.channel_id.say(&ctx.http, "Playback stopped!").await); check_msg(msg.channel_id.say(&ctx.http, "Playback stopped!").await);
} 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,
); );
} }
Ok(()) Ok(())
} }

View File

@@ -30,8 +30,9 @@ 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::loopcurrent::*;
use crate::commands::music::unmute::*; use crate::commands::music::pause::*;
use crate::commands::music::resume::*;
// tools // tools
use crate::commands::tools::ping::*; use crate::commands::tools::ping::*;
@@ -61,7 +62,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, loopcurrent, pause, resume
)] )]
struct General; struct General;