Added send_oper(...) to allow bots to oper up.

This commit is contained in:
Aaron Weiss 2014-10-29 00:17:49 -04:00
parent 7f67bd2905
commit 803e1e8ff4
2 changed files with 13 additions and 0 deletions

View file

@ -42,6 +42,10 @@ impl<'a, T, U> Bot for IrcBot<'a, T, U> where T: IrcWriter, U: IrcReader {
self.conn.send(Message::new(None, "MODE", [chan[], mode[]]))
}
fn send_oper(&self, name: &str, password: &str) -> IoResult<()> {
self.conn.send(Message::new(None, "OPER", [name[], password[]]))
}
fn send_topic(&self, chan: &str, topic: &str) -> IoResult<()> {
self.conn.send(Message::new(None, "TOPIC", [chan[], topic[]]))
}
@ -203,6 +207,14 @@ mod test {
assert_eq!(data(b.conn), format!("MODE #test :+i\r\n"));
}
#[test]
fn send_oper() {
let c = Connection::new(MemWriter::new(), NullReader).unwrap();
let b = IrcBot::from_connection(c, |_, _, _, _| { Ok(()) }).unwrap();
b.send_oper("test", "test").unwrap();
assert_eq!(data(b.conn), format!("OPER test :test\r\n"));
}
#[test]
fn send_topic() {
let c = Connection::new(MemWriter::new(), NullReader).unwrap();

View file

@ -17,6 +17,7 @@ pub trait Bot {
fn send_user(&self, username: &str, real_name: &str) -> IoResult<()>;
fn send_join(&self, chan: &str) -> IoResult<()>;
fn send_mode(&self, chan: &str, mode: &str) -> IoResult<()>;
fn send_oper(&self, name: &str, password: &str) -> IoResult<()>;
fn send_topic(&self, chan: &str, topic: &str) -> IoResult<()>;
fn send_invite(&self, person: &str, chan: &str) -> IoResult<()>;
fn send_privmsg(&self, chan: &str, msg: &str) -> IoResult<()>;