Connect to Twitch PubSub from Rust land.
This crate is basically randers' twitch-irc-rs
but for PubSub.
For the provided types,
this crate is using the types provided by twitch_api2
from Emilgardis.
Documentation can be found at docs.rs.
Not yet.
- Automatic reconnection
- Connection pooling
- Custom token handling
use twitch_pubsub::{
PubsubClient,
Topic,
moderation,
providers::StaticTokenProvider,
ClientConfig,
ServerMessage,
TopicData,
};
#[tokio::main]
pub async fn main() {
let config = ClientConfig::new(StaticTokenProvider::new("MY STATIC SECRET TOKEN"));
let (mut incoming, client) = PubsubClient::new(config);
client.listen(Topic::ChatModeratorActions(moderation::ChatModeratorActions {
// your user-id
user_id: 129546453,
channel_id: 129546453
})).await.expect("Failed listening to chat-moderator-actions");
while let Some(message) = incoming.recv().await {
match message {
ServerMessage::Data(
TopicData::ChatModeratorActions { topic, reply }
)=> {
println!("Message on {:?}: {:?}", topic, reply);
},
// handle other messages here
_ => ()
}
}
}