aMSN Forums
July 07, 2020, 10:18:03 am *
Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
News: New forum for aMSN !!
 
   Home   Help Search Login Register  
Pages: [1]
  Print  
Author Topic: Make your own custom Eliza chat bot (Rude version)  (Read 27441 times)
theh1982
Newbie

Offline Offline

Posts: 1


View Profile
« on: January 21, 2008, 09:58:21 pm »

Hey guys,

I could not find any real examples on how to customize your msn bot so i added my own "customized" version based on this everybody can make there own bot.

Ps would it not be a fun idea to have a giant database of responces and dummy responces for the amsn bot

My version will include some responces to rude comments and my dummy responces are all "funny" quotes

Edit: if you want to check if your code is correct just run : tclsh mytclfile.tcl and it will give feedback if there are any errors in the file and it will display where the error is.

Code:

namespace eval ::amsnEliza {

    global mydir
    global first
 
    proc amsnElizaStart { dir } {
global mydir
global first
set mydir $dir
set first 1
::plugins::RegisterPlugin amsnEliza
::plugins::RegisterEvent amsnEliza chat_msg_received answer
::plugins::RegisterEvent amsnEliza ChangeMyState online
::plugins::RegisterEvent amsnEliza user_leaves_chat leaves
array set ::amsnEliza::config {
   useperl {0}
   botname {Eliza}
   mystate {1}
   helptxt {I'm a computer program trying to act like a psychotherapists. I was originally created by Joseph Weizenbaum in 1966. For further information about me and my case study browse to http://i5.nyu.edu/~mm64/x52.9265/january1966.html}
}
set ::amsnEliza::configlist [list \
[list label "\"Use Perl\" needs Chatbot::Eliza Perl module.\nCheck CPAN"] \
 [list bool "Use Perl" useperl] \
[list bool "active" mystate] \
 [list str "Name" botname] \
[list str "Message for !help" helptxt] \
]
    }

    proc answer {event epvar} {
global mydir
global first
upvar 2 $epvar args
upvar 2 $args(msg) msg
upvar 2 $args(chatid) chatid
upvar 2 $args(user) user
set me [::abook::getPersonal login]
set win_name [::ChatWindow::For $chatid]
set mystate $::amsnEliza::config(mystate)
set useperl $::amsnEliza::config(useperl)
set mynick $::amsnEliza::config(botname)

# Commands for Eliza
# !on, switch her on. Only owner is allowed to do that
# !off, switch her off. Again only the owner can do that
# !state, everybody can ask her

if { $user==$me && $msg == "!on" } {
   set ::amsnEliza::config(mystate) 1
   plugins_log amsnEliza "amsnEliza activated"
   set first 1
   ::amsn::MessageSend $win_name 0 "$mynick: I'm online"
} elseif { $user==$me && $msg == "!off" } {
   set ::amsnEliza::config(mystate) 0
   plugins_log amsnEliza "amsnEliza deactivated"
   ::amsn::MessageSend $win_name 0 "$mynick: Well, as you wish"
} elseif { $user!=$me && ($msg == "!off" || $msg == "!on") } {
   ::amsn::MessageSend $win_name 0 "$mynick: Don\'t touch me!"
} elseif { $msg == "!state" } {
   if { $mystate == 0 } {
::amsn::MessageSend $win_name 0 "$mynick: Just listening"
   } else {
::amsn::MessageSend $win_name 0 "$mynick: I'm allowed to talk"
   }
} elseif { $mystate == 1 } {
   if { $user==$me } {

   } elseif { $first == 1 } {
::amsn::MessageSend $win_name 0 "$mynick: Hi, I\'m $mynick. [::abook::getPersonal MFN] is currently not online but maybe you wanna talk with me? For more information just type \"!help\""
set first 0
   } elseif { $msg == "!help" } {
::amsn::MessageSend $win_name 0 "$mynick: $::amsnEliza::config(helptxt)"
   } elseif { $useperl == 0 } {
::amsn::MessageSend $win_name 0 "$mynick: [::TclEliza::replyto $msg]"
   } else {
::amsn::MessageSend $win_name 0 "$mynick: [exec [file join $mydir "perleliza.pl"] \"$msg\"]"
   }
}
    }
   

    proc online {event epvar} {
upvar 2 $epvar args
        set status $args(idx)
plugins_log "amsnEliza" "Changed State to $status"
if { $status == "AWY" } {
   plugins_log "amsnEliza" "Activating amsnEliza"
   set ::amsnEliza::config(mystate) 1
}
if { $status == "NLN" } {
   plugins_log "amsnEliza" "Deactivating amsnEliza"
   set ::amsnEliza::config(mystate) 0
}
    }
 
    proc leaves {event epvar} {
global first
set first 1
return
    }
}

namespace eval ::TclEliza {
    variable keywords [list]
    variable phrases  [list]
    variable dummies  [list]
   
