From 2ec029e2626e98aac8276a957793ce159650d381 Mon Sep 17 00:00:00 2001 From: Jeff Date: Thu, 11 Jul 2024 13:18:55 -0400 Subject: [PATCH] Remove broken announcement --- src/bot.rs | 77 ++++++++++++++++++++++++++++++++++++++---------------- 1 file changed, 54 insertions(+), 23 deletions(-) diff --git a/src/bot.rs b/src/bot.rs index 80da18f..0503f9a 100644 --- a/src/bot.rs +++ b/src/bot.rs @@ -1,15 +1,19 @@ use std::{ - collections::HashMap, + collections::BTreeMap, sync::Arc, time::{Duration, Instant}, }; +use rand::{thread_rng, Rng}; use tokio::runtime::Runtime; use vek::Quaternion; use veloren_client::{addr::ConnectionArgs, Client, Event as VelorenEvent, WorldExt}; use veloren_common::{ clock::Clock, - comp::{invite::InviteKind, item::ItemDefinitionIdOwned, ChatType, ControllerInputs, Ori, Pos}, + comp::{ + invite::InviteKind, item::ItemDefinitionIdOwned, Agent, Anchor, ChatType, ControllerInputs, + Ori, Pos, + }, outcome::Outcome, time::DayPeriod, trade::{PendingTrade, TradeAction, TradeResult}, @@ -18,6 +22,13 @@ use veloren_common::{ DamageSource, ViewDistances, }; use veloren_common_net::sync::WorldSyncExt; +use veloren_world::{ + civ::WorldCivStage, + sim::Location, + site::{Settlement, SiteKindMeta}, + site2::Site, + SettlementKindMeta, +}; const COINS: &str = "common.items.utility.coins"; @@ -32,8 +43,8 @@ pub struct Bot { client: Client, clock: Clock, - buy_prices: HashMap, - sell_prices: HashMap, + buy_prices: BTreeMap, + sell_prices: BTreeMap, trade_mode: TradeMode, last_action: Instant, @@ -49,8 +60,8 @@ impl Bot { password: &str, character: &str, admins: Vec, - buy_prices: HashMap, - sell_prices: HashMap, + buy_prices: BTreeMap, + sell_prices: BTreeMap, position: [f32; 3], orientation: f32, ) -> Result { @@ -141,14 +152,16 @@ impl Bot { self.last_action = Instant::now(); - if self.last_announcement.elapsed() > Duration::from_secs(1200) { + if self.last_announcement.elapsed() > Duration::from_secs(1800) { + log::info!("Making an announcement"); + self.client.send_command( - "region".to_string(), - vec![format!( - "I'm a bot. You can trade with me or check prices: '/tell {} price [search_term]'.", - self.username - )], - ); + "region".to_string(), + vec![format!( + "I'm a bot. You can trade with me or check prices: '/tell {} price [search_term]'.", + self.username + )], + ); self.last_announcement = Instant::now(); } @@ -210,6 +223,24 @@ impl Bot { self.client.send_invite(sender, InviteKind::Trade); } } + "position" => { + if self.is_user_admin(&sender)? { + if let (Some(x), Some(y), Some(z)) = ( + split_content.next(), + split_content.next(), + split_content.next(), + ) { + let position = [ + x.parse::().map_err(|error| error.to_string())?, + y.parse::().map_err(|error| error.to_string())?, + z.parse::().map_err(|error| error.to_string())?, + ]; + + is_correct_format = true; + self.position = position; + } + } + } _ => {} } @@ -568,16 +599,6 @@ impl Bot { Ok(self.admins.contains(sender_name) || self.admins.contains(&sender_uuid)) } - fn find_name<'a>(&'a self, uid: &Uid) -> Option<&'a String> { - self.client.player_list().iter().find_map(|(id, info)| { - if id == uid { - return Some(&info.player_alias); - } - - None - }) - } - fn handle_position_and_orientation(&mut self) -> Result<(), String> { let current_position = self.client.current::(); @@ -604,6 +625,16 @@ impl Bot { Ok(()) } + fn find_name<'a>(&'a self, uid: &Uid) -> Option<&'a String> { + self.client.player_list().iter().find_map(|(id, info)| { + if id == uid { + return Some(&info.player_alias); + } + + None + }) + } + fn find_uuid(&self, target: &Uid) -> Option { self.client.player_list().iter().find_map(|(uid, info)| { if uid == target {