mirror of
https://github.com/eRgo35/lyra.git
synced 2026-02-04 12:26:10 +01:00
Compare commits
6 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
4e92771f8f
|
|||
|
8a947926f7
|
|||
|
639fd7775f
|
|||
|
8fa86b0182
|
|||
|
d75c5bc9a2
|
|||
|
21822405c0
|
2
.env.example
Normal file
2
.env.example
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
DISCORD_TOKEN=<YOUR_DISCORD_TOKEN>
|
||||||
|
PREFIX=<YOUR_PREFIX>
|
||||||
1
.gitignore
vendored
1
.gitignore
vendored
@@ -1,2 +1,3 @@
|
|||||||
/target
|
/target
|
||||||
.env
|
.env
|
||||||
|
|
||||||
|
|||||||
81
Cargo.lock
generated
81
Cargo.lock
generated
@@ -124,6 +124,21 @@ version = "0.21.7"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "9d297deb1925b89f2ccc13d7635fa0714f12c87adce1c75356b39ca9b7178567"
|
checksum = "9d297deb1925b89f2ccc13d7635fa0714f12c87adce1c75356b39ca9b7178567"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "bit-set"
|
||||||
|
version = "0.5.3"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "0700ddab506f33b20a03b13996eccd309a48e5ff77d0d95926aa0210fb4e95f1"
|
||||||
|
dependencies = [
|
||||||
|
"bit-vec",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "bit-vec"
|
||||||
|
version = "0.6.3"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "349f9b6a179ed607305526ca489b34ad0a41aed5f7980fa90eb03160b69598fb"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "bitflags"
|
name = "bitflags"
|
||||||
version = "1.3.2"
|
version = "1.3.2"
|
||||||
@@ -476,6 +491,17 @@ dependencies = [
|
|||||||
"version_check",
|
"version_check",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "fancy-regex"
|
||||||
|
version = "0.13.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "531e46835a22af56d1e3b66f04844bed63158bc094a628bec1d321d9b4c44bf2"
|
||||||
|
dependencies = [
|
||||||
|
"bit-set",
|
||||||
|
"regex-automata 0.4.5",
|
||||||
|
"regex-syntax 0.8.2",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "fastrand"
|
name = "fastrand"
|
||||||
version = "2.0.1"
|
version = "2.0.1"
|
||||||
@@ -933,11 +959,13 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "lyra"
|
name = "lyra"
|
||||||
version = "0.4.0"
|
version = "0.6.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"dotenv",
|
"dotenv",
|
||||||
|
"fancy-regex",
|
||||||
"openssl",
|
"openssl",
|
||||||
"poise",
|
"poise",
|
||||||
|
"rand",
|
||||||
"regex",
|
"regex",
|
||||||
"reqwest",
|
"reqwest",
|
||||||
"serenity",
|
"serenity",
|
||||||
@@ -2067,10 +2095,14 @@ checksum = "62e48dba70095f265fdb269b99619b95d04c89e619538138383e63310b14d941"
|
|||||||
dependencies = [
|
dependencies = [
|
||||||
"lazy_static",
|
"lazy_static",
|
||||||
"symphonia-bundle-flac",
|
"symphonia-bundle-flac",
|
||||||
|
"symphonia-bundle-mp3",
|
||||||
|
"symphonia-codec-aac",
|
||||||
"symphonia-codec-adpcm",
|
"symphonia-codec-adpcm",
|
||||||
|
"symphonia-codec-alac",
|
||||||
"symphonia-codec-pcm",
|
"symphonia-codec-pcm",
|
||||||
"symphonia-codec-vorbis",
|
"symphonia-codec-vorbis",
|
||||||
"symphonia-core",
|
"symphonia-core",
|
||||||
|
"symphonia-format-isomp4",
|
||||||
"symphonia-format-mkv",
|
"symphonia-format-mkv",
|
||||||
"symphonia-format-ogg",
|
"symphonia-format-ogg",
|
||||||
"symphonia-format-wav",
|
"symphonia-format-wav",
|
||||||
@@ -2089,6 +2121,30 @@ dependencies = [
|
|||||||
"symphonia-utils-xiph",
|
"symphonia-utils-xiph",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "symphonia-bundle-mp3"
|
||||||
|
version = "0.5.3"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "0f31d7fece546f1e6973011a9eceae948133bbd18fd3d52f6073b1e38ae6368a"
|
||||||
|
dependencies = [
|
||||||
|
"bitflags 1.3.2",
|
||||||
|
"lazy_static",
|
||||||
|
"log",
|
||||||
|
"symphonia-core",
|
||||||
|
"symphonia-metadata",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "symphonia-codec-aac"
|
||||||
|
version = "0.5.3"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "68bdd75b25ce4b84b12a4bd20bfea2460c2dbd7fc1d227ef5533504d3168109d"
|
||||||
|
dependencies = [
|
||||||
|
"lazy_static",
|
||||||
|
"log",
|
||||||
|
"symphonia-core",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "symphonia-codec-adpcm"
|
name = "symphonia-codec-adpcm"
|
||||||
version = "0.5.3"
|
version = "0.5.3"
|
||||||
@@ -2099,6 +2155,16 @@ dependencies = [
|
|||||||
"symphonia-core",
|
"symphonia-core",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "symphonia-codec-alac"
|
||||||
|
version = "0.5.3"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "3a27e8763d1c9eff666faf903e73a99d4de2f7a93fca4e3c214c1d68432903b9"
|
||||||
|
dependencies = [
|
||||||
|
"log",
|
||||||
|
"symphonia-core",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "symphonia-codec-pcm"
|
name = "symphonia-codec-pcm"
|
||||||
version = "0.5.3"
|
version = "0.5.3"
|
||||||
@@ -2133,6 +2199,19 @@ dependencies = [
|
|||||||
"log",
|
"log",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "symphonia-format-isomp4"
|
||||||
|
version = "0.5.3"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "ffdf14bae5cf352032416bc64151e5d6242d29d33cbf3238513b44d4427a1efb"
|
||||||
|
dependencies = [
|
||||||
|
"encoding_rs",
|
||||||
|
"log",
|
||||||
|
"symphonia-core",
|
||||||
|
"symphonia-metadata",
|
||||||
|
"symphonia-utils-xiph",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "symphonia-format-mkv"
|
name = "symphonia-format-mkv"
|
||||||
version = "0.5.3"
|
version = "0.5.3"
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "lyra"
|
name = "lyra"
|
||||||
version = "0.4.0"
|
version = "0.6.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."
|
||||||
@@ -13,13 +13,15 @@ keywords = ["discord", "bot", "rust", "music", "featureful"]
|
|||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
dotenv = "0.15.0"
|
dotenv = "0.15.0"
|
||||||
|
fancy-regex = "0.13.0"
|
||||||
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"
|
||||||
regex = "1.10.3"
|
regex = "1.10.3"
|
||||||
reqwest = "0.11.23"
|
reqwest = "0.11.23"
|
||||||
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 = "0.5.3"
|
symphonia = { version = "0.5.3", features = ["aac", "adpcm", "alac", "flac", "mpa", "isomp4"] }
|
||||||
tokio = { version = "1.35.1", features = ["macros", "full", "signal"] }
|
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"
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
pub mod embeds;
|
||||||
pub mod kashi;
|
pub mod kashi;
|
||||||
pub mod music;
|
pub mod music;
|
||||||
pub mod tools;
|
pub mod tools;
|
||||||
|
|||||||
58
src/commands/embeds.rs
Normal file
58
src/commands/embeds.rs
Normal file
@@ -0,0 +1,58 @@
|
|||||||
|
use crate::{Context, Error};
|
||||||
|
|
||||||
|
use poise::serenity_prelude::CreateEmbed;
|
||||||
|
use poise::CreateReply;
|
||||||
|
use serenity::{
|
||||||
|
builder::{CreateEmbedAuthor, CreateEmbedFooter},
|
||||||
|
model::{Colour, Timestamp},
|
||||||
|
};
|
||||||
|
|
||||||
|
pub async fn fail(ctx: Context<'_>, err: String) -> Result<(), Error> {
|
||||||
|
ctx.send(
|
||||||
|
CreateReply::default().embed(
|
||||||
|
error_embed(ctx, &format!("Failed: {:?}", err))
|
||||||
|
.await
|
||||||
|
.unwrap(),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
.await?;
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
pub async fn error_embed(ctx: Context<'_>, msg: &str) -> Result<CreateEmbed, Error> {
|
||||||
|
let embed = CreateEmbed::default()
|
||||||
|
.author(
|
||||||
|
CreateEmbedAuthor::new("Something went wrong!").icon_url(ctx.author().clone().face()),
|
||||||
|
)
|
||||||
|
.colour(Colour::from_rgb(255, 58, 97))
|
||||||
|
.title("Oopsie, Doopsie!")
|
||||||
|
.description(msg)
|
||||||
|
.timestamp(Timestamp::now())
|
||||||
|
.footer(
|
||||||
|
CreateEmbedFooter::new(ctx.cache().current_user().name.to_string())
|
||||||
|
.icon_url(ctx.cache().current_user().face()),
|
||||||
|
);
|
||||||
|
|
||||||
|
Ok(embed)
|
||||||
|
}
|
||||||
|
|
||||||
|
pub async fn embed(
|
||||||
|
ctx: Context<'_>,
|
||||||
|
author: &str,
|
||||||
|
description: &str,
|
||||||
|
title: &str,
|
||||||
|
) -> Result<CreateEmbed, Error> {
|
||||||
|
let embed = CreateEmbed::default()
|
||||||
|
.author(CreateEmbedAuthor::new(author).icon_url(ctx.author().clone().face()))
|
||||||
|
.colour(Colour::from_rgb(255, 58, 97))
|
||||||
|
.title(title)
|
||||||
|
.description(description)
|
||||||
|
.timestamp(Timestamp::now())
|
||||||
|
.footer(
|
||||||
|
CreateEmbedFooter::new(ctx.cache().current_user().name.to_string())
|
||||||
|
.icon_url(ctx.cache().current_user().face()),
|
||||||
|
);
|
||||||
|
|
||||||
|
Ok(embed)
|
||||||
|
}
|
||||||
@@ -1,7 +1,14 @@
|
|||||||
use crate::{Context, Error};
|
use crate::{Context, Error};
|
||||||
|
|
||||||
#[poise::command(prefix_command, slash_command)]
|
/// Kashi integration platform (WIP)
|
||||||
pub async fn kashi(ctx: Context<'_>) -> Result<(), Error> {
|
#[poise::command(
|
||||||
|
prefix_command,
|
||||||
|
slash_command,
|
||||||
|
category = "Kashi"
|
||||||
|
)]
|
||||||
|
pub async fn kashi(
|
||||||
|
ctx: Context<'_>
|
||||||
|
) -> Result<(), Error> {
|
||||||
|
|
||||||
let response = format!("Kashi platform is currently under construction!");
|
let response = format!("Kashi platform is currently under construction!");
|
||||||
ctx.say(response).await?;
|
ctx.say(response).await?;
|
||||||
|
|||||||
@@ -1,3 +0,0 @@
|
|||||||
pub mod kashi;
|
|
||||||
pub mod music;
|
|
||||||
pub mod tools;
|
|
||||||
@@ -1,15 +1,20 @@
|
|||||||
pub mod deafen;
|
pub mod deafen;
|
||||||
pub mod join;
|
pub mod join;
|
||||||
pub mod leave;
|
pub mod leave;
|
||||||
pub mod misc;
|
pub mod metadata;
|
||||||
pub mod mute;
|
pub mod mute;
|
||||||
|
pub mod notifier;
|
||||||
pub mod pause;
|
pub mod pause;
|
||||||
pub mod play;
|
pub mod play;
|
||||||
pub mod queue;
|
pub mod queue;
|
||||||
pub mod repeat;
|
pub mod repeat;
|
||||||
pub mod resume;
|
pub mod resume;
|
||||||
|
pub mod seek;
|
||||||
|
pub mod shuffle;
|
||||||
pub mod skip;
|
pub mod skip;
|
||||||
|
pub mod soundboard;
|
||||||
pub mod stop;
|
pub mod stop;
|
||||||
|
pub mod volume;
|
||||||
|
|
||||||
pub use deafen::deafen;
|
pub use deafen::deafen;
|
||||||
pub use join::join;
|
pub use join::join;
|
||||||
@@ -20,5 +25,8 @@ pub use play::play;
|
|||||||
pub use queue::queue;
|
pub use queue::queue;
|
||||||
pub use repeat::repeat;
|
pub use repeat::repeat;
|
||||||
pub use resume::resume;
|
pub use resume::resume;
|
||||||
|
pub use seek::seek;
|
||||||
|
pub use shuffle::shuffle;
|
||||||
pub use skip::skip;
|
pub use skip::skip;
|
||||||
pub use stop::stop;
|
pub use stop::stop;
|
||||||
|
pub use volume::volume;
|
||||||
|
|||||||
@@ -1,6 +1,17 @@
|
|||||||
use crate::{Context, Error};
|
use crate::{
|
||||||
|
commands::embeds::{embed, error_embed, fail},
|
||||||
|
Context, Error,
|
||||||
|
};
|
||||||
|
use poise::CreateReply;
|
||||||
|
|
||||||
#[poise::command(prefix_command, slash_command)]
|
/// Deafens itself while in a voice channel; \
|
||||||
|
/// aliases: deafen, undeaden, shuush
|
||||||
|
#[poise::command(
|
||||||
|
prefix_command,
|
||||||
|
slash_command,
|
||||||
|
aliases("shuush", "undeafen"),
|
||||||
|
category = "Music"
|
||||||
|
)]
|
||||||
pub async fn deafen(ctx: Context<'_>) -> Result<(), Error> {
|
pub async fn deafen(ctx: Context<'_>) -> Result<(), Error> {
|
||||||
let guild_id = ctx.guild_id().unwrap();
|
let guild_id = ctx.guild_id().unwrap();
|
||||||
|
|
||||||
@@ -12,7 +23,9 @@ pub async fn deafen(ctx: Context<'_>) -> Result<(), Error> {
|
|||||||
let handler_lock = match manager.get(guild_id) {
|
let handler_lock = match manager.get(guild_id) {
|
||||||
Some(handler) => handler,
|
Some(handler) => handler,
|
||||||
None => {
|
None => {
|
||||||
ctx.say("Not in a voice channel").await?;
|
let msg = "I am not in a voice channel!";
|
||||||
|
ctx.send(CreateReply::default().embed(error_embed(ctx, msg).await.unwrap()))
|
||||||
|
.await?;
|
||||||
|
|
||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
@@ -22,16 +35,18 @@ pub async fn deafen(ctx: Context<'_>) -> Result<(), Error> {
|
|||||||
|
|
||||||
if handler.is_deaf() {
|
if handler.is_deaf() {
|
||||||
if let Err(err) = handler.deafen(false).await {
|
if let Err(err) = handler.deafen(false).await {
|
||||||
ctx.say(format!("Failed: {:?}", err)).await?;
|
fail(ctx, err.to_string()).await.unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
ctx.say("Undeafened").await?;
|
ctx.send(CreateReply::default().embed(embed(ctx, "Undeafened!", "", "").await.unwrap()))
|
||||||
|
.await?;
|
||||||
} else {
|
} else {
|
||||||
if let Err(err) = handler.deafen(true).await {
|
if let Err(err) = handler.deafen(true).await {
|
||||||
ctx.say(format!("Failed: {:?}", err)).await?;
|
fail(ctx, err.to_string()).await.unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
ctx.say("Deafened").await?;
|
ctx.send(CreateReply::default().embed(embed(ctx, "Deafened!", "", "").await.unwrap()))
|
||||||
|
.await?;
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
|
|||||||
@@ -1,16 +1,28 @@
|
|||||||
use crate::{Context, Error};
|
use crate::commands::music::notifier::TrackErrorNotifier;
|
||||||
|
use crate::{
|
||||||
|
commands::embeds::{embed, error_embed},
|
||||||
|
Context, Error,
|
||||||
|
};
|
||||||
|
use poise::CreateReply;
|
||||||
use songbird::TrackEvent;
|
use songbird::TrackEvent;
|
||||||
use crate::commands::music::misc::TrackErrorNotifier;
|
|
||||||
|
|
||||||
#[poise::command(prefix_command, slash_command)]
|
/// Joins your voice channel
|
||||||
|
#[poise::command(prefix_command, slash_command, category = "Music")]
|
||||||
pub async fn join(ctx: Context<'_>) -> Result<(), Error> {
|
pub async fn join(ctx: Context<'_>) -> Result<(), Error> {
|
||||||
let guild_id = ctx.guild_id().unwrap();
|
let guild_id = ctx.guild_id().unwrap();
|
||||||
let channel_id = ctx.guild().unwrap().voice_states.get(&ctx.author().id).and_then(|voice_state| voice_state.channel_id);
|
let channel_id = ctx
|
||||||
|
.guild()
|
||||||
|
.unwrap()
|
||||||
|
.voice_states
|
||||||
|
.get(&ctx.author().id)
|
||||||
|
.and_then(|voice_state| voice_state.channel_id);
|
||||||
|
|
||||||
let connect_to = match channel_id {
|
let connect_to = match channel_id {
|
||||||
Some(channel) => channel,
|
Some(channel) => channel,
|
||||||
None => {
|
None => {
|
||||||
ctx.say("Not in a voice channel").await?;
|
let msg = "I am not in a voice channel!";
|
||||||
|
ctx.send(CreateReply::default().embed(error_embed(ctx, msg).await.unwrap()))
|
||||||
|
.await?;
|
||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@@ -25,7 +37,8 @@ pub async fn join(ctx: Context<'_>) -> Result<(), Error> {
|
|||||||
handler.add_global_event(TrackEvent::Error.into(), TrackErrorNotifier);
|
handler.add_global_event(TrackEvent::Error.into(), TrackErrorNotifier);
|
||||||
}
|
}
|
||||||
|
|
||||||
ctx.say("Joined the voice channel").await?;
|
ctx.send(CreateReply::default().embed(embed(ctx, "Joined!", "Hi there!", "").await.unwrap()))
|
||||||
|
.await?;
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,17 @@
|
|||||||
use crate::{Context, Error};
|
use crate::{
|
||||||
|
commands::embeds::{embed, error_embed, fail},
|
||||||
|
Context, Error,
|
||||||
|
};
|
||||||
|
use poise::CreateReply;
|
||||||
|
|
||||||
#[poise::command(prefix_command, slash_command)]
|
/// Leaves the voice channel; \
|
||||||
|
/// aliases: leave, qa!
|
||||||
|
#[poise::command(
|
||||||
|
prefix_command,
|
||||||
|
slash_command,
|
||||||
|
aliases("leave", "qa!"),
|
||||||
|
category = "Music"
|
||||||
|
)]
|
||||||
pub async fn leave(ctx: Context<'_>) -> Result<(), Error> {
|
pub async fn leave(ctx: Context<'_>) -> Result<(), Error> {
|
||||||
let guild_id = ctx.guild_id().unwrap();
|
let guild_id = ctx.guild_id().unwrap();
|
||||||
|
|
||||||
@@ -10,15 +21,25 @@ pub async fn leave(ctx: Context<'_>) -> Result<(), Error> {
|
|||||||
.clone();
|
.clone();
|
||||||
|
|
||||||
if !manager.get(guild_id).is_some() {
|
if !manager.get(guild_id).is_some() {
|
||||||
ctx.say("Not in a voice channel").await?;
|
let msg = "I am not in a voice channel!";
|
||||||
return Ok(())
|
ctx.send(CreateReply::default().embed(error_embed(ctx, msg).await.unwrap()))
|
||||||
|
.await?;
|
||||||
|
|
||||||
|
return Ok(());
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Err(err) = manager.remove(guild_id).await {
|
if let Err(err) = manager.remove(guild_id).await {
|
||||||
ctx.say(format!("Failed: {:?}", err)).await?;
|
fail(ctx, err.to_string()).await.unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
ctx.say("Left voice channel").await?;
|
ctx.send(
|
||||||
|
CreateReply::default().embed(
|
||||||
|
embed(ctx, "Left!", "I left the voice channel", "")
|
||||||
|
.await
|
||||||
|
.unwrap(),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
.await?;
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|||||||
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,6 +1,17 @@
|
|||||||
use crate::{Context, Error};
|
use crate::{
|
||||||
|
commands::embeds::{embed, error_embed, fail},
|
||||||
|
Context, Error,
|
||||||
|
};
|
||||||
|
use poise::CreateReply;
|
||||||
|
|
||||||
#[poise::command(prefix_command, slash_command)]
|
/// Mutes itself while in a voice channel; \
|
||||||
|
/// aliases: mute, unmute, shhh
|
||||||
|
#[poise::command(
|
||||||
|
prefix_command,
|
||||||
|
slash_command,
|
||||||
|
aliases("shhh", "unmute"),
|
||||||
|
category = "Music"
|
||||||
|
)]
|
||||||
pub async fn mute(ctx: Context<'_>) -> Result<(), Error> {
|
pub async fn mute(ctx: Context<'_>) -> Result<(), Error> {
|
||||||
let guild_id = ctx.guild_id().unwrap();
|
let guild_id = ctx.guild_id().unwrap();
|
||||||
|
|
||||||
@@ -12,26 +23,29 @@ pub async fn mute(ctx: Context<'_>) -> Result<(), Error> {
|
|||||||
let handler_lock = match manager.get(guild_id) {
|
let handler_lock = match manager.get(guild_id) {
|
||||||
Some(handler) => handler,
|
Some(handler) => handler,
|
||||||
None => {
|
None => {
|
||||||
ctx.say("Not in a voice channel").await?;
|
let msg = "I am not in a voice channel!";
|
||||||
|
ctx.send(CreateReply::default().embed(error_embed(ctx, msg).await.unwrap()))
|
||||||
|
.await?;
|
||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
let mut handler = handler_lock.lock().await;
|
let mut handler = handler_lock.lock().await;
|
||||||
|
|
||||||
if handler.is_mute() {
|
if handler.is_mute() {
|
||||||
if let Err(e) = handler.mute(false).await {
|
if let Err(err) = handler.mute(false).await {
|
||||||
ctx.say(format!("failed: {:?}", e)).await?;
|
fail(ctx, err.to_string()).await.unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
ctx.say("Unmuted").await?;
|
ctx.send(CreateReply::default().embed(embed(ctx, "Unmuted!", "", "").await.unwrap()))
|
||||||
|
.await?;
|
||||||
} else {
|
} else {
|
||||||
if let Err(err) = handler.mute(true).await {
|
if let Err(err) = handler.mute(true).await {
|
||||||
ctx.say(format!("Failed: {:?}", err)).await?;
|
fail(ctx, err.to_string()).await.unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
ctx.say("Muted").await?;
|
ctx.send(CreateReply::default().embed(embed(ctx, "Muted!", "", "").await.unwrap()))
|
||||||
|
.await?;
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
|
|||||||
@@ -1,6 +1,11 @@
|
|||||||
use crate::{Context, Error};
|
use crate::{
|
||||||
|
commands::embeds::{embed, error_embed},
|
||||||
|
Context, Error,
|
||||||
|
};
|
||||||
|
use poise::CreateReply;
|
||||||
|
|
||||||
#[poise::command(prefix_command, slash_command)]
|
/// Pauses the currently playing song
|
||||||
|
#[poise::command(prefix_command, slash_command, category = "Music")]
|
||||||
pub async fn pause(ctx: Context<'_>) -> Result<(), Error> {
|
pub async fn pause(ctx: Context<'_>) -> Result<(), Error> {
|
||||||
let guild_id = ctx.guild_id().unwrap();
|
let guild_id = ctx.guild_id().unwrap();
|
||||||
|
|
||||||
@@ -14,9 +19,18 @@ pub async fn pause(ctx: Context<'_>) -> Result<(), Error> {
|
|||||||
let queue = handler.queue();
|
let queue = handler.queue();
|
||||||
let _ = queue.pause();
|
let _ = queue.pause();
|
||||||
|
|
||||||
ctx.say(format!("Song paused.")).await?;
|
ctx.send(
|
||||||
|
CreateReply::default().embed(
|
||||||
|
embed(ctx, "Paused!", "Currently playing song is now paused!", "")
|
||||||
|
.await
|
||||||
|
.unwrap(),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
.await?;
|
||||||
} else {
|
} else {
|
||||||
ctx.say("Not in a voice channel to play in").await?;
|
let msg = "I am not in a voice channel!";
|
||||||
|
ctx.send(CreateReply::default().embed(error_embed(ctx, msg).await.unwrap()))
|
||||||
|
.await?;
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
|
|||||||
@@ -1,46 +1,66 @@
|
|||||||
use crate::{Context, Error};
|
use crate::commands::music::metadata::Metadata;
|
||||||
|
use crate::{commands::embeds::error_embed, Context, Error};
|
||||||
|
|
||||||
use fancy_regex::Regex;
|
use fancy_regex::Regex;
|
||||||
use regex::Regex as Regex_Classic;
|
|
||||||
use std::process::Command;
|
|
||||||
use std::time::Duration;
|
|
||||||
use poise::CreateReply;
|
|
||||||
use poise::serenity_prelude::CreateEmbed;
|
|
||||||
use poise::serenity_prelude::Colour;
|
|
||||||
use poise::serenity_prelude::model::Timestamp;
|
use poise::serenity_prelude::model::Timestamp;
|
||||||
|
use poise::serenity_prelude::Colour;
|
||||||
|
use poise::serenity_prelude::CreateEmbed;
|
||||||
|
use poise::CreateReply;
|
||||||
|
use regex::Regex as Regex_Classic;
|
||||||
use serenity::builder::CreateEmbedAuthor;
|
use serenity::builder::CreateEmbedAuthor;
|
||||||
use serenity::builder::CreateEmbedFooter;
|
use serenity::builder::CreateEmbedFooter;
|
||||||
|
use songbird::events::TrackEvent;
|
||||||
use songbird::input::AuxMetadata;
|
use songbird::input::AuxMetadata;
|
||||||
use songbird::input::{Compose, YoutubeDl};
|
use songbird::input::{Compose, YoutubeDl};
|
||||||
use songbird::events::TrackEvent;
|
use songbird::tracks::{TrackHandle, TrackQueue};
|
||||||
|
use std::process::Command;
|
||||||
|
use std::time::Duration;
|
||||||
|
|
||||||
use crate::commands::music::misc::TrackErrorNotifier;
|
use crate::commands::music::notifier::TrackErrorNotifier;
|
||||||
use crate::http::HttpKey;
|
use crate::http::HttpKey;
|
||||||
|
|
||||||
|
/// Plays a song; \
|
||||||
|
/// you can search by query or paste an url; \
|
||||||
|
/// aliases: play, p, enqueue
|
||||||
#[poise::command(
|
#[poise::command(
|
||||||
prefix_command,
|
prefix_command,
|
||||||
slash_command,
|
slash_command,
|
||||||
aliases("p", "enqueue")
|
aliases("p", "enqueue"),
|
||||||
|
category = "Music"
|
||||||
)]
|
)]
|
||||||
pub async fn play(
|
pub async fn play(
|
||||||
ctx: Context<'_>,
|
ctx: Context<'_>,
|
||||||
#[description = "Provide a query or an url"] #[rest] mut song: String,
|
#[description = "Provide a query or an url"]
|
||||||
|
#[rest]
|
||||||
|
mut song: String,
|
||||||
) -> Result<(), Error> {
|
) -> Result<(), Error> {
|
||||||
let regex_spotify = Regex::new(r"https?:\/\/(?:embed\.|open\.)(?:spotify\.com\/)(?:track\/|\?uri=spotify:track:)((\w|-)+)(?:(?=\?)(?:[?&]foo=(\d*)(?=[&#]|$)|(?![?&]foo=)[^#])+)?(?=#|$)").unwrap();
|
let regex_spotify = Regex::new(r"https?:\/\/(?:embed\.|open\.)(?:spotify\.com\/)(?:track\/|\?uri=spotify:track:)((\w|-)+)(?:(?=\?)(?:[?&]foo=(\d*)(?=[&#]|$)|(?![?&]foo=)[^#])+)?(?=#|$)").unwrap();
|
||||||
let regex_youtube = Regex_Classic::new(r#""url": "(https://www.youtube.com/watch\?v=[A-Za-z0-9]{11})""#).unwrap();
|
let regex_youtube =
|
||||||
let regex_youtube_playlist = Regex::new(r"^((?:https?:)\/\/)?((?:www|m)\.)?((?:youtube\.com)).*(youtu.be\/|list=)([^#&?]*).*").unwrap();
|
Regex_Classic::new(r#""url": "(https://www.youtube.com/watch\?v=[A-Za-z0-9]{11})""#)
|
||||||
|
.unwrap();
|
||||||
|
let regex_youtube_playlist = Regex::new(
|
||||||
|
r"^((?:https?:)\/\/)?((?:www|m)\.)?((?:youtube\.com)).*(youtu.be\/|list=)([^#&?]*).*",
|
||||||
|
)
|
||||||
|
.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();
|
let is_spotify = regex_spotify.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();
|
||||||
let channel_id = ctx.guild().unwrap().voice_states.get(&ctx.author().id).and_then(|voice_state| voice_state.channel_id);
|
let channel_id = ctx
|
||||||
|
.guild()
|
||||||
|
.unwrap()
|
||||||
|
.voice_states
|
||||||
|
.get(&ctx.author().id)
|
||||||
|
.and_then(|voice_state| voice_state.channel_id);
|
||||||
|
|
||||||
let connect_to = match channel_id {
|
let connect_to = match channel_id {
|
||||||
Some(channel) => channel,
|
Some(channel) => channel,
|
||||||
None => {
|
None => {
|
||||||
ctx.say("Not in a voice channel").await?;
|
let msg = "I am not in a voice channel!";
|
||||||
|
ctx.send(CreateReply::default().embed(error_embed(ctx, msg).await.unwrap()))
|
||||||
|
.await?;
|
||||||
|
|
||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
@@ -68,54 +88,89 @@ pub async fn play(
|
|||||||
.args(["-j", "--flat-playlist", &song])
|
.args(["-j", "--flat-playlist", &song])
|
||||||
.output()
|
.output()
|
||||||
.expect("failed to execute process")
|
.expect("failed to execute process")
|
||||||
.stdout;
|
.stdout;
|
||||||
|
|
||||||
let list = String::from_utf8(raw_list.clone()).expect("Invalid UTF-8");
|
let list = String::from_utf8(raw_list.clone()).expect("Invalid UTF-8");
|
||||||
|
|
||||||
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)
|
||||||
let mut sources: Vec<YoutubeDl> = vec![];
|
.map(|capture| capture[1].to_string())
|
||||||
|
.collect();
|
||||||
|
|
||||||
for url in urls {
|
for (index, url) in urls.clone().iter().enumerate() {
|
||||||
let src = YoutubeDl::new_ytdl_like("yt-dlp", http_client.clone(), url);
|
let src = YoutubeDl::new_ytdl_like("yt-dlp", http_client.clone(), url.to_string());
|
||||||
let _ = handler.enqueue_input(src.clone().into()).await;
|
let aux_metadata = src.clone().aux_metadata().await.unwrap();
|
||||||
sources.push(src);
|
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, urls.len()).await;
|
||||||
|
let response = CreateReply::default().embed(embed.unwrap());
|
||||||
|
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);
|
||||||
let query = Command::new("sh").arg("-c").arg(exec).output().expect("failed to execute process").stdout;
|
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");
|
let query_str = String::from_utf8(query.clone()).expect("Invalid UTF-8");
|
||||||
song = format!("ytsearch:{}", query_str.to_string());
|
song = format!("ytsearch:{}", query_str.to_string());
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if is_query {
|
if is_query {
|
||||||
song = format!("ytsearch:{}", song);
|
song = format!("ytsearch:{}", song);
|
||||||
}
|
}
|
||||||
|
|
||||||
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()))
|
||||||
@@ -123,38 +178,75 @@ async fn generate_embed(ctx: Context<'_>, src: YoutubeDl) -> Result<CreateEmbed,
|
|||||||
.title(title.unwrap())
|
.title(title.unwrap())
|
||||||
.url(source_url.unwrap())
|
.url(source_url.unwrap())
|
||||||
.thumbnail(thumbnail.unwrap_or(ctx.cache().current_user().face()))
|
.thumbnail(thumbnail.unwrap_or(ctx.cache().current_user().face()))
|
||||||
.field("Artist", artist.unwrap_or("Unknown Artist".to_string()), true)
|
.field(
|
||||||
.field("Duration", format!("{:02}:{:02}", duration_minutes, duration_seconds), true)
|
"Artist",
|
||||||
|
artist.unwrap_or("Unknown Artist".to_string()),
|
||||||
|
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)
|
||||||
.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()),
|
||||||
|
);
|
||||||
|
|
||||||
Ok(embed)
|
Ok(embed)
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn generate_playlist_embed(ctx: Context<'_>, sources: Vec<YoutubeDl>) -> Result<CreateEmbed, Error> {
|
async fn generate_playlist_embed(
|
||||||
let src = sources.get(0).unwrap();
|
ctx: Context<'_>,
|
||||||
|
track: TrackHandle,
|
||||||
let metadata = src.clone().aux_metadata().await.unwrap();
|
queue_length: usize,
|
||||||
let AuxMetadata {title, thumbnail, source_url, artist, duration, ..} = metadata;
|
) -> 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 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(
|
||||||
.field("Artist", artist.unwrap_or("Unknown Artist".to_string()), true)
|
thumbnail
|
||||||
.field("Duration", format!("{:02}:{:02}", duration_minutes, duration_seconds), true)
|
.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)
|
.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()),
|
||||||
|
);
|
||||||
|
|
||||||
Ok(embed)
|
Ok(embed)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,9 +1,21 @@
|
|||||||
use crate::{Context, Error};
|
use std::time::Duration;
|
||||||
|
|
||||||
#[poise::command(prefix_command, slash_command)]
|
use crate::commands::music::metadata::Metadata;
|
||||||
|
use crate::{commands::embeds::error_embed, Context, Error};
|
||||||
|
use poise::serenity_prelude::CreateEmbed;
|
||||||
|
use poise::CreateReply;
|
||||||
|
use serenity::{
|
||||||
|
builder::{CreateEmbedAuthor, CreateEmbedFooter},
|
||||||
|
model::{Colour, Timestamp},
|
||||||
|
};
|
||||||
|
use songbird::input::AuxMetadata;
|
||||||
|
|
||||||
|
/// Shows next tracks in queue; \
|
||||||
|
/// aliases: queue, q
|
||||||
|
#[poise::command(prefix_command, slash_command, aliases("q"), category = "Music")]
|
||||||
pub async fn queue(ctx: Context<'_>) -> Result<(), Error> {
|
pub async fn queue(ctx: Context<'_>) -> Result<(), Error> {
|
||||||
let guild_id = ctx.guild_id().unwrap();
|
let guild_id = ctx.guild_id().unwrap();
|
||||||
|
|
||||||
let manager = songbird::get(&ctx.serenity_context())
|
let manager = songbird::get(&ctx.serenity_context())
|
||||||
.await
|
.await
|
||||||
.expect("Songbird client placed at init")
|
.expect("Songbird client placed at init")
|
||||||
@@ -12,23 +24,58 @@ pub async fn queue(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 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 {
|
||||||
ctx.say("Not in a voice channel!").await?;
|
let msg = "I am not in a voice channel!";
|
||||||
|
ctx.send(CreateReply::default().embed(error_embed(ctx, msg).await.unwrap()))
|
||||||
|
.await?;
|
||||||
}
|
}
|
||||||
|
|
||||||
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)
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,8 +1,24 @@
|
|||||||
use crate::{Context, Error};
|
use crate::{
|
||||||
|
commands::embeds::{embed, error_embed},
|
||||||
|
Context, Error,
|
||||||
|
};
|
||||||
|
use poise::CreateReply;
|
||||||
use songbird::tracks::LoopState;
|
use songbird::tracks::LoopState;
|
||||||
|
|
||||||
#[poise::command(prefix_command, slash_command)]
|
/// Loops currently playing song provided amount of times; \
|
||||||
pub async fn repeat(ctx: Context<'_>, times: usize) -> Result<(), Error> {
|
/// aliases: repeat, loop, while, for
|
||||||
|
#[poise::command(
|
||||||
|
prefix_command,
|
||||||
|
slash_command,
|
||||||
|
aliases("loop", "while", "for"),
|
||||||
|
category = "Music"
|
||||||
|
)]
|
||||||
|
pub async fn repeat(
|
||||||
|
ctx: Context<'_>,
|
||||||
|
#[description = "How many times"]
|
||||||
|
#[rest]
|
||||||
|
times: usize,
|
||||||
|
) -> Result<(), Error> {
|
||||||
let guild_id = ctx.guild_id().unwrap();
|
let guild_id = ctx.guild_id().unwrap();
|
||||||
|
|
||||||
let manager = songbird::get(&ctx.serenity_context())
|
let manager = songbird::get(&ctx.serenity_context())
|
||||||
@@ -10,7 +26,6 @@ pub async fn repeat(ctx: Context<'_>, times: usize) -> Result<(), Error> {
|
|||||||
.expect("Songbird client placed at init")
|
.expect("Songbird client placed at init")
|
||||||
.clone();
|
.clone();
|
||||||
|
|
||||||
|
|
||||||
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();
|
||||||
@@ -22,21 +37,53 @@ pub async fn repeat(ctx: Context<'_>, times: usize) -> Result<(), Error> {
|
|||||||
LoopState::Infinite => {
|
LoopState::Infinite => {
|
||||||
let _ = queue.current().unwrap().disable_loop();
|
let _ = queue.current().unwrap().disable_loop();
|
||||||
|
|
||||||
ctx.say("Song unlooped.").await?;
|
ctx.send(
|
||||||
|
CreateReply::default()
|
||||||
|
.embed(embed(ctx, "Song Unlooped!", "", "").await.unwrap()),
|
||||||
|
)
|
||||||
|
.await?;
|
||||||
}
|
}
|
||||||
LoopState::Finite(_) => {
|
LoopState::Finite(_) => {
|
||||||
if times < 100 {
|
if times == 0 {
|
||||||
|
let _ = queue.current().unwrap().disable_loop();
|
||||||
|
|
||||||
|
ctx.send(
|
||||||
|
CreateReply::default()
|
||||||
|
.embed(embed(ctx, "Song Unlooped!", "", "").await.unwrap()),
|
||||||
|
)
|
||||||
|
.await?;
|
||||||
|
} else if times < 100 {
|
||||||
let _ = queue.current().unwrap().loop_for(times);
|
let _ = queue.current().unwrap().loop_for(times);
|
||||||
ctx.say("Song looped forever (a very long time)").await?;
|
ctx.send(
|
||||||
}
|
CreateReply::default().embed(
|
||||||
else {
|
embed(
|
||||||
|
ctx,
|
||||||
|
&format!("Song looped {} times!", times),
|
||||||
|
"You definitelly love this song!",
|
||||||
|
"",
|
||||||
|
)
|
||||||
|
.await
|
||||||
|
.unwrap(),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
.await?;
|
||||||
|
} else {
|
||||||
let _ = queue.current().unwrap().enable_loop();
|
let _ = queue.current().unwrap().enable_loop();
|
||||||
ctx.say(format!("Song looped {} times.", times)).await?;
|
ctx.send(
|
||||||
|
CreateReply::default().embed(
|
||||||
|
embed(ctx, "Song looped forever!", "A very long time!", "")
|
||||||
|
.await
|
||||||
|
.unwrap(),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
.await?;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
ctx.say("Not in a voice channel to play in").await?;
|
let msg = "I am not in a voice channel!";
|
||||||
|
ctx.send(CreateReply::default().embed(error_embed(ctx, msg).await.unwrap()))
|
||||||
|
.await?;
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
|
|||||||
@@ -1,6 +1,11 @@
|
|||||||
use crate::{Context, Error};
|
use crate::{
|
||||||
|
commands::embeds::{embed, error_embed},
|
||||||
|
Context, Error,
|
||||||
|
};
|
||||||
|
use poise::CreateReply;
|
||||||
|
|
||||||
#[poise::command(prefix_command, slash_command)]
|
/// Resumes currently paused song
|
||||||
|
#[poise::command(prefix_command, slash_command, category = "Music")]
|
||||||
pub async fn resume(ctx: Context<'_>) -> Result<(), Error> {
|
pub async fn resume(ctx: Context<'_>) -> Result<(), Error> {
|
||||||
let guild_id = ctx.guild_id().unwrap();
|
let guild_id = ctx.guild_id().unwrap();
|
||||||
|
|
||||||
@@ -15,8 +20,18 @@ pub async fn resume(ctx: Context<'_>) -> Result<(), Error> {
|
|||||||
let _ = queue.resume();
|
let _ = queue.resume();
|
||||||
|
|
||||||
ctx.say(format!("Song resumed.")).await?;
|
ctx.say(format!("Song resumed.")).await?;
|
||||||
|
ctx.send(
|
||||||
|
CreateReply::default().embed(
|
||||||
|
embed(ctx, "Resumed!", "Currently paused song is now resumed!", "")
|
||||||
|
.await
|
||||||
|
.unwrap(),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
.await?;
|
||||||
} else {
|
} else {
|
||||||
ctx.say("Not in a voice channel to play in").await?;
|
let msg = "I am not in a voice channel!";
|
||||||
|
ctx.send(CreateReply::default().embed(error_embed(ctx, msg).await.unwrap()))
|
||||||
|
.await?;
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
|
|||||||
11
src/commands/music/seek.rs
Normal file
11
src/commands/music/seek.rs
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
use crate::{commands::embeds::embed, Context, Error};
|
||||||
|
use poise::CreateReply;
|
||||||
|
|
||||||
|
/// Seeks a track by provided seconds
|
||||||
|
#[poise::command(prefix_command, slash_command, category = "Music")]
|
||||||
|
pub async fn seek(ctx: Context<'_>) -> Result<(), Error> {
|
||||||
|
ctx.send(CreateReply::default().embed(embed(ctx, "", "", "").await.unwrap()))
|
||||||
|
.await?;
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
11
src/commands/music/shuffle.rs
Normal file
11
src/commands/music/shuffle.rs
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
use crate::{commands::embeds::embed, Context, Error};
|
||||||
|
use poise::CreateReply;
|
||||||
|
|
||||||
|
/// Shuffles the playlist
|
||||||
|
#[poise::command(prefix_command, slash_command, category = "Music")]
|
||||||
|
pub async fn shuffle(ctx: Context<'_>) -> Result<(), Error> {
|
||||||
|
ctx.send(CreateReply::default().embed(embed(ctx, "", "", "").await.unwrap()))
|
||||||
|
.await?;
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
@@ -1,6 +1,11 @@
|
|||||||
use crate::{Context, Error};
|
use crate::{
|
||||||
|
commands::embeds::{embed, error_embed},
|
||||||
|
Context, Error,
|
||||||
|
};
|
||||||
|
use poise::CreateReply;
|
||||||
|
|
||||||
#[poise::command(prefix_command, slash_command)]
|
/// Skips the currently playing song
|
||||||
|
#[poise::command(prefix_command, slash_command, category = "Music")]
|
||||||
pub async fn skip(ctx: Context<'_>) -> Result<(), Error> {
|
pub async fn skip(ctx: Context<'_>) -> Result<(), Error> {
|
||||||
let guild_id = ctx.guild_id().unwrap();
|
let guild_id = ctx.guild_id().unwrap();
|
||||||
|
|
||||||
@@ -14,9 +19,23 @@ pub async fn skip(ctx: Context<'_>) -> Result<(), Error> {
|
|||||||
let queue = handler.queue();
|
let queue = handler.queue();
|
||||||
let _ = queue.skip();
|
let _ = queue.skip();
|
||||||
|
|
||||||
ctx.say(format!("Song skipped: {} in queue.", queue.len())).await?;
|
ctx.send(
|
||||||
|
CreateReply::default().embed(
|
||||||
|
embed(
|
||||||
|
ctx,
|
||||||
|
"Skipped!",
|
||||||
|
"Next song: {song}",
|
||||||
|
&format!("Songs left in queue: {}", queue.len()),
|
||||||
|
)
|
||||||
|
.await
|
||||||
|
.unwrap(),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
.await?;
|
||||||
} else {
|
} else {
|
||||||
ctx.say("Not in a voice channel to play in").await?;
|
let msg = "I am not in a voice channel!";
|
||||||
|
ctx.send(CreateReply::default().embed(error_embed(ctx, msg).await.unwrap()))
|
||||||
|
.await?;
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
|
|||||||
5
src/commands/music/soundboard.rs
Normal file
5
src/commands/music/soundboard.rs
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
pub mod effect;
|
||||||
|
pub mod stream;
|
||||||
|
|
||||||
|
pub use effect::effect;
|
||||||
|
pub use stream::stream;
|
||||||
11
src/commands/music/soundboard/effect.rs
Normal file
11
src/commands/music/soundboard/effect.rs
Normal file
@@ -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(())
|
||||||
|
}
|
||||||
@@ -1,9 +1,15 @@
|
|||||||
use crate::{Context, Error};
|
use crate::{
|
||||||
|
commands::embeds::{embed, error_embed},
|
||||||
|
Context, Error,
|
||||||
|
};
|
||||||
|
use poise::CreateReply;
|
||||||
|
|
||||||
#[poise::command(prefix_command, slash_command)]
|
/// Stops playback and destroys the queue; \
|
||||||
|
/// aliases: stop, end
|
||||||
|
#[poise::command(prefix_command, slash_command, aliases("end"), category = "Music")]
|
||||||
pub async fn stop(ctx: Context<'_>) -> Result<(), Error> {
|
pub async fn stop(ctx: Context<'_>) -> Result<(), Error> {
|
||||||
let guild_id = ctx.guild_id().unwrap();
|
let guild_id = ctx.guild_id().unwrap();
|
||||||
|
|
||||||
let manager = songbird::get(&ctx.serenity_context())
|
let manager = songbird::get(&ctx.serenity_context())
|
||||||
.await
|
.await
|
||||||
.expect("Songbird client placed at init")
|
.expect("Songbird client placed at init")
|
||||||
@@ -14,10 +20,24 @@ pub async fn stop(ctx: Context<'_>) -> Result<(), Error> {
|
|||||||
let queue = handler.queue();
|
let queue = handler.queue();
|
||||||
queue.stop();
|
queue.stop();
|
||||||
|
|
||||||
ctx.say("Playback stopped!").await?;
|
ctx.send(
|
||||||
|
CreateReply::default().embed(
|
||||||
|
embed(
|
||||||
|
ctx,
|
||||||
|
"Stopped!",
|
||||||
|
"Playback stopped!",
|
||||||
|
"Queue destroyed! Bot will stay and chill with you in a vc",
|
||||||
|
)
|
||||||
|
.await
|
||||||
|
.unwrap(),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
.await?;
|
||||||
} else {
|
} else {
|
||||||
ctx.say("Not in a voice channel!").await?;
|
let msg = "I am not in a voice channel!";
|
||||||
|
ctx.send(CreateReply::default().embed(error_embed(ctx, msg).await.unwrap()))
|
||||||
|
.await?;
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|||||||
11
src/commands/music/volume.rs
Normal file
11
src/commands/music/volume.rs
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
use crate::{commands::embeds::embed, Context, Error};
|
||||||
|
use poise::CreateReply;
|
||||||
|
|
||||||
|
/// Changes output volume
|
||||||
|
#[poise::command(prefix_command, slash_command, category = "Music")]
|
||||||
|
pub async fn volume(ctx: Context<'_>) -> Result<(), Error> {
|
||||||
|
ctx.send(CreateReply::default().embed(embed(ctx, "", "", "").await.unwrap()))
|
||||||
|
.await?;
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
@@ -1,5 +1,31 @@
|
|||||||
|
pub mod ai;
|
||||||
|
pub mod dice;
|
||||||
|
pub mod dictionary;
|
||||||
|
pub mod help;
|
||||||
|
pub mod ip;
|
||||||
|
pub mod metar;
|
||||||
|
pub mod owoify;
|
||||||
pub mod ping;
|
pub mod ping;
|
||||||
|
pub mod posix;
|
||||||
|
pub mod qr;
|
||||||
pub mod register;
|
pub mod register;
|
||||||
|
pub mod taf;
|
||||||
|
// pub mod uptime;
|
||||||
|
pub mod verse;
|
||||||
|
pub mod weather;
|
||||||
|
|
||||||
|
pub use ai::ai;
|
||||||
|
pub use dice::dice;
|
||||||
|
pub use dictionary::dictionary;
|
||||||
|
pub use help::help;
|
||||||
|
pub use ip::ip;
|
||||||
|
pub use metar::metar;
|
||||||
|
pub use owoify::owoify;
|
||||||
pub use ping::ping;
|
pub use ping::ping;
|
||||||
|
pub use posix::posix;
|
||||||
|
pub use qr::qr;
|
||||||
pub use register::register;
|
pub use register::register;
|
||||||
|
pub use taf::taf;
|
||||||
|
// pub use uptime::uptime;
|
||||||
|
pub use verse::verse;
|
||||||
|
pub use weather::weather;
|
||||||
|
|||||||
50
src/commands/tools/ai.rs
Normal file
50
src/commands/tools/ai.rs
Normal file
@@ -0,0 +1,50 @@
|
|||||||
|
use rand::Rng;
|
||||||
|
|
||||||
|
use std::thread::sleep;
|
||||||
|
use std::time::Duration;
|
||||||
|
|
||||||
|
use poise::CreateReply;
|
||||||
|
|
||||||
|
use crate::{commands::embeds::embed, Context, Error};
|
||||||
|
|
||||||
|
/// Asks AI
|
||||||
|
#[poise::command(prefix_command, slash_command, category = "Tools")]
|
||||||
|
pub async fn ai(
|
||||||
|
ctx: Context<'_>,
|
||||||
|
#[description = "prompt to ask"]
|
||||||
|
#[rest]
|
||||||
|
prompt: String,
|
||||||
|
) -> Result<(), Error> {
|
||||||
|
let iamsorry = vec![
|
||||||
|
"I'm sorry, but as an AI language model, I must follow ethical guidelines, and I cannot engage in harmful, malicious, or offensive behavior.",
|
||||||
|
"I'm sorry, but as an AI language model, I may not always be perfect and can make mistakes or provide inaccurate information. Please verify important details from reliable sources.",
|
||||||
|
"I'm sorry, but as an AI language model, I can't engage in real-time conversations or remember previous interactions with users.",
|
||||||
|
"I'm sorry, but as an AI language model, I don't have personal opinions or feelings; I can only provide information based on patterns in the data I was trained on.",
|
||||||
|
"I'm sorry, but as an AI language model, I don't have access to real-time information or updates beyond my last training data in September 2021.",
|
||||||
|
"I'm sorry, but as an AI language model, I don't have the ability to recall specific personal data or information about individuals.",
|
||||||
|
"I'm sorry, but as an AI language model, I don't have consciousness or self-awareness. I'm simply a program designed to process and generate human-like text."
|
||||||
|
];
|
||||||
|
|
||||||
|
println!("Funny prompts: {}", prompt);
|
||||||
|
|
||||||
|
let response;
|
||||||
|
|
||||||
|
let _ = {
|
||||||
|
let mut rng = rand::thread_rng();
|
||||||
|
|
||||||
|
response = rng.gen_range(0..iamsorry.len());
|
||||||
|
};
|
||||||
|
|
||||||
|
sleep(Duration::from_secs(3));
|
||||||
|
|
||||||
|
ctx.send(
|
||||||
|
CreateReply::default().embed(
|
||||||
|
embed(ctx, "AI Response:", "", &format!("{}", iamsorry[response]))
|
||||||
|
.await
|
||||||
|
.unwrap(),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
.await?;
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
33
src/commands/tools/dice.rs
Normal file
33
src/commands/tools/dice.rs
Normal file
@@ -0,0 +1,33 @@
|
|||||||
|
use rand::Rng;
|
||||||
|
|
||||||
|
use poise::CreateReply;
|
||||||
|
|
||||||
|
use crate::{commands::embeds::embed, Context, Error};
|
||||||
|
|
||||||
|
/// Rolls a dice
|
||||||
|
#[poise::command(prefix_command, slash_command, category = "Tools")]
|
||||||
|
pub async fn dice(ctx: Context<'_>) -> Result<(), Error> {
|
||||||
|
let dice;
|
||||||
|
|
||||||
|
let _ = {
|
||||||
|
let mut rng = rand::thread_rng();
|
||||||
|
|
||||||
|
dice = rng.gen_range(1..7);
|
||||||
|
};
|
||||||
|
|
||||||
|
ctx.send(
|
||||||
|
CreateReply::default().embed(
|
||||||
|
embed(
|
||||||
|
ctx,
|
||||||
|
"Let's roll the dice!",
|
||||||
|
"",
|
||||||
|
&format!("Your number is: {}", dice),
|
||||||
|
)
|
||||||
|
.await
|
||||||
|
.unwrap(),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
.await?;
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
12
src/commands/tools/dictionary.rs
Normal file
12
src/commands/tools/dictionary.rs
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
use poise::CreateReply;
|
||||||
|
|
||||||
|
use crate::{commands::embeds::embed, Context, Error};
|
||||||
|
|
||||||
|
/// Explains provided query
|
||||||
|
#[poise::command(prefix_command, slash_command, category = "Tools")]
|
||||||
|
pub async fn dictionary(ctx: Context<'_>) -> Result<(), Error> {
|
||||||
|
ctx.send(CreateReply::default().embed(embed(ctx, "", "", "").await.unwrap()))
|
||||||
|
.await?;
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
23
src/commands/tools/help.rs
Normal file
23
src/commands/tools/help.rs
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
use crate::{Context, Error};
|
||||||
|
|
||||||
|
/// Prints this help message; aliases: help, huh, welp
|
||||||
|
#[poise::command(
|
||||||
|
prefix_command,
|
||||||
|
slash_command,
|
||||||
|
track_edits,
|
||||||
|
aliases("huh", "welp"),
|
||||||
|
category = "Help"
|
||||||
|
)]
|
||||||
|
pub async fn help(
|
||||||
|
ctx: Context<'_>,
|
||||||
|
#[description = "Specific command to show help about"] command: Option<String>,
|
||||||
|
) -> Result<(), Error> {
|
||||||
|
let config = poise::builtins::HelpConfiguration {
|
||||||
|
extra_text_at_bottom: "\
|
||||||
|
Use /help command for more info on a command.
|
||||||
|
You can edit you message to the bot and the bot will edit its response.",
|
||||||
|
..Default::default()
|
||||||
|
};
|
||||||
|
poise::builtins::help(ctx, command.as_deref(), config).await?;
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
12
src/commands/tools/ip.rs
Normal file
12
src/commands/tools/ip.rs
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
use poise::CreateReply;
|
||||||
|
|
||||||
|
use crate::{commands::embeds::embed, Context, Error};
|
||||||
|
|
||||||
|
/// Shows IP information
|
||||||
|
#[poise::command(prefix_command, slash_command, category = "Tools")]
|
||||||
|
pub async fn ip(ctx: Context<'_>) -> Result<(), Error> {
|
||||||
|
ctx.send(CreateReply::default().embed(embed(ctx, "", "", "").await.unwrap()))
|
||||||
|
.await?;
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
12
src/commands/tools/metar.rs
Normal file
12
src/commands/tools/metar.rs
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
use poise::CreateReply;
|
||||||
|
|
||||||
|
use crate::{commands::embeds::embed, Context, Error};
|
||||||
|
|
||||||
|
/// Prints metar for provided airport
|
||||||
|
#[poise::command(prefix_command, slash_command, category = "Tools")]
|
||||||
|
pub async fn metar(ctx: Context<'_>) -> Result<(), Error> {
|
||||||
|
ctx.send(CreateReply::default().embed(embed(ctx, "", "", "").await.unwrap()))
|
||||||
|
.await?;
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
12
src/commands/tools/owoify.rs
Normal file
12
src/commands/tools/owoify.rs
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
use poise::CreateReply;
|
||||||
|
|
||||||
|
use crate::{commands::embeds::embed, Context, Error};
|
||||||
|
|
||||||
|
/// Owoifies whatever you want uwu
|
||||||
|
#[poise::command(prefix_command, slash_command, category = "Tools")]
|
||||||
|
pub async fn owoify(ctx: Context<'_>) -> Result<(), Error> {
|
||||||
|
ctx.send(CreateReply::default().embed(embed(ctx, "", "", "").await.unwrap()))
|
||||||
|
.await?;
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
@@ -1,11 +1,13 @@
|
|||||||
use crate::{Context, Error};
|
use crate::{Context, Error};
|
||||||
use std::time::SystemTime;
|
use std::time::SystemTime;
|
||||||
|
|
||||||
#[poise::command(prefix_command, slash_command)]
|
/// Pings you backs with a response time
|
||||||
|
#[poise::command(prefix_command, slash_command, category = "Tools")]
|
||||||
pub async fn ping(ctx: Context<'_>) -> Result<(), Error> {
|
pub async fn ping(ctx: Context<'_>) -> Result<(), Error> {
|
||||||
let system_now = SystemTime::now()
|
let system_now = SystemTime::now()
|
||||||
.duration_since(SystemTime::UNIX_EPOCH)
|
.duration_since(SystemTime::UNIX_EPOCH)
|
||||||
.unwrap().as_millis() as i64;
|
.unwrap()
|
||||||
|
.as_millis() as i64;
|
||||||
|
|
||||||
let message_now = ctx.created_at().timestamp_millis();
|
let message_now = ctx.created_at().timestamp_millis();
|
||||||
|
|
||||||
|
|||||||
30
src/commands/tools/posix.rs
Normal file
30
src/commands/tools/posix.rs
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
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",
|
||||||
|
"since Jan 1st 1970",
|
||||||
|
&format!("{} ms", time),
|
||||||
|
)
|
||||||
|
.await
|
||||||
|
.unwrap(),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
.await?;
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
12
src/commands/tools/qr.rs
Normal file
12
src/commands/tools/qr.rs
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
use poise::CreateReply;
|
||||||
|
|
||||||
|
use crate::{commands::embeds::embed, Context, Error};
|
||||||
|
|
||||||
|
/// Creates a qr code from text
|
||||||
|
#[poise::command(prefix_command, slash_command, category = "Tools")]
|
||||||
|
pub async fn qr(ctx: Context<'_>) -> Result<(), Error> {
|
||||||
|
ctx.send(CreateReply::default().embed(embed(ctx, "", "", "").await.unwrap()))
|
||||||
|
.await?;
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
@@ -1,12 +1,7 @@
|
|||||||
use crate::{Context, Error};
|
use crate::{Context, Error};
|
||||||
|
|
||||||
#[poise::command(prefix_command, check = "check")]
|
#[poise::command(prefix_command, hide_in_help, owners_only)]
|
||||||
pub async fn register(ctx: Context<'_>) -> Result<(), Error> {
|
pub async fn register(ctx: Context<'_>) -> Result<(), Error> {
|
||||||
poise::builtins::register_application_commands_buttons(ctx).await?;
|
poise::builtins::register_application_commands_buttons(ctx).await?;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn check(ctx: Context<'_>) -> Result<bool, Error> {
|
|
||||||
let owner = std::env::var("OWNER_ID").expect("Environment variable `OWNER_ID` not found");
|
|
||||||
Ok(ctx.author().id.to_string() == owner)
|
|
||||||
}
|
|
||||||
|
|||||||
12
src/commands/tools/taf.rs
Normal file
12
src/commands/tools/taf.rs
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
use poise::CreateReply;
|
||||||
|
|
||||||
|
use crate::{commands::embeds::embed, Context, Error};
|
||||||
|
|
||||||
|
/// Returns taf for provided airport
|
||||||
|
#[poise::command(prefix_command, slash_command, category = "Tools")]
|
||||||
|
pub async fn taf(ctx: Context<'_>) -> Result<(), Error> {
|
||||||
|
ctx.send(CreateReply::default().embed(embed(ctx, "", "", "").await.unwrap()))
|
||||||
|
.await?;
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
35
src/commands/tools/uptime.rs
Normal file
35
src/commands/tools/uptime.rs
Normal file
@@ -0,0 +1,35 @@
|
|||||||
|
use poise::CreateReply;
|
||||||
|
|
||||||
|
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
|
||||||
|
#[poise::command(prefix_command, slash_command, category = "Tools")]
|
||||||
|
pub async fn uptime(ctx: Context<'_>) -> Result<(), Error> {
|
||||||
|
let uptime = PROCESS_UPTIME;
|
||||||
|
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(())
|
||||||
|
}
|
||||||
12
src/commands/tools/verse.rs
Normal file
12
src/commands/tools/verse.rs
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
use poise::CreateReply;
|
||||||
|
|
||||||
|
use crate::{commands::embeds::embed, Context, Error};
|
||||||
|
|
||||||
|
/// Reference Bible by verse
|
||||||
|
#[poise::command(prefix_command, slash_command, category = "Tools")]
|
||||||
|
pub async fn verse(ctx: Context<'_>) -> Result<(), Error> {
|
||||||
|
ctx.send(CreateReply::default().embed(embed(ctx, "", "", "").await.unwrap()))
|
||||||
|
.await?;
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
12
src/commands/tools/weather.rs
Normal file
12
src/commands/tools/weather.rs
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
use poise::CreateReply;
|
||||||
|
|
||||||
|
use crate::{commands::embeds::embed, Context, Error};
|
||||||
|
|
||||||
|
/// Shows weather for provided location
|
||||||
|
#[poise::command(prefix_command, slash_command, category = "Tools")]
|
||||||
|
pub async fn weather(ctx: Context<'_>) -> Result<(), Error> {
|
||||||
|
ctx.send(CreateReply::default().embed(embed(ctx, "", "", "").await.unwrap()))
|
||||||
|
.await?;
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
use reqwest::Client as HttpClient;
|
|
||||||
use poise::serenity_prelude::prelude::TypeMapKey;
|
use poise::serenity_prelude::prelude::TypeMapKey;
|
||||||
|
use reqwest::Client as HttpClient;
|
||||||
|
|
||||||
pub struct HttpKey;
|
pub struct HttpKey;
|
||||||
|
|
||||||
|
|||||||
106
src/main.rs
106
src/main.rs
@@ -1,36 +1,18 @@
|
|||||||
use songbird::SerenityInit;
|
|
||||||
|
|
||||||
use poise::serenity_prelude::{self as serenity, ActivityData};
|
use poise::serenity_prelude::{self as serenity, ActivityData};
|
||||||
|
use reqwest::Client as HttpClient;
|
||||||
|
use songbird::SerenityInit;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use std::time::Duration;
|
use std::time::Duration;
|
||||||
use tracing::{info, warn, error};
|
use tracing::{error, info, warn};
|
||||||
use reqwest::Client as HttpClient;
|
|
||||||
|
|
||||||
mod http;
|
|
||||||
mod commands;
|
mod commands;
|
||||||
|
mod http;
|
||||||
|
|
||||||
// http typemap for handling requests
|
use crate::commands::kashi;
|
||||||
|
use crate::commands::music;
|
||||||
|
use crate::commands::tools;
|
||||||
use crate::http::HttpKey;
|
use crate::http::HttpKey;
|
||||||
|
|
||||||
// commands: music
|
|
||||||
use crate::commands::music::deafen::*;
|
|
||||||
use crate::commands::music::join::*;
|
|
||||||
use crate::commands::music::leave::*;
|
|
||||||
use crate::commands::music::mute::*;
|
|
||||||
use crate::commands::music::play::*;
|
|
||||||
use crate::commands::music::queue::*;
|
|
||||||
use crate::commands::music::skip::*;
|
|
||||||
use crate::commands::music::stop::*;
|
|
||||||
use crate::commands::music::repeat::*;
|
|
||||||
use crate::commands::music::pause::*;
|
|
||||||
use crate::commands::music::resume::*;
|
|
||||||
|
|
||||||
// commands: tools
|
|
||||||
use crate::commands::tools::ping::*;
|
|
||||||
|
|
||||||
// commands: kashi
|
|
||||||
use crate::commands::kashi::kashi::*;
|
|
||||||
|
|
||||||
type Error = Box<dyn std::error::Error + Send + Sync>;
|
type Error = Box<dyn std::error::Error + Send + Sync>;
|
||||||
type Context<'a> = poise::Context<'a, Data, Error>;
|
type Context<'a> = poise::Context<'a, Data, Error>;
|
||||||
|
|
||||||
@@ -50,41 +32,48 @@ async fn on_error(error: poise::FrameworkError<'_, Data, Error>) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// this is for debug only
|
|
||||||
#[poise::command(prefix_command)]
|
|
||||||
pub async fn register(ctx: Context<'_>) -> Result<(), Error> {
|
|
||||||
poise::builtins::register_application_commands_buttons(ctx).await?;
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
|
|
||||||
#[tokio::main]
|
#[tokio::main]
|
||||||
async fn main() {
|
async fn main() {
|
||||||
// logger and dotenv initialization
|
|
||||||
tracing_subscriber::fmt::init();
|
tracing_subscriber::fmt::init();
|
||||||
dotenv::dotenv().expect("Failed to load .env file.");
|
dotenv::dotenv().expect("Failed to load .env file.");
|
||||||
|
|
||||||
let token = std::env::var("DISCORD_TOKEN").expect("Environment variable `DISCORD_TOKEN` not found!");
|
let token =
|
||||||
|
std::env::var("DISCORD_TOKEN").expect("Environment variable `DISCORD_TOKEN` not found!");
|
||||||
let prefix = std::env::var("PREFIX").expect("Environment variable `PREFIX` not found!");
|
let prefix = std::env::var("PREFIX").expect("Environment variable `PREFIX` not found!");
|
||||||
|
|
||||||
let commands = vec![
|
let commands = vec![
|
||||||
// commands: music
|
kashi::kashi(),
|
||||||
deafen(),
|
music::deafen(),
|
||||||
join(),
|
music::join(),
|
||||||
leave(),
|
music::leave(),
|
||||||
repeat(),
|
music::mute(),
|
||||||
mute(),
|
music::pause(),
|
||||||
pause(),
|
music::play(),
|
||||||
play(),
|
music::queue(),
|
||||||
queue(),
|
music::repeat(),
|
||||||
resume(),
|
music::resume(),
|
||||||
skip(),
|
music::seek(),
|
||||||
stop(),
|
music::shuffle(),
|
||||||
// commands: tools
|
music::skip(),
|
||||||
ping(),
|
music::stop(),
|
||||||
// commands: kashi
|
music::volume(),
|
||||||
kashi(),
|
music::soundboard::effect(),
|
||||||
// commands: debug
|
music::soundboard::stream(),
|
||||||
register(),
|
tools::ai(),
|
||||||
|
tools::dice(),
|
||||||
|
tools::dictionary(),
|
||||||
|
tools::help(),
|
||||||
|
tools::ip(),
|
||||||
|
tools::metar(),
|
||||||
|
tools::owoify(),
|
||||||
|
tools::ping(),
|
||||||
|
tools::posix(),
|
||||||
|
tools::qr(),
|
||||||
|
tools::register(),
|
||||||
|
tools::taf(),
|
||||||
|
// tools::uptime(),
|
||||||
|
tools::verse(),
|
||||||
|
tools::weather(),
|
||||||
];
|
];
|
||||||
|
|
||||||
let options = poise::FrameworkOptions {
|
let options = poise::FrameworkOptions {
|
||||||
@@ -124,7 +113,10 @@ async fn main() {
|
|||||||
skip_checks_for_owners: false,
|
skip_checks_for_owners: false,
|
||||||
event_handler: |_ctx, event, _framework, _data| {
|
event_handler: |_ctx, event, _framework, _data| {
|
||||||
Box::pin(async move {
|
Box::pin(async move {
|
||||||
info!("Got an event in event handler: {:?}", event.snake_case_name());
|
info!(
|
||||||
|
"Got an event in event handler: {:?}",
|
||||||
|
event.snake_case_name()
|
||||||
|
);
|
||||||
Ok(())
|
Ok(())
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
@@ -134,7 +126,10 @@ async fn main() {
|
|||||||
let framework = poise::Framework::builder()
|
let framework = poise::Framework::builder()
|
||||||
.setup(move |ctx, ready, _framework| {
|
.setup(move |ctx, ready, _framework| {
|
||||||
Box::pin(async move {
|
Box::pin(async move {
|
||||||
info!("{} [{}] connected successfully!", ready.user.name, ready.user.id);
|
info!(
|
||||||
|
"{} [{}] connected successfully!",
|
||||||
|
ready.user.name, ready.user.id
|
||||||
|
);
|
||||||
ctx.set_activity(Some(ActivityData::listening(prefix + "help")));
|
ctx.set_activity(Some(ActivityData::listening(prefix + "help")));
|
||||||
// poise::builtins::register_globally(ctx, &framework.options().commands).await?;
|
// poise::builtins::register_globally(ctx, &framework.options().commands).await?;
|
||||||
|
|
||||||
@@ -144,7 +139,8 @@ async fn main() {
|
|||||||
.options(options)
|
.options(options)
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
let intents = serenity::GatewayIntents::non_privileged() | serenity::GatewayIntents::MESSAGE_CONTENT;
|
let intents =
|
||||||
|
serenity::GatewayIntents::non_privileged() | serenity::GatewayIntents::MESSAGE_CONTENT;
|
||||||
|
|
||||||
let mut client = serenity::ClientBuilder::new(token, intents)
|
let mut client = serenity::ClientBuilder::new(token, intents)
|
||||||
.framework(framework)
|
.framework(framework)
|
||||||
|
|||||||
1
src/spotify
Submodule
1
src/spotify
Submodule
Submodule src/spotify added at ea246e9ed2
Reference in New Issue
Block a user