3 Commits
0.4.0 ... 0.5.0

Author SHA1 Message Date
8fa86b0182 0.5.0 embed, help, refractor 2024-02-13 18:44:01 +01:00
d75c5bc9a2 lyra spotify repos 2024-02-13 13:48:20 +01:00
21822405c0 cleanup part two 2024-02-12 22:29:14 +01:00
27 changed files with 443 additions and 148 deletions

2
.env.example Normal file
View File

@@ -0,0 +1,2 @@
DISCORD_TOKEN=<YOUR_DISCORD_TOKEN>
PREFIX=<YOUR_PREFIX>

1
.gitignore vendored
View File

@@ -1,2 +1,3 @@
/target /target
.env .env

80
Cargo.lock generated
View File

@@ -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,9 +959,10 @@ dependencies = [
[[package]] [[package]]
name = "lyra" name = "lyra"
version = "0.4.0" version = "0.5.0"
dependencies = [ dependencies = [
"dotenv", "dotenv",
"fancy-regex",
"openssl", "openssl",
"poise", "poise",
"regex", "regex",
@@ -2067,10 +2094,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 +2120,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 +2154,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 +2198,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"

View File

@@ -1,6 +1,6 @@
[package] [package]
name = "lyra" name = "lyra"
version = "0.4.0" version = "0.5.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,14 @@ 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"
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"

View File

@@ -1,3 +1,4 @@
pub mod kashi; pub mod kashi;
pub mod music; pub mod music;
pub mod tools; pub mod tools;
pub mod embeds;

37
src/commands/embeds.rs Normal file
View File

@@ -0,0 +1,37 @@
use crate::{Context, Error};
use serenity::{builder::{CreateEmbedAuthor, CreateEmbedFooter}, model::{Colour, Timestamp}};
use poise::serenity_prelude::CreateEmbed;
use poise::CreateReply;
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)
}

View File

@@ -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?;

View File

@@ -1,3 +0,0 @@
pub mod kashi;
pub mod music;
pub mod tools;

View File

@@ -1,7 +1,7 @@
pub mod deafen; pub mod deafen;
pub mod join; pub mod join;
pub mod leave; pub mod leave;
pub mod misc; pub mod notifier;
pub mod mute; pub mod mute;
pub mod pause; pub mod pause;
pub mod play; pub mod play;

View File

@@ -1,7 +1,17 @@
use crate::{Context, Error}; use crate::{commands::embeds::{error_embed, embed, fail}, Context, Error};
use poise::CreateReply;
#[poise::command(prefix_command, slash_command)] /// Deafens itself while in a voice channel; \
pub async fn deafen(ctx: Context<'_>) -> Result<(), Error> { /// aliases: deafen, undeaden, shuush
#[poise::command(
prefix_command,
slash_command,
aliases("shuush", "undeafen"),
category = "Music"
)]
pub async fn deafen(
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())
@@ -12,8 +22,11 @@ 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,20 @@ 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(())

View File

@@ -1,16 +1,29 @@
use crate::{Context, Error}; use crate::{commands::embeds::{error_embed, embed}, Context, Error};
use poise::CreateReply;
use songbird::TrackEvent; use songbird::TrackEvent;
use crate::commands::music::misc::TrackErrorNotifier; use crate::commands::music::notifier::TrackErrorNotifier;
#[poise::command(prefix_command, slash_command)] /// Joins your voice channel
pub async fn join(ctx: Context<'_>) -> Result<(), Error> { #[poise::command(
prefix_command,
slash_command,
category = "Music"
)]
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 +38,9 @@ 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(())
} }

View File

