Skip to content

Nerixyz/twitch-pubsub-rs

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

38 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

twitch-pubsub

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

Documentation can be found at docs.rs. Not yet.

Features

  • Automatic reconnection
  • Connection pooling
  • Custom token handling

Example

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
            _ => ()
        }
    }
}

About

Connect to Twitch PubSub from Rust land.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages