Added kick command.

This commit is contained in:
Aaron Weiss 2014-10-26 23:29:31 -04:00
parent d719cc006b
commit f0bd2b99f1
2 changed files with 13 additions and 0 deletions

View file

@ -50,6 +50,10 @@ impl<'a, T, U> Bot for IrcBot<'a, T, U> where T: IrcWriter, U: IrcReader {
self.conn.send(Message::new(None, "INVITE", [person.as_slice(), chan.as_slice()]))
}
fn send_kick(&self, chan: &str, user: &str, msg: &str) -> IoResult<()> {
self.conn.send(Message::new(None, "KICK", [chan.as_slice(), user.as_slice(), msg.as_slice()]))
}
fn send_privmsg(&self, chan: &str, msg: &str) -> IoResult<()> {
for line in msg.split_str("\r\n") {
try!(self.conn.send(Message::new(None, "PRIVMSG", [chan.as_slice(), line.as_slice()])));
@ -222,6 +226,14 @@ mod test {
assert_eq!(b.conn.writer().deref_mut().get_ref(), "INVITE test2 :#test\r\n".as_bytes());
}
#[test]
fn send_kick() {
let c = Connection::new(MemWriter::new(), NullReader).unwrap();
let b = IrcBot::from_connection(c, |_, _, _, _| { Ok(()) }).unwrap();
b.send_kick("#test", "test2", "Goodbye.").unwrap();
assert_eq!(b.conn.writer().deref_mut().get_ref(), "KICK #test test2 :Goodbye.\r\n".as_bytes());
}
#[test]
fn send_privmsg() {
let c = Connection::new(MemWriter::new(), NullReader).unwrap();

View file

@ -18,6 +18,7 @@ pub trait Bot {
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<()>;
fn send_kick(&self, chan: &str, user: &str, msg: &str) -> IoResult<()>;
fn identify(&self) -> IoResult<()>;
fn output(&mut self) -> IoResult<()>;
fn config(&self) -> &Config;