mirror of
https://github.com/eRgo35/lyra.git
synced 2026-02-04 20:36:10 +01:00
Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
ee3d9a0c45
|
|||
|
4e92771f8f
|
3
.gitmodules
vendored
Normal file
3
.gitmodules
vendored
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
[submodule "src/spotify-parser"]
|
||||||
|
path = src/spotify-parser
|
||||||
|
url = https://github.com/eRgo35/spotify-parser
|
||||||
22
Cargo.lock
generated
22
Cargo.lock
generated
@@ -902,6 +902,12 @@ dependencies = [
|
|||||||
"wasm-bindgen",
|
"wasm-bindgen",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "json"
|
||||||
|
version = "0.12.4"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "078e285eafdfb6c4b434e0d31e8cfcb5115b651496faca5749b88fafd4f23bfd"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "lazy_static"
|
name = "lazy_static"
|
||||||
version = "1.4.0"
|
version = "1.4.0"
|
||||||
@@ -963,11 +969,14 @@ version = "0.6.0"
|
|||||||
dependencies = [
|
dependencies = [
|
||||||
"dotenv",
|
"dotenv",
|
||||||
"fancy-regex",
|
"fancy-regex",
|
||||||
|
"json",
|
||||||
"openssl",
|
"openssl",
|
||||||
"poise",
|
"poise",
|
||||||
"rand",
|
"rand",
|
||||||
"regex",
|
"regex",
|
||||||
"reqwest",
|
"reqwest",
|
||||||
|
"serde",
|
||||||
|
"serde_json",
|
||||||
"serenity",
|
"serenity",
|
||||||
"songbird",
|
"songbird",
|
||||||
"symphonia",
|
"symphonia",
|
||||||
@@ -975,6 +984,7 @@ dependencies = [
|
|||||||
"tracing",
|
"tracing",
|
||||||
"tracing-futures",
|
"tracing-futures",
|
||||||
"tracing-subscriber",
|
"tracing-subscriber",
|
||||||
|
"url",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@@ -1802,9 +1812,9 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "serde"
|
name = "serde"
|
||||||
version = "1.0.196"
|
version = "1.0.197"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "870026e60fa08c69f064aa766c10f10b1d62db9ccd4d0abb206472bee0ce3b32"
|
checksum = "3fb1c873e1b9b056a4dc4c0c198b24c3ffa059243875552b2bd0933b1aee4ce2"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"serde_derive",
|
"serde_derive",
|
||||||
]
|
]
|
||||||
@@ -1832,9 +1842,9 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "serde_derive"
|
name = "serde_derive"
|
||||||
version = "1.0.196"
|
version = "1.0.197"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "33c85360c95e7d137454dc81d9a4ed2b8efd8fbe19cee57357b32b9771fccb67"
|
checksum = "7eb0b34b42edc17f6b7cac84a52a1c5f0e1bb2227e997ca9011ea3dd34e8610b"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"proc-macro2",
|
"proc-macro2",
|
||||||
"quote",
|
"quote",
|
||||||
@@ -1843,9 +1853,9 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "serde_json"
|
name = "serde_json"
|
||||||
version = "1.0.113"
|
version = "1.0.114"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "69801b70b1c3dac963ecb03a364ba0ceda9cf60c71cfe475e99864759c8b8a79"
|
checksum = "c5f09b1bd632ef549eaa9f60a1f8de742bdbc698e6cee2095fc84dde5f549ae0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"itoa",
|
"itoa",
|
||||||
"ryu",
|
"ryu",
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "lyra"
|
name = "lyra"
|
||||||
version = "0.6.0"
|
version = "0.7.0"
|
||||||
authors = ["Michał Czyż <mike@c2yz.com>"]
|
authors = ["Michał Czyż <mike@c2yz.com>"]
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
description = "A featureful Discord bot written in Rust."
|
description = "A featureful Discord bot written in Rust."
|
||||||
@@ -14,11 +14,14 @@ keywords = ["discord", "bot", "rust", "music", "featureful"]
|
|||||||
[dependencies]
|
[dependencies]
|
||||||
dotenv = "0.15.0"
|
dotenv = "0.15.0"
|
||||||
fancy-regex = "0.13.0"
|
fancy-regex = "0.13.0"
|
||||||
|
json = "0.12.4"
|
||||||
openssl = { version = "0.10.63", features = ["vendored"] }
|
openssl = { version = "0.10.63", features = ["vendored"] }
|
||||||
poise = "0.6.1"
|
poise = "0.6.1"
|
||||||
rand = "0.8.5"
|
rand = "0.8.5"
|
||||||
regex = "1.10.3"
|
regex = "1.10.3"
|
||||||
reqwest = "0.11.23"
|
reqwest = { version = "0.11.23", features = ["json"]}
|
||||||
|
serde = { version = "1.0.197", features = ["derive"] }
|
||||||
|
serde_json = "1.0.114"
|
||||||
serenity = { version = "0.12.0", features = ["cache", "framework", "standard_framework", "voice"] }
|
serenity = { version = "0.12.0", features = ["cache", "framework", "standard_framework", "voice"] }
|
||||||
songbird = { version = "0.4.0", features = ["builtin-queue", "serenity"] }
|
songbird = { version = "0.4.0", features = ["builtin-queue", "serenity"] }
|
||||||
symphonia = { version = "0.5.3", features = ["aac", "adpcm", "alac", "flac", "mpa", "isomp4"] }
|
symphonia = { version = "0.5.3", features = ["aac", "adpcm", "alac", "flac", "mpa", "isomp4"] }
|
||||||
@@ -26,3 +29,4 @@ tokio = { version = "1.35.1", features = ["macros", "full", "signal"] }
|
|||||||
tracing = "0.1.40"
|
tracing = "0.1.40"
|
||||||
tracing-futures = "0.2.5"
|
tracing-futures = "0.2.5"
|
||||||
tracing-subscriber = "0.3.18"
|
tracing-subscriber = "0.3.18"
|
||||||
|
url = "2.5.0"
|
||||||
|
|||||||
@@ -28,6 +28,5 @@ pub use resume::resume;
|
|||||||
pub use seek::seek;
|
pub use seek::seek;
|
||||||
pub use shuffle::shuffle;
|
pub use shuffle::shuffle;
|
||||||
pub use skip::skip;
|
pub use skip::skip;
|
||||||
pub use soundboard::soundboard;
|
|
||||||
pub use stop::stop;
|
pub use stop::stop;
|
||||||
pub use volume::volume;
|
pub use volume::volume;
|
||||||
|
|||||||
@@ -42,9 +42,12 @@ pub async fn play(
|
|||||||
r"^((?:https?:)\/\/)?((?:www|m)\.)?((?:youtube\.com)).*(youtu.be\/|list=)([^#&?]*).*",
|
r"^((?:https?:)\/\/)?((?:www|m)\.)?((?:youtube\.com)).*(youtu.be\/|list=)([^#&?]*).*",
|
||||||
)
|
)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
let regex_spotify_playlist = Regex::new(r"https?:\/\/(?:embed\.|open\.)(?:spotify\.com\/)(?:(album|playlist)\/|\?uri=spotify:playlist:)((\w|-)+)(?:(?=\?)(?:[?&]foo=(\d*)(?=[&#]|$)|(?![?&]foo=)[^#])+)?(?=#|$)").unwrap();
|
||||||
|
|
||||||
let is_playlist = regex_youtube_playlist.is_match(&song).unwrap();
|
let is_playlist = regex_youtube_playlist.is_match(&song).unwrap()
|
||||||
let is_spotify = regex_spotify.is_match(&song).unwrap();
|
|| regex_spotify_playlist.is_match(&song).unwrap();
|
||||||
|
let is_spotify =
|
||||||
|
regex_spotify.is_match(&song).unwrap() || regex_spotify_playlist.is_match(&song).unwrap();
|
||||||
let is_query = !song.starts_with("http");
|
let is_query = !song.starts_with("http");
|
||||||
|
|
||||||
let guild_id = ctx.guild_id().unwrap();
|
let guild_id = ctx.guild_id().unwrap();
|
||||||
@@ -83,6 +86,43 @@ pub async fn play(
|
|||||||
|
|
||||||
handler.add_global_event(TrackEvent::Error.into(), TrackErrorNotifier);
|
handler.add_global_event(TrackEvent::Error.into(), TrackErrorNotifier);
|
||||||
|
|
||||||
|
if is_playlist && is_spotify {
|
||||||
|
let raw_list = Command::new("node")
|
||||||
|
.args(["./src/spotify-parser", &song])
|
||||||
|
.output()
|
||||||
|
.expect("failed to execute process")
|
||||||
|
.stdout;
|
||||||
|
let list = String::from_utf8(raw_list.clone()).expect("Invalid UTF-8");
|
||||||
|
|
||||||
|
let tracks: Vec<String> = list.split("\n").map(str::to_string).collect();
|
||||||
|
|
||||||
|
for (index, url) in tracks.clone().iter().enumerate() {
|
||||||
|
if url.is_empty() {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
let src = YoutubeDl::new_ytdl_like(
|
||||||
|
"yt-dlp",
|
||||||
|
http_client.clone(),
|
||||||
|
format!("ytsearch:{}", 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);
|
||||||
|
|
||||||
|
if index == 0 {
|
||||||
|
let embed = generate_playlist_embed(ctx, track, tracks.len()).await;
|
||||||
|
let response = CreateReply::default().embed(embed.unwrap());
|
||||||
|
ctx.send(response).await?;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return Ok(());
|
||||||
|
}
|
||||||
|
|
||||||
if is_playlist {
|
if is_playlist {
|
||||||
let raw_list = Command::new("yt-dlp")
|
let raw_list = Command::new("yt-dlp")
|
||||||
.args(["-j", "--flat-playlist", &song])
|
.args(["-j", "--flat-playlist", &song])
|
||||||
@@ -98,6 +138,9 @@ pub async fn play(
|
|||||||
.collect();
|
.collect();
|
||||||
|
|
||||||
for (index, url) in urls.clone().iter().enumerate() {
|
for (index, url) in urls.clone().iter().enumerate() {
|
||||||
|
if url.is_empty() {
|
||||||
|
break;
|
||||||
|
}
|
||||||
let src = YoutubeDl::new_ytdl_like("yt-dlp", http_client.clone(), url.to_string());
|
let src = YoutubeDl::new_ytdl_like("yt-dlp", http_client.clone(), url.to_string());
|
||||||
let aux_metadata = src.clone().aux_metadata().await.unwrap();
|
let aux_metadata = src.clone().aux_metadata().await.unwrap();
|
||||||
let track = handler.enqueue_input(src.clone().into()).await;
|
let track = handler.enqueue_input(src.clone().into()).await;
|
||||||
@@ -113,37 +156,37 @@ pub async fn play(
|
|||||||
ctx.send(response).await?;
|
ctx.send(response).await?;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
if is_spotify {
|
|
||||||
let exec = format!("node ./src/spotify --url {}", song);
|
|
||||||
let query = Command::new("sh")
|
|
||||||
.arg("-c")
|
|
||||||
.arg(exec)
|
|
||||||
.output()
|
|
||||||
.expect("failed to execute process")
|
|
||||||
.stdout;
|
|
||||||
let query_str = String::from_utf8(query.clone()).expect("Invalid UTF-8");
|
|
||||||
song = format!("ytsearch:{}", query_str.to_string());
|
|
||||||
}
|
|
||||||
|
|
||||||
if is_query {
|
return Ok(());
|
||||||
song = format!("ytsearch:{}", song);
|
|
||||||
}
|
|
||||||
|
|
||||||
let src = YoutubeDl::new_ytdl_like("yt-dlp", http_client, song);
|
|
||||||
let embed = generate_embed(ctx, src.clone(), handler.queue()).await;
|
|
||||||
let response = CreateReply::default().embed(embed.unwrap());
|
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if is_spotify {
|
||||||
|
let query = Command::new("node")
|
||||||
|
.args(["./src/spotify-parser", &song])
|
||||||
|
.output()
|
||||||
|
.expect("failed to execute process")
|
||||||
|
.stdout;
|
||||||
|
let query_str = String::from_utf8(query.clone()).expect("Invalid UTF-8");
|
||||||
|
song = format!("ytsearch:{}", query_str.to_string());
|
||||||
|
}
|
||||||
|
|
||||||
|
if is_query {
|
||||||
|
song = format!("ytsearch:{}", song);
|
||||||
|
}
|
||||||
|
|
||||||
|
let src = YoutubeDl::new_ytdl_like("yt-dlp", http_client, song);
|
||||||
|
let embed = generate_embed(ctx, src.clone(), handler.queue()).await;
|
||||||
|
let response = CreateReply::default().embed(embed.unwrap());
|
||||||
|
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(())
|
||||||
@@ -166,7 +209,7 @@ async fn generate_embed(
|
|||||||
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());
|
let mut description = format!("Song added to queue @ {}", queue.len() + 1);
|
||||||
|
|
||||||
if queue.len() == 0 {
|
if queue.len() == 0 {
|
||||||
description = format!("Playing now!");
|
description = format!("Playing now!");
|
||||||
|
|||||||
@@ -10,6 +10,8 @@ use serenity::{
|
|||||||
};
|
};
|
||||||
use songbird::input::AuxMetadata;
|
use songbird::input::AuxMetadata;
|
||||||
|
|
||||||
|
const QUEUE_DISPLAY_LENGTH: usize = 10;
|
||||||
|
|
||||||
/// Shows next tracks in queue; \
|
/// Shows next tracks in queue; \
|
||||||
/// aliases: queue, q
|
/// aliases: queue, q
|
||||||
#[poise::command(prefix_command, slash_command, aliases("q"), category = "Music")]
|
#[poise::command(prefix_command, slash_command, aliases("q"), category = "Music")]
|
||||||
@@ -25,8 +27,9 @@ pub async fn queue(ctx: Context<'_>) -> Result<(), Error> {
|
|||||||
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("");
|
let mut queue_res = String::from("");
|
||||||
|
let mut too_long = false;
|
||||||
|
|
||||||
for (index, song) in queue.current_queue().iter().enumerate() {
|
for (index, song) in queue.clone().current_queue().iter().enumerate() {
|
||||||
let meta_typemap = song.typemap().read().await;
|
let meta_typemap = song.typemap().read().await;
|
||||||
let metadata = meta_typemap.get::<Metadata>().unwrap();
|
let metadata = meta_typemap.get::<Metadata>().unwrap();
|
||||||
let AuxMetadata {
|
let AuxMetadata {
|
||||||
@@ -39,8 +42,6 @@ pub async fn queue(ctx: Context<'_>) -> Result<(), Error> {
|
|||||||
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;
|
||||||
|
|
||||||
// println!("{:?}", metadata.clone());
|
|
||||||
|
|
||||||
queue_res.push_str(&format!(
|
queue_res.push_str(&format!(
|
||||||
"{}. {} - {} [{:02}:{:02}] \n",
|
"{}. {} - {} [{:02}:{:02}] \n",
|
||||||
index,
|
index,
|
||||||
@@ -49,6 +50,17 @@ pub async fn queue(ctx: Context<'_>) -> Result<(), Error> {
|
|||||||
duration_minutes,
|
duration_minutes,
|
||||||
duration_seconds
|
duration_seconds
|
||||||
));
|
));
|
||||||
|
|
||||||
|
if index + 1 == QUEUE_DISPLAY_LENGTH {
|
||||||
|
too_long = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if too_long {
|
||||||
|
queue_res.push_str(&format!(
|
||||||
|
"and {} more...",
|
||||||
|
queue.len() - QUEUE_DISPLAY_LENGTH
|
||||||
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
ctx.send(CreateReply::default().embed(embed(ctx, queue_res).await.unwrap()))
|
ctx.send(CreateReply::default().embed(embed(ctx, queue_res).await.unwrap()))
|
||||||
|
|||||||
@@ -1,8 +1,16 @@
|
|||||||
|
use crate::commands::music::metadata::Metadata;
|
||||||
|
use std::time::Duration;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
commands::embeds::{embed, error_embed},
|
commands::embeds::{embed, error_embed},
|
||||||
Context, Error,
|
Context, Error,
|
||||||
};
|
};
|
||||||
use poise::CreateReply;
|
use poise::CreateReply;
|
||||||
|
use serenity::{
|
||||||
|
builder::{CreateEmbed, CreateEmbedAuthor, CreateEmbedFooter},
|
||||||
|
model::{Colour, Timestamp},
|
||||||
|
};
|
||||||
|
use songbird::{input::AuxMetadata, tracks::TrackHandle};
|
||||||
|
|
||||||
/// Skips the currently playing song
|
/// Skips the currently playing song
|
||||||
#[poise::command(prefix_command, slash_command, category = "Music")]
|
#[poise::command(prefix_command, slash_command, category = "Music")]
|
||||||
@@ -17,21 +25,31 @@ pub async fn skip(ctx: Context<'_>) -> Result<(), Error> {
|
|||||||
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 _ = queue.skip();
|
let _ = queue.clone().skip();
|
||||||
|
let track_raw = queue.clone().current_queue();
|
||||||
|
let track = track_raw.get(1);
|
||||||
|
let queue_length = queue.len() - 1;
|
||||||
|
|
||||||
ctx.send(
|
let response;
|
||||||
CreateReply::default().embed(
|
|
||||||
embed(
|
match track {
|
||||||
ctx,
|
Some(track) => {
|
||||||
"Skipped!",
|
response = CreateReply::default().embed(
|
||||||
"Next song: {song}",
|
generate_embed(ctx, track.clone(), queue_length)
|
||||||
&format!("Songs left in queue: {}", queue.len()),
|
.await
|
||||||
)
|
.unwrap(),
|
||||||
.await
|
);
|
||||||
.unwrap(),
|
}
|
||||||
),
|
None => {
|
||||||
)
|
response = CreateReply::default().embed(
|
||||||
.await?;
|
embed(ctx, "Skipped!", "The queue is empty!", "")
|
||||||
|
.await
|
||||||
|
.unwrap(),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
ctx.send(response).await?;
|
||||||
} else {
|
} else {
|
||||||
let msg = "I am not in a voice channel!";
|
let msg = "I am not in a voice channel!";
|
||||||
ctx.send(CreateReply::default().embed(error_embed(ctx, msg).await.unwrap()))
|
ctx.send(CreateReply::default().embed(error_embed(ctx, msg).await.unwrap()))
|
||||||
@@ -40,3 +58,55 @@ pub async fn skip(ctx: Context<'_>) -> Result<(), Error> {
|
|||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async fn generate_embed(
|
||||||
|
ctx: Context<'_>,
|
||||||
|
track: TrackHandle,
|
||||||
|
queue_length: usize,
|
||||||
|
) -> Result<CreateEmbed, Error> {
|
||||||
|
let meta_typemap = track.typemap().read().await;
|
||||||
|
let metadata = meta_typemap.get::<Metadata>().unwrap();
|
||||||
|
let AuxMetadata {
|
||||||
|
title,
|
||||||
|
thumbnail,
|
||||||
|
source_url,
|
||||||
|
artist,
|
||||||
|
duration,
|
||||||
|
..
|
||||||
|
} = metadata;
|
||||||
|
let timestamp = Timestamp::now();
|
||||||
|
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 description = format!("Song skipped! Queue length is {}", queue_length);
|
||||||
|
|
||||||
|
let embed = CreateEmbed::default()
|
||||||
|
.author(CreateEmbedAuthor::new("Skipped!").icon_url(ctx.author().clone().face()))
|
||||||
|
.colour(Colour::from_rgb(255, 58, 97))
|
||||||
|
.title(title.as_ref().unwrap())
|
||||||
|
.url(source_url.as_ref().unwrap())
|
||||||
|
.thumbnail(
|
||||||
|
thumbnail
|
||||||
|
.as_ref()
|
||||||
|
.unwrap_or(&ctx.cache().current_user().face()),
|
||||||
|
)
|
||||||
|
.field(
|
||||||
|
"Artist",
|
||||||
|
artist.as_ref().unwrap_or(&"Unknown Artist".to_string()),
|
||||||
|
true,
|
||||||
|
)
|
||||||
|
.field(
|
||||||
|
"Duration",
|
||||||
|
format!("{:02}:{:02}", duration_minutes, duration_seconds),
|
||||||
|
true,
|
||||||
|
)
|
||||||
|
.field("DJ", ctx.author().name.clone(), true)
|
||||||
|
.description(description)
|
||||||
|
.timestamp(timestamp)
|
||||||
|
.footer(
|
||||||
|
CreateEmbedFooter::new(ctx.cache().current_user().name.to_string())
|
||||||
|
.icon_url(ctx.cache().current_user().face()),
|
||||||
|
);
|
||||||
|
|
||||||
|
Ok(embed)
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,11 +1,5 @@
|
|||||||
use crate::{commands::embeds::embed, Context, Error};
|
pub mod effect;
|
||||||
use poise::CreateReply;
|
pub mod stream;
|
||||||
|
|
||||||
/// A better soundboard
|
pub use effect::effect;
|
||||||
#[poise::command(prefix_command, slash_command, category = "Music")]
|
pub use stream::stream;
|
||||||
pub async fn soundboard(ctx: Context<'_>) -> Result<(), Error> {
|
|
||||||
ctx.send(CreateReply::default().embed(embed(ctx, "", "", "").await.unwrap()))
|
|
||||||
.await?;
|
|
||||||
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -0,0 +1,11 @@
|
|||||||
|
use crate::{commands::embeds::embed, Context, Error};
|
||||||
|
use poise::CreateReply;
|
||||||
|
|
||||||
|
/// Plays one of available audio effects
|
||||||
|
#[poise::command(prefix_command, slash_command, category = "Music")]
|
||||||
|
pub async fn effect(ctx: Context<'_>) -> Result<(), Error> {
|
||||||
|
ctx.send(CreateReply::default().embed(embed(ctx, "Playing an effect", "", "").await.unwrap()))
|
||||||
|
.await?;
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|||||||
11
src/commands/music/soundboard/stream.rs
Normal file
11
src/commands/music/soundboard/stream.rs
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
use crate::{commands::embeds::embed, Context, Error};
|
||||||
|
use poise::CreateReply;
|
||||||
|
|
||||||
|
/// Hijacks current audio output and plays selected audio
|
||||||
|
#[poise::command(prefix_command, slash_command, aliases("override"), category = "Music")]
|
||||||
|
pub async fn stream(ctx: Context<'_>) -> Result<(), Error> {
|
||||||
|
ctx.send(CreateReply::default().embed(embed(ctx, "Playing audio", "", "").await.unwrap()))
|
||||||
|
.await?;
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
@@ -10,7 +10,7 @@ pub mod posix;
|
|||||||
pub mod qr;
|
pub mod qr;
|
||||||
pub mod register;
|
pub mod register;
|
||||||
pub mod taf;
|
pub mod taf;
|
||||||
pub mod uptime;
|
// pub mod uptime;
|
||||||
pub mod verse;
|
pub mod verse;
|
||||||
pub mod weather;
|
pub mod weather;
|
||||||
|
|
||||||
@@ -26,6 +26,6 @@ pub use posix::posix;
|
|||||||
pub use qr::qr;
|
pub use qr::qr;
|
||||||
pub use register::register;
|
pub use register::register;
|
||||||
pub use taf::taf;
|
pub use taf::taf;
|
||||||
pub use uptime::uptime;
|
// pub use uptime::uptime;
|
||||||
pub use verse::verse;
|
pub use verse::verse;
|
||||||
pub use weather::weather;
|
pub use weather::weather;
|
||||||
|
|||||||
@@ -1,12 +1,48 @@
|
|||||||
use poise::CreateReply;
|
use poise::CreateReply;
|
||||||
|
use serenity::{
|
||||||
|
builder::{CreateEmbed, CreateEmbedAuthor, CreateEmbedFooter},
|
||||||
|
model::{Colour, Timestamp},
|
||||||
|
};
|
||||||
|
|
||||||
use crate::{commands::embeds::embed, Context, Error};
|
use crate::{Context, Error};
|
||||||
|
use url::form_urlencoded;
|
||||||
|
|
||||||
/// Creates a qr code from text
|
/// Creates a qr code from text
|
||||||
#[poise::command(prefix_command, slash_command, category = "Tools")]
|
#[poise::command(prefix_command, slash_command, category = "Tools")]
|
||||||
pub async fn qr(ctx: Context<'_>) -> Result<(), Error> {
|
pub async fn qr(
|
||||||
ctx.send(CreateReply::default().embed(embed(ctx, "", "", "").await.unwrap()))
|
ctx: Context<'_>,
|
||||||
.await?;
|
#[description = "Message to encode"]
|
||||||
|
#[rest]
|
||||||
|
message: String,
|
||||||
|
) -> Result<(), Error> {
|
||||||
|
let response = CreateReply::default().embed(generate_embed(ctx, message).await.unwrap());
|
||||||
|
ctx.send(response).await?;
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async fn generate_embed(ctx: Context<'_>, message: String) -> Result<CreateEmbed, Error> {
|
||||||
|
let timestamp = Timestamp::now();
|
||||||
|
let data: String = form_urlencoded::byte_serialize(message.as_bytes()).collect();
|
||||||
|
let url = format!(
|
||||||
|
"http://api.qrserver.com/v1/create-qr-code/?data={}&size=1000x1000&ecc=Q&margin=8",
|
||||||
|
data
|
||||||
|
);
|
||||||
|
|
||||||
|
let embed = CreateEmbed::default()
|
||||||
|
.author(
|
||||||
|
CreateEmbedAuthor::new("Your message as a QR Code!")
|
||||||
|
.icon_url(ctx.author().clone().face()),
|
||||||
|
)
|
||||||
|
.colour(Colour::from_rgb(255, 58, 97))
|
||||||
|
.title("Your QR Code:")
|
||||||
|
.url(url.clone())
|
||||||
|
.image(url)
|
||||||
|
.timestamp(timestamp)
|
||||||
|
.footer(
|
||||||
|
CreateEmbedFooter::new(ctx.cache().current_user().name.to_string())
|
||||||
|
.icon_url(ctx.cache().current_user().face()),
|
||||||
|
);
|
||||||
|
|
||||||
|
Ok(embed)
|
||||||
|
}
|
||||||
|
|||||||
@@ -2,11 +2,34 @@ use poise::CreateReply;
|
|||||||
|
|
||||||
use crate::{commands::embeds::embed, Context, Error};
|
use crate::{commands::embeds::embed, Context, Error};
|
||||||
|
|
||||||
|
// Currently unable to get information on how long the thread was running.
|
||||||
|
const PROCESS_UPTIME: i64 = 1000;
|
||||||
|
|
||||||
/// Checks how long the bot has been running
|
/// Checks how long the bot has been running
|
||||||
#[poise::command(prefix_command, slash_command, category = "Tools")]
|
#[poise::command(prefix_command, slash_command, category = "Tools")]
|
||||||
pub async fn uptime(ctx: Context<'_>) -> Result<(), Error> {
|
pub async fn uptime(ctx: Context<'_>) -> Result<(), Error> {
|
||||||
ctx.send(CreateReply::default().embed(embed(ctx, "", "", "").await.unwrap()))
|
let uptime = PROCESS_UPTIME;
|
||||||
.await?;
|
let days = uptime / (24 * 60 * 60);
|
||||||
|
let hours = (uptime % (24 * 60 * 60)) / 3600;
|
||||||
|
let minutes = (uptime % 60 * 60) / 60;
|
||||||
|
let seconds = uptime % 60;
|
||||||
|
|
||||||
|
ctx.send(
|
||||||
|
CreateReply::default().embed(
|
||||||
|
embed(
|
||||||
|
ctx,
|
||||||
|
"I have been up and awake for",
|
||||||
|
&format!("{} seconds", uptime),
|
||||||
|
&format!(
|
||||||
|
"{} days, {} hours, {} minutes and {} seconds",
|
||||||
|
days, hours, minutes, seconds
|
||||||
|
),
|
||||||
|
)
|
||||||
|
.await
|
||||||
|
.unwrap(),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
.await?;
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,12 +1,78 @@
|
|||||||
|
use crate::{
|
||||||
|
commands::embeds::{embed, error_embed},
|
||||||
|
Context, Error,
|
||||||
|
};
|
||||||
use poise::CreateReply;
|
use poise::CreateReply;
|
||||||
|
use serde::{Deserialize, Serialize};
|
||||||
use crate::{commands::embeds::embed, Context, Error};
|
use url::form_urlencoded;
|
||||||
|
|
||||||
/// Reference Bible by verse
|
/// Reference Bible by verse
|
||||||
#[poise::command(prefix_command, slash_command, category = "Tools")]
|
#[poise::command(prefix_command, slash_command, category = "Tools")]
|
||||||
pub async fn verse(ctx: Context<'_>) -> Result<(), Error> {
|
pub async fn verse(
|
||||||
ctx.send(CreateReply::default().embed(embed(ctx, "", "", "").await.unwrap()))
|
ctx: Context<'_>,
|
||||||
.await?;
|
#[description = "Latin?"]
|
||||||
|
#[flag]
|
||||||
|
latin: bool,
|
||||||
|
#[description = "BOOK+CHAPTER:VERSE"]
|
||||||
|
#[rest]
|
||||||
|
verse: String,
|
||||||
|
) -> Result<(), Error> {
|
||||||
|
let data: String = form_urlencoded::byte_serialize(verse.as_bytes()).collect();
|
||||||
|
let translation = if latin { "clementine" } else { "web" };
|
||||||
|
let client = reqwest::Client::new();
|
||||||
|
let response = client
|
||||||
|
.get(format!(
|
||||||
|
"https://bible-api.com/{}?translation={}",
|
||||||
|
data, translation
|
||||||
|
))
|
||||||
|
.send()
|
||||||
|
.await
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
|
match response.status() {
|
||||||
|
reqwest::StatusCode::OK => {
|
||||||
|
match response.json::<APIResponse>().await {
|
||||||
|
Ok(parsed) => {
|
||||||
|
if parsed.text.len() > 4000 {
|
||||||
|
ctx.send(
|
||||||
|
CreateReply::default()
|
||||||
|
.embed(error_embed(ctx, "Quoted text is too long!").await.unwrap()),
|
||||||
|
)
|
||||||
|
.await?;
|
||||||
|
return Ok(());
|
||||||
|
}
|
||||||
|
ctx.send(
|
||||||
|
CreateReply::default().embed(
|
||||||
|
embed(
|
||||||
|
ctx,
|
||||||
|
&parsed.translation_name,
|
||||||
|
&parsed.text,
|
||||||
|
&parsed.reference,
|
||||||
|
)
|
||||||
|
.await
|
||||||
|
.unwrap(),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
.await?;
|
||||||
|
}
|
||||||
|
Err(err) => println!("Something is messed up! {:?}", err),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
reqwest::StatusCode::UNAUTHORIZED => {
|
||||||
|
println!("Unauthorized.. Uoops!!");
|
||||||
|
}
|
||||||
|
error => {
|
||||||
|
println!("Something went wrong: {:?}", error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Serialize, Deserialize, Debug)]
|
||||||
|
struct APIResponse {
|
||||||
|
reference: String,
|
||||||
|
text: String,
|
||||||
|
translation_name: String,
|
||||||
|
translation_note: String,
|
||||||
|
}
|
||||||
|
|||||||
@@ -4,7 +4,12 @@ use crate::{commands::embeds::embed, Context, Error};
|
|||||||
|
|
||||||
/// Shows weather for provided location
|
/// Shows weather for provided location
|
||||||
#[poise::command(prefix_command, slash_command, category = "Tools")]
|
#[poise::command(prefix_command, slash_command, category = "Tools")]
|
||||||
pub async fn weather(ctx: Context<'_>) -> Result<(), Error> {
|
pub async fn weather(
|
||||||
|
ctx: Context<'_>,
|
||||||
|
#[description = "Provide a city name"]
|
||||||
|
#[rest]
|
||||||
|
_location: String,
|
||||||
|
) -> Result<(), Error> {
|
||||||
ctx.send(CreateReply::default().embed(embed(ctx, "", "", "").await.unwrap()))
|
ctx.send(CreateReply::default().embed(embed(ctx, "", "", "").await.unwrap()))
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
|
|||||||
@@ -55,9 +55,10 @@ async fn main() {
|
|||||||
music::seek(),
|
music::seek(),
|
||||||
music::shuffle(),
|
music::shuffle(),
|
||||||
music::skip(),
|
music::skip(),
|
||||||
music::soundboard(),
|
|
||||||
music::stop(),
|
music::stop(),
|
||||||
music::volume(),
|
music::volume(),
|
||||||
|
music::soundboard::effect(),
|
||||||
|
music::soundboard::stream(),
|
||||||
tools::ai(),
|
tools::ai(),
|
||||||
tools::dice(),
|
tools::dice(),
|
||||||
tools::dictionary(),
|
tools::dictionary(),
|
||||||
@@ -70,7 +71,7 @@ async fn main() {
|
|||||||
tools::qr(),
|
tools::qr(),
|
||||||
tools::register(),
|
tools::register(),
|
||||||
tools::taf(),
|
tools::taf(),
|
||||||
tools::uptime(),
|
// tools::uptime(),
|
||||||
tools::verse(),
|
tools::verse(),
|
||||||
tools::weather(),
|
tools::weather(),
|
||||||
];
|
];
|
||||||
|
|||||||
Submodule src/spotify deleted from ea246e9ed2
1
src/spotify-parser
Submodule
1
src/spotify-parser
Submodule
Submodule src/spotify-parser added at e3b3c0fb6e
Reference in New Issue
Block a user