Add silly features; Clean up

This commit is contained in:
Jeff 2024-07-08 16:39:26 -04:00
parent 7c8267b598
commit 1fa74aad14
2 changed files with 45 additions and 24 deletions

View File

@ -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()],
);
}
}
_ => (),
}

View File

@ -15,15 +15,6 @@ pub struct Secrets {
pub password: String,
}
impl Secrets {
fn read() -> Result<Self, String> {
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::<Secrets>(&config_file_content).map_err(|error| error.to_string())
}
}
#[derive(Serialize, Deserialize)]
struct Config {
pub buy_prices: HashMap<String, u32>,
@ -32,22 +23,26 @@ struct Config {
pub orientation: String,
}
impl Config {
fn read() -> Result<Self, String> {
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>(&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::<Secrets>(&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::<Config>(&file_content).expect("Failed to parse secrets")
};
let mut bot = Bot::new(
&secrets.username,
&secrets.password,