Added CAP LS with negotiation version API for IRCv3.2.
This commit is contained in:
parent
3805c7c914
commit
e1abb935b1
4 changed files with 20 additions and 4 deletions
|
@ -14,6 +14,14 @@ pub enum Capability {
|
|||
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 {
|
||||
fn as_ref(&self) -> &str {
|
||||
match *self {
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
//! 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::config::Config;
|
||||
pub use client::data::message::Message;
|
||||
|
|
|
@ -8,7 +8,7 @@ pub mod prelude {
|
|||
//! A client-side IRC prelude, re-exporting all the necessary basics.
|
||||
pub use client::server::{IrcServer, Server};
|
||||
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};
|
||||
}
|
||||
|
||||
|
|
|
@ -1,16 +1,24 @@
|
|||
//! Utilities and shortcuts for working with IRC servers.
|
||||
use std::io::Result;
|
||||
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::{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};
|
||||
#[cfg(feature = "ctcp")] use time::get_time;
|
||||
use client::server::Server;
|
||||
|
||||
/// Extensions for Server capabilities that make it easier to work directly with the protocol.
|
||||
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.
|
||||
fn send_cap_req(&self, extensions: &[Capability]) -> Result<()> {
|
||||
let append = |mut s: String, c| { s.push_str(c); s.push(' '); s };
|
||||
|
|
Loading…
Add table
Reference in a new issue