From f511152cb33743026503297a18a74f118dec4bc6 Mon Sep 17 00:00:00 2001 From: Daniel Schadt Date: Thu, 18 Jun 2020 02:05:59 +0200 Subject: respect Discord message max length This will ensure that ezau will post a new message if editing the old one would push it above the character limit. --- src/discord.rs | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) (limited to 'src/discord.rs') diff --git a/src/discord.rs b/src/discord.rs index 4f946bc..32cbf16 100644 --- a/src/discord.rs +++ b/src/discord.rs @@ -12,6 +12,7 @@ use log::info; use super::categories::Categorizable; const MAX_HOURS: i64 = 5; +const MAX_MESSAGE_LENGTH: usize = 2000; struct ShardManagerContainer; @@ -44,12 +45,15 @@ impl Handler { if let Some(mut m) = messages.pop() { let new_text = insert_link(&m.content, &self.log, &self.link); - m.edit(ctx, |m| m.content(new_text))?; - } else { - let new_text = insert_link("", &self.log, &self.link); - ChannelId(self.channel_id).say(ctx, new_text)?; + if new_text.len() <= MAX_MESSAGE_LENGTH { + m.edit(ctx, |m| m.content(new_text))?; + return Ok(()); + } } + let new_text = insert_link("", &self.log, &self.link); + ChannelId(self.channel_id).say(ctx, new_text)?; + Ok(()) } } -- cgit v1.2.3