Bonjour,

je cherche à creer un robot qui puisse dialoguer à ma place sur msn.
Mon probleme serait de savoir comment reconnaitre un contact qui tente d'ouvrir une conversation avec le robot.
Le code ci dessous me permet de detecter une question et d'y répondre...mais de répondre à TOUT mes contacts, ce qui n'est pas tres pratique.
Si vous aviez une solution pour que le, robot puisse reconnaitre qui lui parle ou un lien pour mieux comprendre l'API, je vous en serais tres reconnaissant.

Merci !


Ma source, si ca peut en éclairer certains :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
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
'convert in lower case
Usersay = LCase(Usersay)
'open file
Open App.Path & "\replies.txt" For Input As #1
Do Until EOF(1) 'do until the file end
'read line and put in reply string
Line Input #1, replystring
question = Split(replystring, "#")
'test if There is Usersay in question
test = InStr(Usersay, question(0))
If test > 0 Then
   'verify if there is several pipes and exit if there isn't any
   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
  'get the number of "|" (=replies) after #
replies = Split(question(1), "|")
nbrrep = UBound(replies)
  'make a random number between 0 to nbrrep
Randomize
randomnbr = Int(Rnd() * (nbrrep - 0 + 1)) + 0
'if there is nothing to reply (two pipes), we leaves
If replies(randomnbr) = "" Then
Close #1
Exit Sub
End If
  'replie with the random number
User.SendText bstrMsgHeader, replies(randomnbr), MMSGTYPE_ALL_RESULTS
 If replies(randomnbr) <> vbCrLf Then
 Print #2, "Bot :" & replies(randomnbr)
 End If
End If
Loop
Close #1
End Sub