From 259b6a14c3129c49de16fd64791836f55125e7f7 Mon Sep 17 00:00:00 2001 From: Max batleforc Date: Fri, 21 Jun 2024 15:14:00 +0200 Subject: [PATCH] feat: Handle in period the case where the duration input is invalid --- src/botv2/cmd/concour/period.rs | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/src/botv2/cmd/concour/period.rs b/src/botv2/cmd/concour/period.rs index d5137a5..9ea9883 100644 --- a/src/botv2/cmd/concour/period.rs +++ b/src/botv2/cmd/concour/period.rs @@ -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() {