From d55106f9dd53fd8f718cd6603cba1d08cf8ed4fe Mon Sep 17 00:00:00 2001 From: liyunze <50455574+liyunze-coding@users.noreply.github.com> Date: Tue, 4 Nov 2025 23:34:43 +1100 Subject: [PATCH] updated structure --- src/commands.rs | 52 +---------------------------------------- src/commands/info.rs | 55 ++++++++++++++++++++++++++++++++++++++++++++ src/main.rs | 2 +- 3 files changed, 57 insertions(+), 52 deletions(-) create mode 100644 src/commands/info.rs diff --git a/src/commands.rs b/src/commands.rs index e3de73d..4b8757f 100644 --- a/src/commands.rs +++ b/src/commands.rs @@ -1,51 +1 @@ -use poise::CreateReply; -use serenity::all::CreateEmbed; - -use crate::{Context, Error}; -use std::time::Instant; - -/// Show this help menu -#[poise::command(track_edits, slash_command)] -pub async fn help( - ctx: Context<'_>, - #[description = "Specific command to show help about"] - #[autocomplete = "poise::builtins::autocomplete_command"] - command: Option, -) -> Result<(), Error> { - poise::builtins::help( - ctx, - command.as_deref(), - poise::builtins::HelpConfiguration { - extra_text_at_bottom: "This is an example bot made to showcase features of my custom Discord bot framework", - ..Default::default() - }, - ) - .await?; - Ok(()) -} - -/// Ping the bot -// #[poise::command(slash_command)] -// pub async fn ping(ctx: Context<'_>) -> Result<(), Error> { -// let start = Instant::now(); - -// let msg = ctx.say("Pinging... ").await?; - -// let elapsed_ms = start.elapsed().as_millis(); - -// msg.edit( -// ctx, -// CreateReply::default().content(format!("Pong!\nTime elapsed: {elapsed_ms} ms")), -// ) -// .await?; - -// Ok(()) -// } - -/// Ping the bot -#[poise::command(slash_command)] -pub async fn ping(ctx: Context<'_>) -> Result<(), Error> { - let start = Instant::now(); - - let start_embed_msg = CreateEmbed::new().title("Pinging...").color(); -} +pub mod info; diff --git a/src/commands/info.rs b/src/commands/info.rs new file mode 100644 index 0000000..093df4b --- /dev/null +++ b/src/commands/info.rs @@ -0,0 +1,55 @@ +use poise::CreateReply; +use serenity::all::{Colour, CreateEmbed}; + +use crate::{Context, Error}; +use std::time::Instant; + +/// Show this help menu +#[poise::command(track_edits, slash_command)] +pub async fn help( + ctx: Context<'_>, + #[description = "Specific command to show help about"] + #[autocomplete = "poise::builtins::autocomplete_command"] + command: Option, +) -> Result<(), Error> { + poise::builtins::help( + ctx, + command.as_deref(), + poise::builtins::HelpConfiguration { + extra_text_at_bottom: "This is an example bot made to showcase features of my custom Discord bot framework", + ..Default::default() + }, + ) + .await?; + Ok(()) +} + +/// Ping the bot +/// +/// Check the bot's ping +#[poise::command(slash_command)] +pub async fn ping(ctx: Context<'_>) -> Result<(), Error> { + let start = Instant::now(); + + let embed_color = Colour::DARK_GREY; + + let start_embed_msg = CreateEmbed::new().title("Pinging...").color(embed_color); + + let first_reply: CreateReply = CreateReply::default().embed(start_embed_msg); + + let msg = ctx.send(first_reply).await?; + + // record ping + let elapsed_ms = start.elapsed().as_millis(); + + // create the 2nd embed + let result_embed_msg = CreateEmbed::new() + .title("Pong!") + .description(format!("{} ms", elapsed_ms)) + .color(embed_color); + + msg.edit(ctx, CreateReply::default().embed(result_embed_msg)) + .await?; + + Ok(()) +} diff --git a/src/main.rs b/src/main.rs index 8a8b1c2..b072221 100644 --- a/src/main.rs +++ b/src/main.rs @@ -17,7 +17,7 @@ async fn main() { let framework = poise::Framework::builder() .options(poise::FrameworkOptions { - commands: vec![commands::help(), commands::ping()], + commands: vec![commands::info::help(), commands::info::ping()], ..Default::default() }) .setup(|ctx, _ready, framework| {