feat: start work on 0.2.0

This commit is contained in:
2025-01-19 05:13:25 -05:00
parent 771057925d
commit 4fa508ec81
16 changed files with 2363 additions and 4046 deletions

48
src/events.rs Normal file
View File

@@ -0,0 +1,48 @@
use crate::{State, commands::CommandSource, scripting};
use azalea::prelude::*;
use mlua::Function;
pub async fn handle_event(client: Client, event: Event, state: State) -> anyhow::Result<()> {
let globals = state.lua.lock().globals();
match event {
Event::Chat(message) => {
println!("{}", message.message().to_ansi());
let owners = globals.get::<Vec<String>>("OWNERS")?;
if message.is_whisper()
&& let (Some(sender), content) = message.split_sender_and_content()
&& owners.contains(&sender)
{
if let Err(error) = state.commands.execute(
content,
CommandSource {
client: client.clone(),
message: message.clone(),
state: state.clone(),
}
.into(),
) {
CommandSource {
client,
message,
state,
}
.reply(&format!("{error:?}"));
};
}
}
Event::Init => {
globals.set(
"client",
scripting::client::Client {
inner: Some(client),
},
)?;
globals.get::<Function>("Init")?.call::<()>(())?
}
_ => (),
};
Ok(())
}