use crate::{Context, Error};
use tracing::{trace, debug};
use crate::shared_functions::trace_message;

/// Get the bot's current version
#[poise::command(slash_command, prefix_command)]
pub async fn version(ctx: Context<'_>) -> Result<(), Error> {
    trace!("version command called by user {} in guild {}", ctx.author().id.get(), ctx.guild_id().unwrap().get());
    trace!("Loading version from environment");
    let version = std::env::var("CARGO_PKG_VERSION").unwrap_or_else(|_| "Unknown".to_string());
    let msg = format!("Current version: {}", version);
    trace_message(msg.clone(), ctx.channel_id().to_string(), ctx.guild_id().unwrap().to_string()).await;
    ctx.say(msg).await?;
    debug!("Version command performed for user {} with version {}", ctx.author().name, version);
    Ok(())
}