From a4ff2ad2e4b7e09c9d2ccee0744b63413e4cc7e6 Mon Sep 17 00:00:00 2001 From: Jeff Date: Thu, 11 Jul 2024 02:58:52 -0400 Subject: [PATCH] Fix bug by removing /say commands --- src/bot.rs | 19 ++++++++++++------- src/main.rs | 2 +- 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/src/bot.rs b/src/bot.rs index 81e6425..6cceead 100644 --- a/src/bot.rs +++ b/src/bot.rs @@ -24,6 +24,7 @@ const COINS: &str = "common.items.utility.coins"; /// A Bot instance represents an active connection to the server and it will /// attempt to run every time the `tick` function is called. pub struct Bot { + username: String, position: [f32; 3], orientation: f32, admins: Vec, @@ -44,7 +45,7 @@ impl Bot { /// Connect to the official veloren server, select the specified character /// return a Bot instance ready to run. pub fn new( - username: &str, + username: String, password: &str, character: &str, admins: Vec, @@ -55,7 +56,7 @@ impl Bot { ) -> Result { log::info!("Connecting to veloren"); - let mut client = connect_to_veloren(username, password)?; + let mut client = connect_to_veloren(&username, password)?; let mut clock = Clock::new(Duration::from_secs_f64(1.0 / 30.0)); log::info!("Selecting a character"); @@ -90,6 +91,7 @@ impl Bot { let now = Instant::now(); Ok(Bot { + username, position, orientation, admins, @@ -137,7 +139,10 @@ impl Bot { if self.last_announcement.elapsed() > Duration::from_secs(1200) { self.client.send_command( "region".to_string(), - vec!["I'm a bot. You can trade with me or use /say or /tell to check prices: 'price [search_term]'".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(); @@ -153,10 +158,10 @@ impl Bot { fn handle_veloren_event(&mut self, event: VelorenEvent) -> Result<(), String> { match event { VelorenEvent::Chat(message) => { - let sender = match message.chat_type { - ChatType::Tell(uid, _) => uid, - ChatType::Say(uid) => uid, - _ => return Ok(()), + let sender = if let ChatType::Tell(uid, _) = message.chat_type { + uid + } else { + return Ok(()); }; let content = message.content().as_plain().unwrap_or_default(); let mut split_content = content.split(' '); diff --git a/src/main.rs b/src/main.rs index 0580bb4..cf569a1 100644 --- a/src/main.rs +++ b/src/main.rs @@ -60,7 +60,7 @@ fn main() { .collect(); let mut bot = Bot::new( - &secrets.username, + secrets.username, &secrets.password, &secrets.character, secrets.admins,