Added support for IRCv3.1 extended-join.

This commit is contained in:
Aaron Weiss 2015-05-21 22:55:49 -04:00
parent fc175bb68a
commit 3805c7c914
4 changed files with 23 additions and 12 deletions

View file

@ -10,6 +10,8 @@ pub enum Capability {
AccountNotify, AccountNotify,
/// [away-notify](http://ircv3.net/specs/extensions/away-notify-3.1.html) /// [away-notify](http://ircv3.net/specs/extensions/away-notify-3.1.html)
AwayNotify, AwayNotify,
/// [extended-join](http://ircv3.net/specs/extensions/extended-join-3.1.html)
ExtendedJoin,
} }
impl AsRef<str> for Capability { impl AsRef<str> for Capability {
@ -18,6 +20,7 @@ impl AsRef<str> for Capability {
Capability::MultiPrefix => "multi-prefix", Capability::MultiPrefix => "multi-prefix",
Capability::AccountNotify => "account-notify", Capability::AccountNotify => "account-notify",
Capability::AwayNotify => "away-notify", Capability::AwayNotify => "away-notify",
Capability::ExtendedJoin => "extended-join",
} }
} }
} }
@ -31,5 +34,6 @@ mod test {
assert_eq!(MultiPrefix.as_ref(), "multi-prefix"); assert_eq!(MultiPrefix.as_ref(), "multi-prefix");
assert_eq!(AccountNotify.as_ref(), "account-notify"); assert_eq!(AccountNotify.as_ref(), "account-notify");
assert_eq!(AwayNotify.as_ref(), "away-notify"); assert_eq!(AwayNotify.as_ref(), "away-notify");
assert_eq!(ExtendedJoin.as_ref(), "extended-join");
} }
} }

View file

@ -31,7 +31,7 @@ pub enum Command {
// 3.2 Channel operations // 3.2 Channel operations
/// JOIN chanlist [chankeys] /// JOIN chanlist [chankeys]
JOIN(String, Option<String>), JOIN(String, Option<String>, Option<String>),
/// PART chanlist :[comment] /// PART chanlist :[comment]
PART(String, Option<String>), PART(String, Option<String>),
// MODE is already defined. // MODE is already defined.
@ -152,7 +152,9 @@ pub enum Command {
/// ACCOUNT [account name] /// ACCOUNT [account name]
ACCOUNT(String), ACCOUNT(String),
// AWAY is already defined as a send-only message. // AWAY is already defined as a send-only message.
//AWAY(Option<String>), // AWAY(Option<String>),
// JOIN is already defined.
// JOIN(String, Option<String>, Option<String>),
} }
impl Into<Message> for Command { impl Into<Message> for Command {
@ -175,10 +177,10 @@ impl Into<Message> for Command {
Command::QUIT(None) => Message::from_owned(None, string("QUIT"), None, None), Command::QUIT(None) => Message::from_owned(None, string("QUIT"), None, None),
Command::SQUIT(s, c) => Command::SQUIT(s, c) =>
Message::from_owned(None, string("SQUIT"), Some(vec![s]), Some(c)), Message::from_owned(None, string("SQUIT"), Some(vec![s]), Some(c)),
Command::JOIN(c, Some(k)) => Command::JOIN(c, Some(k), n) =>
Message::from_owned(None, string("JOIN"), Some(vec![c, k]), None), Message::from_owned(None, string("JOIN"), Some(vec![c, k]), n),
Command::JOIN(c, None) => Command::JOIN(c, None, n) =>
Message::from_owned(None, string("JOIN"), Some(vec![c]), None), Message::from_owned(None, string("JOIN"), Some(vec![c]), n),
Command::PART(c, Some(m)) => Command::PART(c, Some(m)) =>
Message::from_owned(None, string("PART"), Some(vec![c]), Some(m)), Message::from_owned(None, string("PART"), Some(vec![c]), Some(m)),
Command::PART(c, None) => Command::PART(c, None) =>
@ -427,16 +429,21 @@ impl Command {
} 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 {
Command::JOIN(suffix.clone(), None) Command::JOIN(suffix.clone(), None, None)
} else if m.args.len() == 1 { } else if m.args.len() == 1 {
Command::JOIN(m.args[0].clone(), Some(suffix.clone())) Command::JOIN(m.args[0].clone(), Some(suffix.clone()), None)
} else if m.args.len() == 2 {
Command::JOIN(m.args[0].clone(), Some(m.args[1].clone()), Some(suffix.clone()))
} else { } else {
return Err(invalid_input()) return Err(invalid_input())
}, },
None => if m.args.len() == 1 { None => if m.args.len() == 1 {
Command::JOIN(m.args[0].clone(), None) Command::JOIN(m.args[0].clone(), None, None)
} else if m.args.len() == 2 { } else if m.args.len() == 2 {
Command::JOIN(m.args[0].clone(), Some(m.args[1].clone())) Command::JOIN(m.args[0].clone(), Some(m.args[1].clone()), None)
} else if m.args.len() == 3 {
Command::JOIN(m.args[0].clone(), Some(m.args[1].clone()),
Some(m.args[2].clone()))
} else { } else {
return Err(invalid_input()) return Err(invalid_input())
} }

View file

@ -150,7 +150,7 @@ impl<T: IrcRead, U: IrcWrite> IrcServer<T, U> {
self.config.umodes().to_owned(), None)).unwrap(); self.config.umodes().to_owned(), None)).unwrap();
} }
for chan in self.config.channels().into_iter() { for chan in self.config.channels().into_iter() {
self.send(JOIN(chan.to_owned(), None)).unwrap(); self.send(JOIN(chan.to_owned(), None, None)).unwrap();
} }
} else if resp == Response::ERR_NICKNAMEINUSE || } else if resp == Response::ERR_NICKNAMEINUSE ||
resp == Response::ERR_ERRONEOUSNICKNAME { resp == Response::ERR_ERRONEOUSNICKNAME {

View file

@ -40,7 +40,7 @@ pub trait ServerExt<'a, T, U>: Server<'a, T, U> {
/// Joins the specified channel or chanlist. /// Joins the specified channel or chanlist.
fn send_join(&self, chanlist: &str) -> Result<()> { fn send_join(&self, chanlist: &str) -> Result<()> {
self.send(JOIN(chanlist.to_owned(), None)) self.send(JOIN(chanlist.to_owned(), None, None))
} }
/// Attempts to oper up using the specified username and password. /// Attempts to oper up using the specified username and password.