Option Explicit
Public WithEvents msn As MsgrObject
Dim test As Integer
Private Sub Form_Load()
Set msn = New MsgrObject
Open App.Path & "log.txt" For Append As #2
Print #2, "*** Session open the " & Date; " at " & Time() & " ***"
End Sub
Private Sub Form_Unload(Cancel As Integer)
Print #2, "*** Session close the " & Date; " at " & Time() & " ***"
Close #2
End Sub
Private Sub msn_OnTextReceived(ByVal pIMSession As Messenger.IMsgrIMSession, ByVal User As Messenger.IMsgrUser, ByVal bstrMsgHeader As String, ByVal Usersay As String, pfEnableDefault As Boolean)
Dim replystring As String
Dim question() As String
Dim replies() As String
Dim nbrrep As Integer
Dim randomnbr As Integer
If Usersay <> vbCrLf Then
Print #2, "User :" & Usersay
End If
'convertit en minuscule
Usersay = LCase(Usersay)
'ouvre un fichier
Open App.Path & "replies.txt" For Input As #1
Do Until EOF(1) 'repete tout ca jusqu'a la fin du fichier texte
'lit une line du fichier et la stocke dans replystring
Line Input #1, replystring
question = Split(replystring, "#")
'regarde si ce que dis le contact est dans le replystring
test = InStr(Usersay, question(0))
If test > 0 Then
'regarde s'il y a plusieur barres | et quitte s'il n'y en a aucune
test = InStr(question(1), "|")
If test < 1 Then
User.SendText bstrMsgHeader, question(1), MMSGTYPE_ALL_RESULTS
Print #2, "Bot :" & question(1)
Close #1
Exit Sub
End If
'trouve le nombre de barres apres #
replies = Split(question(1), "|")
nbrrep = UBound(replies)
'créé un nombre aléatoire entre 0 et nbrrep
Randomize
randomnbr = Int(Rnd() * (nbrrep - 0 + 1)) + 0
'si il n'y a rien à répondre (deux barres ||), on quitte
If replies(randomnbr) = "" Then
Close #1
Exit Sub
End If
'on répond avec le nombre aléatoire
User.SendText bstrMsgHeader, replies(randomnbr), MMSGTYPE_ALL_RESULTS
Close #1
Exit Sub
If replies(randomnbr) <> vbCrLf Then
Print #2, "Bot :" & replies(randomnbr)
End If
End If
Loop
Close #1
End Sub
Option Explicit
Public WithEvents msn As MsgrObject
Dim test As Integer
Private Sub Form_Load()
Set msn = New MsgrObject
Open App.Path & "log.txt" For Append As #2
Print #2, "*** Session open the " & Date; " at " & Time() & " ***"
End Sub
Private Sub Form_Unload(Cancel As Integer)
Print #2, "*** Session close the " & Date; " at " & Time() & " ***"
Close #2
End Sub
Private Sub msn_OnTextReceived(ByVal pIMSession As Messenger.IMsgrIMSession, ByVal User As Messenger.IMsgrUser, ByVal bstrMsgHeader As String, ByVal Usersay As String, pfEnableDefault As Boolean)
Dim replystring As String
Dim question() As String
Dim replies() As String
Dim nbrrep As Integer
Dim randomnbr As Integer
If Usersay <> vbCrLf Then
Print #2, "User :" & Usersay
End If
'convertit en minuscule
Usersay = LCase(Usersay)
'ouvre un fichier
Open App.Path & "replies.txt" For Input As #1
Do Until EOF(1) 'repete tout ca jusqu'a la fin du fichier texte
'lit une line du fichier et la stocke dans replystring
Line Input #1, replystring
question = Split(replystring, "#")
'regarde si ce que dis le contact est dans le replystring
test = InStr(Usersay, question(0))
If test > 0 Then
'regarde s'il y a plusieur barres | et quitte s'il n'y en a aucune
test = InStr(question(1), "|")
If test < 1 Then
User.SendText bstrMsgHeader, question(1), MMSGTYPE_ALL_RESULTS
Print #2, "Bot :" & question(1)
Close #1
Exit Sub
End If
'trouve le nombre de barres apres #
replies = Split(question(1), "|")
nbrrep = UBound(replies)
'créé un nombre aléatoire entre 0 et nbrrep
Randomize
randomnbr = Int(Rnd() * (nbrrep - 0 + 1)) + 0
'si il n'y a rien à répondre (deux barres ||), on quitte
If replies(randomnbr) = "" Then
Close #1
Exit Sub
End If
'on répond avec le nombre aléatoire
User.SendText bstrMsgHeader, replies(randomnbr), MMSGTYPE_ALL_RESULTS
Close #1
Exit Sub
If replies(randomnbr) <> vbCrLf Then
Print #2, "Bot :" & replies(randomnbr)
End If
End If
Loop
Close #1
End Sub
|