Obviously you want to know how I did it (take a cup of coffee and read):

I've put all the phrases and words that should be recognized in an .ini file (main), the answers the bot should give in another .ini file (answer) and special words and phrases for second level dialogues in a third .ini file (special).

The main file contains three sections in which I store words and phrases for direct conversation (somebody calls the bot and talks to it), interference (nobody calls the bot, but the bot sometimes reacts to something that is said, f.i. somebody says "i'm going to sleep" then the bot could say "have a good night") and random replies (when there is no direct conversation and nobody said something that could be recognized then the bot sometimes smiles, yawns or says "brb, I have to kick the cat outside"). I will explain later how I organized the words and phrases in these sections and how I organized the answers and special dialogues.

The script contains two main parts: an event handler and a dialogue handler. The task of the event handler is to prevent that the bot reacts to everybody and everything, to simulate human behaviour (or better: average chatter behaviour) and to recognize phrases and words. If something could be recognized it passes the matched string to the dialogue handler and tells the dialogue handler what kind of conversation is going on (direct, interference or random). I will explain later how the event handler uses timers to simulate chatter behaviour.

The dialogue handler generates answers, performs functions to incorporate into the answers and tells the event handler what to do next. Every answer in the answer file contains some special characters, with which I can influence the event and dialogue handler. Most of these codes only have effect to the dialogue handler, e.g.:
- give the answer immediately (for helpdesk channels) or delayed
- don't make syntax errors in this answer (e.g. for helpdesk channels, btw the bot can have several kinds of conversations in several rooms concurrently)
- issue this answer as a message or an action
- fill in the nickname, time, date, result of a calculation, etc
- execute a command together with this answer (/kick, /dcc send, start a game, tell a joke, etc.)
- find out the chatter's sex (formal replies for helpdesks - sir, madam - or informal replies - honey, stud -)
- go into a second level dialogue
... and more.

There are 4 codes in answers that can be passed to the event handler:
- keep on listening to this chatter, conversation is not finished
- ignore this chatter, conversation with him is over
- be quiet for a number of minutes
- find out yourself what should happen next

The event handler uses a number of timers to simulate chatter behaviour and can listen to only one, two or another maximum number of chatters. These parameters are stored in a separate .ini file. The most important timers it uses are:
- listen to one chatter only during a certain number of seconds (direct conversation when somebody called the bot's name or the dialogue handler told to do so)
- don't listen to anybody until the last (delayed) answer has been put in the channel (the bot does one thing at a time: òr listening òr answering)
- when somebody joins the channel, listen for some time to everybody, no matter if there is a direct conversation going on (newcomers can take over a conversation)
There are more timers, but I have to dive into details to explain them.

I use some parameters to define the reaction level for the event handler. When somebody calls the bot's name, the event handler will stick to that chatter, but if not it will randomly try to find out whether it can interfere or should trigger a random answer. Otherwise it will randomly try to combine two sentences from its log based on the first three words of a chatter's sentence (I explained this in one of my earlier replies). This gives quite varied behaviour.

Now I come back to the organization of phrases, words and answers. These are stored in three .ini files: main, answers and special. I can have several groups of these files, a group for normal channels, several groups for several heldesk channels, groups for word-games, groups for operator channels (the bot can present a menu that contains commands to execute in another channel were the bot is joined as an operator), etc.

The main .ini file contains three sections, one which contains phrases and words to be recognized during direct conversations, one which contains words to be recognized when the bot is going to interfere and one which is used when the bot has to generate a random answer. Every section contains a number of items in which the phrases and words to be recognized are stored.

For direct conversations I use three kinds of items: one kind with regex matchstrings which enables the bot to recognize a variety of sentences with the same meaning, one kind that contains words or phrases that have to be recognized completely and one kind that can be recognized partially. The event handler searches these in a strict order: first direct regex, then direct full recognition, then direct partial recognition, then interfere and at last random. An example:

main .ini file (note that an item is restricted to contain about 900 characters):
[DIRECT]
INDEXR1=matchstring1 matchstring2 matchstring3 ....
INDEXR2=matchstringn matchstringn+1
INDEXRn=etcetera
INDEXCn=fullword fullphrase etc
INDEXPn=partialword partialphrase etc.

[INTERFERE]
INDEXPn=partialword partialphrase etc.

[RANDOM]
RANDOM=randomanswer1 randomanswer2

Each matchstring, fullword/phrase and partialword/phrase refers to one or more answers, which are picked randomly by the dialogue handler, for instance:

[DIRECT]
INDEXR1=matchstring1 matchstring2 matchstring3 ....
matchstring1=1 2 3 4
matchstring2=5 6
matchstring3=7 8 9 1 3
INDEXR2=matchstringn matchstringn+1
matchstringn=10 5 9 12
matchstringn+1=11 12 7 9
etc.

Answers are stored in a separate answer .ini file (except for random answers which are in the main .ini file) like this:

[ANSWERS]
1=answer1-1 answer1-2 answer1-3...
2=answer2-1 answer2-2...
etc.

This gives very varied answers. First the dialogue handler picks a random answernumber from the main .ini file, then it picks a random answer from the answerfile belonging to that number.

I can also refer to answers in other groups, by using:

INDEXR2=matchstringn matchstringn+1
matchstringn=10+CHATROOM1 5+HELPDESK1 9+HELPDESK2 12+WORDGAME1

For second level dialogues I use a special .ini file which has about the same structure as the main .ini file. But in the special .ini file only words and phrases are stored that belong to a certain type of conversation. For instance, the dialogue handler picks an answer that contains a special code plus name for a second level dialogue, like in:

[ANSWERS]
123=answer123-1 answer123-2*KICK

I use this when somebody talks about a footballclub which is not the bot's favorite club. Answer123-1 could contain something like: "don't talk about that club". Answer123-2*KICK could contain: "you want to win an award? if not, stop talking :)". Then it would dive into the special KICK dialogue to find out whether the chatter keeps on nagging the bot. If so the chatter gets a chance to be kicked. Btw, there is a special timer which tells the event handler how long to stay in a second level dialogue, otherwise the bot would could get lost and never come out of it.

There is more to tell, but that would be too detailed.

As you can understand, this is not a self learning botscript, almost everything is predefined. I watched a lot of conversations between human chatters to find out what kind of matchstrings, words and phrases I should add to the bot. Most conversations are like: hello, how are you, how old are you (what is your age), what have you eaten (the bot will answer according to the actual time: in the morning he had a breakfast, in the afternoon lunch and in the evening some kind of hot dish), can I have a picture of you (I want a picture of you, please send me a picture), what is your favorite thing, where do you live (where do you come from), what are you doing now. My bot is capable of answering these kind of questions and ask meaningful questions too. But for a self learning bot you will need a kind of event and dialogue handler as described above plus an analyser that is capable of analyzing natural language. And such an analyser is very difficult to script. Also it would cost you a lot of time to learn the bot talking.

English is not my native language, I hope I made myself clear. Good luck!

Last edited by noMen; 18/09/07 10:15 AM.