diff options
author | Daniel Schadt <kingdread@gmx.de> | 2020-06-18 02:05:59 +0200 |
---|---|---|
committer | Daniel Schadt <kingdread@gmx.de> | 2020-06-18 02:05:59 +0200 |
commit | f511152cb33743026503297a18a74f118dec4bc6 (patch) | |
tree | 20fd65fd1bfdae2704d844dabacdb41554506f8f /src | |
parent | 507757d227aa00874a2d33caed1a78c5b8cc7132 (diff) | |
download | ezau-f511152cb33743026503297a18a74f118dec4bc6.tar.gz ezau-f511152cb33743026503297a18a74f118dec4bc6.tar.bz2 ezau-f511152cb33743026503297a18a74f118dec4bc6.zip |
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.
Diffstat (limited to 'src')
-rw-r--r-- | src/discord.rs | 12 |
1 files changed, 8 insertions, 4 deletions
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(()) } } |