From 6db71ded01869ff0855d3f2797b5616857d1b9ed Mon Sep 17 00:00:00 2001 From: Aaron Weiss Date: Mon, 3 Nov 2014 14:12:23 -0500 Subject: [PATCH] Provided access to internal connections where needed, and added multi-line support to send_privmsg(...). --- src/conn.rs | 8 +++++++- src/lib.rs | 2 +- src/server/mod.rs | 5 +++++ src/server/utils.rs | 5 ++++- 4 files changed, 17 insertions(+), 3 deletions(-) diff --git a/src/conn.rs b/src/conn.rs index b057c50..533de00 100644 --- a/src/conn.rs +++ b/src/conn.rs @@ -1,6 +1,6 @@ //! Thread-safe connections on any IrcWriters and IrcReaders #![experimental] -use std::sync::Mutex; +use std::sync::{Mutex, MutexGuard}; use std::io::{BufferedReader, BufferedWriter, IoResult, TcpStream}; use data::kinds::{IrcWriter, IrcReader}; use data::message::Message; @@ -44,4 +44,10 @@ impl Connection where T: IrcWriter, U: IrcReader { pub fn recv(&self) -> IoResult { self.reader.lock().read_line() } + + /// Acquires the Writer lock + #[experimental] + pub fn writer<'a>(&'a self) -> MutexGuard<'a, T> { + self.writer.lock() + } } diff --git a/src/lib.rs b/src/lib.rs index 8c902f9..330f3df 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -7,6 +7,6 @@ #![feature(slicing_syntax)] extern crate serialize; - mod conn; +pub mod conn; pub mod data; pub mod server; diff --git a/src/server/mod.rs b/src/server/mod.rs index 0b24548..66634e8 100644 --- a/src/server/mod.rs +++ b/src/server/mod.rs @@ -70,6 +70,11 @@ impl<'a, T, U> IrcServer<'a, T, U> where T: IrcWriter, U: IrcReader { }) } + /// Gets a reference to the IRC server's connection + pub fn conn(&self) -> &Connection { + &self.conn + } + /// Handles messages internally for basic bot functionality #[experimental] fn handle_message(&self, message: &Message) { diff --git a/src/server/utils.rs b/src/server/utils.rs index 78c4bc6..3bd4afd 100644 --- a/src/server/utils.rs +++ b/src/server/utils.rs @@ -62,7 +62,10 @@ impl<'a, T, U> Wrapper<'a, T, U> where T: IrcWriter, U: IrcReader { /// Sends a message to the specified target #[experimental] pub fn send_privmsg(&self, target: &str, message: &str) -> IoResult<()> { - self.server.send(PRIVMSG(target, message)) + for line in message.split_str("\r\n") { + try!(self.server.send(PRIVMSG(target, line))) + } + Ok(()) } /// Kills the target with the provided message