feat: Handle in period the case where the duration input is invalid

This commit is contained in:
Max batleforc 2024-06-21 15:14:00 +02:00
parent 154b99265d
commit 259b6a14c3
No known key found for this signature in database
GPG Key ID: 25D243AB4B6AC9E7

View File

@ -9,7 +9,7 @@ use poise::{
serenity_prelude::{model::colour, CreateEmbed, CreateEmbedFooter, Mentionable, RoleId},
CreateReply,
};
use tracing::instrument;
use tracing::{info, instrument};
/// Update the step duration of a concour (only for admin)
#[instrument(skip(ctx), level = "info", fields(channel = ctx.channel_id().get(), guild = ?ctx.guild_id().unwrap().get()))]
@ -59,7 +59,23 @@ pub async fn period(
return Ok(());
}
};
let duration = time::Duration::new(step.try_into().unwrap(), 0);
let duration = match step.try_into() {
Ok(val) => time::Duration::new(val, 0),
Err(_) => {
info!("Invalid Duration input");
let embed = CreateEmbed::new()
.title("Invalid duration input")
.color(colour::Color::RED)
.footer(footer);
if let Err(why) = ctx
.send(CreateReply::default().embed(embed).ephemeral(true))
.await
{
tracing::error!("Error sending message: {:?}", why);
}
return Ok(());
}
};
let concour = match set_periode(guild.get(), ctx.channel_id().get(), duration).await {
Ok(concour) => {
if concour.is_none() {