twitch irc rs
v5.0.1
Twitch 채팅과 인터페이스하기 위한 클라이언트 라이브러리입니다.
이 라이브러리는 비동기식이며 tokio
런타임을 사용하여 실행됩니다.
사용 예(이것은 simple_listener
예입니다. examples/simple_listener.rs
참조하고 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 ( ) ;
}
자세한 내용은 docs.rs의 설명서를 확인하세요.