Added from_connection(...) to make an IrcBot from any arbitrary connection.

This commit is contained in:
Aaron Weiss 2014-10-08 14:08:27 -04:00
parent af1f8ecf14
commit bb58dac93c

View file

@ -103,6 +103,16 @@ impl<'a, T, U> Bot<'a> for IrcBot<'a, T, U> where T: IrcWriter, U: IrcReader {
}
impl<'a, T, U> IrcBot<'a, T, U> where T: IrcWriter, U: IrcReader {
pub fn from_connection(conn: Connection<T, U>, process: |&IrcBot<T, U>, &str, &str, &[&str]|:'a -> IoResult<()>) -> IoResult<IrcBot<'a, T, U>> {
let config = try!(Config::load());
Ok(IrcBot {
conn: RefCell::new(conn),
config: config,
process: RefCell::new(process),
chanlists: HashMap::new(),
})
}
fn handle_command(&mut self, source: &str, command: &str, args: &[&str]) -> IoResult<()> {
match (command, args) {
("PING", [msg]) => {