mirror of
https://github.com/eRgo35/lyra.git
synced 2026-02-04 20:36:10 +01:00
more commands incoming
This commit is contained in:
@@ -2,6 +2,7 @@ pub mod deafen;
|
|||||||
pub mod join;
|
pub mod join;
|
||||||
pub mod leave;
|
pub mod leave;
|
||||||
pub mod notifier;
|
pub mod notifier;
|
||||||
|
pub mod metadata;
|
||||||
pub mod mute;
|
pub mod mute;
|
||||||
pub mod pause;
|
pub mod pause;
|
||||||
pub mod play;
|
pub mod play;
|
||||||
|
|||||||
7
src/commands/music/metadata.rs
Normal file
7
src/commands/music/metadata.rs
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
use songbird::{input::AuxMetadata, typemap::TypeMapKey};
|
||||||
|
|
||||||
|
pub struct Metadata;
|
||||||
|
|
||||||
|
impl TypeMapKey for Metadata {
|
||||||
|
type Value = AuxMetadata;
|
||||||
|
}
|
||||||
@@ -1,7 +1,9 @@
|
|||||||
use crate::{commands::embeds::error_embed, Context, Error};
|
use crate::{commands::embeds::error_embed, Context, Error};
|
||||||
|
use crate::commands::music::metadata::Metadata;
|
||||||
|
|
||||||
use fancy_regex::Regex;
|
use fancy_regex::Regex;
|
||||||
use regex::Regex as Regex_Classic;
|
use regex::Regex as Regex_Classic;
|
||||||
|
use songbird::tracks::{TrackHandle, TrackQueue};
|
||||||
use std::process::Command;
|
use std::process::Command;
|
||||||
use std::time::Duration;
|
use std::time::Duration;
|
||||||
use poise::CreateReply;
|
use poise::CreateReply;
|
||||||
@@ -81,17 +83,19 @@ pub async fn play(
|
|||||||
|
|
||||||
let urls: Vec<String> = regex_youtube.captures_iter(&list).map(|capture| capture[1].to_string()).collect();
|
let urls: Vec<String> = regex_youtube.captures_iter(&list).map(|capture| capture[1].to_string()).collect();
|
||||||
|
|
||||||
let mut sources: Vec<YoutubeDl> = vec![];
|
for (index, url) in urls.clone().iter().enumerate() {
|
||||||
|
let src = YoutubeDl::new_ytdl_like("yt-dlp", http_client.clone(), url.to_string());
|
||||||
|
let aux_metadata = src.clone().aux_metadata().await.unwrap();
|
||||||
|
let track = handler.enqueue_input(src.clone().into()).await;
|
||||||
|
let _ = track.typemap().write().await.insert::<Metadata>(aux_metadata);
|
||||||
|
|
||||||
for url in urls {
|
if index == 0 {
|
||||||
let src = YoutubeDl::new_ytdl_like("yt-dlp", http_client.clone(), url);
|
let embed = generate_playlist_embed(ctx, track, urls.len()).await;
|
||||||
let _ = handler.enqueue_input(src.clone().into()).await;
|
let response = CreateReply::default().embed(embed.unwrap());
|
||||||
sources.push(src);
|
ctx.send(response).await?;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let embed = generate_playlist_embed(ctx, sources).await;
|
|
||||||
let response = CreateReply::default().embed(embed.unwrap());
|
|
||||||
ctx.send(response).await?;
|
|
||||||
} else {
|
} else {
|
||||||
if is_spotify {
|
if is_spotify {
|
||||||
let exec = format!("node ./src/spotify --url {}", song);
|
let exec = format!("node ./src/spotify --url {}", song);
|
||||||
@@ -106,23 +110,31 @@ pub async fn play(
|
|||||||
}
|
}
|
||||||
|
|
||||||
let src = YoutubeDl::new_ytdl_like("yt-dlp", http_client, song);
|
let src = YoutubeDl::new_ytdl_like("yt-dlp", http_client, song);
|
||||||
let _ = handler.enqueue_input(src.clone().into()).await;
|
let embed = generate_embed(ctx, src.clone(), handler.queue()).await;
|
||||||
|
|
||||||
let embed = generate_embed(ctx, src).await;
|
|
||||||
let response = CreateReply::default().embed(embed.unwrap());
|
let response = CreateReply::default().embed(embed.unwrap());
|
||||||
ctx.send(response).await?;
|
ctx.send(response).await?;
|
||||||
|
|
||||||
|
let aux_metadata = src.clone().aux_metadata().await.unwrap();
|
||||||
|
|
||||||
|
let track = handler.enqueue_input(src.clone().into()).await;
|
||||||
|
let _ = track.typemap().write().await.insert::<Metadata>(aux_metadata);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn generate_embed(ctx: Context<'_>, src: YoutubeDl) -> Result<CreateEmbed, Error> {
|
async fn generate_embed(ctx: Context<'_>, src: YoutubeDl, queue: &TrackQueue) -> Result<CreateEmbed, Error> {
|
||||||
let metadata = src.clone().aux_metadata().await.unwrap();
|
let metadata = src.clone().aux_metadata().await.unwrap();
|
||||||
let AuxMetadata {title, thumbnail, source_url, artist, duration, ..} = metadata;
|
let AuxMetadata {title, thumbnail, source_url, artist, duration, ..} = metadata;
|
||||||
let timestamp = Timestamp::now();
|
let timestamp = Timestamp::now();
|
||||||
let duration_minutes = duration.unwrap_or(Duration::new(0, 0)).clone().as_secs() / 60;
|
let duration_minutes = duration.unwrap_or(Duration::new(0, 0)).clone().as_secs() / 60;
|
||||||
let duration_seconds = duration.unwrap_or(Duration::new(0, 0)).clone().as_secs() % 60;
|
let duration_seconds = duration.unwrap_or(Duration::new(0, 0)).clone().as_secs() % 60;
|
||||||
|
let mut description = format!("Song added to queue @ {}", queue.len());
|
||||||
|
|
||||||
|
if queue.len() == 0 {
|
||||||
|
description = format!("Playing now!");
|
||||||
|
}
|
||||||
|
|
||||||
let embed = CreateEmbed::default()
|
let embed = CreateEmbed::default()
|
||||||
.author(CreateEmbedAuthor::new("Track enqueued").icon_url(ctx.author().clone().face()))
|
.author(CreateEmbedAuthor::new("Track enqueued").icon_url(ctx.author().clone().face()))
|
||||||
@@ -133,32 +145,32 @@ async fn generate_embed(ctx: Context<'_>, src: YoutubeDl) -> Result<CreateEmbed,
|
|||||||
.field("Artist", artist.unwrap_or("Unknown Artist".to_string()), true)
|
.field("Artist", artist.unwrap_or("Unknown Artist".to_string()), true)
|
||||||
.field("Duration", format!("{:02}:{:02}", duration_minutes, duration_seconds), true)
|
.field("Duration", format!("{:02}:{:02}", duration_minutes, duration_seconds), true)
|
||||||
.field("DJ", ctx.author().name.clone(), true)
|
.field("DJ", ctx.author().name.clone(), true)
|
||||||
.timestamp(timestamp)
|
.description(description)
|
||||||
.footer(CreateEmbedFooter::new(ctx.cache().current_user().name.to_string()).icon_url(ctx.cache().current_user().face()));
|
.timestamp(timestamp)
|
||||||
|
.footer(CreateEmbedFooter::new(ctx.cache().current_user().name.to_string()).icon_url(ctx.cache().current_user().face()));
|
||||||
Ok(embed)
|
|
||||||
}
|
Ok(embed)
|
||||||
|
}
|
||||||
async fn generate_playlist_embed(ctx: Context<'_>, sources: Vec<YoutubeDl>) -> Result<CreateEmbed, Error> {
|
|
||||||
let src = sources.get(0).unwrap();
|
async fn generate_playlist_embed(ctx: Context<'_>, track: TrackHandle, queue_length: usize) -> Result<CreateEmbed, Error> {
|
||||||
|
let meta_typemap = track.typemap().read().await;
|
||||||
let metadata = src.clone().aux_metadata().await.unwrap();
|
let metadata = meta_typemap.get::<Metadata>().unwrap();
|
||||||
let AuxMetadata {title, thumbnail, source_url, artist, duration, ..} = metadata;
|
let AuxMetadata {title, thumbnail, source_url, artist, duration, ..} = metadata;
|
||||||
let timestamp = Timestamp::now();
|
let timestamp = Timestamp::now();
|
||||||
let duration_minutes = duration.unwrap_or(Duration::new(0, 0)).clone().as_secs() / 60;
|
let duration_minutes = duration.unwrap_or(Duration::new(0, 0)).clone().as_secs() / 60;
|
||||||
let duration_seconds = duration.unwrap_or(Duration::new(0, 0)).clone().as_secs() % 60;
|
let duration_seconds = duration.unwrap_or(Duration::new(0, 0)).clone().as_secs() % 60;
|
||||||
|
|
||||||
let description = format!("Enqueued tracks: {}", sources.len() - 1);
|
let description = format!("Enqueued tracks: {}", queue_length - 1);
|
||||||
|
|
||||||
let embed = CreateEmbed::default()
|
let embed = CreateEmbed::default()
|
||||||
.author(CreateEmbedAuthor::new("Playlist enqueued").icon_url(ctx.author().clone().face()))
|
.author(CreateEmbedAuthor::new("Playlist enqueued").icon_url(ctx.author().clone().face()))
|
||||||
.colour(Colour::from_rgb(255, 58, 97))
|
.colour(Colour::from_rgb(255, 58, 97))
|
||||||
.title(title.unwrap())
|
.title(title.as_ref().unwrap())
|
||||||
.url(source_url.unwrap())
|
.url(source_url.as_ref().unwrap())
|
||||||
.thumbnail(thumbnail.unwrap_or(ctx.cache().current_user().face()))
|
.thumbnail(thumbnail.as_ref().unwrap_or(&ctx.cache().current_user().face()))
|
||||||
.field("Artist", artist.unwrap_or("Unknown Artist".to_string()), true)
|
.field("Artist", artist.as_ref().unwrap_or(&"Unknown Artist".to_string()), true)
|
||||||
.field("Duration", format!("{:02}:{:02}", duration_minutes, duration_seconds), true)
|
.field("Duration", format!("{:02}:{:02}", duration_minutes, duration_seconds), true)
|
||||||
.field("DJ", ctx.author().name.clone(), true)
|
.field("DJ", ctx.author().name.clone(), true)
|
||||||
.description(description)
|
.description(description)
|
||||||
.timestamp(timestamp)
|
.timestamp(timestamp)
|
||||||
.footer(CreateEmbedFooter::new(ctx.cache().current_user().name.to_string()).icon_url(ctx.cache().current_user().face()));
|
.footer(CreateEmbedFooter::new(ctx.cache().current_user().name.to_string()).icon_url(ctx.cache().current_user().face()));
|
||||||
|
|||||||
@@ -1,5 +1,11 @@
|
|||||||
|
use std::time::Duration;
|
||||||
|
|
||||||
use crate::{commands::embeds::error_embed, Context, Error};
|
use crate::{commands::embeds::error_embed, Context, Error};
|
||||||
|
use crate::commands::music::metadata::Metadata;
|
||||||
use poise::CreateReply;
|
use poise::CreateReply;
|
||||||
|
use serenity::{builder::{CreateEmbedAuthor, CreateEmbedFooter}, model::{Colour, Timestamp}};
|
||||||
|
use poise::serenity_prelude::CreateEmbed;
|
||||||
|
use songbird::input::AuxMetadata;
|
||||||
|
|
||||||
/// Shows next tracks in queue; \
|
/// Shows next tracks in queue; \
|
||||||
/// aliases: queue, q
|
/// aliases: queue, q
|
||||||
@@ -22,20 +28,31 @@ pub async fn queue(
|
|||||||
if let Some(handler_lock) = manager.get(guild_id) {
|
if let Some(handler_lock) = manager.get(guild_id) {
|
||||||
let handler = handler_lock.lock().await;
|
let handler = handler_lock.lock().await;
|
||||||
let queue = handler.queue();
|
let queue = handler.queue();
|
||||||
let mut queue_res = String::from("Queue: \n");
|
let mut queue_res = String::from("");
|
||||||
|
|
||||||
|
for (index, song) in queue.current_queue().iter().enumerate() {
|
||||||
|
let meta_typemap = song.typemap().read().await;
|
||||||
|
let metadata = meta_typemap.get::<Metadata>().unwrap();
|
||||||
|
let AuxMetadata { title, artist, duration, ..} = metadata;
|
||||||
|
|
||||||
|
let duration_minutes = duration.unwrap_or(Duration::new(0, 0)).clone().as_secs() / 60;
|
||||||
|
let duration_seconds = duration.unwrap_or(Duration::new(0, 0)).clone().as_secs() % 60;
|
||||||
|
|
||||||
|
// println!("{:?}", metadata.clone());
|
||||||
|
|
||||||
for (i, song) in queue.current_queue().iter().enumerate() {
|
|
||||||
queue_res.push_str(&format!(
|
queue_res.push_str(&format!(
|
||||||
"{}. {} - {}\n",
|
"{}. {} - {} [{:02}:{:02}] \n",
|
||||||
i + 1,
|
index,
|
||||||
song.uuid(),
|
title.as_ref().unwrap(),
|
||||||
"Artist"
|
artist.as_ref().unwrap(),
|
||||||
// song.metadata().artist.clone().unwrap_or_else(|| String::from("Unknown"))
|
duration_minutes,
|
||||||
|
duration_seconds
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
ctx.say(queue_res).await?;
|
ctx.send(
|
||||||
|
CreateReply::default().embed(embed(ctx, queue_res).await.unwrap())
|
||||||
|
).await?;
|
||||||
} else {
|
} else {
|
||||||
let msg = "I am not in a voice channel!";
|
let msg = "I am not in a voice channel!";
|
||||||
ctx.send(
|
ctx.send(
|
||||||
@@ -45,3 +62,19 @@ pub async fn queue(
|
|||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async fn embed(ctx: Context<'_>, queue: String) -> Result<CreateEmbed, Error> {
|
||||||
|
|
||||||
|
let title = "Now playing";
|
||||||
|
let timestamp = Timestamp::now();
|
||||||
|
|
||||||
|
let embed = CreateEmbed::default()
|
||||||
|
.author(CreateEmbedAuthor::new("Queue").icon_url(ctx.author().clone().face()))
|
||||||
|
.colour(Colour::from_rgb(255, 58, 97))
|
||||||
|
.title(title)
|
||||||
|
.description(queue)
|
||||||
|
.timestamp(timestamp)
|
||||||
|
.footer(CreateEmbedFooter::new(ctx.cache().current_user().name.to_string()).icon_url(ctx.cache().current_user().face()));
|
||||||
|
|
||||||
|
Ok(embed)
|
||||||
|
}
|
||||||
|
|||||||
0
src/commands/music/seek.rs
Normal file
0
src/commands/music/seek.rs
Normal file
0
src/commands/music/shuffle.rs
Normal file
0
src/commands/music/shuffle.rs
Normal file
0
src/commands/music/soundboard.rs
Normal file
0
src/commands/music/soundboard.rs
Normal file
0
src/commands/music/soundboard/effect.rs
Normal file
0
src/commands/music/soundboard/effect.rs
Normal file
0
src/commands/music/soundboard/override.rs
Normal file
0
src/commands/music/soundboard/override.rs
Normal file
0
src/commands/music/volume.rs
Normal file
0
src/commands/music/volume.rs
Normal file
@@ -1,7 +1,9 @@
|
|||||||
pub mod ping;
|
pub mod ping;
|
||||||
pub mod register;
|
pub mod register;
|
||||||
pub mod help;
|
pub mod help;
|
||||||
|
pub mod posix;
|
||||||
|
|
||||||
pub use ping::ping;
|
pub use ping::ping;
|
||||||
pub use register::register;
|
pub use register::register;
|
||||||
pub use help::help;
|
pub use help::help;
|
||||||
|
pub use posix::posix;
|
||||||
|
|||||||
0
src/commands/tools/ai.rs
Normal file
0
src/commands/tools/ai.rs
Normal file
0
src/commands/tools/dice.rs
Normal file
0
src/commands/tools/dice.rs
Normal file
0
src/commands/tools/dictionary.rs
Normal file
0
src/commands/tools/dictionary.rs
Normal file
0
src/commands/tools/ip.rs
Normal file
0
src/commands/tools/ip.rs
Normal file
0
src/commands/tools/metar.rs
Normal file
0
src/commands/tools/metar.rs
Normal file
0
src/commands/tools/owoify.rs
Normal file
0
src/commands/tools/owoify.rs
Normal file
23
src/commands/tools/posix.rs
Normal file
23
src/commands/tools/posix.rs
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
use std::time::SystemTime;
|
||||||
|
|
||||||
|
use poise::CreateReply;
|
||||||
|
|
||||||
|
use crate::{commands::embeds::embed, Context, Error};
|
||||||
|
|
||||||
|
/// Prints current time in POSIX format
|
||||||
|
#[poise::command(
|
||||||
|
prefix_command,
|
||||||
|
slash_command,
|
||||||
|
category = "Tools"
|
||||||
|
)]
|
||||||
|
pub async fn posix(
|
||||||
|
ctx: Context<'_>
|
||||||
|
) -> Result<(), Error> {
|
||||||
|
let time = SystemTime::now().duration_since(SystemTime::UNIX_EPOCH).unwrap().as_millis();
|
||||||
|
|
||||||
|
ctx.send(
|
||||||
|
CreateReply::default().embed(embed(ctx, "The time is", &format!("{} ms", time), "since Jan 1st 1970").await.unwrap())
|
||||||
|
).await?;
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
0
src/commands/tools/qr.rs
Normal file
0
src/commands/tools/qr.rs
Normal file
0
src/commands/tools/taf.rs
Normal file
0
src/commands/tools/taf.rs
Normal file
0
src/commands/tools/uptime.rs
Normal file
0
src/commands/tools/uptime.rs
Normal file
0
src/commands/tools/verse.rs
Normal file
0
src/commands/tools/verse.rs
Normal file
0
src/commands/tools/weather.rs
Normal file
0
src/commands/tools/weather.rs
Normal file
@@ -56,6 +56,7 @@ async fn main() {
|
|||||||
tools::ping(),
|
tools::ping(),
|
||||||
tools::register(),
|
tools::register(),
|
||||||
tools::help(),
|
tools::help(),
|
||||||
|
tools::posix(),
|
||||||
];
|
];
|
||||||
|
|
||||||
let options = poise::FrameworkOptions {
|
let options = poise::FrameworkOptions {
|
||||||
|
|||||||
Reference in New Issue
Block a user