diff --git a/crates/chatbot/src/lib.rs b/crates/chatbot/src/lib.rs index 7ec2afc..8f90b82 100644 --- a/crates/chatbot/src/lib.rs +++ b/crates/chatbot/src/lib.rs @@ -20,27 +20,30 @@ pub async fn gen_random_number() -> usize { /// A chatbot that responds to inputs. pub struct Chatbot { - emoji: String, + emojis: Vec, + emoji_counter: usize, } impl Chatbot { /// Creates a new chatbot that uses the provided emoji in its responses. - pub fn new(emoji: String) -> Self { - Chatbot { emoji } + pub fn new(emojis: Vec) -> Self { + Chatbot { + emojis, + emoji_counter: 0, + } } /// Generates a list of possible responses given the current chat. /// /// Warning: may take a few seconds! - pub async fn query_chat(&self, messages: &[String]) -> Vec { + pub async fn query_chat(&mut self, messages: &[String]) -> Vec { std::thread::sleep(Duration::from_secs(2)); let most_recent = messages.last().unwrap(); + let emoji = &self.emojis[self.emoji_counter]; + self.emoji_counter = (self.emoji_counter + 1) % self.emojis.len(); vec![ - format!( - "\"{most_recent}\"? And how does that make you feel? {}", - self.emoji - ), - format!("\"{most_recent}\"! Interesting! Go on... {}", self.emoji), + format!("\"{most_recent}\"? And how does that make you feel? {emoji}",), + format!("\"{most_recent}\"! Interesting! Go on... {emoji}"), ] } }