echo/
echo.rs

1//! A simple bot that repeats chat messages sent by other players.
2
3use azalea::prelude::*;
4
5#[tokio::main]
6async fn main() -> AppExit {
7    let account = Account::offline("bot");
8    // or let account = Account::microsoft("email").await.unwrap();
9
10    ClientBuilder::new()
11        .set_handler(handle)
12        .start(account, "localhost")
13        .await
14}
15
16#[derive(Clone, Component, Default)]
17pub struct State {}
18
19async fn handle(bot: Client, event: Event, _state: State) -> anyhow::Result<()> {
20    if let Event::Chat(m) = event
21        && let (Some(sender), content) = m.split_sender_and_content()
22    {
23        if sender == bot.username() {
24            // ignore our own messages
25            return Ok(());
26        }
27        bot.chat(content);
28    }
29
30    Ok(())
31}