aboutsummaryrefslogtreecommitdiff
path: root/azalea/examples/echo.rs
diff options
context:
space:
mode:
authormat <github@matdoes.dev>2022-10-23 16:51:49 -0500
committermat <github@matdoes.dev>2022-10-23 16:51:49 -0500
commit2eade86cf7a12a6ec64496aedbfc3d3a3bd44e1a (patch)
treec010d3f02beaec29741b723a1bc6e7eaad59e193 /azalea/examples/echo.rs
parenta9ff79a10553026b0fa32f0e31f1e0442467ca78 (diff)
downloadazalea-drasl-2eade86cf7a12a6ec64496aedbfc3d3a3bd44e1a.tar.xz
make `handle` cleaner
Arc<Event> -> Event, Arc<Mutex<State>> -> State Items in State now need to have interior mutability (i.e. Arc<Mutex<T>>), but it's a worthwhile tradeoff since it allows the user to customize it for each field
Diffstat (limited to 'azalea/examples/echo.rs')
-rw-r--r--azalea/examples/echo.rs13
1 files changed, 5 insertions, 8 deletions
diff --git a/azalea/examples/echo.rs b/azalea/examples/echo.rs
index a5280d8b..07dd50c1 100644
--- a/azalea/examples/echo.rs
+++ b/azalea/examples/echo.rs
@@ -12,7 +12,7 @@ async fn main() {
azalea::start(azalea::Options {
account,
address: "localhost",
- state: Arc::new(Mutex::new(State::default())),
+ state: State::default(),
plugins: vec![],
handle,
})
@@ -20,19 +20,16 @@ async fn main() {
.unwrap();
}
+#[derive(Default, Clone)]
pub struct State {}
-async fn handle(bot: Client, event: Arc<Event>, state: Arc<Mutex<State>>) -> anyhow::Result<()> {
- match *event {
+async fn handle(bot: Client, event: Event, state: State) -> anyhow::Result<()> {
+ match event {
Event::Chat(m) => {
if m.username == bot.username {
return Ok(()); // ignore our own messages
};
- bot.chat(m.message).await;
- }
- Event::Kick(m) => {
- println!(m);
- bot.reconnect().await.unwrap();
+ bot.chat(m.content).await;
}
_ => {}
}