4 releases
0.1.5 | Oct 24, 2023 |
---|---|
0.1.4 | Apr 16, 2023 |
#826 in Web programming
21KB
244 lines
Rust TwitchAlerts
A rust crate to allow the users to detect when a streamer is live a trigger a custom event. Rate Limiting is currently hardcoded at 80ms between individual checks but the delay between Check Cycles is fully customisable. Each streamer can currently be checked once every 30 seconds.
If you find any bugs or have a feature request, please report them on GitHub and any improvements and additions are welcome through pull requests
Features
- Stream Alerts
- Custom Delay
- Custom Error Handling
Setup
The first run will create a config file, this should contain the client-id, token, delay and list of streamers to monitor.
To get your OAuth token for twitch go to https://dev.twitch.tv/console create an application and use the Client ID & Secret with the command below
curl -X POST 'https://id.twitch.tv/oauth2/token' \
-H 'Content-Type: application/x-www-form-urlencoded' \
-d 'client_id=<your client id goes here>&client_secret=<your client secret goes here>&grant_type=client_credentials'
Example Config
streamers = ["streamer", "streamer2"]
delay = 80
token = "my_token"
user_id = "my_user_id"
Example
use async_trait::async_trait;
use twitchalerts::client::{StreamData, Streamer, Client};
use twitchalerts::traits::EventHandler;
pub struct Handler;
#[async_trait]
impl EventHandler for Handler {
async fn on_stream(&self, streamer: &String, stream: &StreamData) {
!todo();
}
async fn on_error(&self, error: String) {
!todo();
}
}
async fn main() -> Result<(), ()> {
_ = Client::new("client id", "client token").event_handler(Handler).run().await?;
Ok(())
}
Dependencies
Contributors
Dependencies
~7–23MB
~275K SLoC