reminder-bot/src/commands/clock_context_menu.rs
2024-02-17 18:55:16 +00:00

28 lines
705 B
Rust

use chrono::Utc;
use poise::{
serenity_prelude::{Mentionable, User},
CreateReply,
};
use crate::{models::CtxData, Context, Error};
/// View the current time in a user's selected timezone
#[poise::command(context_menu_command = "View Local Time")]
pub async fn clock_context_menu(ctx: Context<'_>, user: User) -> Result<(), Error> {
ctx.defer_ephemeral().await?;
let user_data = ctx.user_data(user.id).await?;
let tz = user_data.timezone();
let now = Utc::now().with_timezone(&tz);
ctx.send(CreateReply::default().ephemeral(true).content(format!(
"Time in {}'s timezone: `{}`",
user.mention(),
now.format("%H:%M")
)))
.await?;
Ok(())
}