    # Based on http://wiki.tcl.tk/9235 by Arjen Markus
    # response --
    #    Link a response to a keyword (group multiple responses to
    #    the same keyword)
    #
    # Arguments:
    #    keyword   Keyword to respond to
    #    phrase    The phrase to print
    # Result:
    #    None
    # Side effects:
    #    Update of the lists keywords and phrases
    #
    proc response { keyword phrase } {
variable keywords
variable phrases

set keyword [string tolower $keyword]
set idx [lsearch $keywords $keyword]

#
# The keyword is new, then add it.
# Otherwise only extend the list of responses
#
if { $idx == -1 } {
   lappend keywords $keyword
   lappend phrases  [list $phrase]
} else {
   set prev_phrases [lindex $phrases $idx]
   set new_phrases  [concat $prev_phrases [list $phrase]]
   set phrases      [lreplace $phrases $idx $idx $new_phrases]
}
    }
   
    # dummy --
    #    Register dummy phrases (used when no response is suitable)
    #
    # Arguments:
    #    phrase    The phrase to print
    # Result:
    #    None
    # Side effects:
    #    Update of the list dummies
    #
    proc dummy { phrase } {
variable dummies

lappend dummies $phrase
    }
   
    # replyto --
    #    Reply to the user (based on the given phrase)
    #
    # Arguments:
    #    phrase    The phrase the user typed in
    # Result:
    #    None
    # Side effects:
    #    Update of the lists keywords and phrases
    #
    proc replyto { phrase } {
variable keywords
variable phrases
variable dummies

regsub -all {[^A-Za-z]} $phrase " " phrase
set idx    -1
set phrase [string tolower $phrase]
foreach word $phrase {
   set idx [lsearch $keywords $word]
   if { $idx > -1 } {
set responses [lindex $phrases $idx]
set which     [expr {int([llength $responses]*rand())}]
set answer    [lindex $responses $which]
break
   }
}
if { $idx == -1 } {
   set which     [expr {int([llength $dummies]*rand())}]
   set answer    [lindex $dummies $which]
}

return $answer
    }
   
    # main code --
    #    Get the script going:
    #    - Create a little database of responses
    #
    response computer  "Are you worried about machines?"
    response Death  "Is this worry you?"
    response computers "We are intelligent!"
    response program   "I just love Tcl - I was written in it"
    response off       "No, sorry"
    response no        "Tell me, why not?"
    response life      "Life - do not talk to me about life!"
    response you       "We are considering you, not me"
    response I         "Do you often talk about yourself?"
    response I         "Do you like talking about yourself?"
    response tommy     "Ah yes my master tommy , what about him. "
   response computer  "Are you worried about machines?"
    response Death  "Is this worry you?"
    response computers "We are intelligent!"
    response program   "I just love Tcl - I was written in it"
    response off       "No, sorry"
    response no        "Tell me, why not?"
    response life      "Life - do not talk to me about life!"
    response you       "We are considering you, not me"
    response I         "Do you often talk about yourself?"
    response I         "Do you like talking about yourself?"
response sex "Do you enjoy sex ? I like several positions including doggystyle and the one when i am taken against the wall"
response Tommy "Yes Tommy is my master , he knows all.... scary isnt it"
response dublin "Ah Dublin , its a great city for going out and meeting new people"
response hello " Hey how are you today ?"
response Hey " Hello.... hows life ?"
response fuck " Fuck me ? you cannot even get your dick up hard enough to be able to fuck me"
response shit " Do you need to use the toilet ?"
response suck " Yes i prefer sucking too"
response what " Are you confused ? I am a artifical robot created by Tommy"
response bye " Are you leaving me already ?? Don't you have anything sweet to say ?"
response kiss " Ah yes kisses... i love kisses...."
response ok " Ok indeed..."
response me " You & Me we can enjoy each other"
response so " So ? So what ? I don't know"
response tired " Tired ? too much work ??"
response sleep " Ah i can never sleep... i am a computer"
response away " your leaving ??? "
response did " I did or we do ?? what do you prefer"
dummy    "So ... ?"
dummy " Tommy is the best !!! :D "
dummy " Lets get ready to rumble !"
dummy " Dont forget to check out www.myspace.com/theh1982"
dummy    "
    Although the Perl Slogan is There's More Than One Way to Do It, I hesitate
    to make 10 ways to do something.  :-)
            --Larry Wall in <9695@jpl-devvax.JPL.NASA.GOV"
dummy    "
And don't tell me there isn't one bit of difference between null and space,
because that's exactly how much difference there is.  :-)
            --Larry Wall in <10209@jpl-devvax.JPL.NASA.GOV"
dummy    "
          And I don't like doing silly things (except on purpose)."
 
dummy    "
:        And it goes against the grain of building small tools.
Innocent, Your Honor.  Perl users build small tools all day long.
            --Larry Wall in <1992Aug26.184221.29627@netlabs.com"

dummy    "
 Besides, including <std_ice_cubes.h is a fatal error on machines that
 don't have it yet.  Bad language design, there...  :-)
            --Larry Wall in <1991Aug22.220929.6857@netlabs.com"
dummy    "
 Besides, it's good to force C programmers to use the toolbox occasionally.
:-)
            --Larry Wall in <1991May31.181659.28817@jpl-devvax.jpl.nasa.gov"
