pub struct Client { /* private fields */ }
Expand description
The canonical implementation of a connection to an IRC server.
For a full example usage, see [irc::client
].
Implementations§
source§impl Client
impl Client
sourcepub async fn new<P: AsRef<Path>>(config: P) -> Result<Client>
pub async fn new<P: AsRef<Path>>(config: P) -> Result<Client>
Creates a new Client
from the configuration at the specified path, connecting
immediately. This function is short-hand for loading the configuration and then calling
Client::from_config
and consequently inherits its behaviors.
§Example
let client = Client::new("config.toml").await?;
sourcepub async fn from_config(config: Config) -> Result<Client>
pub async fn from_config(config: Config) -> Result<Client>
Creates a Future
of an Client
from the specified configuration and on the event loop
corresponding to the given handle. This can be used to set up a number of Clients
on a
single, shared event loop. It can also be used to take more control over execution and error
handling. Connection will not occur until the event loop is run.
sourcepub fn outgoing(&mut self) -> Option<Outgoing>
pub fn outgoing(&mut self) -> Option<Outgoing>
Take the outgoing future in order to drive it yourself.
Must be called before stream
if you intend to drive this future
yourself.
sourcepub fn sender(&self) -> Sender
pub fn sender(&self) -> Sender
Get access to a thread-safe sender that can be used with the client.
sourcepub fn stream(&mut self) -> Result<ClientStream>
pub fn stream(&mut self) -> Result<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
You can find some examples of setups using stream
in the
GitHub repository.
Note: The stream can only be returned once. Subsequent attempts will cause a panic.
sourcepub fn list_channels(&self) -> Option<Vec<String>>
pub fn list_channels(&self) -> Option<Vec<String>>
Gets a list of currently joined channels. This will be None
if tracking is disabled
altogether by disabling the channel-lists
feature.
sourcepub fn list_users(&self, chan: &str) -> Option<Vec<User>>
pub fn list_users(&self, chan: &str) -> Option<Vec<User>>
Gets a list of [Users
] in the specified channel. If the
specified channel hasn’t been joined or the channel-lists
feature is disabled, 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])?;
client.identify()?;
sourcepub fn current_nickname(&self) -> &str
pub fn current_nickname(&self) -> &str
Gets the current nickname in use. This may be the primary username set in the configuration, or it could be any of the alternative nicknames listed as well. As a result, this is the preferred way to refer to the client’s nickname.
sourcepub fn send_mode<S, T>(&self, target: S, modes: &[Mode<T>]) -> Result<()>
pub fn send_mode<S, T>(&self, target: S, modes: &[Mode<T>]) -> Result<()>
Changes the modes for the specified target.
sourcepub fn send_join<S>(&self, chanlist: S) -> Result<()>where
S: Display,
pub fn send_join<S>(&self, chanlist: S) -> Result<()>where
S: Display,
Joins the specified channel or chanlist.
sourcepub fn send_join_with_keys<S1, S2>(
&self,
chanlist: S1,
keylist: S2
) -> Result<()>
pub fn send_join_with_keys<S1, S2>( &self, chanlist: S1, keylist: S2 ) -> Result<()>
Joins the specified channel or chanlist using the specified key or keylist.
sourcepub fn send_notice<S1, S2>(&self, target: S1, message: S2) -> Result<()>
pub fn send_notice<S1, S2>(&self, target: S1, message: S2) -> Result<()>
Sends a notice to the specified target.
sourcepub fn send_cap_ls(&self, version: NegotiationVersion) -> Result<()>
pub fn send_cap_ls(&self, version: NegotiationVersion) -> Result<()>
Sends a request for a list of server capabilities for a specific IRCv3 version.
sourcepub fn send_cap_req(&self, extensions: &[Capability]) -> Result<()>
pub fn send_cap_req(&self, extensions: &[Capability]) -> Result<()>
Sends an IRCv3 capabilities request for the specified extensions.
sourcepub fn send_sasl<S: Display>(&self, data: S) -> Result<()>
pub fn send_sasl<S: Display>(&self, data: S) -> Result<()>
Sends a SASL AUTHENTICATE message with the specified data.
sourcepub fn send_sasl_plain(&self) -> Result<()>
pub fn send_sasl_plain(&self) -> Result<()>
Sends a SASL AUTHENTICATE request to use the PLAIN mechanism.
sourcepub fn send_sasl_external(&self) -> Result<()>
pub fn send_sasl_external(&self) -> Result<()>
Sends a SASL AUTHENTICATE request to use the EXTERNAL mechanism.
sourcepub fn send_sasl_abort(&self) -> Result<()>
pub fn send_sasl_abort(&self) -> Result<()>
Sends a SASL AUTHENTICATE request to abort authentication.
sourcepub fn send_pong<S>(&self, msg: S) -> Result<()>where
S: Display,
pub fn send_pong<S>(&self, msg: S) -> Result<()>where
S: Display,
Sends a PONG with the specified message.
sourcepub fn send_part<S>(&self, chanlist: S) -> Result<()>where
S: Display,
pub fn send_part<S>(&self, chanlist: S) -> Result<()>where
S: Display,
Parts the specified channel or chanlist.
sourcepub fn send_oper<S1, S2>(&self, username: S1, password: S2) -> Result<()>
pub fn send_oper<S1, S2>(&self, username: S1, password: S2) -> Result<()>
Attempts to oper up using the specified username and password.
sourcepub fn send_privmsg<S1, S2>(&self, target: S1, message: S2) -> Result<()>
pub fn send_privmsg<S1, S2>(&self, target: S1, message: S2) -> Result<()>
Sends a message to the specified target. If the message contains IRC newlines (\r\n
), it
will automatically be split and sent as multiple separate PRIVMSG
s to the specified
target. If you absolutely must avoid this behavior, you can do
client.send(PRIVMSG(target, message))
directly.
sourcepub fn send_topic<S1, S2>(&self, channel: S1, topic: S2) -> Result<()>
pub fn send_topic<S1, S2>(&self, channel: S1, topic: S2) -> Result<()>
Sets the topic of a channel or requests the current one.
If topic
is an empty string, it won’t be included in the message.
sourcepub fn send_kill<S1, S2>(&self, target: S1, message: S2) -> Result<()>
pub fn send_kill<S1, S2>(&self, target: S1, message: S2) -> Result<()>
Kills the target with the provided message.
sourcepub fn send_kick<S1, S2, S3>(
&self,
chanlist: S1,
nicklist: S2,
message: S3
) -> Result<()>
pub fn send_kick<S1, S2, S3>( &self, chanlist: S1, nicklist: S2, message: S3 ) -> Result<()>
Kicks the listed nicknames from the listed channels with a comment.
If message
is an empty string, it won’t be included in the message.
sourcepub fn send_samode<S1, S2, S3>(
&self,
target: S1,
mode: S2,
modeparams: S3
) -> Result<()>
pub fn send_samode<S1, S2, S3>( &self, target: S1, mode: S2, modeparams: S3 ) -> Result<()>
Changes the mode of the target by force.
If modeparams
is an empty string, it won’t be included in the message.
sourcepub fn send_sanick<S1, S2>(&self, old_nick: S1, new_nick: S2) -> Result<()>
pub fn send_sanick<S1, S2>(&self, old_nick: S1, new_nick: S2) -> Result<()>
Forces a user to change from the old nickname to the new nickname.
sourcepub fn send_invite<S1, S2>(&self, nick: S1, chan: S2) -> Result<()>
pub fn send_invite<S1, S2>(&self, nick: S1, chan: S2) -> Result<()>
Invites a user to the specified channel.
sourcepub fn send_quit<S>(&self, msg: S) -> Result<()>where
S: Display,
pub fn send_quit<S>(&self, msg: S) -> Result<()>where
S: Display,
Quits the server entirely with a message.
This defaults to Powered by Rust.
if none is specified.
sourcepub fn send_ctcp<S1, S2>(&self, target: S1, msg: S2) -> Result<()>
pub fn send_ctcp<S1, S2>(&self, target: S1, msg: S2) -> Result<()>
Sends a CTCP-escaped message to the specified target. This requires the CTCP feature to be enabled.
sourcepub fn send_action<S1, S2>(&self, target: S1, msg: S2) -> Result<()>
pub fn send_action<S1, S2>(&self, target: S1, msg: S2) -> Result<()>
Sends an action command to the specified target. This requires the CTCP feature to be enabled.
sourcepub fn send_finger<S>(&self, target: S) -> Result<()>where
S: Display,
pub fn send_finger<S>(&self, target: S) -> Result<()>where
S: Display,
Sends a finger request to the specified target. This requires the CTCP feature to be enabled.
sourcepub fn send_version<S>(&self, target: S) -> Result<()>where
S: Display,
pub fn send_version<S>(&self, target: S) -> Result<()>where
S: Display,
Sends a version request to the specified target. This requires the CTCP feature to be enabled.
sourcepub fn send_source<S>(&self, target: S) -> Result<()>where
S: Display,
pub fn send_source<S>(&self, target: S) -> Result<()>where
S: Display,
Sends a source request to the specified target. This requires the CTCP feature to be enabled.
sourcepub fn send_user_info<S>(&self, target: S) -> Result<()>where
S: Display,
pub fn send_user_info<S>(&self, target: S) -> Result<()>where
S: Display,
Sends a user info request to the specified target. This requires the CTCP feature to be enabled.
sourcepub fn send_ctcp_ping<S>(&self, target: S) -> Result<()>where
S: Display,
pub fn send_ctcp_ping<S>(&self, target: S) -> Result<()>where
S: Display,
Sends a finger request to the specified target. This requires the CTCP feature to be enabled.