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) } diff --git a/src/irc_discord.rs b/src/irc_discord.rs index ab25be7..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()); @@ -227,13 +223,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;