1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
use futures_util::TryStreamExt;
use licoricedev::client::{Lichess};
use licoricedev::models::board::{Event};

pub struct LichessBot {
}

impl LichessBot {
	pub fn new() -> LichessBot {
		LichessBot {

		}
	}

	pub fn process_event_stream_event(&mut self, event: Event){
		println!("event {:?}", event)
	}

	pub async fn stream(&mut self) -> Result<(), Box::<dyn std::error::Error>> {
		let lichess = Lichess::new(std::env::var("RUST_BOT_TOKEN").unwrap());
	
		let mut event_stream = lichess
			.stream_incoming_events()
			.await
			.unwrap();

		while let Some(event) = event_stream.try_next().await? {			
	    	self.process_event_stream_event(event);
	    }

	    Ok(())
	}
}