Updated library for changes to enumerations.

This commit is contained in:
Aaron Weiss 2014-11-18 19:00:18 -05:00
parent df0f05f4be
commit 18646ae291
6 changed files with 263 additions and 254 deletions

View file

@ -19,7 +19,7 @@ impl Connection<BufferedStream<TcpStream>> {
#[experimental] #[experimental]
pub fn connect(host: &str, port: u16) -> IoResult<Connection<BufferedStream<NetStream>>> { pub fn connect(host: &str, port: u16) -> IoResult<Connection<BufferedStream<NetStream>>> {
let socket = try!(TcpStream::connect(format!("{}:{}", host, port)[])); let socket = try!(TcpStream::connect(format!("{}:{}", host, port)[]));
Ok(Connection::new(BufferedStream::new(UnsecuredTcpStream(socket)))) Ok(Connection::new(BufferedStream::new(NetStream::UnsecuredTcpStream(socket))))
} }
/// Creates a thread-safe TCP connection to the specified server over SSL. /// Creates a thread-safe TCP connection to the specified server over SSL.
@ -30,7 +30,7 @@ impl Connection<BufferedStream<TcpStream>> {
let socket = try!(TcpStream::connect(format!("{}:{}", host, port)[])); let socket = try!(TcpStream::connect(format!("{}:{}", host, port)[]));
let ssl = try!(ssl_to_io(SslContext::new(Tlsv1))); let ssl = try!(ssl_to_io(SslContext::new(Tlsv1)));
let ssl_socket = try!(ssl_to_io(SslStream::new(&ssl, socket))); let ssl_socket = try!(ssl_to_io(SslStream::new(&ssl, socket)));
Ok(Connection::new(BufferedStream::new(SslTcpStream(ssl_socket)))) Ok(Connection::new(BufferedStream::new(NetStream::SslTcpStream(ssl_socket))))
} }
/// Creates a thread-safe TCP connection to the specified server over SSL. /// Creates a thread-safe TCP connection to the specified server over SSL.
@ -69,9 +69,9 @@ pub enum NetStream {
impl Reader for NetStream { impl Reader for NetStream {
fn read(&mut self, buf: &mut [u8]) -> IoResult<uint> { fn read(&mut self, buf: &mut [u8]) -> IoResult<uint> {
match self { match self {
&UnsecuredTcpStream(ref mut stream) => stream.read(buf), &NetStream::UnsecuredTcpStream(ref mut stream) => stream.read(buf),
#[cfg(feature = "ssl")] #[cfg(feature = "ssl")]
&SslTcpStream(ref mut stream) => stream.read(buf), &NetStream::SslTcpStream(ref mut stream) => stream.read(buf),
} }
} }
} }
@ -79,9 +79,9 @@ impl Reader for NetStream {
impl Writer for NetStream { impl Writer for NetStream {
fn write(&mut self, buf: &[u8]) -> IoResult<()> { fn write(&mut self, buf: &[u8]) -> IoResult<()> {
match self { match self {
&UnsecuredTcpStream(ref mut stream) => stream.write(buf), &NetStream::UnsecuredTcpStream(ref mut stream) => stream.write(buf),
#[cfg(feature = "ssl")] #[cfg(feature = "ssl")]
&SslTcpStream(ref mut stream) => stream.write(buf), &NetStream::SslTcpStream(ref mut stream) => stream.write(buf),
} }
} }
} }

View file

@ -135,94 +135,103 @@ impl<'a> Command<'a> {
#[stable] #[stable]
pub fn to_message(self) -> Message { pub fn to_message(self) -> Message {
match self { match self {
PASS(p) => Message::new(None, "PASS", None, Some(p)), Command::PASS(p) => Message::new(None, "PASS", None, Some(p)),
NICK(n) => Message::new(None, "NICK", None, Some(n)), Command::NICK(n) => Message::new(None, "NICK", None, Some(n)),
USER(u, m, r) => Message::new(None, "USER", Some(vec![u, m, "*"]), Some(r)), Command::USER(u, m, r) => Message::new(None, "USER", Some(vec![u, m, "*"]), Some(r)),
OPER(u, p) => Message::new(None, "OPER", Some(vec![u]), Some(p)), Command::OPER(u, p) => Message::new(None, "OPER", Some(vec![u]), Some(p)),
MODE(t, m, Some(p)) => Message::new(None, "MODE", Some(vec![t, m, p]), None), Command::MODE(t, m, Some(p)) => Message::new(None, "MODE", Some(vec![t, m, p]), None),
MODE(t, m, None) => Message::new(None, "MODE", Some(vec![t, m]), None), Command::MODE(t, m, None) => Message::new(None, "MODE", Some(vec![t, m]), None),
SERVICE(n, r, d, t, re, i) => Message::new(None, "SERVICE", Command::SERVICE(n, r, d, t, re, i) => Message::new(None, "SERVICE",
Some(vec![n, r, d, t, re]), Some(i)), Some(vec![n, r, d, t, re]), Some(i)),
QUIT(Some(m)) => Message::new(None, "QUIT", None, Some(m)), Command::QUIT(Some(m)) => Message::new(None, "QUIT", None, Some(m)),
QUIT(None) => Message::new(None, "QUIT", None, None), Command::QUIT(None) => Message::new(None, "QUIT", None, None),
SQUIT(s, c) => Message::new(None, "SQUIT", Some(vec![s]), Some(c)), Command::SQUIT(s, c) => Message::new(None, "SQUIT", Some(vec![s]), Some(c)),
JOIN(c, Some(k)) => Message::new(None, "JOIN", Some(vec![c, k]), None), Command::JOIN(c, Some(k)) => Message::new(None, "JOIN", Some(vec![c, k]), None),
JOIN(c, None) => Message::new(None, "JOIN", Some(vec![c]), None), Command::JOIN(c, None) => Message::new(None, "JOIN", Some(vec![c]), None),
PART(c, Some(m)) => Message::new(None, "PART", Some(vec![c]), Some(m)), Command::PART(c, Some(m)) => Message::new(None, "PART", Some(vec![c]), Some(m)),
PART(c, None) => Message::new(None, "PART", Some(vec![c]), None), Command::PART(c, None) => Message::new(None, "PART", Some(vec![c]), None),
TOPIC(c, Some(t)) => Message::new(None, "TOPIC", Some(vec![c]), Some(t)), Command::TOPIC(c, Some(t)) => Message::new(None, "TOPIC", Some(vec![c]), Some(t)),
TOPIC(c, None) => Message::new(None, "TOPIC", Some(vec![c]), None), Command::TOPIC(c, None) => Message::new(None, "TOPIC", Some(vec![c]), None),
NAMES(Some(c), Some(t)) => Message::new(None, "NAMES", Some(vec![c]), Some(t)), Command::NAMES(Some(c), Some(t)) => Message::new(None, "NAMES", Some(vec![c]), Some(t)),
NAMES(Some(c), None) => Message::new(None, "NAMES", Some(vec![c]), None), Command::NAMES(Some(c), None) => Message::new(None, "NAMES", Some(vec![c]), None),
NAMES(None, _) => Message::new(None, "NAMES", None, None), Command::NAMES(None, _) => Message::new(None, "NAMES", None, None),
LIST(Some(c), Some(t)) => Message::new(None, "LIST", Some(vec![c]), Some(t)), Command::LIST(Some(c), Some(t)) => Message::new(None, "LIST", Some(vec![c]), Some(t)),
LIST(Some(c), None) => Message::new(None, "LIST", Some(vec![c]), None), Command::LIST(Some(c), None) => Message::new(None, "LIST", Some(vec![c]), None),
LIST(None, _) => Message::new(None, "LIST", None, None), Command::LIST(None, _) => Message::new(None, "LIST", None, None),
INVITE(n, c) => Message::new(None, "INVITE", Some(vec![n, c]), None), Command::INVITE(n, c) => Message::new(None, "INVITE", Some(vec![n, c]), None),
KICK(c, n, Some(r)) => Message::new(None, "KICK", Some(vec![c, n]), Some(r)), Command::KICK(c, n, Some(r)) => Message::new(None, "KICK", Some(vec![c, n]), Some(r)),
KICK(c, n, None) => Message::new(None, "KICK", Some(vec![c, n]), None), Command::KICK(c, n, None) => Message::new(None, "KICK", Some(vec![c, n]), None),
PRIVMSG(t, m) => Message::new(None, "PRIVMSG", Some(vec![t]), Some(m)), Command::PRIVMSG(t, m) => Message::new(None, "PRIVMSG", Some(vec![t]), Some(m)),
NOTICE(t, m) => Message::new(None, "NOTICE", Some(vec![t]), Some(m)), Command::NOTICE(t, m) => Message::new(None, "NOTICE", Some(vec![t]), Some(m)),
MOTD(Some(t)) => Message::new(None, "MOTD", None, Some(t)), Command::MOTD(Some(t)) => Message::new(None, "MOTD", None, Some(t)),
MOTD(None) => Message::new(None, "MOTD", None, None), Command::MOTD(None) => Message::new(None, "MOTD", None, None),
LUSERS(Some(m), Some(t)) => Message::new(None, "LUSERS", Some(vec![m]), Some(t)), Command::LUSERS(Some(m), Some(t)) => Message::new(None, "LUSERS", Some(vec![m]),
LUSERS(Some(m), None) => Message::new(None, "LUSERS", Some(vec![m]), None), Some(t)),
LUSERS(None, _) => Message::new(None, "LUSERS", None, None), Command::LUSERS(Some(m), None) => Message::new(None, "LUSERS", Some(vec![m]), None),
VERSION(Some(t)) => Message::new(None, "VERSION", None, Some(t)), Command::LUSERS(None, _) => Message::new(None, "LUSERS", None, None),
VERSION(None) => Message::new(None, "VERSION", None, None), Command::VERSION(Some(t)) => Message::new(None, "VERSION", None, Some(t)),
STATS(Some(q), Some(t)) => Message::new(None, "STATS", Some(vec![q]), Some(t)), Command::VERSION(None) => Message::new(None, "VERSION", None, None),
STATS(Some(q), None) => Message::new(None, "STATS", Some(vec![q]), None), Command::STATS(Some(q), Some(t)) => Message::new(None, "STATS", Some(vec![q]), Some(t)),
STATS(None, _) => Message::new(None, "STATS", None, None), Command::STATS(Some(q), None) => Message::new(None, "STATS", Some(vec![q]), None),
LINKS(Some(r), Some(s)) => Message::new(None, "LINKS", Some(vec![r]), Some(s)), Command::STATS(None, _) => Message::new(None, "STATS", None, None),
LINKS(None, Some(s)) => Message::new(None, "LINKS", None, Some(s)), Command::LINKS(Some(r), Some(s)) => Message::new(None, "LINKS", Some(vec![r]), Some(s)),
LINKS(_, None) => Message::new(None, "LINKS", None, None), Command::LINKS(None, Some(s)) => Message::new(None, "LINKS", None, Some(s)),
TIME(Some(t)) => Message::new(None, "TIME", None, Some(t)), Command::LINKS(_, None) => Message::new(None, "LINKS", None, None),
TIME(None) => Message::new(None, "TIME", None, None), Command::TIME(Some(t)) => Message::new(None, "TIME", None, Some(t)),
CONNECT(t, p, Some(r)) => Message::new(None, "CONNECT", Some(vec![t, p]), Some(r)), Command::TIME(None) => Message::new(None, "TIME", None, None),
CONNECT(t, p, None) => Message::new(None, "CONNECT", Some(vec![t, p]), None), Command::CONNECT(t, p, Some(r)) => Message::new(None, "CONNECT", Some(vec![t, p]),
TRACE(Some(t)) => Message::new(None, "TRACE", None, Some(t)), Some(r)),
TRACE(None) => Message::new(None, "TRACE", None, None), Command::CONNECT(t, p, None) => Message::new(None, "CONNECT", Some(vec![t, p]), None),
ADMIN(Some(t)) => Message::new(None, "ADMIN", None, Some(t)), Command::TRACE(Some(t)) => Message::new(None, "TRACE", None, Some(t)),
ADMIN(None) => Message::new(None, "ADMIN", None, None), Command::TRACE(None) => Message::new(None, "TRACE", None, None),
INFO(Some(t)) => Message::new(None, "INFO", None, Some(t)), Command::ADMIN(Some(t)) => Message::new(None, "ADMIN", None, Some(t)),
INFO(None) => Message::new(None, "INFO", None, None), Command::ADMIN(None) => Message::new(None, "ADMIN", None, None),
SERVLIST(Some(m), Some(t)) => Message::new(None, "SERVLIST", Some(vec![m]), Some(t)), Command::INFO(Some(t)) => Message::new(None, "INFO", None, Some(t)),
SERVLIST(Some(m), None) => Message::new(None, "SERVLIST", Some(vec![m]), None), Command::INFO(None) => Message::new(None, "INFO", None, None),
SERVLIST(None, _) => Message::new(None, "SERVLIST", None, None), Command::SERVLIST(Some(m), Some(t)) => Message::new(None, "SERVLIST", Some(vec![m]),
SQUERY(s, t) => Message::new(None, "SQUERY", Some(vec![s, t]), None), Some(t)),
WHO(Some(s), Some(true)) => Message::new(None, "WHO", Some(vec![s, "o"]), None), Command::SERVLIST(Some(m), None) => Message::new(None, "SERVLIST", Some(vec![m]), None),
WHO(Some(s), _) => Message::new(None, "WHO", Some(vec![s]), None), Command::SERVLIST(None, _) => Message::new(None, "SERVLIST", None, None),
WHO(None, _) => Message::new(None, "WHO", None, None), Command::SQUERY(s, t) => Message::new(None, "SQUERY", Some(vec![s, t]), None),
WHOIS(Some(t), m) => Message::new(None, "WHOIS", Some(vec![t, m]), None), Command::WHO(Some(s), Some(true)) => Message::new(None, "WHO", Some(vec![s, "o"]),
WHOIS(None, m) => Message::new(None, "WHOIS", Some(vec![m]), None), None),
WHOWAS(n, Some(c), Some(t)) => Message::new(None, "WHOWAS", Some(vec![n, c]), Some(t)), Command::WHO(Some(s), _) => Message::new(None, "WHO", Some(vec![s]), None),
WHOWAS(n, Some(c), None) => Message::new(None, "WHOWAS", Some(vec![n, c]), None), Command::WHO(None, _) => Message::new(None, "WHO", None, None),
WHOWAS(n, None, _) => Message::new(None, "WHOWAS", Some(vec![n]), None), Command::WHOIS(Some(t), m) => Message::new(None, "WHOIS", Some(vec![t, m]), None),
KILL(n, c) => Message::new(None, "KILL", Some(vec![n]), Some(c)), Command::WHOIS(None, m) => Message::new(None, "WHOIS", Some(vec![m]), None),
PING(s, Some(t)) => Message::new(None, "PING", Some(vec![s]), Some(t)), Command::WHOWAS(n, Some(c), Some(t)) => Message::new(None, "WHOWAS", Some(vec![n, c]),
PING(s, None) => Message::new(None, "PING", None, Some(s)), Some(t)),
PONG(s, Some(t)) => Message::new(None, "PONG", Some(vec![s]), Some(t)), Command::WHOWAS(n, Some(c), None) => Message::new(None, "WHOWAS", Some(vec![n, c]),
PONG(s, None) => Message::new(None, "PONG", None, Some(s)), None),
ERROR(m) => Message::new(None, "ERROR", None, Some(m)), Command::WHOWAS(n, None, _) => Message::new(None, "WHOWAS", Some(vec![n]), None),
AWAY(Some(m)) => Message::new(None, "AWAY", None, Some(m)), Command::KILL(n, c) => Message::new(None, "KILL", Some(vec![n]), Some(c)),
AWAY(None) => Message::new(None, "AWAY", None, None), Command::PING(s, Some(t)) => Message::new(None, "PING", Some(vec![s]), Some(t)),
REHASH => Message::new(None, "REHASH", None, None), Command::PING(s, None) => Message::new(None, "PING", None, Some(s)),
DIE => Message::new(None, "DIE", None, None), Command::PONG(s, Some(t)) => Message::new(None, "PONG", Some(vec![s]), Some(t)),
RESTART => Message::new(None, "RESTART", None, None), Command::PONG(s, None) => Message::new(None, "PONG", None, Some(s)),
SUMMON(u, Some(t), Some(c)) => Message::new(None, "SUMMON", Some(vec![u, t]), Some(c)), Command::ERROR(m) => Message::new(None, "ERROR", None, Some(m)),
SUMMON(u, Some(t), None) => Message::new(None, "SUMMON", Some(vec![u, t]), None), Command::AWAY(Some(m)) => Message::new(None, "AWAY", None, Some(m)),
SUMMON(u, None, _) => Message::new(None, "SUMMON", Some(vec![u]), None), Command::AWAY(None) => Message::new(None, "AWAY", None, None),
USERS(Some(t)) => Message::new(None, "USERS", None, Some(t)), Command::REHASH => Message::new(None, "REHASH", None, None),
USERS(None) => Message::new(None, "USERS", None, None), Command::DIE => Message::new(None, "DIE", None, None),
WALLOPS(t) => Message::new(None, "WALLOPS", None, Some(t)), Command::RESTART => Message::new(None, "RESTART", None, None),
USERHOST(u) => Message::new(None, "USERHOST", Some(u), None), Command::SUMMON(u, Some(t), Some(c)) => Message::new(None, "SUMMON", Some(vec![u, t]),
ISON(u) => Message::new(None, "ISON", Some(u), None), Some(c)),
SAJOIN(n, c) => Message::new(None, "SAJOIN", Some(vec![n, c]), None), Command::SUMMON(u, Some(t), None) => Message::new(None, "SUMMON", Some(vec![u, t]),
SAMODE(t, m, Some(p)) => Message::new(None, "SAMODE", Some(vec![t, m, p]), None), None),
SAMODE(t, m, None) => Message::new(None, "SAMODE", Some(vec![t, m]), None), Command::SUMMON(u, None, _) => Message::new(None, "SUMMON", Some(vec![u]), None),
SANICK(o, n) => Message::new(None, "SANICK", Some(vec![o, n]), None), Command::USERS(Some(t)) => Message::new(None, "USERS", None, Some(t)),
SAPART(c, r) => Message::new(None, "SAPART", Some(vec![c]), Some(r)), Command::USERS(None) => Message::new(None, "USERS", None, None),
SAQUIT(c, r) => Message::new(None, "SAQUIT", Some(vec![c]), Some(r)), Command::WALLOPS(t) => Message::new(None, "WALLOPS", None, Some(t)),
Command::USERHOST(u) => Message::new(None, "USERHOST", Some(u), None),
Command::ISON(u) => Message::new(None, "ISON", Some(u), None),
Command::SAJOIN(n, c) => Message::new(None, "SAJOIN", Some(vec![n, c]), None),
Command::SAMODE(t, m, Some(p)) => Message::new(None, "SAMODE", Some(vec![t, m, p]),
None),
Command::SAMODE(t, m, None) => Message::new(None, "SAMODE", Some(vec![t, m]), None),
Command::SANICK(o, n) => Message::new(None, "SANICK", Some(vec![o, n]), None),
Command::SAPART(c, r) => Message::new(None, "SAPART", Some(vec![c]), Some(r)),
Command::SAQUIT(c, r) => Message::new(None, "SAQUIT", Some(vec![c]), Some(r)),
} }
} }
@ -233,56 +242,56 @@ impl<'a> Command<'a> {
match m.suffix { match m.suffix {
Some(ref suffix) => { Some(ref suffix) => {
if m.args.len() != 0 { return Err(invalid_input()) } if m.args.len() != 0 { return Err(invalid_input()) }
PASS(suffix[]) Command::PASS(suffix[])
}, },
None => { None => {
if m.args.len() != 1 { return Err(invalid_input()) } if m.args.len() != 1 { return Err(invalid_input()) }
PASS(m.args[0][]) Command::PASS(m.args[0][])
} }
} }
} else if let "NICK" = m.command[] { } else if let "NICK" = m.command[] {
match m.suffix { match m.suffix {
Some(ref suffix) => { Some(ref suffix) => {
if m.args.len() != 0 { return Err(invalid_input()) } if m.args.len() != 0 { return Err(invalid_input()) }
NICK(suffix[]) Command::NICK(suffix[])
}, },
None => { None => {
if m.args.len() != 1 { return Err(invalid_input()) } if m.args.len() != 1 { return Err(invalid_input()) }
NICK(m.args[0][]) Command::NICK(m.args[0][])
} }
} }
} else if let "USER" = m.command[] { } else if let "USER" = m.command[] {
match m.suffix { match m.suffix {
Some(ref suffix) => { Some(ref suffix) => {
if m.args.len() != 2 { return Err(invalid_input()) } if m.args.len() != 2 { return Err(invalid_input()) }
USER(m.args[0][], m.args[1][], suffix[]) Command::USER(m.args[0][], m.args[1][], suffix[])
}, },
None => { None => {
if m.args.len() != 3 { return Err(invalid_input()) } if m.args.len() != 3 { return Err(invalid_input()) }
USER(m.args[0][], m.args[1][], m.args[2][]) Command::USER(m.args[0][], m.args[1][], m.args[2][])
} }
} }
} else if let "OPER" = m.command[] { } else if let "OPER" = m.command[] {
match m.suffix { match m.suffix {
Some(ref suffix) => { Some(ref suffix) => {
if m.args.len() != 1 { return Err(invalid_input()) } if m.args.len() != 1 { return Err(invalid_input()) }
OPER(m.args[0][], suffix[]) Command::OPER(m.args[0][], suffix[])
}, },
None => { None => {
if m.args.len() != 2 { return Err(invalid_input()) } if m.args.len() != 2 { return Err(invalid_input()) }
OPER(m.args[0][], m.args[1][]) Command::OPER(m.args[0][], m.args[1][])
} }
} }
} else if let "MODE" = m.command[] { } else if let "MODE" = m.command[] {
match m.suffix { match m.suffix {
Some(ref suffix) => { Some(ref suffix) => {
if m.args.len() != 2 { return Err(invalid_input()) } if m.args.len() != 2 { return Err(invalid_input()) }
MODE(m.args[0][], m.args[1][], Some(suffix[])) Command::MODE(m.args[0][], m.args[1][], Some(suffix[]))
} }
None => if m.args.len() == 3 { None => if m.args.len() == 3 {
MODE(m.args[0][], m.args[1][], Some(m.args[2][])) Command::MODE(m.args[0][], m.args[1][], Some(m.args[2][]))
} else if m.args.len() == 2 { } else if m.args.len() == 2 {
MODE(m.args[0][], m.args[1][], None) Command::MODE(m.args[0][], m.args[1][], None)
} else { } else {
return Err(invalid_input()) return Err(invalid_input())
} }
@ -291,43 +300,45 @@ impl<'a> Command<'a> {
match m.suffix { match m.suffix {
Some(ref suffix) => { Some(ref suffix) => {
if m.args.len() != 5 { return Err(invalid_input()) } if m.args.len() != 5 { return Err(invalid_input()) }
SERVICE(m.args[0][], m.args[1][], m.args[2][], m.args[3][], m.args[4][], suffix[]) Command::SERVICE(m.args[0][], m.args[1][], m.args[2][], m.args[3][],
m.args[4][], suffix[])
}, },
None => { None => {
if m.args.len() != 6 { return Err(invalid_input()) } if m.args.len() != 6 { return Err(invalid_input()) }
SERVICE(m.args[0][], m.args[1][], m.args[2][], m.args[3][], m.args[4][], m.args[5][]) Command::SERVICE(m.args[0][], m.args[1][], m.args[2][], m.args[3][],
m.args[4][], m.args[5][])
} }
} }
} else if let "QUIT" = m.command[] { } else if let "QUIT" = m.command[] {
if m.args.len() != 0 { return Err(invalid_input()) } if m.args.len() != 0 { return Err(invalid_input()) }
match m.suffix { match m.suffix {
Some(ref suffix) => QUIT(Some(suffix[])), Some(ref suffix) => Command::QUIT(Some(suffix[])),
None => QUIT(None) None => Command::QUIT(None)
} }
} else if let "SQUIT" = m.command[] { } else if let "SQUIT" = m.command[] {
match m.suffix { match m.suffix {
Some(ref suffix) => { Some(ref suffix) => {
if m.args.len() != 1 { return Err(invalid_input()) } if m.args.len() != 1 { return Err(invalid_input()) }
SQUIT(m.args[0][], suffix[]) Command::SQUIT(m.args[0][], suffix[])
}, },
None => { None => {
if m.args.len() != 2 { return Err(invalid_input()) } if m.args.len() != 2 { return Err(invalid_input()) }
SQUIT(m.args[0][], m.args[1][]) Command::SQUIT(m.args[0][], m.args[1][])
} }
} }
} else if let "JOIN" = m.command[] { } else if let "JOIN" = m.command[] {
match m.suffix { match m.suffix {
Some(ref suffix) => if m.args.len() == 0 { Some(ref suffix) => if m.args.len() == 0 {
JOIN(suffix[], None) Command::JOIN(suffix[], None)
} else if m.args.len() == 1 { } else if m.args.len() == 1 {
JOIN(m.args[0][], Some(suffix[])) Command::JOIN(m.args[0][], Some(suffix[]))
} else { } else {
return Err(invalid_input()) return Err(invalid_input())
}, },
None => if m.args.len() == 1 { None => if m.args.len() == 1 {
JOIN(m.args[0][], None) Command::JOIN(m.args[0][], None)
} else if m.args.len() == 2 { } else if m.args.len() == 2 {
JOIN(m.args[0][], Some(m.args[1][])) Command::JOIN(m.args[0][], Some(m.args[1][]))
} else { } else {
return Err(invalid_input()) return Err(invalid_input())
} }
@ -335,16 +346,16 @@ impl<'a> Command<'a> {
} else if let "PART" = m.command[] { } else if let "PART" = m.command[] {
match m.suffix { match m.suffix {
Some(ref suffix) => if m.args.len() == 0 { Some(ref suffix) => if m.args.len() == 0 {
PART(suffix[], None) Command::PART(suffix[], None)
} else if m.args.len() == 1 { } else if m.args.len() == 1 {
PART(m.args[0][], Some(suffix[])) Command::PART(m.args[0][], Some(suffix[]))
} else { } else {
return Err(invalid_input()) return Err(invalid_input())
}, },
None => if m.args.len() == 1 { None => if m.args.len() == 1 {
PART(m.args[0][], None) Command::PART(m.args[0][], None)
} else if m.args.len() == 2 { } else if m.args.len() == 2 {
PART(m.args[0][], Some(m.args[1][])) Command::PART(m.args[0][], Some(m.args[1][]))
} else { } else {
return Err(invalid_input()) return Err(invalid_input())
} }
@ -352,16 +363,16 @@ impl<'a> Command<'a> {
} else if let "TOPIC" = m.command[] { } else if let "TOPIC" = m.command[] {
match m.suffix { match m.suffix {
Some(ref suffix) => if m.args.len() == 0 { Some(ref suffix) => if m.args.len() == 0 {
TOPIC(suffix[], None) Command::TOPIC(suffix[], None)
} else if m.args.len() == 1 { } else if m.args.len() == 1 {
TOPIC(m.args[0][], Some(suffix[])) Command::TOPIC(m.args[0][], Some(suffix[]))
} else { } else {
return Err(invalid_input()) return Err(invalid_input())
}, },
None => if m.args.len() == 1 { None => if m.args.len() == 1 {
TOPIC(m.args[0][], None) Command::TOPIC(m.args[0][], None)
} else if m.args.len() == 2 { } else if m.args.len() == 2 {
TOPIC(m.args[0][], Some(m.args[1][])) Command::TOPIC(m.args[0][], Some(m.args[1][]))
} else { } else {
return Err(invalid_input()) return Err(invalid_input())
} }
@ -369,18 +380,18 @@ impl<'a> Command<'a> {
} else if let "NAMES" = m.command[] { } else if let "NAMES" = m.command[] {
match m.suffix { match m.suffix {
Some(ref suffix) => if m.args.len() == 0 { Some(ref suffix) => if m.args.len() == 0 {
NAMES(Some(suffix[]), None) Command::NAMES(Some(suffix[]), None)
} else if m.args.len() == 1 { } else if m.args.len() == 1 {
NAMES(Some(m.args[0][]), Some(suffix[])) Command::NAMES(Some(m.args[0][]), Some(suffix[]))
} else { } else {
return Err(invalid_input()) return Err(invalid_input())
}, },
None => if m.args.len() == 0 { None => if m.args.len() == 0 {
NAMES(None, None) Command::NAMES(None, None)
} else if m.args.len() == 1 { } else if m.args.len() == 1 {
NAMES(Some(m.args[0][]), None) Command::NAMES(Some(m.args[0][]), None)
} else if m.args.len() == 2 { } else if m.args.len() == 2 {
NAMES(Some(m.args[0][]), Some(m.args[1][])) Command::NAMES(Some(m.args[0][]), Some(m.args[1][]))
} else { } else {
return Err(invalid_input()) return Err(invalid_input())
} }
@ -388,18 +399,18 @@ impl<'a> Command<'a> {
} else if let "LIST" = m.command[] { } else if let "LIST" = m.command[] {
match m.suffix { match m.suffix {
Some(ref suffix) => if m.args.len() == 0 { Some(ref suffix) => if m.args.len() == 0 {
LIST(Some(suffix[]), None) Command::LIST(Some(suffix[]), None)
} else if m.args.len() == 1 { } else if m.args.len() == 1 {
LIST(Some(m.args[0][]), Some(suffix[])) Command::LIST(Some(m.args[0][]), Some(suffix[]))
} else { } else {
return Err(invalid_input()) return Err(invalid_input())
}, },
None => if m.args.len() == 0 { None => if m.args.len() == 0 {
LIST(None, None) Command::LIST(None, None)
} else if m.args.len() == 1 { } else if m.args.len() == 1 {
LIST(Some(m.args[0][]), None) Command::LIST(Some(m.args[0][]), None)
} else if m.args.len() == 2 { } else if m.args.len() == 2 {
LIST(Some(m.args[0][]), Some(m.args[1][])) Command::LIST(Some(m.args[0][]), Some(m.args[1][]))
} else { } else {
return Err(invalid_input()) return Err(invalid_input())
} }
@ -408,29 +419,29 @@ impl<'a> Command<'a> {
match m.suffix { match m.suffix {
Some(ref suffix) => { Some(ref suffix) => {
if m.args.len() != 1 { return Err(invalid_input()) } if m.args.len() != 1 { return Err(invalid_input()) }
INVITE(m.args[0][], suffix[]) Command::INVITE(m.args[0][], suffix[])
}, },
None => { None => {
if m.args.len() != 2 { return Err(invalid_input()) } if m.args.len() != 2 { return Err(invalid_input()) }
INVITE(m.args[0][], m.args[1][]) Command::INVITE(m.args[0][], m.args[1][])
} }
} }
} else if let "KICK" = m.command[] { } else if let "KICK" = m.command[] {
match m.suffix { match m.suffix {
Some(ref suffix) => { Some(ref suffix) => {
if m.args.len() != 2 { return Err(invalid_input()) } if m.args.len() != 2 { return Err(invalid_input()) }
KICK(m.args[0][], m.args[1][], Some(suffix[])) Command::KICK(m.args[0][], m.args[1][], Some(suffix[]))
}, },
None => { None => {
if m.args.len() != 2 { return Err(invalid_input()) } if m.args.len() != 2 { return Err(invalid_input()) }
KICK(m.args[0][], m.args[1][], None) Command::KICK(m.args[0][], m.args[1][], None)
}, },
} }
} else if let "PRIVMSG" = m.command[] { } else if let "PRIVMSG" = m.command[] {
match m.suffix { match m.suffix {
Some(ref suffix) => { Some(ref suffix) => {
if m.args.len() != 1 { return Err(invalid_input()) } if m.args.len() != 1 { return Err(invalid_input()) }
PRIVMSG(m.args[0][], suffix[]) Command::PRIVMSG(m.args[0][], suffix[])
}, },
None => return Err(invalid_input()) None => return Err(invalid_input())
} }
@ -438,31 +449,31 @@ impl<'a> Command<'a> {
match m.suffix { match m.suffix {
Some(ref suffix) => { Some(ref suffix) => {
if m.args.len() != 1 { return Err(invalid_input()) } if m.args.len() != 1 { return Err(invalid_input()) }
NOTICE(m.args[0][], suffix[]) Command::NOTICE(m.args[0][], suffix[])
}, },
None => return Err(invalid_input()) None => return Err(invalid_input())
} }
} else if let "MOTD" = m.command[] { } else if let "MOTD" = m.command[] {
if m.args.len() != 0 { return Err(invalid_input()) } if m.args.len() != 0 { return Err(invalid_input()) }
match m.suffix { match m.suffix {
Some(ref suffix) => MOTD(Some(suffix[])), Some(ref suffix) => Command::MOTD(Some(suffix[])),
None => MOTD(None) None => Command::MOTD(None)
} }
} else if let "LUSERS" = m.command[] { } else if let "LUSERS" = m.command[] {
match m.suffix { match m.suffix {
Some(ref suffix) => if m.args.len() == 0 { Some(ref suffix) => if m.args.len() == 0 {
LUSERS(Some(suffix[]), None) Command::LUSERS(Some(suffix[]), None)
} else if m.args.len() == 1 { } else if m.args.len() == 1 {
LUSERS(Some(m.args[0][]), Some(suffix[])) Command::LUSERS(Some(m.args[0][]), Some(suffix[]))
} else { } else {
return Err(invalid_input()) return Err(invalid_input())
}, },
None => if m.args.len() == 0 { None => if m.args.len() == 0 {
LUSERS(None, None) Command::LUSERS(None, None)
} else if m.args.len() == 1 { } else if m.args.len() == 1 {
LUSERS(Some(m.args[0][]), None) Command::LUSERS(Some(m.args[0][]), None)
} else if m.args.len() == 2 { } else if m.args.len() == 2 {
LUSERS(Some(m.args[0][]), Some(m.args[1][])) Command::LUSERS(Some(m.args[0][]), Some(m.args[1][]))
} else { } else {
return Err(invalid_input()) return Err(invalid_input())
} }
@ -470,24 +481,24 @@ impl<'a> Command<'a> {
} else if let "VERSION" = m.command[] { } else if let "VERSION" = m.command[] {
if m.args.len() != 0 { return Err(invalid_input()) } if m.args.len() != 0 { return Err(invalid_input()) }
match m.suffix { match m.suffix {
Some(ref suffix) => VERSION(Some(suffix[])), Some(ref suffix) => Command::VERSION(Some(suffix[])),
None => VERSION(None) None => Command::VERSION(None)
} }
} else if let "STATS" = m.command[] { } else if let "STATS" = m.command[] {
match m.suffix { match m.suffix {
Some(ref suffix) => if m.args.len() == 0 { Some(ref suffix) => if m.args.len() == 0 {
STATS(Some(suffix[]), None) Command::STATS(Some(suffix[]), None)
} else if m.args.len() == 1 { } else if m.args.len() == 1 {
STATS(Some(m.args[0][]), Some(suffix[])) Command::STATS(Some(m.args[0][]), Some(suffix[]))
} else { } else {
return Err(invalid_input()) return Err(invalid_input())
}, },
None => if m.args.len() == 0 { None => if m.args.len() == 0 {
STATS(None, None) Command::STATS(None, None)
} else if m.args.len() == 1 { } else if m.args.len() == 1 {
STATS(Some(m.args[0][]), None) Command::STATS(Some(m.args[0][]), None)
} else if m.args.len() == 2 { } else if m.args.len() == 2 {
STATS(Some(m.args[0][]), Some(m.args[1][])) Command::STATS(Some(m.args[0][]), Some(m.args[1][]))
} else { } else {
return Err(invalid_input()) return Err(invalid_input())
} }
@ -495,14 +506,14 @@ impl<'a> Command<'a> {
} else if let "LINKS" = m.command[] { } else if let "LINKS" = m.command[] {
match m.suffix { match m.suffix {
Some(ref suffix) => if m.args.len() == 0 { Some(ref suffix) => if m.args.len() == 0 {
LINKS(None, Some(suffix[])) Command::LINKS(None, Some(suffix[]))
} else if m.args.len() == 1 { } else if m.args.len() == 1 {
LINKS(Some(m.args[0][]), Some(suffix[])) Command::LINKS(Some(m.args[0][]), Some(suffix[]))
} else { } else {
return Err(invalid_input()) return Err(invalid_input())
}, },
None => if m.args.len() == 0 { None => if m.args.len() == 0 {
LINKS(None, None) Command::LINKS(None, None)
} else { } else {
return Err(invalid_input()) return Err(invalid_input())
} }
@ -510,53 +521,53 @@ impl<'a> Command<'a> {
} else if let "TIME" = m.command[] { } else if let "TIME" = m.command[] {
if m.args.len() != 0 { return Err(invalid_input()) } if m.args.len() != 0 { return Err(invalid_input()) }
match m.suffix { match m.suffix {
Some(ref suffix) => TIME(Some(suffix[])), Some(ref suffix) => Command::TIME(Some(suffix[])),
None => TIME(None) None => Command::TIME(None)
} }
} else if let "CONNECT" = m.command[] { } else if let "CONNECT" = m.command[] {
match m.suffix { match m.suffix {
Some(ref suffix) => { Some(ref suffix) => {
if m.args.len() != 2 { return Err(invalid_input()) } if m.args.len() != 2 { return Err(invalid_input()) }
CONNECT(m.args[0][], m.args[1][], Some(suffix[])) Command::CONNECT(m.args[0][], m.args[1][], Some(suffix[]))
}, },
None => { None => {
if m.args.len() != 2 { return Err(invalid_input()) } if m.args.len() != 2 { return Err(invalid_input()) }
CONNECT(m.args[0][], m.args[1][], None) Command::CONNECT(m.args[0][], m.args[1][], None)
} }
} }
} else if let "TRACE" = m.command[] { } else if let "TRACE" = m.command[] {
if m.args.len() != 0 { return Err(invalid_input()) } if m.args.len() != 0 { return Err(invalid_input()) }
match m.suffix { match m.suffix {
Some(ref suffix) => TRACE(Some(suffix[])), Some(ref suffix) => Command::TRACE(Some(suffix[])),
None => TRACE(None) None => Command::TRACE(None)
} }
} else if let "ADMIN" = m.command[] { } else if let "ADMIN" = m.command[] {
if m.args.len() != 0 { return Err(invalid_input()) } if m.args.len() != 0 { return Err(invalid_input()) }
match m.suffix { match m.suffix {
Some(ref suffix) => ADMIN(Some(suffix[])), Some(ref suffix) => Command::ADMIN(Some(suffix[])),
None => ADMIN(None) None => Command::ADMIN(None)
} }
} else if let "INFO" = m.command[] { } else if let "INFO" = m.command[] {
if m.args.len() != 0 { return Err(invalid_input()) } if m.args.len() != 0 { return Err(invalid_input()) }
match m.suffix { match m.suffix {
Some(ref suffix) => INFO(Some(suffix[])), Some(ref suffix) => Command::INFO(Some(suffix[])),
None => INFO(None) None => Command::INFO(None)
} }
} else if let "SERVLIST" = m.command[] { } else if let "SERVLIST" = m.command[] {
match m.suffix { match m.suffix {
Some(ref suffix) => if m.args.len() == 0 { Some(ref suffix) => if m.args.len() == 0 {
SERVLIST(Some(suffix[]), None) Command::SERVLIST(Some(suffix[]), None)
} else if m.args.len() == 1 { } else if m.args.len() == 1 {
SERVLIST(Some(m.args[0][]), Some(suffix[])) Command::SERVLIST(Some(m.args[0][]), Some(suffix[]))
} else { } else {
return Err(invalid_input()) return Err(invalid_input())
}, },
None => if m.args.len() == 0 { None => if m.args.len() == 0 {
SERVLIST(None, None) Command::SERVLIST(None, None)
} else if m.args.len() == 1 { } else if m.args.len() == 1 {
SERVLIST(Some(m.args[0][]), None) Command::SERVLIST(Some(m.args[0][]), None)
} else if m.args.len() == 2 { } else if m.args.len() == 2 {
SERVLIST(Some(m.args[0][]), Some(m.args[1][])) Command::SERVLIST(Some(m.args[0][]), Some(m.args[1][]))
} else { } else {
return Err(invalid_input()) return Err(invalid_input())
} }
@ -565,28 +576,28 @@ impl<'a> Command<'a> {
match m.suffix { match m.suffix {
Some(ref suffix) => { Some(ref suffix) => {
if m.args.len() != 1 { return Err(invalid_input()) } if m.args.len() != 1 { return Err(invalid_input()) }
SQUERY(m.args[0][], suffix[]) Command::SQUERY(m.args[0][], suffix[])
}, },
None => { None => {
if m.args.len() != 2 { return Err(invalid_input()) } if m.args.len() != 2 { return Err(invalid_input()) }
SQUERY(m.args[0][], m.args[1][]) Command::SQUERY(m.args[0][], m.args[1][])
} }
} }
} else if let "WHO" = m.command[] { } else if let "WHO" = m.command[] {
match m.suffix { match m.suffix {
Some(ref suffix) => if m.args.len() == 0 { Some(ref suffix) => if m.args.len() == 0 {
WHO(Some(suffix[]), None) Command::WHO(Some(suffix[]), None)
} else if m.args.len() == 1 { } else if m.args.len() == 1 {
WHO(Some(m.args[0][]), Some(suffix[] == "o")) Command::WHO(Some(m.args[0][]), Some(suffix[] == "o"))
} else { } else {
return Err(invalid_input()) return Err(invalid_input())
}, },
None => if m.args.len() == 0 { None => if m.args.len() == 0 {
WHO(None, None) Command::WHO(None, None)
} else if m.args.len() == 1 { } else if m.args.len() == 1 {
WHO(Some(m.args[0][]), None) Command::WHO(Some(m.args[0][]), None)
} else if m.args.len() == 2 { } else if m.args.len() == 2 {
WHO(Some(m.args[0][]), Some(m.args[1][] == "o")) Command::WHO(Some(m.args[0][]), Some(m.args[1][] == "o"))
} else { } else {
return Err(invalid_input()) return Err(invalid_input())
} }
@ -594,16 +605,16 @@ impl<'a> Command<'a> {
} else if let "WHOIS" = m.command[] { } else if let "WHOIS" = m.command[] {
match m.suffix { match m.suffix {
Some(ref suffix) => if m.args.len() == 0 { Some(ref suffix) => if m.args.len() == 0 {
WHOIS(None, suffix[]) Command::WHOIS(None, suffix[])
} else if m.args.len() == 1 { } else if m.args.len() == 1 {
WHOIS(Some(m.args[0][]), suffix[]) Command::WHOIS(Some(m.args[0][]), suffix[])
} else { } else {
return Err(invalid_input()) return Err(invalid_input())
}, },
None => if m.args.len() == 1 { None => if m.args.len() == 1 {
WHOIS(None, m.args[0][]) Command::WHOIS(None, m.args[0][])
} else if m.args.len() == 2 { } else if m.args.len() == 2 {
WHOIS(Some(m.args[0][]), m.args[1][]) Command::WHOIS(Some(m.args[0][]), m.args[1][])
} else { } else {
return Err(invalid_input()) return Err(invalid_input())
} }
@ -611,20 +622,20 @@ impl<'a> Command<'a> {
} else if let "WHOWAS" = m.command[] { } else if let "WHOWAS" = m.command[] {
match m.suffix { match m.suffix {
Some(ref suffix) => if m.args.len() == 0 { Some(ref suffix) => if m.args.len() == 0 {
WHOWAS(suffix[], None, None) Command::WHOWAS(suffix[], None, None)
} else if m.args.len() == 1 { } else if m.args.len() == 1 {
WHOWAS(m.args[0][], None, Some(suffix[])) Command::WHOWAS(m.args[0][], None, Some(suffix[]))
} else if m.args.len() == 2 { } else if m.args.len() == 2 {
WHOWAS(m.args[0][], Some(m.args[1][]), Some(suffix[])) Command::WHOWAS(m.args[0][], Some(m.args[1][]), Some(suffix[]))
} else { } else {
return Err(invalid_input()) return Err(invalid_input())
}, },
None => if m.args.len() == 1 { None => if m.args.len() == 1 {
WHOWAS(m.args[0][], None, None) Command::WHOWAS(m.args[0][], None, None)
} else if m.args.len() == 2 { } else if m.args.len() == 2 {
WHOWAS(m.args[0][], None, Some(m.args[1][])) Command::WHOWAS(m.args[0][], None, Some(m.args[1][]))
} else if m.args.len() == 3 { } else if m.args.len() == 3 {
WHOWAS(m.args[0][], Some(m.args[1][]), Some(m.args[2][])) Command::WHOWAS(m.args[0][], Some(m.args[1][]), Some(m.args[2][]))
} else { } else {
return Err(invalid_input()) return Err(invalid_input())
} }
@ -633,26 +644,26 @@ impl<'a> Command<'a> {
match m.suffix { match m.suffix {
Some(ref suffix) => { Some(ref suffix) => {
if m.args.len() != 1 { return Err(invalid_input()) } if m.args.len() != 1 { return Err(invalid_input()) }
KILL(m.args[0][], suffix[]) Command::KILL(m.args[0][], suffix[])
}, },
None => { None => {
if m.args.len() != 2 { return Err(invalid_input()) } if m.args.len() != 2 { return Err(invalid_input()) }
KILL(m.args[0][], m.args[1][]) Command::KILL(m.args[0][], m.args[1][])
} }
} }
} else if let "PING" = m.command[] { } else if let "PING" = m.command[] {
match m.suffix { match m.suffix {
Some(ref suffix) => if m.args.len() == 0 { Some(ref suffix) => if m.args.len() == 0 {
PING(suffix[], None) Command::PING(suffix[], None)
} else if m.args.len() == 1 { } else if m.args.len() == 1 {
PING(m.args[0][], Some(suffix[])) Command::PING(m.args[0][], Some(suffix[]))
} else { } else {
return Err(invalid_input()) return Err(invalid_input())
}, },
None => if m.args.len() == 1 { None => if m.args.len() == 1 {
PING(m.args[0][], None) Command::PING(m.args[0][], None)
} else if m.args.len() == 2 { } else if m.args.len() == 2 {
PING(m.args[0][], Some(m.args[1][])) Command::PING(m.args[0][], Some(m.args[1][]))
} else { } else {
return Err(invalid_input()) return Err(invalid_input())
} }
@ -660,16 +671,16 @@ impl<'a> Command<'a> {
} else if let "PONG" = m.command[] { } else if let "PONG" = m.command[] {
match m.suffix { match m.suffix {
Some(ref suffix) => if m.args.len() == 0 { Some(ref suffix) => if m.args.len() == 0 {
PONG(suffix[], None) Command::PONG(suffix[], None)
} else if m.args.len() == 1 { } else if m.args.len() == 1 {
PONG(m.args[0][], Some(suffix[])) Command::PONG(m.args[0][], Some(suffix[]))
} else { } else {
return Err(invalid_input()) return Err(invalid_input())
}, },
None => if m.args.len() == 1 { None => if m.args.len() == 1 {
PONG(m.args[0][], None) Command::PONG(m.args[0][], None)
} else if m.args.len() == 2 { } else if m.args.len() == 2 {
PONG(m.args[0][], Some(m.args[1][])) Command::PONG(m.args[0][], Some(m.args[1][]))
} else { } else {
return Err(invalid_input()) return Err(invalid_input())
} }
@ -677,7 +688,7 @@ impl<'a> Command<'a> {
} else if let "ERROR" = m.command[] { } else if let "ERROR" = m.command[] {
match m.suffix { match m.suffix {
Some(ref suffix) => if m.args.len() == 0 { Some(ref suffix) => if m.args.len() == 0 {
ERROR(suffix[]) Command::ERROR(suffix[])
} else { } else {
return Err(invalid_input()) return Err(invalid_input())
}, },
@ -686,7 +697,7 @@ impl<'a> Command<'a> {
} else if let "AWAY" = m.command[] { } else if let "AWAY" = m.command[] {
match m.suffix { match m.suffix {
Some(ref suffix) => if m.args.len() == 0 { Some(ref suffix) => if m.args.len() == 0 {
AWAY(Some(suffix[])) Command::AWAY(Some(suffix[]))
} else { } else {
return Err(invalid_input()) return Err(invalid_input())
}, },
@ -694,39 +705,39 @@ impl<'a> Command<'a> {
} }
} else if let "REHASH" = m.command[] { } else if let "REHASH" = m.command[] {
if m.args.len() == 0 { if m.args.len() == 0 {
REHASH Command::REHASH
} else { } else {
return Err(invalid_input()) return Err(invalid_input())
} }
} else if let "DIE" = m.command[] { } else if let "DIE" = m.command[] {
if m.args.len() == 0 { if m.args.len() == 0 {
DIE Command::DIE
} else { } else {
return Err(invalid_input()) return Err(invalid_input())
} }
} else if let "RESTART" = m.command[] { } else if let "RESTART" = m.command[] {
if m.args.len() == 0 { if m.args.len() == 0 {
RESTART Command::RESTART
} else { } else {
return Err(invalid_input()) return Err(invalid_input())
} }
} else if let "SUMMON" = m.command[] { } else if let "SUMMON" = m.command[] {
match m.suffix { match m.suffix {
Some(ref suffix) => if m.args.len() == 0 { Some(ref suffix) => if m.args.len() == 0 {
SUMMON(suffix[], None, None) Command::SUMMON(suffix[], None, None)
} else if m.args.len() == 1 { } else if m.args.len() == 1 {
SUMMON(m.args[0][], Some(suffix[]), None) Command::SUMMON(m.args[0][], Some(suffix[]), None)
} else if m.args.len() == 2 { } else if m.args.len() == 2 {
SUMMON(m.args[0][], Some(m.args[1][]), Some(suffix[])) Command::SUMMON(m.args[0][], Some(m.args[1][]), Some(suffix[]))
} else { } else {
return Err(invalid_input()) return Err(invalid_input())
}, },
None => if m.args.len() == 1 { None => if m.args.len() == 1 {
SUMMON(m.args[0][], None, None) Command::SUMMON(m.args[0][], None, None)
} else if m.args.len() == 2 { } else if m.args.len() == 2 {
SUMMON(m.args[0][], Some(m.args[1][]), None) Command::SUMMON(m.args[0][], Some(m.args[1][]), None)
} else if m.args.len() == 3 { } else if m.args.len() == 3 {
SUMMON(m.args[0][], Some(m.args[1][]), Some(m.args[2][])) Command::SUMMON(m.args[0][], Some(m.args[1][]), Some(m.args[2][]))
} else { } else {
return Err(invalid_input()) return Err(invalid_input())
} }
@ -735,33 +746,33 @@ impl<'a> Command<'a> {
match m.suffix { match m.suffix {
Some(ref suffix) => { Some(ref suffix) => {
if m.args.len() != 0 { return Err(invalid_input()) } if m.args.len() != 0 { return Err(invalid_input()) }
USERS(Some(suffix[])) Command::USERS(Some(suffix[]))
}, },
None => { None => {
if m.args.len() != 1 { return Err(invalid_input()) } if m.args.len() != 1 { return Err(invalid_input()) }
USERS(Some(m.args[0][])) Command::USERS(Some(m.args[0][]))
} }
} }
} else if let "WALLOPS" = m.command[] { } else if let "WALLOPS" = m.command[] {
match m.suffix { match m.suffix {
Some(ref suffix) => { Some(ref suffix) => {
if m.args.len() != 0 { return Err(invalid_input()) } if m.args.len() != 0 { return Err(invalid_input()) }
WALLOPS(suffix[]) Command::WALLOPS(suffix[])
}, },
None => { None => {
if m.args.len() != 1 { return Err(invalid_input()) } if m.args.len() != 1 { return Err(invalid_input()) }
WALLOPS(m.args[0][]) Command::WALLOPS(m.args[0][])
} }
} }
} else if let "USERHOST" = m.command[] { } else if let "USERHOST" = m.command[] {
if m.suffix.is_none() { if m.suffix.is_none() {
USERHOST(m.args.iter().map(|s| s[]).collect()) Command::USERHOST(m.args.iter().map(|s| s[]).collect())
} else { } else {
return Err(invalid_input()) return Err(invalid_input())
} }
} else if let "ISON" = m.command[] { } else if let "ISON" = m.command[] {
if m.suffix.is_none() { if m.suffix.is_none() {
USERHOST(m.args.iter().map(|s| s[]).collect()) Command::USERHOST(m.args.iter().map(|s| s[]).collect())
} else { } else {
return Err(invalid_input()) return Err(invalid_input())
} }
@ -769,26 +780,26 @@ impl<'a> Command<'a> {
match m.suffix { match m.suffix {
Some(ref suffix) => { Some(ref suffix) => {
if m.args.len() != 1 { return Err(invalid_input()) } if m.args.len() != 1 { return Err(invalid_input()) }
SAJOIN(m.args[0][], suffix[]) Command::SAJOIN(m.args[0][], suffix[])
}, },
None => { None => {
if m.args.len() != 2 { return Err(invalid_input()) } if m.args.len() != 2 { return Err(invalid_input()) }
SAJOIN(m.args[0][], m.args[1][]) Command::SAJOIN(m.args[0][], m.args[1][])
} }
} }
} else if let "SAMODE" = m.command[] { } else if let "SAMODE" = m.command[] {
match m.suffix { match m.suffix {
Some(ref suffix) => if m.args.len() == 1 { Some(ref suffix) => if m.args.len() == 1 {
SAMODE(m.args[0][], suffix[], None) Command::SAMODE(m.args[0][], suffix[], None)
} else if m.args.len() == 2 { } else if m.args.len() == 2 {
SAMODE(m.args[0][], m.args[1][], Some(suffix[])) Command::SAMODE(m.args[0][], m.args[1][], Some(suffix[]))
} else { } else {
return Err(invalid_input()) return Err(invalid_input())
}, },
None => if m.args.len() == 2 { None => if m.args.len() == 2 {
SAMODE(m.args[0][], m.args[1][], None) Command::SAMODE(m.args[0][], m.args[1][], None)
} else if m.args.len() == 3 { } else if m.args.len() == 3 {
SAMODE(m.args[0][], m.args[1][], Some(m.args[2][])) Command::SAMODE(m.args[0][], m.args[1][], Some(m.args[2][]))
} else { } else {
return Err(invalid_input()) return Err(invalid_input())
} }
@ -797,33 +808,33 @@ impl<'a> Command<'a> {
match m.suffix { match m.suffix {
Some(ref suffix) => { Some(ref suffix) => {
if m.args.len() != 1 { return Err(invalid_input()) } if m.args.len() != 1 { return Err(invalid_input()) }
SANICK(m.args[0][], suffix[]) Command::SANICK(m.args[0][], suffix[])
}, },
None => { None => {
if m.args.len() != 2 { return Err(invalid_input()) } if m.args.len() != 2 { return Err(invalid_input()) }
SANICK(m.args[0][], m.args[1][]) Command::SANICK(m.args[0][], m.args[1][])
} }
} }
} else if let "SAPART" = m.command[] { } else if let "SAPART" = m.command[] {
match m.suffix { match m.suffix {
Some(ref suffix) => { Some(ref suffix) => {
if m.args.len() != 1 { return Err(invalid_input()) } if m.args.len() != 1 { return Err(invalid_input()) }
SAPART(m.args[0][], suffix[]) Command::SAPART(m.args[0][], suffix[])
}, },
None => { None => {
if m.args.len() != 2 { return Err(invalid_input()) } if m.args.len() != 2 { return Err(invalid_input()) }
SAPART(m.args[0][], m.args[1][]) Command::SAPART(m.args[0][], m.args[1][])
} }
} }
} else if let "SAQUIT" = m.command[] { } else if let "SAQUIT" = m.command[] {
match m.suffix { match m.suffix {
Some(ref suffix) => { Some(ref suffix) => {
if m.args.len() != 1 { return Err(invalid_input()) } if m.args.len() != 1 { return Err(invalid_input()) }
SAQUIT(m.args[0][], suffix[]) Command::SAQUIT(m.args[0][], suffix[])
}, },
None => { None => {
if m.args.len() != 2 { return Err(invalid_input()) } if m.args.len() != 2 { return Err(invalid_input()) }
SAQUIT(m.args[0][], m.args[1][]) Command::SAQUIT(m.args[0][], m.args[1][])
} }
} }
} else { } else {

View file

@ -1,6 +1,6 @@
//! Messages to and from the server. //! Messages to and from the server.
#![experimental] #![experimental]
use std::from_str::FromStr; use std::str::FromStr;
/// IRC Message data. /// IRC Message data.
#[experimental] #[experimental]

View file

@ -1,5 +1,5 @@
//! Data for tracking user information. //! Data for tracking user information.
use std::from_str::FromStr; use std::str::FromStr;
/// IRC User data. /// IRC User data.
#[deriving(Clone, Show)] #[deriving(Clone, Show)]
@ -17,7 +17,7 @@ impl User {
pub fn new(name: &str) -> User { pub fn new(name: &str) -> User {
let rank = from_str(name); let rank = from_str(name);
User { User {
name: if let Some(Member) = rank { name: if let Some(AccessLevel::Member) = rank {
name.into_string() name.into_string()
} else { } else {
name[1..].into_string() name[1..].into_string()
@ -34,16 +34,16 @@ impl User {
/// Updates the user's access level. /// Updates the user's access level.
pub fn update_access_level(&mut self, mode: &str) { pub fn update_access_level(&mut self, mode: &str) {
self.access_level = match mode { self.access_level = match mode {
"+q" => Owner, "+q" => AccessLevel::Owner,
"-q" => Member, "-q" => AccessLevel::Member,
"+a" => Admin, "+a" => AccessLevel::Admin,
"-a" => Member, "-a" => AccessLevel::Member,
"+o" => Oper, "+o" => AccessLevel::Oper,
"-o" => Member, "-o" => AccessLevel::Member,
"+h" => HalfOp, "+h" => AccessLevel::HalfOp,
"-h" => Member, "-h" => AccessLevel::Member,
"+v" => Voice, "+v" => AccessLevel::Voice,
"-v" => Member, "-v" => AccessLevel::Member,
_ => self.access_level, _ => self.access_level,
} }
} }
@ -74,14 +74,14 @@ pub enum AccessLevel {
impl FromStr for AccessLevel { impl FromStr for AccessLevel {
fn from_str(s: &str) -> Option<AccessLevel> { fn from_str(s: &str) -> Option<AccessLevel> {
if s.len() == 0 { Some(Member) } else { if s.len() == 0 { Some(AccessLevel::Member) } else {
Some(match s.char_at(0) { Some(match s.char_at(0) {
'~' => Owner, '~' => AccessLevel::Owner,
'&' => Admin, '&' => AccessLevel::Admin,
'@' => Oper, '@' => AccessLevel::Oper,
'%' => HalfOp, '%' => AccessLevel::HalfOp,
'+' => Voice, '+' => AccessLevel::Voice,
_ => Member, _ => AccessLevel::Member,
}) })
} }
} }

View file

@ -4,11 +4,9 @@ use std::collections::HashMap;
use std::io::{BufferedStream, IoResult}; use std::io::{BufferedStream, IoResult};
use std::sync::Mutex; use std::sync::Mutex;
use conn::{Connection, NetStream}; use conn::{Connection, NetStream};
use data::command::{Command, JOIN, PONG}; use data::command::Command::{JOIN, PONG};
use data::config::Config; use data::{Command, Config, Message, User};
use data::kinds::IrcStream; use data::kinds::IrcStream;
use data::message::Message;
use data::user::User;
pub mod utils; pub mod utils;
@ -75,7 +73,7 @@ impl<'a, T> Server<'a, T> for IrcServer<T> where T: IrcStream {
} }
fn list_users(&self, chan: &str) -> Option<Vec<User>> { fn list_users(&self, chan: &str) -> Option<Vec<User>> {
self.chanlists.lock().find_copy(&chan.into_string()) self.chanlists.lock().get(&chan.into_string()).cloned()
} }
} }

View file

@ -3,8 +3,8 @@
use std::io::IoResult; use std::io::IoResult;
use data::{Command, Config, User}; use data::{Command, Config, User};
use data::command::{INVITE, JOIN, KILL, MODE, NICK, KICK}; use data::command::Command::{INVITE, JOIN, KILL, MODE, NICK, KICK};
use data::command::{OPER, PONG, PRIVMSG, SAMODE, SANICK, TOPIC, USER}; use data::command::Command::{OPER, PONG, PRIVMSG, SAMODE, SANICK, TOPIC, USER};
use data::kinds::IrcStream; use data::kinds::IrcStream;
use server::{Server, ServerIterator}; use server::{Server, ServerIterator};