Added CAP LS with negotiation version API for IRCv3.2.

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

View file

@ -14,6 +14,14 @@ pub enum Capability {
ExtendedJoin, ExtendedJoin,
} }
/// List of IRCv3 capability negotiation versions.
pub enum NegotiationVersion {
/// [IRCv3.1](http://ircv3.net/specs/core/capability-negotiation-3.1.html)
V301,
/// [IRCv3.2](http://ircv3.net/specs/core/capability-negotiation-3.2.html)
V302,
}
impl AsRef<str> for Capability { impl AsRef<str> for Capability {
fn as_ref(&self) -> &str { fn as_ref(&self) -> &str {
match *self { match *self {

View file

@ -1,6 +1,6 @@
//! Data related to IRC functionality. //! Data related to IRC functionality.
pub use client::data::caps::Capability; pub use client::data::caps::{Capability, NegotiationVersion};
pub use client::data::command::Command; pub use client::data::command::Command;
pub use client::data::config::Config; pub use client::data::config::Config;
pub use client::data::message::Message; pub use client::data::message::Message;

View file

@ -8,7 +8,7 @@ pub mod prelude {
//! A client-side IRC prelude, re-exporting all the necessary basics. //! A client-side IRC prelude, re-exporting all the necessary basics.
pub use client::server::{IrcServer, Server}; pub use client::server::{IrcServer, Server};
pub use client::server::utils::ServerExt; pub use client::server::utils::ServerExt;
pub use client::data::{Capability, Command, Config, Message, Response}; pub use client::data::{Capability, Command, Config, Message, NegotiationVersion, Response};
pub use client::data::kinds::{IrcRead, IrcWrite}; pub use client::data::kinds::{IrcRead, IrcWrite};
} }

View file

@ -1,16 +1,24 @@
//! Utilities and shortcuts for working with IRC servers. //! Utilities and shortcuts for working with IRC servers.
use std::io::Result; use std::io::Result;
use std::borrow::ToOwned; use std::borrow::ToOwned;
use client::data::Capability; use client::data::{Capability, NegotiationVersion};
use client::data::Command::{CAP, INVITE, JOIN, KICK, KILL, MODE, NICK, NOTICE}; use client::data::Command::{CAP, INVITE, JOIN, KICK, KILL, MODE, NICK, NOTICE};
use client::data::Command::{OPER, PASS, PONG, PRIVMSG, QUIT, SAMODE, SANICK, TOPIC, USER}; use client::data::Command::{OPER, PASS, PONG, PRIVMSG, QUIT, SAMODE, SANICK, TOPIC, USER};
use client::data::command::CapSubCommand::{END, REQ}; use client::data::command::CapSubCommand::{END, LS, REQ};
use client::data::kinds::{IrcRead, IrcWrite}; use client::data::kinds::{IrcRead, IrcWrite};
#[cfg(feature = "ctcp")] use time::get_time; #[cfg(feature = "ctcp")] use time::get_time;
use client::server::Server; use client::server::Server;
/// Extensions for Server capabilities that make it easier to work directly with the protocol. /// Extensions for Server capabilities that make it easier to work directly with the protocol.
pub trait ServerExt<'a, T, U>: Server<'a, T, U> { pub trait ServerExt<'a, T, U>: Server<'a, T, U> {
/// Sends a request for a list of server capabilities for a specific IRCv3 version.
fn send_cap_ls(&self, version: NegotiationVersion) -> Result<()> {
self.send(CAP(None, LS, match version {
NegotiationVersion::V301 => None,
NegotiationVersion::V302 => Some("302".to_owned()),
}, None))
}
/// Sends an IRCv3 capabilities request for the specified extensions. /// Sends an IRCv3 capabilities request for the specified extensions.
fn send_cap_req(&self, extensions: &[Capability]) -> Result<()> { fn send_cap_req(&self, extensions: &[Capability]) -> Result<()> {
let append = |mut s: String, c| { s.push_str(c); s.push(' '); s }; let append = |mut s: String, c| { s.push_str(c); s.push(' '); s };