Separate secrets and config files

This commit is contained in:
Jeff 2024-07-08 14:09:15 -04:00
parent a8cbd70884
commit e63980858e
4 changed files with 61 additions and 7 deletions

2
.gitignore vendored
View File

@ -1,2 +1,2 @@
target/ target/
config.toml secrets.toml

33
config.toml Normal file
View File

@ -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

View File

@ -114,8 +114,8 @@ impl Bot {
self.client.respawn(); self.client.respawn();
} }
self.handle_lantern();
self.handle_position_and_orientation()?; self.handle_position_and_orientation()?;
self.handle_lantern();
if let Some((_, trade, _)) = self.client.pending_trade() { if let Some((_, trade, _)) = self.client.pending_trade() {
match self.trade_mode { match self.trade_mode {

View File

@ -10,9 +10,29 @@ use bot::Bot;
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
#[derive(Serialize, Deserialize)] #[derive(Serialize, Deserialize)]
struct Config { pub struct Secrets {
pub username: String, pub username: String,
pub password: String, 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())
}
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<String, u32>, pub buy_prices: HashMap<String, u32>,
pub sell_prices: HashMap<String, u32>, pub sell_prices: HashMap<String, u32>,
pub position: [f32; 3], pub position: [f32; 3],
@ -21,14 +41,14 @@ struct Config {
impl Config { impl Config {
fn read() -> Result<Self, String> { fn read() -> Result<Self, 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_file_content = read_to_string(config_path).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>(&config_file_content).map_err(|error| error.to_string()) toml::from_str::<Config>(&config_file_content).map_err(|error| error.to_string())
} }
fn _write(&self) -> Result<(), 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())?; let config_string = toml::to_string(self).map_err(|error| error.to_string())?;
write(config_path, config_string).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() { fn main() {
env_logger::init(); env_logger::init();
let secrets = Secrets::read().unwrap();
let config = Config::read().unwrap(); let config = Config::read().unwrap();
let mut bot = Bot::new( let mut bot = Bot::new(
config.username, secrets.username,
&config.password, &secrets.password,
config.buy_prices, config.buy_prices,
config.sell_prices, config.sell_prices,
config.position, config.position,