Crates.io | twitch-irc |
lib.rs | twitch-irc |
version | 5.0.1 |
source | src |
created_at | 2020-08-19 19:23:39.762717 |
updated_at | 2023-08-29 20:48:22.634177 |
description | Connect to Twitch chat from a Rust application. |
homepage | |
repository | https://github.com/robotty/twitch-irc-rs |
max_upload_size | |
id | 278356 |
size | 404,811 |
This is a client library to interface with Twitch chat.
This library is async and runs using the tokio
runtime.
Example usage (This is the simple_listener
example, see examples/simple_listener.rs
and run it with cargo run --example simple_listener
):
use twitch_irc::login::StaticLoginCredentials;
use twitch_irc::TwitchIRCClient;
use twitch_irc::{ClientConfig, SecureTCPTransport};
#[tokio::main]
pub async fn main() {
// default configuration is to join chat as anonymous.
let config = ClientConfig::default();
let (mut incoming_messages, client) =
TwitchIRCClient::<SecureTCPTransport, StaticLoginCredentials>::new(config);
// first thing you should do: start consuming incoming messages,
// otherwise they will back up.
let join_handle = tokio::spawn(async move {
while let Some(message) = incoming_messages.recv().await {
println!("Received message: {:?}", message);
}
});
// join a channel
// This function only returns an error if the passed channel login name is malformed,
// so in this simple case where the channel name is hardcoded we can ignore the potential
// error with `unwrap`.
client.join("sodapoppin".to_owned()).unwrap();
// keep the tokio executor alive.
// If you return instead of waiting the background task will exit.
join_handle.await.unwrap();
}
Check out the documentation on docs.rs for more details.