diff --git a/crates/chatbot/src/lib.rs b/crates/chatbot/src/lib.rs index 31b0066..e573899 100644 --- a/crates/chatbot/src/lib.rs +++ b/crates/chatbot/src/lib.rs @@ -20,23 +20,29 @@ 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 emoji = &self.emojis[self.emoji_counter]; + self.emoji_counter = (self.emoji_counter + 1) % self.emojis.len(); vec![ - format!("And how does that make you feel? {}", self.emoji), - format!("Interesting! Go on... {}", self.emoji), + format!("And how does that make you feel? {emoji}"), + format!("Interesting! Go on... {emoji}"), ] } }