Link all top-level commands with macro recording/replaying logic

This commit is contained in:
jude
2024-02-18 13:24:37 +00:00
parent 5e39e16060
commit 76a286076b
25 changed files with 619 additions and 410 deletions

View File

@ -2,29 +2,35 @@ use chrono::Utc;
use poise::CreateReply;
use serde::{Deserialize, Serialize};
use crate::{models::CtxData, utils::Extract, Context, Error};
use crate::{
models::CtxData,
utils::{Extract, Recordable},
Context, Error,
};
#[derive(Serialize, Deserialize, Extract)]
pub struct Options;
pub async fn clock(ctx: Context<'_>, _options: Options) -> Result<(), Error> {
ctx.defer_ephemeral().await?;
impl Recordable for Options {
async fn run(self, ctx: Context<'_>) -> Result<(), Error> {
ctx.defer_ephemeral().await?;
let tz = ctx.timezone().await;
let now = Utc::now().with_timezone(&tz);
let tz = ctx.timezone().await;
let now = Utc::now().with_timezone(&tz);
ctx.send(CreateReply::default().ephemeral(true).content(format!(
"Time in **{}**: `{}`",
tz,
now.format("%H:%M")
)))
.await?;
ctx.send(CreateReply::default().ephemeral(true).content(format!(
"Time in **{}**: `{}`",
tz,
now.format("%H:%M")
)))
.await?;
Ok(())
Ok(())
}
}
/// View the current time in your selected timezone
#[poise::command(slash_command, rename = "clock")]
#[poise::command(slash_command, rename = "clock", identifying_name = "clock")]
pub async fn command(ctx: Context<'_>) -> Result<(), Error> {
clock(ctx, Options {}).await
(Options {}).run(ctx).await
}