summaryrefslogtreecommitdiff
path: root/src/commands/general
diff options
context:
space:
mode:
authorseth <[email protected]>2023-12-15 15:50:33 -0500
committerseth <[email protected]>2023-12-15 16:41:13 -0500
commite78f09012cef68cbbde8ace7d95d3c5dd5645a67 (patch)
tree3873234a55605c370e40315b20999b5d45a29967 /src/commands/general
parent49a521d27d859c7b94f3944a44d29660118e5561 (diff)
commands: handle bad user input in convert from_bottom
Diffstat (limited to 'src/commands/general')
-rw-r--r--src/commands/general/convert.rs17
1 files changed, 15 insertions, 2 deletions
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(())
}