mirror of
https://github.com/dsec-hub/dsec-discord-bot.git
synced 2026-09-22 07:44:26 +00:00
updated structure
This commit is contained in:
parent
05af0ab9a4
commit
d55106f9dd
3 changed files with 57 additions and 52 deletions
|
|
@ -1,51 +1 @@
|
||||||
use poise::CreateReply;
|
pub mod info;
|
||||||
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<String>,
|
|
||||||
) -> 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();
|
|
||||||
}
|
|
||||||
|
|
|
||||||
55
src/commands/info.rs
Normal file
55
src/commands/info.rs
Normal file
|
|
@ -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<String>,
|
||||||
|
) -> 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(())
|
||||||
|
}
|
||||||
|
|
@ -17,7 +17,7 @@ async fn main() {
|
||||||
|
|
||||||
let framework = poise::Framework::builder()
|
let framework = poise::Framework::builder()
|
||||||
.options(poise::FrameworkOptions {
|
.options(poise::FrameworkOptions {
|
||||||
commands: vec![commands::help(), commands::ping()],
|
commands: vec![commands::info::help(), commands::info::ping()],
|
||||||
..Default::default()
|
..Default::default()
|
||||||
})
|
})
|
||||||
.setup(|ctx, _ready, framework| {
|
.setup(|ctx, _ready, framework| {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue