diff --git a/.gitignore b/.gitignore index bab85c2..6d62a10 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,2 @@ target/ -config.toml +secrets.toml diff --git a/config.toml b/config.toml new file mode 100644 index 0000000..fc054b8 --- /dev/null +++ b/config.toml @@ -0,0 +1,33 @@ +position = [17689.0, 14964.0, 238.0] +orientation = "East" + +[buy_prices] +"common.items.food.cheese" = 50 + +[sell_prices] +"common.items.armor.boreal.back" = 250_000 +"common.items.armor.boreal.belt" = 250_000 +"common.items.armor.boreal.chest" = 250_000 +"common.items.armor.boreal.foot" = 250_000 +"common.items.armor.boreal.hand" = 250_000 +"common.items.armor.boreal.pants" = 250_000 +"common.items.armor.boreal.shoulder" = 250_000 + +"common.items.armor.misc.head.boreal_warhelm" = 450_000 +"common.items.armor.misc.head.cat_capuche" = 600_000 +"common.items.armor.misc.head.hare_hat" = 100_000 +"common.items.armor.misc.head.winged_coronet" = 20_000 + +"common.items.consumable.potion_minor" = 150 + +"common.items.glider.skullgrin" = 20_000 + +"common.items.tool.instruments.steeltonguedrum" = 300_000 + +"common.items.weapons.axe.parashu" = 100_000 +"common.items.weapons.sword.caladbolg" = 100_000 +"common.items.weapons.staff.laevateinn" = 50_000 +"common.items.weapons.hammer.mjolnir" = 100_000 +"common.items.weapons.sceptre.caduceus" = 100_000 + +"common.items.lantern.geode_purple" = 20_000 diff --git a/src/bot.rs b/src/bot.rs index 7f914ca..61f4088 100644 --- a/src/bot.rs +++ b/src/bot.rs @@ -114,8 +114,8 @@ impl Bot { self.client.respawn(); } - self.handle_lantern(); self.handle_position_and_orientation()?; + self.handle_lantern(); if let Some((_, trade, _)) = self.client.pending_trade() { match self.trade_mode { diff --git a/src/main.rs b/src/main.rs index a249144..b9edc7c 100644 --- a/src/main.rs +++ b/src/main.rs @@ -10,9 +10,29 @@ use bot::Bot; use serde::{Deserialize, Serialize}; #[derive(Serialize, Deserialize)] -struct Config { +pub struct Secrets { pub username: String, 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()) + } + + fn _write(&self) -> Result<(), String> { + let config_path = var("SECRETS").map_err(|error| error.to_string())?; + let config_string = toml::to_string(self).map_err(|error| error.to_string())?; + + write(config_path, config_string).map_err(|error| error.to_string()) + } +} + +#[derive(Serialize, Deserialize)] +struct Config { pub buy_prices: HashMap, pub sell_prices: HashMap, pub position: [f32; 3], @@ -21,14 +41,14 @@ struct Config { impl Config { fn read() -> Result { - let config_path = var("CONFIG_PATH").map_err(|error| error.to_string())?; + let config_path = var("CONFIG").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()) } fn _write(&self) -> Result<(), String> { - let config_path = var("CONFIG_PATH").map_err(|error| error.to_string())?; + let config_path = var("CONFIG").map_err(|error| error.to_string())?; let config_string = toml::to_string(self).map_err(|error| error.to_string())?; write(config_path, config_string).map_err(|error| error.to_string()) @@ -38,10 +58,11 @@ impl Config { fn main() { env_logger::init(); + let secrets = Secrets::read().unwrap(); let config = Config::read().unwrap(); let mut bot = Bot::new( - config.username, - &config.password, + secrets.username, + &secrets.password, config.buy_prices, config.sell_prices, config.position,