Merge pull request 'fix stuff for large messages' (#22) from missing/dircord:master into master

Reviewed-on: #22
This commit is contained in:
Yash Karandikar 2022-06-18 00:30:54 -05:00
commit c025ee2291
2 changed files with 21 additions and 18 deletions

View file

@ -46,7 +46,7 @@ impl<'a> Iterator for StrChunks<'a> {
} }
}; };
self.v = &self.v[self.v.len()..]; self.v = &self.v[offset..];
Some(res) 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],
&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) (prefix, content_limit)
} }

View file

@ -46,24 +46,20 @@ pub async fn irc_loop(
} }
while let Some(orig_message) = stream.next().await.transpose()? { while let Some(orig_message) = stream.next().await.transpose()? {
match orig_message.command { if let Command::Response(response, args) = orig_message.command {
Command::Response(response, args) => { use irc::client::prelude::Response;
use irc::client::prelude::Response;
// if let Response::RPL_NAMREPLY = response { if response == Response::RPL_NAMREPLY {
if response == Response::RPL_NAMREPLY { let channel = args[2].to_string();
let channel = args[2].to_string(); let users = args[3]
let users = args[3] .split(' ')
.split(' ') .map(ToOwned::to_owned)
.map(ToOwned::to_owned) .collect::<Vec<String>>();
.collect::<Vec<String>>();
channel_users.insert(channel, users); channel_users.insert(channel, users);
}
continue;
} }
_ => {}
continue;
}; };
let nickname = unwrap_or_continue!(orig_message.source_nickname()); let nickname = unwrap_or_continue!(orig_message.source_nickname());
@ -227,13 +223,18 @@ fn irc_to_discord_processing(
) )
.into_owned(); .into_owned();
computed = { #[allow(clippy::map_unwrap_or)]
{
computed = computed computed = computed
.strip_prefix("\x01ACTION ") .strip_prefix("\x01ACTION ")
.and_then(|s| s.strip_suffix('\x01')) .and_then(|s| s.strip_suffix('\x01'))
.map(|s| format!("*{}*", s)) .map(|s| format!("*{}*", s))
.unwrap_or_else(|| computed); // if any step in the way fails, fall back to using computed .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 new = String::with_capacity(computed.len());
let mut has_opened_bold = false; let mut has_opened_bold = false;
let mut has_opened_italic = false; let mut has_opened_italic = false;