Add silly features; Clean up
This commit is contained in:
parent
7c8267b598
commit
1fa74aad14
30
src/bot.rs
30
src/bot.rs
@ -12,7 +12,7 @@ use veloren_common::{
|
|||||||
comp::{invite::InviteKind, item::ItemDefinitionIdOwned, ChatType, ControllerInputs, Ori, Pos},
|
comp::{invite::InviteKind, item::ItemDefinitionIdOwned, ChatType, ControllerInputs, Ori, Pos},
|
||||||
outcome::Outcome,
|
outcome::Outcome,
|
||||||
time::DayPeriod,
|
time::DayPeriod,
|
||||||
trade::{PendingTrade, TradeAction},
|
trade::{PendingTrade, TradeAction, TradeResult},
|
||||||
uid::Uid,
|
uid::Uid,
|
||||||
ViewDistances,
|
ViewDistances,
|
||||||
};
|
};
|
||||||
@ -173,7 +173,7 @@ impl Bot {
|
|||||||
..
|
..
|
||||||
}) => {
|
}) => {
|
||||||
if let Some(uid) = self.client.uid() {
|
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
|
self.client
|
||||||
.send_command("say".to_string(), vec!["Ouch!".to_string()]);
|
.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, .. } => {
|
VelorenEvent::TradeComplete { result, .. } => {
|
||||||
log::info!("Completed trade: {result:?}");
|
log::info!("Completed trade: {result:?}");
|
||||||
|
|
||||||
if let TradeMode::Take = self.trade_mode {
|
if let TradeMode::Take = self.trade_mode {
|
||||||
self.trade_mode = TradeMode::Trade
|
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()],
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
_ => (),
|
_ => (),
|
||||||
}
|
}
|
||||||
|
39
src/main.rs
39
src/main.rs
@ -15,15 +15,6 @@ pub struct Secrets {
|
|||||||
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())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize)]
|
#[derive(Serialize, Deserialize)]
|
||||||
struct Config {
|
struct Config {
|
||||||
pub buy_prices: HashMap<String, u32>,
|
pub buy_prices: HashMap<String, u32>,
|
||||||
@ -32,22 +23,26 @@ struct Config {
|
|||||||
pub orientation: String,
|
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() {
|
fn main() {
|
||||||
env_logger::init();
|
env_logger::init();
|
||||||
|
|
||||||
let secrets = Secrets::read().unwrap();
|
let secrets = {
|
||||||
let config = Config::read().unwrap();
|
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(
|
let mut bot = Bot::new(
|
||||||
&secrets.username,
|
&secrets.username,
|
||||||
&secrets.password,
|
&secrets.password,
|
||||||
|
Loading…
Reference in New Issue
Block a user