smalld_rust 0.2.0

A minimalist client for the Discord API
use log::{debug, warn};
use serde_json::json;
use smalld::SmallD;

fn main() {
    pretty_env_logger::init();

    let smalld = SmallD::new().expect("Failed to initialize smalld");

    smalld.on_event("MESSAGE_CREATE", move |smalld, json| {
        if let Some("++ping") = json.get("content").and_then(|c| c.as_str()) {
            debug!("Pong!");
            if let Some(channel_id) = json.get("channel_id").and_then(|c| c.as_str()) {
                if let Err(err) = smalld.post(
                    format!("/channels/{}/messages", channel_id),
                    json!({"content":"pong"}),
                ) {
                    warn!("Error sending pong response: {}", err);
                }
            }
        }
    });

    smalld.run();
}