refactor: minor changes
This commit is contained in:
parent
c2c9ca609e
commit
f367fce138
@ -8,7 +8,6 @@ use mlua::{Lua, Result, Table};
|
|||||||
|
|
||||||
pub fn best_tool_for_block(lua: &Lua, client: &Client, block_state: u16) -> 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 result = client.best_tool_in_hotbar_for_block(BlockState { id: block_state });
|
||||||
|
|
||||||
let table = lua.create_table()?;
|
let table = lua.create_table()?;
|
||||||
table.set("index", result.index)?;
|
table.set("index", result.index)?;
|
||||||
table.set("percentage_per_tick", result.percentage_per_tick)?;
|
table.set("percentage_per_tick", result.percentage_per_tick)?;
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
use super::MatrixContext;
|
use super::Context;
|
||||||
use crate::{
|
use crate::{
|
||||||
events::call_listeners,
|
events::call_listeners,
|
||||||
lua::{self, matrix::room::Room as LuaRoom},
|
lua::{self, matrix::room::Room as LuaRoom},
|
||||||
@ -19,7 +19,7 @@ use tokio::time::sleep;
|
|||||||
pub async fn on_regular_room_message(
|
pub async fn on_regular_room_message(
|
||||||
event: OriginalSyncRoomMessageEvent,
|
event: OriginalSyncRoomMessageEvent,
|
||||||
room: Room,
|
room: Room,
|
||||||
ctx: Ctx<MatrixContext>,
|
ctx: Ctx<Context>,
|
||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
if room.state() != RoomState::Joined {
|
if room.state() != RoomState::Joined {
|
||||||
return Ok(());
|
return Ok(());
|
||||||
@ -90,7 +90,7 @@ pub async fn on_stripped_state_member(
|
|||||||
member: StrippedRoomMemberEvent,
|
member: StrippedRoomMemberEvent,
|
||||||
client: Client,
|
client: Client,
|
||||||
room: Room,
|
room: Room,
|
||||||
ctx: Ctx<MatrixContext>,
|
ctx: Ctx<Context>,
|
||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
if let Some(user_id) = client.user_id()
|
if let Some(user_id) = client.user_id()
|
||||||
&& member.state_key == user_id
|
&& member.state_key == user_id
|
||||||
|
@ -2,7 +2,7 @@ mod bot;
|
|||||||
mod verification;
|
mod verification;
|
||||||
|
|
||||||
use crate::{State, lua::matrix::client::Client as LuaClient};
|
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 bot::{on_regular_room_message, on_stripped_state_member};
|
||||||
use log::{error, warn};
|
use log::{error, warn};
|
||||||
use matrix_sdk::{
|
use matrix_sdk::{
|
||||||
@ -15,7 +15,7 @@ use tokio::fs;
|
|||||||
use verification::{on_device_key_verification_request, on_room_message_verification_request};
|
use verification::{on_device_key_verification_request, on_room_message_verification_request};
|
||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
pub struct MatrixContext {
|
pub struct Context {
|
||||||
state: State,
|
state: State,
|
||||||
name: String,
|
name: String,
|
||||||
}
|
}
|
||||||
@ -62,8 +62,8 @@ pub async fn login(
|
|||||||
let client = builder.build().await?;
|
let client = builder.build().await?;
|
||||||
|
|
||||||
let mut new_session;
|
let mut new_session;
|
||||||
let session_file = root_dir.join("session.json");
|
|
||||||
let mut sync_settings = SyncSettings::default();
|
let mut sync_settings = SyncSettings::default();
|
||||||
|
let session_file = root_dir.join("session.json");
|
||||||
if let Some(session) = fs::read_to_string(&session_file)
|
if let Some(session) = fs::read_to_string(&session_file)
|
||||||
.await
|
.await
|
||||||
.ok()
|
.ok()
|
||||||
@ -88,7 +88,7 @@ pub async fn login(
|
|||||||
fs::write(&session_file, serde_json::to_string(&new_session)?).await?;
|
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);
|
client.add_event_handler(on_stripped_state_member);
|
||||||
loop {
|
loop {
|
||||||
match client.sync_once(sync_settings.clone()).await {
|
match client.sync_once(sync_settings.clone()).await {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user