Struct tmi::client::Client

source ·
pub struct Client { /* private fields */ }
Expand description

Twitch IRC client.

This is the main interface for interacting with Twitch IRC.

This interface provides:

  • Connection handshake
  • Reconnect with backoff
  • Receiving and sending messages

It is a low-level interface, which means it does not automatically handle:

  • Rate limiting
  • Same message bypass
  • Reconnects / rejoining channels
  • Latency measurement

Implementations§

source§

impl Client

source

pub async fn recv(&mut self) -> Result<IrcMessage, RecvError>

Read a single IrcMessage from the underlying stream.

source§

impl Client

source

pub async fn send_raw<'a, S>(&mut self, s: S) -> Result<(), SendError>
where S: TryInto<RawMessage<'a>>, SendError: From<S::Error>,

Send a raw string through the TCP socket.

⚠ This call is not rate limited in any way.

⚠ The string MUST be terminated by \r\n.

source

pub fn privmsg<'a>(&'a mut self, channel: &'a str, text: &'a str) -> Privmsg<'a>

Create a privmsg from a channel and text.

client
  .privmsg(msg.channel(), "yo")
  .reply_to(msg.message_id())
  .send()
  .await?;

You can specify additional properties using the builder methods:

  • reply_to: to specify a reply-parent-msg-id tag, which makes this privmsg a reply to another message.
  • client_nonce: to identify the message in the Notice which Twitch may send as a response to this message.
source

pub async fn ping(&mut self, nonce: &str) -> Result<(), SendError>

Send a PING command with an optional nonce argument.

source

pub async fn pong(&mut self, ping: &Ping<'_>) -> Result<(), SendError>

Send a PONG command in response to a PING.

source

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

Send a JOIN command.

⚠ This call is not rate limited in any way.

channel MUST be a valid channel name prefixed by #.

source

pub async fn join_all<'a, I, C>(&mut self, channels: I) -> Result<(), SendError>
where I: IntoIterator<Item = C>, C: AsRef<str>,

Send a JOIN command.

⚠ This call is not rate limited in any way.

⚠ Each channel in channels MUST be a valid channel name prefixed by #.

source§

impl Client

source

pub fn builder() -> ClientBuilder

The ClientBuilder provides a builder for setting up the client configuration.

source

pub fn anonymous() -> impl Future<Output = Result<Client, ConnectError>>

Attemps to connect anonymously.

source

pub async fn reconnect(&mut self) -> Result<(), ReconnectError>

Attempt to reconnect to Twitch IRC.

source§

impl Client

source

pub fn config(&self) -> &Config

source

pub fn credentials(&self) -> &Credentials

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>,

§

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>,

§

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<V, T> VZip<V> for T
where V: MultiLane<T>,

source§

fn vzip(self) -> V

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