refactor: minor changes

This commit is contained in:
Ryan 2025-03-18 17:04:30 -04:00
parent c2c9ca609e
commit f367fce138
Signed by: ErrorNoInternet
GPG Key ID: 2486BFB7B1E6A4A3
3 changed files with 7 additions and 8 deletions

View File

@ -8,7 +8,6 @@ use mlua::{Lua, Result, Table};
pub fn best_tool_for_block(lua: &Lua, client: &Client, block_state: u16) -> Result<Table> {
let result = client.best_tool_in_hotbar_for_block(BlockState { id: block_state });
let table = lua.create_table()?;
table.set("index", result.index)?;
table.set("percentage_per_tick", result.percentage_per_tick)?;

View File

@ -1,4 +1,4 @@
use super::MatrixContext;
use super::Context;
use crate::{
events::call_listeners,
lua::{self, matrix::room::Room as LuaRoom},
@ -19,7 +19,7 @@ use tokio::time::sleep;
pub async fn on_regular_room_message(
event: OriginalSyncRoomMessageEvent,
room: Room,
ctx: Ctx<MatrixContext>,
ctx: Ctx<Context>,
) -> Result<()> {
if room.state() != RoomState::Joined {
return Ok(());
@ -90,7 +90,7 @@ pub async fn on_stripped_state_member(
member: StrippedRoomMemberEvent,
client: Client,
room: Room,
ctx: Ctx<MatrixContext>,
ctx: Ctx<Context>,
) -> Result<()> {
if let Some(user_id) = client.user_id()
&& member.state_key == user_id

View File

@ -2,7 +2,7 @@ mod bot;
mod verification;
use crate::{State, lua::matrix::client::Client as LuaClient};
use anyhow::{Context, Result};
use anyhow::{Context as _, Result};
use bot::{on_regular_room_message, on_stripped_state_member};
use log::{error, warn};
use matrix_sdk::{
@ -15,7 +15,7 @@ use tokio::fs;
use verification::{on_device_key_verification_request, on_room_message_verification_request};
#[derive(Clone)]
pub struct MatrixContext {
pub struct Context {
state: State,
name: String,
}
@ -62,8 +62,8 @@ pub async fn login(
let client = builder.build().await?;
let mut new_session;
let session_file = root_dir.join("session.json");
let mut sync_settings = SyncSettings::default();
let session_file = root_dir.join("session.json");
if let Some(session) = fs::read_to_string(&session_file)
.await
.ok()
@ -88,7 +88,7 @@ pub async fn login(
fs::write(&session_file, serde_json::to_string(&new_session)?).await?;
}
client.add_event_handler_context(MatrixContext { state, name });
client.add_event_handler_context(Context { state, name });
client.add_event_handler(on_stripped_state_member);
loop {
match client.sync_once(sync_settings.clone()).await {