| Crates.io | twitch_comment_stream |
| lib.rs | twitch_comment_stream |
| version | 0.1.0 |
| created_at | 2024-10-18 13:30:58.787607+00 |
| updated_at | 2024-10-18 13:30:58.787607+00 |
| description | A library to stream comments from Twitch |
| homepage | |
| repository | https://github.com/MorrisFreeman/twitch_comment_stream |
| max_upload_size | |
| id | 1414240 |
| size | 34,602 |
This Rust library provides a simple interface to connect to Twitch chat and read comments in real-time using WebSockets.
Add this library to your Cargo.toml:
[dependencies]
twitch-comment-stream = "0.1.0"
Here's a basic example of how to use the TwitchCommentStream:
use twitch_comment_stream::TwitchCommentStream;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let mut stream = TwitchCommentStream::new("your_channel_name".to_string());
stream.connect().await?;
while let Ok(comment) = stream.next().await {
println!("{}: {}", comment.user, comment.body);
}
Ok(())
}
new(channel: String) -> Self: Creates a new instance for the specified channel.connect(&mut self) -> Result<(), Box<dyn std::error::Error>>: Connects to the Twitch chat.write_message(&mut self, message: String) -> Result<(), Box<dyn std::error::Error>>: Sends a message to the chat.next(&mut self) -> Result<Comment, Box<dyn std::error::Error>>: Retrieves the next comment from the chat.user: String: The username of the commenter.body: String: The content of the comment.Run the tests with:
cargo test
This project is licensed under the MIT License.