diff --git a/src/conn.rs b/src/conn.rs index a4bddf8..53d70ad 100644 --- a/src/conn.rs +++ b/src/conn.rs @@ -11,8 +11,7 @@ pub fn connect(host: &str, port: u16) -> IoResult { fn send_internal(conn: &Connection, msg: &str) -> IoResult<()> { let &Connection(ref tcp) = conn; let mut writer = BufferedWriter::new(tcp.clone()); - writer.write_str(msg); - writer.flush() + writer.write_str(msg) } pub fn send(conn: &Connection, msg: Message) -> IoResult<()> { diff --git a/src/data.rs b/src/data.rs index 52fa150..923fd72 100644 --- a/src/data.rs +++ b/src/data.rs @@ -20,6 +20,7 @@ impl<'a> Message<'a> { #[deriving(Decodable)] pub struct Config { + pub owners: Vec, pub nickname: String, pub username: String, pub realname: String, @@ -39,4 +40,8 @@ impl Config { detail: Some(e.to_string()), }) } + + pub fn is_owner(&self, nickname: &str) -> bool { + self.owners.as_slice().contains(&String::from_str(nickname)) + } } diff --git a/src/lib.rs b/src/lib.rs index 6294ecf..a50bdf4 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -43,7 +43,7 @@ impl<'a> Bot<'a> { pub fn send_join(&self, chan: &str) -> IoResult<()> { send(&self.conn, Message::new(None, "JOIN", [chan.as_slice()])) } - + pub fn send_mode(&self, chan: &str, mode: &str) -> IoResult<()> { send(&self.conn, Message::new(None, "MODE", [chan.as_slice(), mode.as_slice()])) } @@ -61,22 +61,23 @@ impl<'a> Bot<'a> { } pub fn identify(&self) -> IoResult<()> { - self.send_nick(self.config.nickname.as_slice()); + try!(self.send_nick(self.config.nickname.as_slice())); self.send_user(self.config.username.as_slice(), self.config.realname.as_slice()) } - pub fn output(&mut self) { + pub fn output(&mut self) -> IoResult<()> { let mut reader = { let Connection(ref tcp) = self.conn; BufferedReader::new(tcp.clone()) }; for line in reader.lines() { match line { Ok(ln) => { - let (source, command, args) = process(ln.as_slice()).unwrap(); - self.handle_command(source, command, args.as_slice()); + let (source, command, args) = try!(process(ln.as_slice())); + try!(self.handle_command(source, command, args.as_slice())); println!("{}", ln) }, Err(e) => println!("Shit, you're fucked! {}", e), } } + Ok(()) } fn handle_command(&mut self, source: &str, command: &str, args: &[&str]) -> IoResult<()> { @@ -137,7 +138,7 @@ impl<'a> Bot<'a> { } }, _ => { - (*self.process.borrow_mut().deref_mut())(self, source, command, args); + try!((*self.process.borrow_mut().deref_mut())(self, source, command, args)); }, }; Ok(())