Trait irc::client::server::Server [] [src]

pub trait Server {
    fn config(&self) -> &Config;
fn send<M: Into<Message>>(&self, message: M) -> Result<()>
    where
        Self: Sized
;
fn stream(&self) -> ServerStream;
fn list_channels(&self) -> Option<Vec<String>>;
fn list_users(&self, channel: &str) -> Option<Vec<User>>; fn for_each_incoming<F>(&self, f: F) -> Result<()>
    where
        F: FnMut(Message)
, { ... } }

An interface for communicating with an IRC server.

Required Methods

Gets the configuration being used with this Server.

Sends a Command to this Server. This is the core primitive for sending messages to the server. In practice, it's often more pleasant (and more idiomatic) to use the functions defined on ServerExt. They capture a lot of the more repetitive aspects of sending messages.

Example

server.send(Command::NICK("example".to_owned())).unwrap();
server.send(Command::USER("user".to_owned(), "0".to_owned(), "name".to_owned())).unwrap();

Gets a stream of incoming messages from the Server. This is only necessary when trying to set up more complex clients, and requires use of the futures crate. Most IRC bots should be able to get by using only for_each_incoming to handle received messages. You can find some examples of more complex setups using stream in the GitHub repository.

Note: The stream can only be returned once. Subsequent attempts will cause a panic.

Gets a list of currently joined channels. This will be None if tracking is disabled altogether via the nochanlists feature.

Gets a list of Users in the specified channel. If the specified channel hasn't been joined or the nochanlists feature is enabled, this function will return None.

For best results, be sure to request multi-prefix support from the server. This will allow for more accurate tracking of user rank (e.g. oper, half-op, etc.).

Requesting multi-prefix support

use irc::proto::caps::Capability;

server.send_cap_req(&[Capability::MultiPrefix]).unwrap();
server.identify().unwrap();

Provided Methods

Blocks on the stream, running the given function on each incoming message as they arrive.

Example

server.for_each_incoming(|irc_msg| {
  match irc_msg.command {
    Command::PRIVMSG(channel, message) => if message.contains(server.current_nickname()) {
      server.send_privmsg(&channel, "beep boop").unwrap();
    }
    _ => ()
  }
}).unwrap();

Implementors