[−][src]Struct twitchchat::Client
Client for interacting with Twitch's chat.
use twitchchat::{helpers::TestStream, Client}; let stream = TestStream::new(); let (r,w) = (stream.clone(), stream.clone()); let mut client = Client::new(r,w); // moves the r,w // register, join, on, etc client.run().unwrap();
Methods
impl<R, W> Client<R, W> where
R: Read,
W: Write,
[src]
R: Read,
W: Write,
pub fn new(read: R, write: W) -> Self
[src]
pub fn run(self) -> Result<(), Error>
[src]
Runs, consuming all messages.
This also pumping them through
Client::on
filters
pub fn register(&mut self, config: UserConfig) -> Result<(), Error>
[src]
Registers with the server uses the provided UserConfig
This is a very useful step, after you make the client and set up your initial filters
You should call this to send your OAuth token
and Nickname
This also sends the Capabilities
in the correct order
Usage
let config = UserConfig::builder() .token(std::env::var("MY_PASSWORD").unwrap()) .nick("museun") .build() .unwrap(); client.register(config).unwrap(); // we should be connected now // this'll block until everything is read let _ = client.wait_for_ready().unwrap();
pub fn wait_for_ready(&mut self) -> Result<LocalUser, Error>
[src]
Waits for the
GLOBALUSERSTATE
before
continuing, discarding any messages received
Returns some useful information
about your user
This blocks until the twitch registration is completed, this relies on
the Tags Capability
being sent.
Usage:
match client.wait_for_ready() { Ok(user) => println!("user id: {}", user.user_id), Err(err) => panic!("failed to finish registration: {}", err) }; // we can be sure that we're ready to join client.join("some channel").unwrap();
pub fn wait_for_irc_ready(&mut self) -> Result<String, Error>
[src]
Like wait_for_ready
but waits for the end of the IRC MOTD
This will generally happen before GLOBALUSERSTATE
but don't rely on that
Returns the username assigned to you by the server
Usage:
match client.wait_for_irc_ready() { Ok(name) => println!("end of motd, our name is: {}", name), Err(err) => panic!("failed to finish registration: {}", err), }; // we can be sure that we're ready to join client.join("some channel").unwrap();
pub fn read_message(&mut self) -> Result<Message, Error>
[src]
Reads a Message
This will automatically handle some tedious messages, like the heartbeat (PING)
This also 'pumps' the messages through the filter
Using this will drive the client (blocking for a read, then producing messages). Usage:
// block the thread (i.e. wait for the client to close down) while let Ok(msg) = client.read_message() { // match msg { // .. stuff // } } // or incrementally calling `client.read_message()` // when you want the next message
impl<R, W> Client<R, W>
[src]
pub fn on<F, T>(&mut self, f: F) -> Token where
F: FnMut(T) + 'static + Send + Sync,
T: From<Message>,
T: MessageFilter,
[src]
F: FnMut(T) + 'static + Send + Sync,
T: From<Message>,
T: MessageFilter,
When a message, matching the type of the closure, is received run this function with it.
Usage:
use twitchchat::commands::*; let pm_tok = client.on(|msg: PrivMsg| { // msg is now a `twitchchat::commands::PrivMsg` }); let join_tok = client.on(|msg: Join| { // msg is now a `twitchchat::commands::Join` }); // if a PRIVMSG or JOIN is parsed here // the corresponding closure, above, will run client.read_message();
The available filters are the same names as the structs in commands
When Client::read_message
is called, it'll send a copy of the matching message to these filters.
Multiple filters can be 'registered' for the same type
Use the returned token to remove the filter, by passing it to the
Client::off
method
pub fn off(&mut self, tok: Token) -> bool
[src]
Remove a previously registered message filter, using the token returned by on
Returns true if this filter existed
impl<R, W> Client<R, W> where
W: Write,
[src]
W: Write,
pub fn host(&mut self, channel: &str) -> Result<(), Error>
[src]
pub fn unhost(&mut self) -> Result<(), Error>
[src]
pub fn marker(&mut self, comment: Option<&str>) -> Result<(), Error>
[src]
pub fn raid(&mut self, channel: &str) -> Result<(), Error>
[src]
pub fn unraid(&mut self) -> Result<(), Error>
[src]
pub fn color<C: Into<TwitchColor>>(&mut self, color: C) -> Result<(), Error>
[src]
pub fn disconnect(&mut self) -> Result<(), Error>
[src]
pub fn help(&mut self) -> Result<(), Error>
[src]
pub fn mods(&mut self) -> Result<(), Error>
[src]
pub fn vips(&mut self) -> Result<(), Error>
[src]
pub fn commercial(&mut self, length: Option<usize>) -> Result<(), Error>
[src]
pub fn ban(&mut self, username: &str, reason: Option<&str>) -> Result<(), Error>
[src]
pub fn unban(&mut self, username: &str) -> Result<(), Error>
[src]
pub fn clear(&mut self) -> Result<(), Error>
[src]
pub fn emoteonly(&mut self) -> Result<(), Error>
[src]
pub fn emoteonlyoff(&mut self) -> Result<(), Error>
[src]
pub fn followers(&mut self, duration: &str) -> Result<(), Error>
[src]
pub fn followersoff(&mut self) -> Result<(), Error>
[src]
pub fn op(&mut self, username: &str) -> Result<(), Error>
[src]
pub fn unmod(&mut self, username: &str) -> Result<(), Error>
[src]
pub fn r9kbeta(&mut self) -> Result<(), Error>
[src]
pub fn r9kbetaoff(&mut self) -> Result<(), Error>
[src]
pub fn slow(&mut self, duration: Option<usize>) -> Result<(), Error>
[src]
pub fn slowoff(&mut self) -> Result<(), Error>
[src]
pub fn subscribers(&mut self) -> Result<(), Error>
[src]
pub fn subscribersoff(&mut self) -> Result<(), Error>
[src]
pub fn timeout(
&mut self,
username: &str,
duration: Option<&str>,
reason: Option<&str>
) -> Result<(), Error>
[src]
&mut self,
username: &str,
duration: Option<&str>,
reason: Option<&str>
) -> Result<(), Error>
pub fn untimeout(&mut self, username: &str) -> Result<(), Error>
[src]
pub fn vip(&mut self, username: &str) -> Result<(), Error>
[src]
pub fn unvip(&mut self, username: &str) -> Result<(), Error>
[src]
pub fn whisper(&mut self, username: &str, message: &str) -> Result<(), Error>
[src]
pub fn join<C: Into<Channel>>(&mut self, channel: C) -> Result<(), Error>
[src]
Joins a channel
This ensures the channel name is lowercased and begins with a '#'.
The following are equivilant
client.join("museun").unwrap(); client.join("#museun").unwrap(); client.join("Museun").unwrap(); client.join("#MUSEUN").unwrap();
pub fn part<C: Into<Channel>>(&mut self, channel: C) -> Result<(), Error>
[src]
Parts a channel
This ensures the channel name is lowercased and begins with a '#'.
The following are equivilant
client.part("museun").unwrap(); client.part("#museun").unwrap(); client.part("Museun").unwrap(); client.part("#MUSEUN").unwrap();
pub fn me<C, S>(&mut self, channel: C, message: S) -> Result<(), Error> where
C: Into<Channel>,
S: AsRef<str>,
[src]
C: Into<Channel>,
S: AsRef<str>,
Sends an "emote" message
in the third person to the channel
This ensures the channel name is lowercased and begins with a '#'.
pub fn privmsg<C, S>(&mut self, channel: C, message: S) -> Result<(), Error> where
C: Into<Channel>,
S: AsRef<str>,
[src]
C: Into<Channel>,
S: AsRef<str>,
Sends the message
to the channel
This ensures the channel name is lowercased and begins with a '#'.
Same as send
pub fn send<C, S>(&mut self, channel: C, message: S) -> Result<(), Error> where
C: Into<Channel>,
S: AsRef<str>,
[src]
C: Into<Channel>,
S: AsRef<str>,
Sends the message
to the channel
This ensures the channel name is lowercased and begins with a '#'.
Same as privmsg
pub fn command<S>(&mut self, data: S) -> Result<(), Error> where
S: AsRef<str>,
[src]
S: AsRef<str>,
Sends the command: data
(e.g. /color #FFFFFF
)
pub fn raw<S>(&mut self, data: S) -> Result<(), Error> where
S: AsRef<str>,
[src]
S: AsRef<str>,
Sends a raw line (appends the required \r\n
)
Trait Implementations
impl<R, W: Write> ClientExt for Client<R, W>
[src]
fn inspect<F>(&mut self, f: F) where
F: FnMut(String) + Send + Sync + 'static,
[src]
F: FnMut(String) + Send + Sync + 'static,
fn remove_inspect(&mut self)
[src]
fn join_many<'a, I, S>(&mut self, channels: I) -> Result<(), Error> where
I: IntoIterator<Item = S> + 'a,
S: AsRef<str> + 'a,
[src]
I: IntoIterator<Item = S> + 'a,
S: AsRef<str> + 'a,
impl<R, W> Clone for Client<R, W>
[src]
Auto Trait Implementations
impl<R, W> Send for Client<R, W> where
R: Send,
W: Send,
R: Send,
W: Send,
impl<R, W> Sync for Client<R, W> where
R: Send,
W: Send,
R: Send,
W: Send,
Blanket Implementations
impl<T, U> Into for T where
U: From<T>,
[src]
U: From<T>,
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
impl<T> From for T
[src]
impl<T, U> TryFrom for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T> Borrow for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T, U> TryInto for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,