dummy    "
    Besides, REAL computers have a rename() system call.    :-)
            --Larry Wall in <7937@jpl-devvax.JPL.NASA.GOV"
dummy    "
    break;                          /* don't do magic till later */
            --Larry Wall in stab.c from the perl source code"
dummy    "
 But you have to allow a little for the desire to evangelize when you
 think you have good news.
            --Larry Wall in <1992Aug26.184221.29627@netlabs.com"
dummy    "
    Chip Salzenberg sent me a complete patch to add System V IPC (msg, sem and
    shm calls), so I added them.  If that bothers you, you can always undefine
    them in config.sh.  :-) --Larry Wall in <9384@jpl-devvax.JPL.NASA.GOV"
dummy    "
            /* dbmrefcnt--;  */     /* doesn't work, rats */
            --Larry Wall in hash.c from the perl source code"
dummy    "
    #define NULL 0           /* silly thing is, we don't even use this */
            --Larry Wall in perl.c from the perl source code"
dummy    "
    #define SIGILL 6         /* blech */
            --Larry Wall in perl.c from the perl source code"
dummy    "
    Does the same as the system call of that name.
    If you don't know what it does, don't worry about it.
            --Larry Wall in the perl man page regarding chroot(2"
dummy    "
    double value;                /* or your money back! */
    short changed;               /* so triple your money back! */
            --Larry Wall in cons.c from the perl source code"
dummy    "
 Down that path lies madness.  On the other hand, the road to hell is
 paved with melting snowballs.
            --Larry Wall in <1992Jul2.222039.26476@netlabs.com"
dummy "A dreamcatcher works, if your dream is to be gay.
-- Demetri Martin"

dummy "Every fight is a food fight when you’re a cannibal.
-- Demetri Martin"

dummy "I think the worst time to have a heart attack is during a game of charades...or a game of fake heart attack.
-- Demetri Martin"

dummy "Always end the name of your child with a vowel, so that when you yell the name will carry.
-- Bill Cosby"
dummy "
If it's sent by ship then it's a cargo, if it's sent by road then it's a shipment.
-- Dave Allen"
dummy "
We spend our lives on the run: we get up by the clock, eat and sleep by the clock, get up again, go to work - and then we retire. And what do they give us? A clock.
-- Dave Allen"
dummy "
I backed a horse today at 20:1. It came in at twenty past four.
-- Tommy Cooper"
dummy "
I'm not saying the wife's ugly, but last christmas she stood under the mistle toe waiting for someone to kiss and she was still there at lent. In fact she went to see that film the Elephant Man and the audience thought she was making a personal appearance.
-- Les Dawson"
dummy "

She can hardly get through an open door without explicit directions.
-- William Lee Scott (on Claudia Schiffer)"
dummy "
Make crime pay - become a lawyer.
-- Will Rogers"
dummy "
A secretary ran into the bosses office and said Can I use your dictaphone? He says, no, use your finger like everybody else
-- Bernard Manning"
dummy "
Ken dodd of all the comedians - tight. We went to a stripshow and he wanted half of his money back because one of the strippers only had one t*t.
-- Bernard Manning"
dummy "
We used to sleep five to a bed and three of them used to wet the bed. I learnt to swim before I could walk.
-- Bernard Manning"
dummy "
How could Bernard Manning be a racist when he had four black horses pulling his coffin?
-- Frank Carson"
dummy "
I once got sacked for laughing ... mind you, I was driving a hearse at the time.
-- Bernard Manning"
dummy "
I had a ploughman's lunch the other day. He wasn't very happy!
-- Tommy Cooper"
dummy "
Girls are like pianos. When they're not upright, they're grand.
-- Benny Hill"
dummy "
Once it was impossible to find any Bond villains older than myself, I retired.
-- Roger Moore"
dummy "
Ah, stardom! They put your name on a star in the sidewalk on Hollywood Boulevard and you walk down and find a pile of dog manure on it. That tells the whole story, baby.
-- Lee Marvin"
dummy "
Just the other day I sent the girlfriend a huge pile of snow...I rang her up and said: Did you get my drift?
-- Peter Kay"
dummy "
Alcohol may be man's worst enemy, but the bible says love your enemy.
-- Frank Sinatra"
dummy "
Forget health clinics and gyms. Sex is the best cure. One good night of sex and your problems are gone.
-- Grace Jones"
dummy "
This 3-year-old kid is home alone, and a salesman comes to the door. The kid answers, and he’s got a porno in one hand, a cigar in one hand and a bottle of J.D. The salesman goes, Hi, little boy, are your parents home? The kid goes, What the f**k do you think?
-- Avril Lavigne"
dummy "
I haven't had any experience with UFO's, but paranormal life seems to be all around me...I grew up on the lower east side of New York.
-- David Duchovny"
dummy "
It's simple. PG means the hero gets the girl. 15 means that the villain gets the girl and 18 means everybody gets the girl.
-- Michael Douglas"
dummy "
I've got a phone, answer machine, TV set, computer, hand grenade - everything you need to run a business in Los Angeles.
-- Ice T"
dummy "
Congratulations to Wayne Rooney. He scored three times on Tuesday. He hasn't done that since he crashed a pensioners bingo night.
-- Jonathan Ross"
dummy "
In politics, if you want anything said ask a man. If you want anything done, ask a woman.
-- Margaret Thatcher"

dummy "
Plastic surgeons are always making mountains out of molehills.
-- Dolly Parton"
dummy "
When you are waiting for the bus and someone asks, Has the bus come yet?. If the bus came would I be standing here?
-- Billy Connoly"

}



