A rich Spectacles Gateway client for Rust.
This crate allows you to interact with the Discord gateway. Pllease refer to the Discord Gateway Docs for more background on how to use this crate.
```rust,norun
use std::env::var; use spectaclesgateway::{ShardManager, ShardStrategy, ManagerOptions, EventHandler, Shard}; use spectaclesmodel::gateway::ReceivePacket; use futures::future::Future;
fn main() { envlogger::init(); let token = var("DISCORDTOKEN").expect("No Discord Token was provided."); // tokio.run() boostraps our Tokio application. tokio::run({ // calling new() here return a new instance of the shard manager. ShardManager::new(token, ManagerOptions { strategy: ShardStrategy::Recommended, handler: Handler }) .andthen(|mut manager| manager.spawn()) // Begins spawning of shards. .maperr(|err| error!("An error occured while processing shards: {:?}", err)) }); } /// Here we define our Handler struct, which we implement the Eventhandler trait for. /// The onpacket() trait method will be called when a packet is received from the Discord gateway. struct Handler; impl EventHandler for Handler { fn onpacket(&self, shard: &mut Shard, pkt: ReceivePacket) { println!("Received Gateway Packet from Shard {:?} - {:?}", shard.info, pkt); // Do other things with message, such as sending it to a message broker. } } ```