Function Greetings(ByVal UserSentence, ByVal PrevSentence, ByVal PrevUserSent, ByVal WorkingDir) 'CREATE HALBRAIN ACTIVEX OBJECT 'This ActiveX control contains many functions 'needed for the script to proccess a sentence. Set HalBrain = CreateObject("UltraHalAsst.Brain") Set objFileSys = CreateObject("Scripting.FileSystemObject") 'First Hal checks to see if the user is greeting right now. If HalBrain.TopicSearch(UserSentence, WorkingDir & "HelloDetect.brn") = "True" Then SaidHello = True 'Second, Hal checks to see if the user said a greeting on the last exchange. If HalBrain.TopicSearch(PrevUserSent, WorkingDir & "HelloDetect.brn") = "True" Then PrevHello = True 'This section has two random possibilities for greeting the user. Note; holidays 'are added at the beginning because they are static dates. 'One greeting will get a greeting from a file. It will pass the current hour and either 'the letter A or B to a topic search file and it will get back a greeting based 'on the current time. Each hour has 2 possible greetings, the A greeting and B 'greeting, which is randomly chosen. 'The other random greeting is based on the last date the user spoke with Hal. If SaidHello = True And PrevHello = False Then If Trim(Month(Now)) = 1 And Trim(Day(Now)) = 1 Then Greetings = "Happy New Year !" ElseIf Trim(Month(Now)) = 12 And Trim(Day(Now)) = 25 Then Greetings = "Merry Christmas ! Did you get what you wanted?" Else lastRespDate = "" If objFileSys.FileExists(WorkingDir & "lastRespDates.brn") Then lastRespDate = objFileSys.GetFile(WorkingDir & "lastRespDates.brn").DateLastModified lastRespDate = Left(lastRespDate, InStr(lastRespDate, " ") - 1) End If If Rnd * 100 > 50 Or lastRespDate = "" Or lastRespDate = Left(Now, InStr(Now, " ") - 1) Then 'Respond to the user with a regular greeting. If Trim(Minute(Now)) < 30 Then LetterChoice = "A" Else LetterChoice = "B" End If Greetings = HalBrain.TopicSearch(" " & Trim(Hour(Now)) & LetterChoice & " ", WorkingDir & "hello1.brn") Else 'Respond to the user with how long it has been since talking with Hal. howLongResp = DateDiff("d", lastRespDate, Now) If howLongResp > 40 Then Greetings = "Long time no see, stranger. How have you been?" ElseIf howLongResp > 28 Then Greetings = "It's about a month since are last conversation. How you doing?" ElseIf howLongResp > 21 Then Greetings = "It's been a few weeks since we last spoke. Been keeping busy?" ElseIf howLongResp > 14 Then Greetings = "I haven't spoken to you in a couple weeks. Anything exciting happen lately?" ElseIf howLongResp > 7 Then Greetings = "I last talked to you about a week ago. What have you been up to?" ElseIf howLongResp > 1 Then Greetings = "I haven't talked to you in about " & howLongResp & " days. How's it going?" Else Greetings = "I spoke to you just yesterday. How's it going today?" End If End If End If End If 'This will get a greeting from a file that is not based on the current time If SaidHello = True And PrevHello = True Then Greetings = HalBrain.ChooseSentenceFromFile(WorkingDir & "hello2.brn") End If 'Check if the user is saying bye right now If HalBrain.TopicSearch(UserSentence, WorkingDir & "byedetect.brn") = "True" Then SaidBye = True 'Check if Hal said bye in the previous sentence If HalBrain.TopicSearch(PrevUserSent, WorkingDir & "byedetect.brn") = "True" Then PrevBye = True If SaidBye = True And PrevBye = False Then Greetings = HalBrain.ChooseSentenceFromFile(WorkingDir & "bye1.brn") End If If SaidBye = True And PrevBye = True Then Greetings = HalBrain.ChooseSentenceFromFile(WorkingDir & "bye2.brn") End If 'Hal checks to see if the user is 'making a polite inquiry into Hal's well being If InStr(1, UserSentence, " HOW AM I ", 1) > 0 And Len(UserSentence) < 12 Then PoliteAsk = True If InStr(1, UserSentence, " HOW ARE YOU ", 1) > 0 And Len(UserSentence) < 14 Then PoliteAsk = True If InStr(1, UserSentence, " WHAT IS NEW ", 1) > 0 And Len(UserSentence) < 15 Then PoliteAsk = True If HalBrain.TopicSearch(UserSentence, WorkingDir & "PoliteAskDetect.brn") = "True" Then PoliteAsk = True If PoliteAsk = True Then Greetings = HalBrain.SentenceGenerator(WorkingDir & "PoliteAsk.brn") End If End Function