1
2
Fork 0
mirror of https://github.com/mat-1/azalea.git synced 2025-08-02 06:16:04 +00:00

simplify boilerplate in examples

This commit is contained in:
mat 2023-12-04 20:23:41 -06:00
parent 797dd91710
commit da4afa8ae3
4 changed files with 25 additions and 34 deletions

View file

@ -50,13 +50,11 @@ async fn main() {
let account = Account::offline("bot");
// or Account::microsoft("example@example.com").await.unwrap();
loop {
let e = ClientBuilder::new()
.set_handler(handle)
.start(account.clone(), "localhost")
.await;
eprintln!("{e:?}");
}
ClientBuilder::new()
.set_handler(handle)
.start(account.clone(), "localhost")
.await
.unwrap();
}
#[derive(Default, Clone, Component)]

View file

@ -21,7 +21,7 @@ struct State {}
struct SwarmState {}
#[tokio::main]
async fn main() -> anyhow::Result<()> {
async fn main() {
{
use parking_lot::deadlock;
use std::thread;
@ -51,20 +51,14 @@ async fn main() -> anyhow::Result<()> {
accounts.push(Account::offline(&format!("bot{i}")));
}
loop {
let e = SwarmBuilder::new()
.add_accounts(accounts.clone())
.set_handler(handle)
.set_swarm_handler(swarm_handle)
.join_delay(Duration::from_millis(100))
.start("localhost")
.await;
// let e = azalea::ClientBuilder::new()
// .set_handler(handle)
// .start(Account::offline("bot"), "localhost")
// .await;
eprintln!("{e:?}");
}
SwarmBuilder::new()
.add_accounts(accounts.clone())
.set_handler(handle)
.set_swarm_handler(swarm_handle)
.join_delay(Duration::from_millis(100))
.start("localhost")
.await
.unwrap();
}
async fn handle(mut bot: Client, event: Event, _state: State) -> anyhow::Result<()> {

View file

@ -10,12 +10,13 @@ async fn main() {
states.push(State::default());
}
let e = SwarmBuilder::new()
SwarmBuilder::new()
.add_accounts(accounts.clone())
.set_handler(handle)
.set_swarm_handler(swarm_handle)
.start("localhost")
.await;
.await
.unwrap();
}
#[derive(Default, Clone, Component)]

View file

@ -470,16 +470,14 @@ pub type BoxSwarmHandleFn<SS> =
/// states.push(State::default());
/// }
///
/// loop {
/// let e = SwarmBuilder::new()
/// .add_accounts(accounts.clone())
/// .set_handler(handle)
/// .set_swarm_handler(swarm_handle)
/// .join_delay(Duration::from_millis(1000))
/// .start("localhost")
/// .await;
/// println!("{e:?}");
/// }
/// SwarmBuilder::new()
/// .add_accounts(accounts.clone())
/// .set_handler(handle)
/// .set_swarm_handler(swarm_handle)
/// .join_delay(Duration::from_millis(1000))
/// .start("localhost")
/// .await
/// .unwrap();
/// }
///
/// async fn handle(bot: Client, event: Event, _state: State) -> anyhow::Result<()> {