@@ -1,7 +1,17 @@
use crate::{Context, Error}; use poise::CreateReply;
use crate::{commands::embeds::{error_embed, fail, embed}, Context, Error};
#[poise::command(prefix_command, slash_command)] /// Leaves the voice channel; \
pub async fn leave(ctx: Context<'_>) -> Result<(), Error> { /// aliases: leave, qa!
#[poise::command(
prefix_command,
slash_command,
aliases("leave", "qa!"),
category = "Music"
)]
pub async fn leave(
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())
@@ -10,15 +20,21 @@ 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!";
ctx.send(
CreateReply::default().embed(error_embed(ctx, msg).await.unwrap())
).await?;
return Ok(()) 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(())
} }

View File

@@ -1,7 +1,17 @@
use crate::{Context, Error}; use crate::{commands::embeds::{error_embed, embed, fail}, Context, Error};
use poise::CreateReply;
#[poise::command(prefix_command, slash_command)] /// Mutes itself while in a voice channel; \
pub async fn mute(ctx: Context<'_>) -> Result<(), Error> { /// aliases: mute, unmute, shhh
#[poise::command(
prefix_command,
slash_command,
aliases("shhh", "unmute"),
category = "Music"
)]
pub async fn mute(
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())
@@ -11,9 +21,11 @@ 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(());
} }
}; };
@@ -21,17 +33,21 @@ pub async fn mute(ctx: Context<'_>) -> Result<(), Error> {
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(())

View File

@@ -1,7 +1,15 @@
use crate::{Context, Error}; use crate::{commands::embeds::{error_embed, embed}, Context, Error};
use poise::CreateReply;
#[poise::command(prefix_command, slash_command)] /// Pauses the currently playing song
pub async fn pause(ctx: Context<'_>) -> Result<(), Error> { #[poise::command(
prefix_command,
slash_command,
category = "Music"
)]
pub async fn pause(
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())
@@ -13,10 +21,15 @@ pub async fn pause(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 _ = queue.pause(); let _ = queue.pause();
ctx.say(format!("Song paused.")).await?; ctx.send(
} else { CreateReply::default().embed(embed(ctx, "Paused!", "Currently playing song is now paused!", "").await.unwrap())
ctx.say("Not in a voice channel to play in").await?; ).await?;
} else {
let msg = "I am not in a voice channel!";
ctx.send(
CreateReply::default().embed(error_embed(ctx, msg).await.unwrap())
).await?;
} }
Ok(()) Ok(())

View File

@@ -1,4 +1,4 @@
use crate::{Context, Error}; use crate::{commands::embeds::error_embed, Context, Error};
use fancy_regex::Regex; use fancy_regex::Regex;
use regex::Regex as Regex_Classic; use regex::Regex as Regex_Classic;
@@ -14,13 +14,17 @@ use songbird::input::AuxMetadata;
use songbird::input::{Compose, YoutubeDl}; use songbird::input::{Compose, YoutubeDl};
use songbird::events::TrackEvent; use songbird::events::TrackEvent;
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<'_>,
@@ -39,8 +43,11 @@ pub async fn play(
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(());
} }

View File

@@ -1,9 +1,19 @@
use crate::{Context, Error}; use crate::{commands::embeds::error_embed, Context, Error};
use poise::CreateReply;
#[poise::command(prefix_command, slash_command)] /// Shows next tracks in queue; \
pub async fn queue(ctx: Context<'_>) -> Result<(), Error> { /// aliases: queue, q
#[poise::command(
prefix_command,
slash_command,
aliases("q"),
category = "Music"
)]
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")
@@ -21,13 +31,16 @@ pub async fn queue(ctx: Context<'_>) -> Result<(), Error> {
song.uuid(), song.uuid(),
"Artist" "Artist"
// song.metadata().artist.clone().unwrap_or_else(|| String::from("Unknown")) // song.metadata().artist.clone().unwrap_or_else(|| String::from("Unknown"))
)); ));
} }
ctx.say(queue_res).await?; ctx.say(queue_res).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(())

View File

