#stream #event-handling #live #streamer #alert #delay #detect

twitchalerts

A crate which when it detect that a streamer is live which trigger the event handler, more features to be added

4 releases

0.1.5 Oct 24, 2023
0.1.4 Apr 16, 2023

#588 in Web programming

Download history 1/week @ 2024-02-23 1/week @ 2024-03-01 20/week @ 2024-03-29 1/week @ 2024-04-05 33/week @ 2024-04-12

54 downloads per month

Apache-2.0

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
~312K SLoC