Trait irc::client::Client [−][src]
pub trait Client { fn config(&self) -> &Config; fn send<M: Into<Message>>(&self, message: M) -> Result<()>
where
Self: Sized; fn stream(&self) -> ClientStream; 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
fn config(&self) -> &Config
Gets the configuration being used with this Client
.
fn send<M: Into<Message>>(&self, message: M) -> Result<()> where
Self: Sized,
Self: Sized,
Sends a Command
as this Client
. 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
ClientExt
. They capture a lot of the more repetitive
aspects of sending messages.
Example
client.send(Command::NICK("example".to_owned())).unwrap(); client.send(Command::USER("user".to_owned(), "0".to_owned(), "name".to_owned())).unwrap();
fn stream(&self) -> ClientStream
Gets a stream of incoming messages from the Client
's connection. 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.
fn list_channels(&self) -> Option<Vec<String>>
Gets a list of currently joined channels. This will be None
if tracking is disabled
altogether via the nochanlists
feature.
fn list_users(&self, channel: &str) -> Option<Vec<User>>
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; client.send_cap_req(&[Capability::MultiPrefix]).unwrap(); client.identify().unwrap();
Provided Methods
fn for_each_incoming<F>(&self, f: F) -> Result<()> where
F: FnMut(Message),
F: FnMut(Message),
Blocks on the stream, running the given function on each incoming message as they arrive.
Example
client.for_each_incoming(|irc_msg| { if let Command::PRIVMSG(channel, message) = irc_msg.command { if message.contains(client.current_nickname()) { client.send_privmsg(&channel, "beep boop").unwrap(); } } }).unwrap();
Implementors
impl Client for IrcClient