Add loop to wait for recently logged out characters

This commit is contained in:
Jeff 2024-07-13 04:37:31 -04:00
parent 29e3178eba
commit 86a579714e
2 changed files with 22 additions and 9 deletions

View File

@ -54,7 +54,7 @@ podman run \
--detach \ --detach \
--name trade_bot \ --name trade_bot \
--secret secrets.toml \ --secret secrets.toml \
-v ./config/:/root/config/ \ --volume ./config/:/root/config/ \
--env CONFIG=/root/config/config.toml \ --env CONFIG=/root/config/config.toml \
--env SECRETS=/run/secrets/secrets.toml \ --env SECRETS=/run/secrets/secrets.toml \
--env RUST_LOG=trade_bot \ --env RUST_LOG=trade_bot \

View File

@ -17,8 +17,12 @@ use tokio::runtime::Runtime;
use vek::Quaternion; use vek::Quaternion;
use veloren_client::{addr::ConnectionArgs, Client, Event as VelorenEvent, SiteInfoRich, WorldExt}; use veloren_client::{addr::ConnectionArgs, Client, Event as VelorenEvent, SiteInfoRich, WorldExt};
use veloren_common::{ use veloren_common::{
character::Character,
clock::Clock, clock::Clock,
comp::{invite::InviteKind, item::ItemDefinitionIdOwned, ChatType, ControllerInputs, Ori, Pos}, comp::{
invite::InviteKind, item::ItemDefinitionIdOwned, CharacterState, ChatType,
ControllerInputs, Health, Ori, Pos,
},
outcome::Outcome, outcome::Outcome,
time::DayPeriod, time::DayPeriod,
trade::{PendingTrade, TradeAction, TradeResult}, trade::{PendingTrade, TradeAction, TradeResult},
@ -96,6 +100,9 @@ impl Bot {
.id .id
.ok_or("Failed to get character ID")?; .ok_or("Failed to get character ID")?;
// This loop waits and retries requesting the character in the case that the character has
// logged out to recently.
while client.position().is_none() {
client.request_character( client.request_character(
character_id, character_id,
ViewDistances { ViewDistances {
@ -104,6 +111,12 @@ impl Bot {
}, },
); );
client
.tick(ControllerInputs::default(), clock.dt())
.map_err(|error| format!("{error:?}"))?;
clock.tick();
}
let now = Instant::now(); let now = Instant::now();
Ok(Bot { Ok(Bot {