https://github.com/nerixyz/twitch-pubsub-rs
Connect to Twitch PubSub from Rust land.
https://github.com/nerixyz/twitch-pubsub-rs
hacktoberfest pubsub rust twitch
Last synced: about 1 month ago
JSON representation
Connect to Twitch PubSub from Rust land.
- Host: GitHub
- URL: https://github.com/nerixyz/twitch-pubsub-rs
- Owner: Nerixyz
- License: mit
- Created: 2021-07-26T18:56:08.000Z (almost 4 years ago)
- Default Branch: master
- Last Pushed: 2024-04-08T10:00:52.000Z (about 1 year ago)
- Last Synced: 2024-04-08T11:24:40.195Z (about 1 year ago)
- Topics: hacktoberfest, pubsub, rust, twitch
- Language: Rust
- Homepage:
- Size: 125 KB
- Stars: 2
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# twitch-pubsub
Connect to Twitch [PubSub](https://dev.twitch.tv/docs/pubsub) from Rust land.
This crate is basically randers' [`twitch-irc-rs`](https://lib.rs/crates/twitch-irc)
but for [PubSub](https://dev.twitch.tv/docs/pubsub).For the provided types,
this crate is using the types provided by [`twitch_api2`](https://lib.rs/crates/twitch_api2) from Emilgardis.# Documentation
~~Documentation can be found at [docs.rs](https://docs.rs/twitch-pubsub).~~
Not yet.# Features
- Automatic reconnection
- Connection pooling
- Custom token handling# Example
```rust
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
_ => ()
}
}
}
```