Provided access to internal connections where needed, and added multi-line support to send_privmsg(...).

This commit is contained in:
Aaron Weiss 2014-11-03 14:12:23 -05:00
parent 25532d145e
commit 6db71ded01
4 changed files with 17 additions and 3 deletions

View file

@ -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<T, U> Connection<T, U> where T: IrcWriter, U: IrcReader {
pub fn recv(&self) -> IoResult<String> {
self.reader.lock().read_line()
}
/// Acquires the Writer lock
#[experimental]
pub fn writer<'a>(&'a self) -> MutexGuard<'a, T> {
self.writer.lock()
}
}

View file

@ -7,6 +7,6 @@
#![feature(slicing_syntax)]
extern crate serialize;
mod conn;
pub mod conn;
pub mod data;
pub mod server;

View file

@ -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<T, U> {
&self.conn
}
/// Handles messages internally for basic bot functionality
#[experimental]
fn handle_message(&self, message: &Message) {

View file

@ -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