From 06068377bd17f95bdafe86ff14bab1d0d852aa53 Mon Sep 17 00:00:00 2001 From: mat <27899617+mat-1@users.noreply.github.com> Date: Sun, 2 Oct 2022 14:58:42 -0500 Subject: New example (#24) the example isn't finished but it's finished enough --- azalea/examples/echo.rs | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 azalea/examples/echo.rs (limited to 'azalea/examples/echo.rs') diff --git a/azalea/examples/echo.rs b/azalea/examples/echo.rs new file mode 100644 index 00000000..c9e46a09 --- /dev/null +++ b/azalea/examples/echo.rs @@ -0,0 +1,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; + } + } + } + } + _ => {} + } +} -- cgit v1.2.3