From 6a020aa6e63b9abf4477bfe6b7b88958ad7320f3 Mon Sep 17 00:00:00 2001 From: Jeff Date: Mon, 8 Jul 2024 22:54:42 -0400 Subject: [PATCH] Polish and add a README --- README.md | 66 ++++++++++++++++++++++++++++++++++++++++++++++ config/config.toml | 4 +-- src/bot.rs | 2 +- src/main.rs | 20 +++++--------- 4 files changed, 76 insertions(+), 16 deletions(-) create mode 100644 README.md diff --git a/README.md b/README.md new file mode 100644 index 0000000..4cc4019 --- /dev/null +++ b/README.md @@ -0,0 +1,66 @@ +# Veloren Trading Bot + +A bot that buys, sells and trades with players. + +## Usage + +All of these steps can be done with docker instead of podman. + +### Running from pre-built image + +#### Setup + +Create a "secrets.toml" file: + +```toml +# secrets.toml +username = "my_username" +password = "my_password" +``` + +Then create a secret to pass the file securely to the container. + +```sh +podman secret create secrets.toml secrets.toml + +``` + +You will also need a "config.toml": + +```toml +# config.toml +character = "my_character" +position = [0.0, 0.0, 0.0] # Change these to the desired X, Y, Z coordinates +orientation = "West" + +[buy_prices] +"common.items.food.cheese" = 50 + +[sell_prices] +"common.items.armor.boreal.back" = 250_000 +``` + +Place this config file inside a directory called "config". + +#### Running + +```sh +podman run \ + --secret secrets.toml \ + -v ./config/:/root/config/ \ + --env CONFIG=/root/config/config.toml \ + --env SECRETS=/run/secrets/secrets.toml \ + --env RUST_LOG=trade_bot \ + git.jeffa.io/jeff/trade_bot +``` + +### Building + +From the directory root: + +```sh +podman build . -t trade_bot +``` + +Then follow the [above](#Running_from_pre-built_image) steps with the tag "trade_bot" instead of +"git.jeffa.io/jeff/trade_bot". diff --git a/config/config.toml b/config/config.toml index 1dd8e26..9587022 100644 --- a/config/config.toml +++ b/config/config.toml @@ -1,5 +1,5 @@ -character = "crabobot_test" -position = [17722.0, 14963.0, 237.0] +character = "Obarc (Merchant)" +position = [17726.0, 14960.0, 237.0] orientation = "West" [buy_prices] diff --git a/src/bot.rs b/src/bot.rs index cf75347..beeb2a1 100644 --- a/src/bot.rs +++ b/src/bot.rs @@ -72,7 +72,7 @@ impl Bot { .characters .iter() .find(|character_item| character_item.character.alias == character) - .expect("No characters to select") + .expect(&format!("No character named {character}")) .character .id .expect("Failed to get character ID"); diff --git a/src/main.rs b/src/main.rs index eb65896..bb81467 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,10 +1,6 @@ mod bot; -use std::{ - collections::HashMap, - env::{args, var}, - fs::read_to_string, -}; +use std::{collections::HashMap, env::var, fs::read_to_string}; use bot::Bot; use serde::{Deserialize, Serialize}; @@ -28,21 +24,19 @@ fn main() { env_logger::init(); let secrets = { - let config_path = + let secrets_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"); + let file_content = read_to_string(secrets_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(&format!("Failed to read config at {config_path}")); + let config_path = + var("CONFIG").expect("Provide a CONFIG variable 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") + toml::from_str::(&file_content).expect("Failed to parse config") }; let mut bot = Bot::new(