![crates-io-badge] Downloads ![docs-badge]

Spectacles Gateway

A rich Spectacles gateway client for Rust.

About

This crate allows you to interact with the Discord gateway. Please refer to the Discord Gateway Docs for more background on how to use this crate.

Features

Example - Basic Sharder

```rust use std::env::var; use spectaclesgateway::{ShardManager, ShardStrategy}; use spectaclesmodel::gateway::ReceivePacket; use futures::future::Future;

fn main() { let token = var("DISCORDTOKEN").expect("No Discord Token was provided."); // tokio.run() boostraps our Tokio application. tokio::run(ShardManager::new(token, ShardStrategy::Recommended) .map(|mut manager| { // The startspawn() method returns a tuple of async streams, for handling spawned shards and shard events. let (spawner, events) = manager.startspawn(); // Now, we poll the streams concurrently in separate threads. tokio::spawn(spawner.foreach(|shard| { println!("Shard {:?} has successfully spawned.", shard.lock().info);

            Ok(())
        }));
        tokio::spawn(events.for_each(|event| {
            if let Some(evt) = event.packet.t {
                println!("Received event from Shard {:?}: {:?}", event.shard.lock().info, evt);
            };

            Ok(())
        }));
    })
    .map_err(|err| {
        eprintln!("Failed to bootstrap sharding manager. {:?}", err);
    })
);

} ```