Skip to content

Commit

Permalink
fix: remove usage in README and link to examples instead
Browse files Browse the repository at this point in the history
  • Loading branch information
y5c4l3 committed Oct 18, 2023
1 parent 4b9288d commit 3407fbf
Showing 1 changed file with 1 addition and 45 deletions.
46 changes: 1 addition & 45 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,48 +6,4 @@ closur: osu!bancho IRC library for Rust

## Usage

[Examples](./examples) require environment variables `BANCHO_USERNAME` and `BANCHO_PASSWORD` at **compile time**, specify them like below:

```bash
BANCHO_USERNAME=username BANCHO_PASSWORD=password cargo run --example echobot
```

This is a minimal echo bot example. See more [examples](./examples).

```rust
use closur::bancho::{Client, ClientOptions, Event};

type Result<T> = std::result::Result<T, Box<dyn std::error::Error + Send + Sync>>;

// This example shows how to create a simple echo bot.
#[tokio::main]
async fn main() -> Result<()> {
// "BANCHO_USERNAME" and "BANCHO_PASSWORD" are **compile-time** environment variables.
// You need to set username and password, e.g. running
// `BANCHO_USERNAME=username BANCHO_PASSWORD=password cargo run --example echobot`
let options = ClientOptions::default()
.username(env!("BANCHO_USERNAME").to_string())
.password(env!("BANCHO_PASSWORD").to_string());

let mut client = Client::new(options).await?;
let mut writer = client.writer();
client.auth().await?;

println!("[ECHOBOT] Connected and authenticated, waiting for events...");
let mut subscriber = client.events();
loop {
let event = subscriber.recv().await?;
match event {
Event::Message { from, body, .. } => {
println!("[PM] {}: {}", from.to_string(), body);
if body.starts_with("!echo") {
let message = body.trim_start_matches("!echo").trim();
println!("[EVENT] Sent echo message to {}: {}", from, message);
writer.send_private_chat(from, message).await?;
}
},
_ => {},
}
}
}
```
See [examples](./examples).

0 comments on commit 3407fbf

Please sign in to comment.