aboutsummaryrefslogtreecommitdiff
path: root/examples/echo.rs
diff options
context:
space:
mode:
authormat <github@matdoes.dev>2022-05-14 20:50:20 -0500
committermat <github@matdoes.dev>2022-05-14 20:50:20 -0500
commit5c1712c8404e52f893e3fc10f79a337933865123 (patch)
treea515b76d77fdf710314f07d70ec639f4a6dded6a /examples/echo.rs
parent4000a9d29cbd286517e00db88a27aeddc1967557 (diff)
downloadazalea-drasl-5c1712c8404e52f893e3fc10f79a337933865123.tar.xz
move examples into examples directory
Diffstat (limited to 'examples/echo.rs')
-rw-r--r--examples/echo.rs38
1 files changed, 38 insertions, 0 deletions
diff --git a/examples/echo.rs b/examples/echo.rs
new file mode 100644
index 00000000..c9e46a09
--- /dev/null
+++ b/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;
+ }
+ }
+ }
+ }
+ _ => {}
+ }
+}