From 8fa86b018205906a9fa1f7afcd8bdd4e05c22255 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michael=20Czy=C5=BC?= Date: Tue, 13 Feb 2024 18:44:01 +0100 Subject: [PATCH] 0.5.0 embed, help, refractor --- .env.example | 2 + Cargo.lock | 2 +- Cargo.toml | 2 +- src/commands.rs | 1 + src/commands/embeds.rs | 37 +++++++++++++++++ src/commands/kashi/kashi.rs | 11 ++++- src/commands/music.rs | 2 +- src/commands/music/deafen.rs | 39 +++++++++++++----- src/commands/music/join.rs | 29 +++++++++---- src/commands/music/leave.rs | 28 ++++++++++--- src/commands/music/mute.rs | 42 +++++++++++++------ src/commands/music/{misc.rs => notifier.rs} | 0 src/commands/music/pause.rs | 27 +++++++++---- src/commands/music/play.rs | 17 +++++--- src/commands/music/queue.rs | 27 +++++++++---- src/commands/music/repeat.rs | 45 ++++++++++++++++----- src/commands/music/resume.rs | 22 ++++++++-- src/commands/music/skip.rs | 23 ++++++++--- src/commands/music/stop.rs | 27 ++++++++++--- src/commands/tools.rs | 2 + src/commands/tools/help.rs | 23 +++++++++++ src/commands/tools/ping.rs | 11 ++++- src/commands/tools/register.rs | 15 +++---- src/main.rs | 1 + 24 files changed, 341 insertions(+), 94 deletions(-) create mode 100644 .env.example create mode 100644 src/commands/embeds.rs rename src/commands/music/{misc.rs => notifier.rs} (100%) create mode 100644 src/commands/tools/help.rs diff --git a/.env.example b/.env.example new file mode 100644 index 0000000..d11c28d --- /dev/null +++ b/.env.example @@ -0,0 +1,2 @@ +DISCORD_TOKEN= +PREFIX= diff --git a/Cargo.lock b/Cargo.lock index a7ec76f..3a36326 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -959,7 +959,7 @@ dependencies = [ [[package]] name = "lyra" -version = "0.4.0" +version = "0.5.0" dependencies = [ "dotenv", "fancy-regex", diff --git a/Cargo.toml b/Cargo.toml index 016f83b..5c67ec3 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "lyra" -version = "0.4.0" +version = "0.5.0" authors = ["Michał Czyż "] edition = "2021" description = "A featureful Discord bot written in Rust." diff --git a/src/commands.rs b/src/commands.rs index 08f5ddf..85ff9ea 100644 --- a/src/commands.rs +++ b/src/commands.rs @@ -1,3 +1,4 @@ pub mod kashi; pub mod music; pub mod tools; +pub mod embeds; diff --git a/src/commands/embeds.rs b/src/commands/embeds.rs new file mode 100644 index 0000000..887b8d2 --- /dev/null +++ b/src/commands/embeds.rs @@ -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 { + 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 { + 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) +} diff --git a/src/commands/kashi/kashi.rs b/src/commands/kashi/kashi.rs index 5719546..8b17975 100644 --- a/src/commands/kashi/kashi.rs +++ b/src/commands/kashi/kashi.rs @@ -1,7 +1,14 @@ use crate::{Context, Error}; -#[poise::command(prefix_command, slash_command)] -pub async fn kashi(ctx: Context<'_>) -> Result<(), Error> { +/// Kashi integration platform (WIP) +#[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!"); ctx.say(response).await?; diff --git a/src/commands/music.rs b/src/commands/music.rs index cbb6a02..fbe606c 100644 --- a/src/commands/music.rs +++ b/src/commands/music.rs @@ -1,7 +1,7 @@ pub mod deafen; pub mod join; pub mod leave; -pub mod misc; +pub mod notifier; pub mod mute; pub mod pause; pub mod play; diff --git a/src/commands/music/deafen.rs b/src/commands/music/deafen.rs index 5c8cb8d..0f4b6dd 100644 --- a/src/commands/music/deafen.rs +++ b/src/commands/music/deafen.rs @@ -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)] -pub async fn deafen(ctx: Context<'_>) -> Result<(), Error> { +/// 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> { let guild_id = ctx.guild_id().unwrap(); 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) { Some(handler) => handler, 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(()); } }; @@ -22,16 +35,20 @@ pub async fn deafen(ctx: Context<'_>) -> Result<(), Error> { if handler.is_deaf() { 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 { - if let Err(err) = handler.deafen(true).await { - ctx.say(format!("Failed: {:?}", err)).await?; + if let Err(err) = handler.deafen(true).await { + fail(ctx, err.to_string()).await.unwrap(); } - - ctx.say("Deafened").await?; + + ctx.send( + CreateReply::default().embed(embed(ctx, "Deafened!", "", "").await.unwrap()) + ).await?; } Ok(()) diff --git a/src/commands/music/join.rs b/src/commands/music/join.rs index f318e3a..4b87b3c 100644 --- a/src/commands/music/join.rs +++ b/src/commands/music/join.rs @@ -1,16 +1,29 @@ -use crate::{Context, Error}; +use crate::{commands::embeds::{error_embed, embed}, Context, Error}; +use poise::CreateReply; use songbird::TrackEvent; -use crate::commands::music::misc::TrackErrorNotifier; +use crate::commands::music::notifier::TrackErrorNotifier; -#[poise::command(prefix_command, slash_command)] -pub async fn join(ctx: Context<'_>) -> Result<(), Error> { +/// Joins your voice channel +#[poise::command( + prefix_command, + slash_command, + category = "Music" +)] +pub async fn join( + ctx: Context<'_> +) -> Result<(), Error> { 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 { Some(channel) => channel, 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(()); } }; @@ -25,7 +38,9 @@ pub async fn join(ctx: Context<'_>) -> Result<(), Error> { 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(()) } diff --git a/src/commands/music/leave.rs b/src/commands/music/leave.rs index db11552..7b8ca45 100644 --- a/src/commands/music/leave.rs +++ b/src/commands/music/leave.rs @@ -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)] -pub async fn leave(ctx: Context<'_>) -> Result<(), Error> { +/// 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> { let guild_id = ctx.guild_id().unwrap(); let manager = songbird::get(&ctx.serenity_context()) @@ -10,15 +20,21 @@ pub async fn leave(ctx: Context<'_>) -> Result<(), Error> { .clone(); 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(()) } 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(()) } diff --git a/src/commands/music/mute.rs b/src/commands/music/mute.rs index dca44c3..c5b11bc 100644 --- a/src/commands/music/mute.rs +++ b/src/commands/music/mute.rs @@ -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)] -pub async fn mute(ctx: Context<'_>) -> Result<(), Error> { +/// 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> { let guild_id = ctx.guild_id().unwrap(); 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) { Some(handler) => handler, - None => { - ctx.say("Not in a voice channel").await?; - + None => { + let msg = "I am not in a voice channel!"; + ctx.send( + CreateReply::default().embed(error_embed(ctx, msg).await.unwrap()) + ).await?; return Ok(()); } }; @@ -21,17 +33,21 @@ pub async fn mute(ctx: Context<'_>) -> Result<(), Error> { let mut handler = handler_lock.lock().await; if handler.is_mute() { - if let Err(e) = handler.mute(false).await { - ctx.say(format!("failed: {:?}", e)).await?; + if let Err(err) = handler.mute(false).await { + fail(ctx, err.to_string()).await.unwrap(); } - - ctx.say("Unmuted").await?; + + ctx.send( + CreateReply::default().embed(embed(ctx, "Unmuted!", "", "").await.unwrap()) + ).await?; } else { 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(()) diff --git a/src/commands/music/misc.rs b/src/commands/music/notifier.rs similarity index 100% rename from src/commands/music/misc.rs rename to src/commands/music/notifier.rs diff --git a/src/commands/music/pause.rs b/src/commands/music/pause.rs index b9a9e83..8a02993 100644 --- a/src/commands/music/pause.rs +++ b/src/commands/music/pause.rs @@ -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)] -pub async fn pause(ctx: Context<'_>) -> Result<(), Error> { +/// Pauses the currently playing song +#[poise::command( + prefix_command, + slash_command, + category = "Music" +)] +pub async fn pause( + ctx: Context<'_> +) -> Result<(), Error> { let guild_id = ctx.guild_id().unwrap(); 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 queue = handler.queue(); let _ = queue.pause(); - - ctx.say(format!("Song paused.")).await?; - } else { - ctx.say("Not in a voice channel to play in").await?; + + ctx.send( + CreateReply::default().embed(embed(ctx, "Paused!", "Currently playing song is now paused!", "").await.unwrap()) + ).await?; + } else { + let msg = "I am not in a voice channel!"; + ctx.send( + CreateReply::default().embed(error_embed(ctx, msg).await.unwrap()) + ).await?; } Ok(()) diff --git a/src/commands/music/play.rs b/src/commands/music/play.rs index 397dff8..941e5d5 100644 --- a/src/commands/music/play.rs +++ b/src/commands/music/play.rs @@ -1,4 +1,4 @@ -use crate::{Context, Error}; +use crate::{commands::embeds::error_embed, Context, Error}; use fancy_regex::Regex; use regex::Regex as Regex_Classic; @@ -14,13 +14,17 @@ use songbird::input::AuxMetadata; use songbird::input::{Compose, YoutubeDl}; use songbird::events::TrackEvent; -use crate::commands::music::misc::TrackErrorNotifier; +use crate::commands::music::notifier::TrackErrorNotifier; use crate::http::HttpKey; +/// Plays a song; \ +/// you can search by query or paste an url; \ +/// aliases: play, p, enqueue #[poise::command( prefix_command, slash_command, - aliases("p", "enqueue") + aliases("p", "enqueue"), + category = "Music" )] pub async fn play( ctx: Context<'_>, @@ -39,8 +43,11 @@ pub async fn play( let connect_to = match channel_id { Some(channel) => channel, - None => { - ctx.say("Not in a voice channel").await?; + None => { + let msg = "I am not in a voice channel!"; + ctx.send( + CreateReply::default().embed(error_embed(ctx, msg).await.unwrap()) + ).await?; return Ok(()); } diff --git a/src/commands/music/queue.rs b/src/commands/music/queue.rs index acc71bf..324f1ae 100644 --- a/src/commands/music/queue.rs +++ b/src/commands/music/queue.rs @@ -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)] -pub async fn queue(ctx: Context<'_>) -> Result<(), Error> { +/// 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> { let guild_id = ctx.guild_id().unwrap(); - + let manager = songbird::get(&ctx.serenity_context()) .await .expect("Songbird client placed at init") @@ -21,13 +31,16 @@ pub async fn queue(ctx: Context<'_>) -> Result<(), Error> { song.uuid(), "Artist" // song.metadata().artist.clone().unwrap_or_else(|| String::from("Unknown")) - )); + )); } - + ctx.say(queue_res).await?; } 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(()) diff --git a/src/commands/music/repeat.rs b/src/commands/music/repeat.rs index 41a2cd7..4bdf053 100644 --- a/src/commands/music/repeat.rs +++ b/src/commands/music/repeat.rs @@ -1,8 +1,19 @@ -use crate::{Context, Error}; +use crate::{commands::embeds::{error_embed, embed}, Context, Error}; +use poise::CreateReply; use songbird::tracks::LoopState; -#[poise::command(prefix_command, slash_command)] -pub async fn repeat(ctx: Context<'_>, times: usize) -> Result<(), Error> { +/// Loops currently playing song provided amount of times; \ +/// 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 manager = songbird::get(&ctx.serenity_context()) @@ -22,21 +33,37 @@ pub async fn repeat(ctx: Context<'_>, times: usize) -> Result<(), Error> { LoopState::Infinite => { 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(_) => { - 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); - 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 { 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 { - ctx.say("Not in a voice channel to play in").await?; + } else { + let msg = "I am not in a voice channel!"; + ctx.send( + CreateReply::default().embed(error_embed(ctx, msg).await.unwrap()) + ).await?; } Ok(()) diff --git a/src/commands/music/resume.rs b/src/commands/music/resume.rs index 864dea8..31236b4 100644 --- a/src/commands/music/resume.rs +++ b/src/commands/music/resume.rs @@ -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)] -pub async fn resume(ctx: Context<'_>) -> Result<(), Error> { +/// Resumes currently paused song +#[poise::command( + prefix_command, + slash_command, + category = "Music" +)] +pub async fn resume( + ctx: Context<'_> +) -> Result<(), Error> { let guild_id = ctx.guild_id().unwrap(); let manager = songbird::get(&ctx.serenity_context()) @@ -15,8 +23,14 @@ pub async fn resume(ctx: Context<'_>) -> Result<(), Error> { let _ = queue.resume(); ctx.say(format!("Song resumed.")).await?; + ctx.send( + CreateReply::default().embed(embed(ctx, "Resumed!", "Currently paused song is now resumed!", "").await.unwrap()) + ).await?; } 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(()) diff --git a/src/commands/music/skip.rs b/src/commands/music/skip.rs index d0abbd4..2256783 100644 --- a/src/commands/music/skip.rs +++ b/src/commands/music/skip.rs @@ -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)] -pub async fn skip(ctx: Context<'_>) -> Result<(), Error> { +/// Skips the currently playing song +#[poise::command( + prefix_command, + slash_command, + category = "Music" +)] +pub async fn skip( + ctx: Context<'_> +) -> Result<(), Error> { let guild_id = ctx.guild_id().unwrap(); 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.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 { - 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(()) diff --git a/src/commands/music/stop.rs b/src/commands/music/stop.rs index 39e2067..d1c15b9 100644 --- a/src/commands/music/stop.rs +++ b/src/commands/music/stop.rs @@ -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)] -pub async fn stop(ctx: Context<'_>) -> Result<(), Error> { +/// 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> { let guild_id = ctx.guild_id().unwrap(); let manager = songbird::get(&ctx.serenity_context()) @@ -14,9 +24,14 @@ pub async fn stop(ctx: Context<'_>) -> Result<(), Error> { let queue = handler.queue(); queue.stop(); - ctx.say("Playback stopped!").await?; - } else { - ctx.say("Not in a voice channel!").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 { + let msg = "I am not in a voice channel!"; + ctx.send( + CreateReply::default().embed(error_embed(ctx, msg).await.unwrap()) + ).await?; } Ok(()) diff --git a/src/commands/tools.rs b/src/commands/tools.rs index 349b23b..4bbb587 100644 --- a/src/commands/tools.rs +++ b/src/commands/tools.rs @@ -1,5 +1,7 @@ pub mod ping; pub mod register; +pub mod help; pub use ping::ping; pub use register::register; +pub use help::help; diff --git a/src/commands/tools/help.rs b/src/commands/tools/help.rs new file mode 100644 index 0000000..3f87410 --- /dev/null +++ b/src/commands/tools/help.rs @@ -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, +) -> 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(()) +} diff --git a/src/commands/tools/ping.rs b/src/commands/tools/ping.rs index ed8deb5..b1bbfff 100644 --- a/src/commands/tools/ping.rs +++ b/src/commands/tools/ping.rs @@ -1,8 +1,15 @@ use crate::{Context, Error}; use std::time::SystemTime; -#[poise::command(prefix_command, slash_command)] -pub async fn ping(ctx: Context<'_>) -> Result<(), Error> { +/// Pings you backs with a response time +#[poise::command( + prefix_command, + slash_command, + category = "Tools" +)] +pub async fn ping( + ctx: Context<'_> +) -> Result<(), Error> { let system_now = SystemTime::now() .duration_since(SystemTime::UNIX_EPOCH) .unwrap().as_millis() as i64; diff --git a/src/commands/tools/register.rs b/src/commands/tools/register.rs index a1edd76..9bf1f08 100644 --- a/src/commands/tools/register.rs +++ b/src/commands/tools/register.rs @@ -1,12 +1,13 @@ use crate::{Context, Error}; -#[poise::command(prefix_command, check = "check")] -pub async fn register(ctx: Context<'_>) -> Result<(), Error> { +#[poise::command( + prefix_command, + hide_in_help, + owners_only +)] +pub async fn register( + ctx: Context<'_> +) -> Result<(), Error> { poise::builtins::register_application_commands_buttons(ctx).await?; Ok(()) } - -async fn check(ctx: Context<'_>) -> Result { - let owner = std::env::var("OWNER_ID").expect("Environment variable `OWNER_ID` not found"); - Ok(ctx.author().id.to_string() == owner) -} diff --git a/src/main.rs b/src/main.rs index 13ed9c1..b3806e7 100644 --- a/src/main.rs +++ b/src/main.rs @@ -55,6 +55,7 @@ async fn main() { music::stop(), tools::ping(), tools::register(), + tools::help(), ]; let options = poise::FrameworkOptions {