From e78f09012cef68cbbde8ace7d95d3c5dd5645a67 Mon Sep 17 00:00:00 2001 From: seth Date: Fri, 15 Dec 2023 15:50:33 -0500 Subject: commands: handle bad user input in convert from_bottom --- src/commands/general/convert.rs | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) (limited to 'src/commands') diff --git a/src/commands/general/convert.rs b/src/commands/general/convert.rs index 5c41dfd..1dd7f60 100644 --- a/src/commands/general/convert.rs +++ b/src/commands/general/convert.rs @@ -2,6 +2,7 @@ use crate::Context; use bottomify::bottom; use color_eyre::eyre::Result; +use poise::serenity_prelude::constants::MESSAGE_CODE_LIMIT; #[allow(clippy::unused_async)] #[poise::command( @@ -51,7 +52,19 @@ pub async fn from_bottom( ctx: Context<'_>, #[description = "What teawie will translate from bottom"] message: String, ) -> Result<()> { - let decoded = bottom::decode_string(&message)?; - ctx.say(decoded).await?; + let resp: String; + + if let Ok(decoded) = bottom::decode_string(&message.clone()) { + resp = if decoded.len() > MESSAGE_CODE_LIMIT { + "The translation is too long to send, sorry :(".to_string() + } else { + decoded + } + } else { + resp = "Couldn't translate that for you :(".to_string(); + } + + ctx.say(resp).await?; + Ok(()) } -- cgit v1.2.3