aboutsummaryrefslogtreecommitdiff
path: root/examples/echo.rs
blob: c9e46a094deb9f33f462dc8d99e58dd6f90a5a59 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
use azalea::{Account, Event};

let account = Account::offline("bot");
// or let account = azalea::Account::microsoft("access token").await;

let bot = account.join("localhost".try_into().unwrap()).await.unwrap();

loop {
    match bot.next().await {
        Event::Message(m) {
            if m.username == bot.username { return };
            bot.chat(m.message).await;
        },
        Event::Kicked(m) {
            println!(m);
            bot.reconnect().await.unwrap();
        },
        Event::Hunger(h) {
            if !h.using_held_item() && h.hunger <= 17 {
                match bot.hold(azalea::ItemGroup::Food).await {
                    Ok(_) => {},
                    Err(e) => {
                        println!("{}", e);
                        break;
                    }
                }
                match bot.use_held_item().await {
                    Ok(_) => {},
                    Err(e) => {
                        println!("{}", e);
                        break;
                    }
                }
            }
        }
        _ => {}
    }
}