From 35d1b9762f38dd607d0ff8216c7f131975257482 Mon Sep 17 00:00:00 2001 From: missing <4a656666official@gmail.com> Date: Fri, 17 Jun 2022 08:10:37 -0500 Subject: [PATCH 1/3] move the ACTION handler slightly --- src/irc_discord.rs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/irc_discord.rs b/src/irc_discord.rs index ab25be7..5f9bc1b 100644 --- a/src/irc_discord.rs +++ b/src/irc_discord.rs @@ -227,13 +227,18 @@ fn irc_to_discord_processing( ) .into_owned(); - computed = { + #[allow(clippy::map_unwrap_or)] + { computed = computed .strip_prefix("\x01ACTION ") .and_then(|s| s.strip_suffix('\x01')) .map(|s| format!("*{}*", s)) .unwrap_or_else(|| computed); // if any step in the way fails, fall back to using computed + } + + computed = { let mut new = String::with_capacity(computed.len()); + let mut has_opened_bold = false; let mut has_opened_italic = false; From c0a896e7c5fa25249b907683f1e4658dbf2e3cdb Mon Sep 17 00:00:00 2001 From: missing <4a656666official@gmail.com> Date: Fri, 17 Jun 2022 13:35:33 -0500 Subject: [PATCH 2/3] follow the clippy lints, they will guide you --- src/irc_discord.rs | 26 +++++++++++--------------- 1 file changed, 11 insertions(+), 15 deletions(-) diff --git a/src/irc_discord.rs b/src/irc_discord.rs index 5f9bc1b..6438d04 100644 --- a/src/irc_discord.rs +++ b/src/irc_discord.rs @@ -46,24 +46,20 @@ pub async fn irc_loop( } while let Some(orig_message) = stream.next().await.transpose()? { - match orig_message.command { - Command::Response(response, args) => { - use irc::client::prelude::Response; + if let Command::Response(response, args) = orig_message.command { + use irc::client::prelude::Response; - // if let Response::RPL_NAMREPLY = response { - if response == Response::RPL_NAMREPLY { - let channel = args[2].to_string(); - let users = args[3] - .split(' ') - .map(ToOwned::to_owned) - .collect::>(); + if response == Response::RPL_NAMREPLY { + let channel = args[2].to_string(); + let users = args[3] + .split(' ') + .map(ToOwned::to_owned) + .collect::>(); - channel_users.insert(channel, users); - } - - continue; + channel_users.insert(channel, users); } - _ => {} + + continue; }; let nickname = unwrap_or_continue!(orig_message.source_nickname()); From 497f04442583dae3a0a241d3dc9d47b159fc16ea Mon Sep 17 00:00:00 2001 From: missing <4a656666official@gmail.com> Date: Fri, 17 Jun 2022 13:36:42 -0500 Subject: [PATCH 3/3] fix StrChunks and content limit shenanigans --- src/discord_irc.rs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/discord_irc.rs b/src/discord_irc.rs index bf2d300..5015f3b 100644 --- a/src/discord_irc.rs +++ b/src/discord_irc.rs @@ -46,7 +46,7 @@ impl<'a> Iterator for StrChunks<'a> { } }; - self.v = &self.v[self.v.len()..]; + self.v = &self.v[offset..]; Some(res) } @@ -79,7 +79,9 @@ async fn create_prefix(msg: &Message, is_reply: bool, http: impl CacheHttp) -> ( &nick[..second_char_offset], &nick[second_char_offset..] ); - let content_limit = 510 - prefix.len(); + // this 400 is basically just a guess. we cant send exactly 512 byte messages, because + // if we do then the server cant send them back without going over the 512 limit itself. + let content_limit = 400 - prefix.len(); (prefix, content_limit) }