Merge pull request #208 from tirz/feature-ctcp_multi_lines

feat: add multi lines support for CTCP
This commit is contained in:
Aaron Weiss 2020-05-14 10:56:08 -04:00 committed by GitHub
commit 99591ffeb0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -336,7 +336,11 @@ macro_rules! pub_sender_base {
S1: fmt::Display,
S2: fmt::Display,
{
self.send_privmsg(target, &format!("\u{001}{}\u{001}", msg.to_string())[..])
let msg = msg.to_string();
for line in msg.split("\r\n") {
self.send(PRIVMSG(target.to_string(), format!("\u{001}{}\u{001}", line)))?
}
Ok(())
}
/// Sends an action command to the specified target.
@ -1842,11 +1846,11 @@ mod test {
#[cfg(feature = "ctcp")]
async fn send_ctcp() -> Result<()> {
let mut client = Client::from_config(test_config()).await?;
client.send_ctcp("test", "MESSAGE")?;
client.send_ctcp("test", "LINE1\r\nLINE2\r\nLINE3")?;
client.stream()?.collect().await?;
assert_eq!(
&get_client_value(client)[..],
"PRIVMSG test \u{001}MESSAGE\u{001}\r\n"
"PRIVMSG test \u{001}LINE1\u{001}\r\nPRIVMSG test \u{001}LINE2\u{001}\r\nPRIVMSG test \u{001}LINE3\u{001}\r\n"
);
Ok(())
}