@@ -1,8 +1,19 @@
use crate::{Context, Error}; use crate::{commands::embeds::{error_embed, 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())
@@ -22,21 +33,37 @@ 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(embed(ctx, &format!("Song looped {} times!", times), "You definitelly love this song!", "").await.unwrap())
).await?;
} }
else { 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(())

View File

@@ -1,7 +1,15 @@
use crate::{Context, Error}; use crate::{commands::embeds::{error_embed, embed}, Context, Error};
use poise::CreateReply;
#[poise::command(prefix_command, slash_command)] /// Resumes currently paused song
pub async fn resume(ctx: Context<'_>) -> Result<(), Error> { #[poise::command(
prefix_command,
slash_command,
category = "Music"
)]
pub async fn resume(
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())
@@ -15,8 +23,14 @@ 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(())

View File

@@ -1,7 +1,15 @@
use crate::{Context, Error}; use crate::{commands::embeds::{error_embed, embed}, Context, Error};
use poise::CreateReply;
#[poise::command(prefix_command, slash_command)] /// Skips the currently playing song
pub async fn skip(ctx: Context<'_>) -> Result<(), Error> { #[poise::command(
prefix_command,
slash_command,
category = "Music"
)]
pub async fn skip(
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())
@@ -14,9 +22,14 @@ 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(())

View File

@@ -1,7 +1,17 @@
use crate::{Context, Error}; use crate::{commands::embeds::{error_embed, embed}, Context, Error};
use poise::CreateReply;
#[poise::command(prefix_command, slash_command)] /// Stops playback and destroys the queue; \
pub async fn stop(ctx: Context<'_>) -> Result<(), Error> { /// aliases: stop, end
#[poise::command(
prefix_command,
slash_command,
aliases("end"),
category = "Music"
)]
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())
@@ -14,9 +24,14 @@ 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(
} else { CreateReply::default().embed(embed(ctx, "Stopped!", "Playback stopped!", "Queue destroyed! Bot will stay and chill with you in a vc").await.unwrap())
ctx.say("Not in a voice channel!").await?; ).await?;
} else {
let msg = "I am not in a voice channel!";
ctx.send(
CreateReply::default().embed(error_embed(ctx, msg).await.unwrap())
).await?;
} }
Ok(()) Ok(())

View File

@@ -1,5 +1,7 @@
pub mod ping; pub mod ping;
pub mod register; pub mod register;
pub mod help;
pub use ping::ping; pub use ping::ping;
pub use register::register; pub use register::register;
pub use help::help;

View 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(())
}

View File

@@ -1,8 +1,15 @@
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
pub async fn ping(ctx: Context<'_>) -> Result<(), Error> { #[poise::command(
prefix_command,
slash_command,
category = "Tools"
)]
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;

View File

@@ -1,12 +1,13 @@
use crate::{Context, Error}; use crate::{Context, Error};
#[poise::command(prefix_command, check = "check")] #[poise::command(
pub async fn register(ctx: Context<'_>) -> Result<(), Error> { prefix_command,
hide_in_help,
owners_only
)]
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)
}

View File

@@ -1,36 +1,18 @@
use songbird::SerenityInit;
use poise::serenity_prelude::{self as serenity, ActivityData};
use std::sync::Arc; use std::sync::Arc;
use std::time::Duration; use std::time::Duration;
use tracing::{info, warn, error}; use tracing::{info, warn, error};
use poise::serenity_prelude::{self as serenity, ActivityData};
use songbird::SerenityInit;
use reqwest::Client as HttpClient; 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,16 +32,8 @@ 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.");
@@ -67,24 +41,21 @@ async fn main() {
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::repeat(),
mute(), music::mute(),
pause(), music::pause(),
play(), music::play(),
queue(), music::queue(),
resume(), music::resume(),
skip(), music::skip(),
stop(), music::stop(),
// commands: tools tools::ping(),
ping(), tools::register(),
// commands: kashi tools::help(),
kashi(),
// commands: debug
register(),
]; ];
let options = poise::FrameworkOptions { let options = poise::FrameworkOptions {

1
src/spotify Submodule

Submodule src/spotify added at ea246e9ed2