Polish and add a README

This commit is contained in:
Jeff 2024-07-08 22:54:42 -04:00
parent 6cd9d71b49
commit 6a020aa6e6
4 changed files with 76 additions and 16 deletions

66
README.md Normal file
View File

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

View File

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

View File

@ -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");

View File

@ -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::<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(&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::<Config>(&file_content).expect("Failed to parse secrets")
toml::from_str::<Config>(&file_content).expect("Failed to parse config")
};
let mut bot = Bot::new(