diff --git a/src/bot.rs b/src/bot.rs index 28e7a01..9b30d29 100644 --- a/src/bot.rs +++ b/src/bot.rs @@ -12,7 +12,7 @@ use veloren_common::{ comp::{invite::InviteKind, item::ItemDefinitionIdOwned, ChatType, ControllerInputs, Ori, Pos}, outcome::Outcome, time::DayPeriod, - trade::{PendingTrade, TradeAction}, + trade::{PendingTrade, TradeAction, TradeResult}, uid::Uid, ViewDistances, }; @@ -173,7 +173,7 @@ impl Bot { .. }) => { if let Some(uid) = self.client.uid() { - if uid == target && self.last_ouch.elapsed() > Duration::from_secs(1) { + if uid == target && self.last_ouch.elapsed() > Duration::from_secs(2) { self.client .send_command("say".to_string(), vec!["Ouch!".to_string()]); @@ -181,12 +181,38 @@ impl Bot { } } } + VelorenEvent::Outcome(Outcome::HealthChange { info, .. }) => { + if let Some(uid) = self.client.uid() { + if uid == info.target + && info.amount.is_sign_positive() + && self.last_ouch.elapsed() > Duration::from_secs(2) + { + self.client + .send_command("say".to_string(), vec!["That hurt!".to_string()]); + + self.last_ouch = Instant::now(); + } + } + } + VelorenEvent::Outcome(Outcome::Death { .. }) => { + self.client + .send_command("say".to_string(), vec!["Really?".to_string()]); + + self.last_ouch = Instant::now(); + } VelorenEvent::TradeComplete { result, .. } => { log::info!("Completed trade: {result:?}"); if let TradeMode::Take = self.trade_mode { self.trade_mode = TradeMode::Trade } + + if let TradeResult::Completed = result { + self.client.send_command( + "say".to_string(), + vec!["Thank you for trading with me!".to_string()], + ); + } } _ => (), } diff --git a/src/main.rs b/src/main.rs index 26fbc16..2d2dd32 100644 --- a/src/main.rs +++ b/src/main.rs @@ -15,15 +15,6 @@ pub struct Secrets { pub password: String, } -impl Secrets { - fn read() -> Result { - let config_path = var("SECRETS").map_err(|error| error.to_string())?; - let config_file_content = read_to_string(config_path).map_err(|error| error.to_string())?; - - toml::from_str::(&config_file_content).map_err(|error| error.to_string()) - } -} - #[derive(Serialize, Deserialize)] struct Config { pub buy_prices: HashMap, @@ -32,22 +23,26 @@ struct Config { pub orientation: String, } -impl Config { - fn read() -> Result { - let config_path = args() - .nth(1) - .expect("Pass an argument specifying the config file"); - let config_file_content = read_to_string(config_path).map_err(|error| error.to_string())?; - - toml::from_str::(&config_file_content).map_err(|error| error.to_string()) - } -} - fn main() { env_logger::init(); - let secrets = Secrets::read().unwrap(); - let config = Config::read().unwrap(); + let secrets = { + let config_path = + var("SECRETS").expect("Provide a SECRETS variable specifying the secrets file"); + let file_content = read_to_string(config_path).expect("Failed to read secrets"); + + toml::from_str::(&file_content).expect("Failed to parse secrets") + }; + + let config = { + let config_path = args() + .nth(1) + .expect("Pass an argument specifying the config file"); + let file_content = read_to_string(config_path).expect("Failed to read config"); + + toml::from_str::(&file_content).expect("Failed to parse secrets") + }; + let mut bot = Bot::new( &secrets.username, &secrets.password,