File tree Expand file tree Collapse file tree 1 file changed +12
-9
lines changed
Expand file tree Collapse file tree 1 file changed +12
-9
lines changed Original file line number Diff line number Diff line change @@ -20,27 +20,30 @@ pub async fn gen_random_number() -> usize {
2020
2121/// A chatbot that responds to inputs.
2222pub struct Chatbot {
23- emoji : String ,
23+ emojis : Vec < String > ,
24+ emoji_counter : usize ,
2425}
2526
2627impl Chatbot {
2728 /// Creates a new chatbot that uses the provided emoji in its responses.
28- pub fn new ( emoji : String ) -> Self {
29- Chatbot { emoji }
29+ pub fn new ( emojis : Vec < String > ) -> Self {
30+ Chatbot {
31+ emojis,
32+ emoji_counter : 0 ,
33+ }
3034 }
3135
3236 /// Generates a list of possible responses given the current chat.
3337 ///
3438 /// Warning: may take a few seconds!
35- pub async fn query_chat ( & self , messages : & [ String ] ) -> Vec < String > {
39+ pub async fn query_chat ( & mut self , messages : & [ String ] ) -> Vec < String > {
3640 std:: thread:: sleep ( Duration :: from_secs ( 2 ) ) ;
3741 let most_recent = messages. last ( ) . unwrap ( ) ;
42+ let emoji = & self . emojis [ self . emoji_counter ] ;
43+ self . emoji_counter = ( self . emoji_counter + 1 ) % self . emojis . len ( ) ;
3844 vec ! [
39- format!(
40- "\" {most_recent}\" ? And how does that make you feel? {}" ,
41- self . emoji
42- ) ,
43- format!( "\" {most_recent}\" ! Interesting! Go on... {}" , self . emoji) ,
45+ format!( "\" {most_recent}\" ? And how does that make you feel? {emoji}" , ) ,
46+ format!( "\" {most_recent}\" ! Interesting! Go on... {emoji}" ) ,
4447 ]
4548 }
4649}
You can’t perform that action at this time.
0 commit comments