#event-handling #dogehouse #handler #msg #fn #self #async

dogehouse-rs

A library for dogehouse written in rust

24 releases

0.1.23 May 8, 2021
0.1.22 May 7, 2021
0.1.20 Apr 13, 2021

#20 in #fn

Download history 3/week @ 2024-02-22 1/week @ 2024-02-29 1/week @ 2024-03-07 55/week @ 2024-03-28 54/week @ 2024-04-04

109 downloads per month

MIT license

16KB
313 lines

dogehouse-rs

WARNING: Still work in progress do not use yet

Documentation Here

Example

In Cargo.toml
dogehouse-rs = "*"
In src/main.rs
use dogehouse_rs::prelude::*;
use dotenv::dotenv;
use std::env;

struct Handler;

#[async_trait]
impl EventHandler for Handler {
	async fn on_message(&self, msg: String) {
		println!("{}", msg);
	}

	async fn on_pong(&self) {
		println!("Received ping")
	}

	async fn connection_closed(&self) {
		println!("Connection has closed");
		std::process::exit(1);
	}
}

#[tokio::main]
async fn main() -> Result<()> {
	dotenv().ok();

	let mut client = Client::new(
		env::var("TOKEN").unwrap(),
		env::var("REFRESH_TOKEN").unwrap()
	).add_event_handler(Handler);

	client.use_create_bot(String::from("coolbotusername")).await?;

	if let Err(err) = client.start("61d5e75b-bc42-42ea-84bc-38a205482d3f").await {
		eprintln!("Client failed to start. {}", err.to_string());
	}

	Ok(())
}

Testing

cd tests/
cargo run

Dependencies

~10–25MB
~406K SLoC