Sign in to follow this  
Followers 0
theguy0000

Making an IM bot...

3 posts in this topic

Ok, so, I am making an MSN IM bot with Paulie's MSN UDFs. I got everything almost figured out, but...

here is an example conversation:

Matt says:

hello

MBx06 says:

Hello. I have detected that you have not contacted me before. Please note that I am not exactly Artificial Inteligence. I am very GIGO, as you humans would call it. If you say something that I cannot understand, you will probably just recieve garbage as a response. When I ask a yes or no questyion, just answer "yes" or "no", nothing extra, or you will mess me up.

MBx06 says:

Please give me an email address that I can use to email you when needed.

MBx06 says:

Thank you. Please ask your question now.

Well, the first problem is obvious. it is supposed to say "Thank you" AFTER I give it my email address, but it doesn't even give me time to say anything.

Second, If I look in the ini file where email addresses are stored, it turns out that the bot made my email address "hello"!

here is my code:

#include <MSN.au3>
#include <XML.au3>
$msn = _msncreate()
$brain = _XMLLoad ("brain.xml")
$CatNum = __StringFindOccurances ($brain, "<category>")
;~~MsgBox (0, "", $CatNum)
Global $questions[$CatNum+1]
Global $answers[$CatNum+1]
$waitingForEmail=0
$waitingForContactAnswer=0
;~~MsgBox (0, "", _msngetstate($msn))
For $i=1 To $CatNum
    ;~~MsgBox (0, "", $i)
    $cat = _XMLGet($brain,"category",$i-1)
    $questions[$i] = _XMLGet($cat, "question")
    $answers[$i] = _XMLGet($cat, "answer")
Next
_ArrayDelete ($questions, 1)
_ArrayDelete ($answers, 1)
;~~_ArrayDisplay ($questions, "questions")
;~~_ArrayDisplay ($answers, "answers")
while 1
sleep(100)
wend

Func _msn_OnTextReceived($IMSession, $IMUser, $MsgHeader, $MsgText, $Something)
Local $waitingForEmail2 = 1
Local $waitingForContactAnswer2 = 1
If Not StringInStr ($MsgHeader, "TypingUser") Then
$win = $msn[2].LaunchIMUI ($IMUser)
$history = _msngetchattext($win)
$email = _GetMembersName($history)
If $waitingForEmail Then
    IniWrite ("bot.ini", "contact", $email, $MsgText)
    $waitingForEmail2 = 0
    _msnsendtext ($win, "Thank you. Please ask your question now.")
ElseIf $waitingForContactAnswer Then
    If $MsgText = "no" or $MsgText = "NO" or $MsgText = "No" Or $MsgText = "nO" Then
        _msnsendtext ($win, "Please give me an email address that I can use to email you when needed.2")
        $waitingForEmail = 1
        $waitingForContactAnswer2 = 0
    Else
        _msnsendtext ($win, "OK. Please ask your question now.")
        $waitingForContactAnswer2 = 0
    EndIf
Else
;~~MsgBox (0, "", $email)
If IniRead ("bot.ini", "active", $email, "err") = "err" Then
    IniWrite ("bot.ini", "active", $email, "active")
    If IniRead ("bot.ini", "contact", $email, "err") = "err" Then
        _msnsendtext ($win, 'Hello. I have detected that you have not contacted me before. Please note that I am not exactly Artificial Inteligence. I am very GIGO, as you humans would call it. If you say something that I cannot understand, you will probably just recieve garbage as a response. When I ask a yes or no questyion, just answer "yes" or "no", nothing extra, or you will mess me up.')
        _msnsendtext ($win, "Please give me an email address that I can use to email you when needed.")
        Global $waitingForEmail = 1
        Return
    Else
        _msnsendtext ($win, 'Hello. I have detected that you have contacted me some time in the past. Is your email address still "'&IniRead ("bot.ini", "contact", $email, "err")&'"? PLEASE just answer ONLY "yes" or "no".')
        Global $waitingForContactAnswer = 1
        Return
    EndIf
EndIf
If Not $waitingForEmail And Not $waitingForContactAnswer Then
_msnsendtext ($win, 'I will now attemt to answer the question "'&$MsgText&'". This may take some time, so please be patient.')
_AnswerTheQuestion ($MsgText, $win, $email)
EndIf
;~~MsgBox (0, "", "IMSession: "&$IMSession&@CRLF&"IMUser: "&$IMUser&@CRLF&"MsgHeader: "&$MsgHeader&@CRLF&"MsgText: "&$MsgText&@CRLF&"Something: "&$Something)
EndIf
EndIf
If $waitingForEmail2=0 Then
    Global $waitingForEmail=0
EndIf
If $waitingForContactAnswer2=0 Then
    Global $waitingForContactAnswer=0
EndIf
EndFunc

Func _GetMembersName ($hist)
    $lines = StringSplit ($hist, @CRLF)
    ;~~_ArrayDisplay ($lines, "History")
    $line = $lines[5]
    Return StringLeft ($line, StringLen($line)-6)
EndFunc

Func _AnswerTheQuestion ($question, $window, $address)
    $pos = _ArraySearch ($questions, $question)
    If $pos = -1 Then
        _msnsendtext ($window, "That question is not currently in my brain. I will now attempt to ask other people for the answer to this question. Please wait.")
        IniDelete ("bot.ini", "active", $address);----\
        ;                                              >}To be removed
        _msnclosechatwindow ($window);----------------/
    Else
        $answer = $answers[$pos]
        If $answer <> "[[ignore]]" Then 
            _msnsendtext ($window, "Your answer is: "&$answer)
            _msnsendtext ($window, "Thank you for contacting MBx06. Goodbye.")
        EndIf
        IniDelete ("bot.ini", "active", $address)
        _msnclosechatwindow ($window)
        Return
    EndIf
EndFunc
(lines beginning with ;~~ are for debugging, and just display what's happening inside while the bot is running.

MSN.au3 and XML.au3 are attached.

Oh and by the way, Other than the email addresses, the bot works fine. It can answer the questions that I ask it. It still doesn't go and ask people a question it doesn't know, but that's irrelavent, and it will be added later.

MSN.au3

XML.au3


The cake is a lie.www.theguy0000.com is currentlyUP images.theguy0000.com is currentlyUP all other *.theguy0000.com sites are DOWN

Share this post


Link to post
Share on other sites



sorry but, bump


The cake is a lie.www.theguy0000.com is currentlyUP images.theguy0000.com is currentlyUP all other *.theguy0000.com sites are DOWN

Share this post


Link to post
Share on other sites

nevermind, i fixed him


The cake is a lie.www.theguy0000.com is currentlyUP images.theguy0000.com is currentlyUP all other *.theguy0000.com sites are DOWN

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0