Struct Client

Source
pub struct Client { /* private fields */ }
Expand description

An IRC client

Implementations§

Source§

impl Client

Source

pub async fn new(config: Config) -> Result<Self, Error>

Creates a new client with a given Config.

§Example
# let config = Default::default();
let mut client = Client::new(config).await?;
# Ok(())
§Errors

Returns error if the client could not connect to the host.

§Panics

Panics if the client can’t connect to the given host.

Source

pub async fn identify(&mut self) -> Result<(), Error>

Identify user and joins the in the Config specified channels.

§Example
# let config = Default::default();
# let mut client = Client::new(config).await?;
client.identify().await?;
# Ok(())
§Errors

Returns error if the client could not write to the stream.

Source

pub async fn read(&mut self) -> Result<Option<Command>, Error>

Read data coming from the IRC as a commands::Command.

§Example
# use async_circe::*;
# let config = Default::default();
# let mut client = Client::new(config).await?;
# client.identify().await?;
loop {
   if let Some(ref command) = client.read().await? {
       if let commands::Command::PRIVMSG(nick, channel, message) = command {
           println!("{} in {}: {}", nick, channel, message);
       }
   }
# break;
}
# Ok(())
§Errors

Returns IO errors from the TcpStream.

Source

pub async fn admin(&mut self, target: &str) -> Result<(), Error>

Request information about the admin of a given server.

§Example
# use async_circe::*;
# let config = Default::default();
# let mut client = Client::new(config).await?;
# client.identify().await?;
client.admin("libera.chat").await?;
# Ok(())
§Errors

Returns IO errors from the TcpStream.

Source

pub async fn away(&mut self, message: &str) -> Result<(), Error>

Set the status of the client.

§Example
# let config = Default::default();
# let mut client = Client::new(config).await?;
# client.identify().await?;
client.away("afk").await?;
# Ok(())
§Errors

Returns IO errors from the TcpStream.

Source

pub async fn invite( &mut self, username: &str, channel: &str, ) -> Result<(), Error>

Invite someone to a channel.

§Example
# let config = Default::default();
# let mut client = Client::new(config).await?;
# client.identify().await?;
client.invite("liblemonirc", "#async-circe").await?;
# Ok(())
§Errors

Returns IO errors from the TcpStream.

Source

pub async fn join(&mut self, channel: &str) -> Result<(), Error>

Join a channel.

§Example
# let config = Default::default();
# let mut client = Client::new(config).await?;
# client.identify().await?;
client.join("#chaos").await?;
# Ok(())
§Errors

Returns IO errors from the TcpStream.

Source

pub async fn list( &mut self, channel: Option<&str>, server: Option<&str>, ) -> Result<(), Error>

List available channels on an IRC, or users in a channel.

§Example
# let config = Default::default();
# let mut client = Client::new(config).await?;
# client.identify().await?;
client.list(None, None).await?;
# Ok(())
§Errors

Returns IO errors from the TcpStream.

Source

pub async fn mode( &mut self, target: &str, mode: Option<&str>, ) -> Result<(), Error>

Set the mode for a user.

§Example
# let config = Default::default();
# let mut client = Client::new(config).await?;
# client.identify().await?;
client.mode("test", Some("+B")).await?;
# Ok(())
§Errors

Returns IO errors from the TcpStream.

Source

pub async fn names( &mut self, channel: &str, server: Option<&str>, ) -> Result<(), Error>

Get all the people online in channels.

§Example
# let config = Default::default();
# let mut client = Client::new(config).await?;
# client.identify().await?;
client.names("#chaos,#async-circe", None).await?;
# Ok(())
§Errors

Returns IO errors from the TcpStream.

Source

pub async fn nick(&mut self, nickname: &str) -> Result<(), Error>

Change your nickname on a server.

§Example
# let config = Default::default();
# let mut client = Client::new(config).await?;
# client.identify().await?;
client.nick("Not async-circe").await?;
# Ok(())
§Errors

Returns IO errors from the TcpStream.

Source

pub async fn oper( &mut self, username: &str, password: &str, ) -> Result<(), Error>

Authentificate as an operator on a server.

§Example
# let config = Default::default();
# let mut client = Client::new(config).await?;
# client.identify().await?;
client.oper("username", "password").await?;
# Ok(())
§Errors

Returns IO errors from the TcpStream.

Source

pub async fn part(&mut self, channel: &str) -> Result<(), Error>

Leave a channel.

§Example
# let config = Default::default();
# let mut client = Client::new(config).await?;
# client.identify().await?;
client.part("#chaos").await?;
# Ok(())
§Errors

Returns IO errors from the TcpStream.

Source

pub async fn ping( &mut self, server1: &str, server2: Option<&str>, ) -> Result<(), Error>

Tests the presence of a connection to a server.

§Example
# let config = Default::default();
# let mut client = Client::new(config).await?;
# client.identify().await?;
client.ping("libera.chat", None).await?;
# Ok(())
§Errors

Returns IO errors from the TcpStream.

Source

pub async fn privmsg( &mut self, channel: &str, message: &str, ) -> Result<(), Error>

Send a message to a channel.

§Example
# let config = Default::default();
# let mut client = Client::new(config).await?;
# client.identify().await?;
client.privmsg("#chaos", "Hello").await?;
# Ok(())
§Errors

Returns IO errors from the TcpStream.

Source

pub async fn quit(&mut self, message: Option<&str>) -> Result<(), Error>

Leave the IRC server you are connected to.

§Example
# use async_circe::*;
# let config = Default::default();
# let mut client = Client::new(config).await?;
# client.identify().await?;
client.quit(None).await?;
# Ok(())
§Errors

Returns IO errors from the TcpStream.

Source

pub async fn topic( &mut self, channel: &str, topic: Option<&str>, ) -> Result<(), Error>

Get the topic of a channel.

§Example
# use async_circe::*;
# let config = Default::default();
# let mut client = Client::new(config).await?;
# client.identify().await?;
client.topic("#chaos", None).await?;
# Ok(())

Set the topic of a channel.

§Example
# let config = Default::default();
# let mut client = Client::new(config).await?;
# client.identify().await?;
client.topic("#chaos", Some("CHAOS")).await?;
# Ok(())
§Errors

Returns IO errors from the TcpStream.

Auto Trait Implementations§

§

impl Freeze for Client

§

impl RefUnwindSafe for Client

§

impl Send for Client

§

impl Sync for Client

§

impl Unpin for Client

§

impl UnwindSafe for Client

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more