Skip to content

Commit

Permalink
Add emoji counter
Browse files Browse the repository at this point in the history
  • Loading branch information
willcrichton committed Aug 12, 2024
1 parent ae6e4a0 commit a020639
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions crates/chatbot/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,23 +20,29 @@ pub async fn gen_random_number() -> usize {

/// A chatbot that responds to inputs.
pub struct Chatbot {
emoji: String,
emojis: Vec<String>,
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<String>) -> 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<String> {
pub async fn query_chat(&mut self, _messages: &[String]) -> Vec<String> {
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}"),
]
}
}

0 comments on commit a020639

Please sign in to comment.