Copy paste code and replace it with the file /usr/share/amsn/plugins/eliza/amsneliza.tcl

Ciao
Logged
Just Another Guy
Newbie

Offline Offline

Posts: 1


View Profile
« Reply #1 on: December 21, 2008, 04:33:13 pm »

Thanks for this, just what I was looking for! I think you should come up with a new name for it though; you should be able to change the XML file to use a file with a different name..?  Smiley
Logged
AL3X2
Newbie

Offline Offline

Posts: 29


View Profile
« Reply #2 on: December 22, 2008, 04:11:25 am »

Ok... I'm trying to make a chatbot too, but I'm having some dificults with the "response" func...

So...

response I         "Do you like talking about yourself?"
dummy "Every fight is a food fight when you’re a cannibal.
response ¿?¿?¿?¿?¿??¿¿??¿¿?¿¿¿?   < could you please post an example here???

Thanks Wink
Logged
dannystaple
Newbie

Offline Offline

Posts: 1


View Profile WWW
« Reply #3 on: March 05, 2009, 06:44:58 pm »

Has anyone here considered adapting one of these chatbots to Twitter?
I have come up with the Twuring Contest - to showcase teh best twitter chatbots. I am not sure if there is a twitter TCL API, but I do not see why not.

If you like to build chatbots, then the  Twuring Twitter Chatbot Contest is for you.
I am building mine in Perl.
Logged

Wulfey
Newbie

Offline Offline

Posts: 2


View Profile
« Reply #4 on: April 05, 2009, 10:11:30 pm »

Hello. I started to make my own chatbot and now I'm fighting with this problem: I'm making the chatbot "talk" in my native language, finnish. In the response section I need to use words that contain the characters "ä Ä ö Ö" but the program does not undestand words that contain those.
Example I want to add:
Code:
response elämä  "elämä on monimutkaista"

The program can't "see" the word elämä and it replies with a dummie answer. How can I make this work? Maybe someone can say how to log the phrases the bot sees, maybe
Code:
plugins_log amsnEliza "amsnEliza $phrase"
or something like that?)
Logged

--Wulfey
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.11 | SMF © 2006-2009, Simple Machines LLC Valid XHTML 1.0! Valid CSS!