Compare commits
4 Commits
e85d02cee2
...
7828d754f5
Author | SHA1 | Date | |
---|---|---|---|
7828d754f5 | |||
58e78c6c44 | |||
e0d86ee529 | |||
228b3e3e54 |
42
Cargo.lock
generated
42
Cargo.lock
generated
@ -378,7 +378,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "azalea"
|
||||
version = "0.11.0+mc1.21.4"
|
||||
source = "git+https://github.com/azalea-rs/azalea#75efbc83fdc4a47f880e95259a339d41839af01a"
|
||||
source = "git+https://github.com/azalea-rs/azalea#aa2039c86888e8ef47072fde63634ec58b22a654"
|
||||
dependencies = [
|
||||
"azalea-auth",
|
||||
"azalea-block",
|
||||
@ -416,7 +416,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "azalea-auth"
|
||||
version = "0.11.0+mc1.21.4"
|
||||
source = "git+https://github.com/azalea-rs/azalea#75efbc83fdc4a47f880e95259a339d41839af01a"
|
||||
source = "git+https://github.com/azalea-rs/azalea#aa2039c86888e8ef47072fde63634ec58b22a654"
|
||||
dependencies = [
|
||||
"azalea-buf",
|
||||
"azalea-crypto",
|
||||
@ -436,7 +436,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "azalea-block"
|
||||
version = "0.11.0+mc1.21.4"
|
||||
source = "git+https://github.com/azalea-rs/azalea#75efbc83fdc4a47f880e95259a339d41839af01a"
|
||||
source = "git+https://github.com/azalea-rs/azalea#aa2039c86888e8ef47072fde63634ec58b22a654"
|
||||
dependencies = [
|
||||
"azalea-block-macros",
|
||||
"azalea-buf",
|
||||
@ -446,7 +446,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "azalea-block-macros"
|
||||
version = "0.11.0+mc1.21.4"
|
||||
source = "git+https://github.com/azalea-rs/azalea#75efbc83fdc4a47f880e95259a339d41839af01a"
|
||||
source = "git+https://github.com/azalea-rs/azalea#aa2039c86888e8ef47072fde63634ec58b22a654"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
@ -456,7 +456,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "azalea-brigadier"
|
||||
version = "0.11.0+mc1.21.4"
|
||||
source = "git+https://github.com/azalea-rs/azalea#75efbc83fdc4a47f880e95259a339d41839af01a"
|
||||
source = "git+https://github.com/azalea-rs/azalea#aa2039c86888e8ef47072fde63634ec58b22a654"
|
||||
dependencies = [
|
||||
"azalea-buf",
|
||||
"azalea-chat",
|
||||
@ -466,7 +466,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "azalea-buf"
|
||||
version = "0.11.0+mc1.21.4"
|
||||
source = "git+https://github.com/azalea-rs/azalea#75efbc83fdc4a47f880e95259a339d41839af01a"
|
||||
source = "git+https://github.com/azalea-rs/azalea#aa2039c86888e8ef47072fde63634ec58b22a654"
|
||||
dependencies = [
|
||||
"azalea-buf-macros",
|
||||
"byteorder",
|
||||
@ -480,7 +480,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "azalea-buf-macros"
|
||||
version = "0.11.0+mc1.21.4"
|
||||
source = "git+https://github.com/azalea-rs/azalea#75efbc83fdc4a47f880e95259a339d41839af01a"
|
||||
source = "git+https://github.com/azalea-rs/azalea#aa2039c86888e8ef47072fde63634ec58b22a654"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
@ -490,7 +490,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "azalea-chat"
|
||||
version = "0.11.0+mc1.21.4"
|
||||
source = "git+https://github.com/azalea-rs/azalea#75efbc83fdc4a47f880e95259a339d41839af01a"
|
||||
source = "git+https://github.com/azalea-rs/azalea#aa2039c86888e8ef47072fde63634ec58b22a654"
|
||||
dependencies = [
|
||||
"azalea-buf",
|
||||
"azalea-language",
|
||||
@ -504,7 +504,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "azalea-client"
|
||||
version = "0.11.0+mc1.21.4"
|
||||
source = "git+https://github.com/azalea-rs/azalea#75efbc83fdc4a47f880e95259a339d41839af01a"
|
||||
source = "git+https://github.com/azalea-rs/azalea#aa2039c86888e8ef47072fde63634ec58b22a654"
|
||||
dependencies = [
|
||||
"azalea-auth",
|
||||
"azalea-block",
|
||||
@ -539,7 +539,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "azalea-core"
|
||||
version = "0.11.0+mc1.21.4"
|
||||
source = "git+https://github.com/azalea-rs/azalea#75efbc83fdc4a47f880e95259a339d41839af01a"
|
||||
source = "git+https://github.com/azalea-rs/azalea#aa2039c86888e8ef47072fde63634ec58b22a654"
|
||||
dependencies = [
|
||||
"azalea-buf",
|
||||
"azalea-chat",
|
||||
@ -556,7 +556,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "azalea-crypto"
|
||||
version = "0.11.0+mc1.21.4"
|
||||
source = "git+https://github.com/azalea-rs/azalea#75efbc83fdc4a47f880e95259a339d41839af01a"
|
||||
source = "git+https://github.com/azalea-rs/azalea#aa2039c86888e8ef47072fde63634ec58b22a654"
|
||||
dependencies = [
|
||||
"aes",
|
||||
"azalea-buf",
|
||||
@ -573,7 +573,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "azalea-entity"
|
||||
version = "0.11.0+mc1.21.4"
|
||||
source = "git+https://github.com/azalea-rs/azalea#75efbc83fdc4a47f880e95259a339d41839af01a"
|
||||
source = "git+https://github.com/azalea-rs/azalea#aa2039c86888e8ef47072fde63634ec58b22a654"
|
||||
dependencies = [
|
||||
"azalea-block",
|
||||
"azalea-buf",
|
||||
@ -597,7 +597,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "azalea-inventory"
|
||||
version = "0.11.0+mc1.21.4"
|
||||
source = "git+https://github.com/azalea-rs/azalea#75efbc83fdc4a47f880e95259a339d41839af01a"
|
||||
source = "git+https://github.com/azalea-rs/azalea#aa2039c86888e8ef47072fde63634ec58b22a654"
|
||||
dependencies = [
|
||||
"azalea-buf",
|
||||
"azalea-chat",
|
||||
@ -613,7 +613,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "azalea-inventory-macros"
|
||||
version = "0.11.0+mc1.21.4"
|
||||
source = "git+https://github.com/azalea-rs/azalea#75efbc83fdc4a47f880e95259a339d41839af01a"
|
||||
source = "git+https://github.com/azalea-rs/azalea#aa2039c86888e8ef47072fde63634ec58b22a654"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
@ -623,7 +623,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "azalea-language"
|
||||
version = "0.11.0+mc1.21.4"
|
||||
source = "git+https://github.com/azalea-rs/azalea#75efbc83fdc4a47f880e95259a339d41839af01a"
|
||||
source = "git+https://github.com/azalea-rs/azalea#aa2039c86888e8ef47072fde63634ec58b22a654"
|
||||
dependencies = [
|
||||
"compact_str",
|
||||
"serde",
|
||||
@ -633,7 +633,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "azalea-physics"
|
||||
version = "0.11.0+mc1.21.4"
|
||||
source = "git+https://github.com/azalea-rs/azalea#75efbc83fdc4a47f880e95259a339d41839af01a"
|
||||
source = "git+https://github.com/azalea-rs/azalea#aa2039c86888e8ef47072fde63634ec58b22a654"
|
||||
dependencies = [
|
||||
"azalea-block",
|
||||
"azalea-core",
|
||||
@ -650,7 +650,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "azalea-protocol"
|
||||
version = "0.11.0+mc1.21.4"
|
||||
source = "git+https://github.com/azalea-rs/azalea#75efbc83fdc4a47f880e95259a339d41839af01a"
|
||||
source = "git+https://github.com/azalea-rs/azalea#aa2039c86888e8ef47072fde63634ec58b22a654"
|
||||
dependencies = [
|
||||
"async-recursion",
|
||||
"azalea-auth",
|
||||
@ -684,7 +684,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "azalea-protocol-macros"
|
||||
version = "0.11.0+mc1.21.4"
|
||||
source = "git+https://github.com/azalea-rs/azalea#75efbc83fdc4a47f880e95259a339d41839af01a"
|
||||
source = "git+https://github.com/azalea-rs/azalea#aa2039c86888e8ef47072fde63634ec58b22a654"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
@ -694,7 +694,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "azalea-registry"
|
||||
version = "0.11.0+mc1.21.4"
|
||||
source = "git+https://github.com/azalea-rs/azalea#75efbc83fdc4a47f880e95259a339d41839af01a"
|
||||
source = "git+https://github.com/azalea-rs/azalea#aa2039c86888e8ef47072fde63634ec58b22a654"
|
||||
dependencies = [
|
||||
"azalea-buf",
|
||||
"azalea-registry-macros",
|
||||
@ -705,7 +705,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "azalea-registry-macros"
|
||||
version = "0.11.0+mc1.21.4"
|
||||
source = "git+https://github.com/azalea-rs/azalea#75efbc83fdc4a47f880e95259a339d41839af01a"
|
||||
source = "git+https://github.com/azalea-rs/azalea#aa2039c86888e8ef47072fde63634ec58b22a654"
|
||||
dependencies = [
|
||||
"quote",
|
||||
"syn",
|
||||
@ -714,7 +714,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "azalea-world"
|
||||
version = "0.11.0+mc1.21.4"
|
||||
source = "git+https://github.com/azalea-rs/azalea#75efbc83fdc4a47f880e95259a339d41839af01a"
|
||||
source = "git+https://github.com/azalea-rs/azalea#aa2039c86888e8ef47072fde63634ec58b22a654"
|
||||
dependencies = [
|
||||
"azalea-block",
|
||||
"azalea-buf",
|
||||
|
@ -111,6 +111,10 @@ function attack_entities(target_kind, minimum)
|
||||
end
|
||||
|
||||
function check_food(hunger)
|
||||
if not hunger then
|
||||
hunger = client.hunger
|
||||
end
|
||||
|
||||
if hunger.food >= 20 then
|
||||
return
|
||||
end
|
||||
|
@ -61,9 +61,11 @@ function update_listeners()
|
||||
message = function()
|
||||
info("bot successfully logged in!")
|
||||
end,
|
||||
},
|
||||
spawn = {
|
||||
eat = function()
|
||||
sleep(5000)
|
||||
check_food(client.hunger)
|
||||
check_food()
|
||||
end,
|
||||
},
|
||||
death = {
|
||||
|
2
main.lua
2
main.lua
@ -2,7 +2,7 @@ Server = "localhost"
|
||||
Username = "ErrorNoWatcher"
|
||||
HttpAddress = "127.0.0.1:8080"
|
||||
Owners = { "ErrorNoInternet" }
|
||||
MatrixOwners = { "@errornointernet:envs.net" }
|
||||
Matrix = { Owners = { "@errornointernet:envs.net" } }
|
||||
|
||||
for _, module in ipairs({
|
||||
"lib",
|
||||
|
@ -46,7 +46,7 @@ pub async fn handle_event(client: Client, event: Event, state: State) -> Result<
|
||||
.call::<String>((options.clone(), content.clone()))
|
||||
.ok()
|
||||
.as_deref()
|
||||
.and_then(|s| trim_header(s).ok())
|
||||
.and_then(|string| trim_header(string).ok())
|
||||
{
|
||||
is_encrypted = true;
|
||||
ncr_options = Some(options);
|
||||
@ -128,6 +128,7 @@ pub async fn handle_event(client: Client, event: Event, state: State) -> Result<
|
||||
Event::RemovePlayer(player_info) => {
|
||||
call_listeners(&state, "remove_player", || Ok(Player::from(player_info))).await
|
||||
}
|
||||
Event::Spawn => call_listeners(&state, "spawn", || Ok(())).await,
|
||||
Event::Tick => call_listeners(&state, "tick", || Ok(())).await,
|
||||
Event::UpdatePlayer(player_info) => {
|
||||
call_listeners(&state, "update_player", || Ok(Player::from(player_info))).await
|
||||
@ -255,6 +256,7 @@ pub async fn handle_event(client: Client, event: Event, state: State) -> Result<
|
||||
});
|
||||
}
|
||||
}
|
||||
_ => todo!(),
|
||||
}
|
||||
}
|
||||
|
||||
@ -278,15 +280,10 @@ async fn lua_init(client: Client, state: &State, globals: &Table) -> Result<()>
|
||||
#[cfg(feature = "matrix")]
|
||||
fn matrix_init(client: &Client, state: State) {
|
||||
let globals = state.lua.globals();
|
||||
if let Ok(homeserver_url) = globals.get::<String>("MatrixHomeserverUrl")
|
||||
&& let Ok(username) = globals.get::<String>("MatrixUsername")
|
||||
&& let Ok(password) = globals.get::<String>("MatrixPassword")
|
||||
{
|
||||
if let Ok(matrix_options) = globals.get::<Table>("MatrixOptions") {
|
||||
let name = client.username();
|
||||
tokio::spawn(async move {
|
||||
if let Err(error) =
|
||||
matrix::login(homeserver_url, username, &password, state, globals, name).await
|
||||
{
|
||||
if let Err(error) = matrix::login(state, matrix_options, globals, name).await {
|
||||
error!("failed to log into matrix account: {error:?}");
|
||||
}
|
||||
});
|
||||
|
@ -22,9 +22,10 @@ pub fn held_slot(_lua: &Lua, client: &Client) -> Result<u8> {
|
||||
|
||||
#[allow(clippy::too_many_lines)]
|
||||
pub fn menu(lua: &Lua, client: &Client) -> Result<Value> {
|
||||
fn from_slot_list<const N: usize>(s: SlotList<N>) -> Vec<ItemStack> {
|
||||
s.iter()
|
||||
.map(|i| ItemStack(i.to_owned()))
|
||||
fn from_slot_list<const N: usize>(slot_list: SlotList<N>) -> Vec<ItemStack> {
|
||||
slot_list
|
||||
.iter()
|
||||
.map(|item_stack| ItemStack(item_stack.to_owned()))
|
||||
.collect::<Vec<_>>()
|
||||
}
|
||||
|
||||
|
@ -28,7 +28,7 @@ pub fn get_block_state(_lua: &Lua, client: &Client, position: Vec3) -> Result<Op
|
||||
position.y as i32,
|
||||
position.z as i32,
|
||||
))
|
||||
.map(|b| b.id))
|
||||
.map(|block| block.id))
|
||||
}
|
||||
|
||||
pub fn get_fluid_state(lua: &Lua, client: &Client, position: Vec3) -> Result<Option<Table>> {
|
||||
|
@ -28,15 +28,7 @@ pub async fn on_regular_room_message(
|
||||
return Ok(());
|
||||
};
|
||||
|
||||
if ctx
|
||||
.state
|
||||
.lua
|
||||
.globals()
|
||||
.get::<Vec<String>>("MatrixOwners")
|
||||
.unwrap_or_default()
|
||||
.contains(&event.sender.to_string())
|
||||
&& text_content.body.starts_with(&ctx.name)
|
||||
{
|
||||
if ctx.is_owner(&event.sender.to_string()) && text_content.body.starts_with(&ctx.name) {
|
||||
let body = text_content.body[ctx.name.len()..]
|
||||
.trim_start_matches(':')
|
||||
.trim();
|
||||
@ -101,13 +93,7 @@ pub async fn on_stripped_state_member(
|
||||
) -> Result<()> {
|
||||
if let Some(user_id) = client.user_id()
|
||||
&& member.state_key == user_id
|
||||
&& ctx
|
||||
.state
|
||||
.lua
|
||||
.globals()
|
||||
.get::<Vec<String>>("MatrixOwners")
|
||||
.unwrap_or_default()
|
||||
.contains(&member.sender.to_string())
|
||||
&& ctx.is_owner(&member.sender.to_string())
|
||||
{
|
||||
debug!("joining room {}", room.room_id());
|
||||
while let Err(error) = room.join().await {
|
||||
|
@ -20,6 +20,23 @@ pub struct Context {
|
||||
name: String,
|
||||
}
|
||||
|
||||
impl Context {
|
||||
fn is_owner(&self, name: &String) -> bool {
|
||||
self.state
|
||||
.lua
|
||||
.globals()
|
||||
.get::<Table>("MatrixOptions")
|
||||
.ok()
|
||||
.and_then(|options| {
|
||||
options
|
||||
.get::<Vec<String>>("Owners")
|
||||
.ok()
|
||||
.and_then(|owners| owners.contains(name).then_some(()))
|
||||
})
|
||||
.is_some()
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Serialize, Deserialize)]
|
||||
struct Session {
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
@ -37,14 +54,13 @@ async fn persist_sync_token(
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub async fn login(
|
||||
homeserver_url: String,
|
||||
username: String,
|
||||
password: &str,
|
||||
state: State,
|
||||
globals: Table,
|
||||
name: String,
|
||||
) -> Result<()> {
|
||||
pub async fn login(state: State, options: Table, globals: Table, name: String) -> Result<()> {
|
||||
let (homeserver_url, username, password) = (
|
||||
options.get::<String>("HomeserverUrl")?,
|
||||
options.get::<String>("Username")?,
|
||||
&options.get::<String>("Password")?,
|
||||
);
|
||||
|
||||
let root_dir = dirs::data_dir()
|
||||
.context("no data directory")?
|
||||
.join("errornowatcher")
|
||||
|
Loading…
x
Reference in New Issue
Block a user