aboutsummaryrefslogtreecommitdiff
path: root/azalea/examples/echo.rs
diff options
context:
space:
mode:
authormat <27899617+mat-1@users.noreply.github.com>2022-10-02 14:58:42 -0500
committerGitHub <noreply@github.com>2022-10-02 14:58:42 -0500
commit06068377bd17f95bdafe86ff14bab1d0d852aa53 (patch)
treeed3f15107d69dc0cc8f6794745832b82a1649c80 /azalea/examples/echo.rs
parent37f9f1c6feda676be30bef31291eaed2a5fc82ce (diff)
downloadazalea-drasl-06068377bd17f95bdafe86ff14bab1d0d852aa53.tar.xz
New example (#24)
the example isn't finished but it's finished enough
Diffstat (limited to 'azalea/examples/echo.rs')
-rw-r--r--azalea/examples/echo.rs38
1 files changed, 38 insertions, 0 deletions
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;
+ }
+ }
+ }
+ }
+ _ => {}
+ }
+}