Project "Kalich" - The intelligent IRC bot

Toolz manual
Statistic man
-> AI <-


Project Loufiz

Powered by
SourceForge Logo

Tracked by
Operation Manual - AI
(Introduction to AI)

Among the rest this bot is capable of chatting with people just like a real human. What's so useful about it you ask? Well I don't know how about you but I find it pretty entertaining to read the logs and discover that someone who thinks that he's talking to a human is actually having an affair with your bot. Anyway... If you want to make your bot talk you gotta teach it how to do it.

How to do it?
(General overview of the process)

Before you can do it there are a few terms you should know.

Types keywords and replies

  • Type - A component of the AI database. A type refers to a phrase that can be said in several forms but have the same meaning. The types are divided into 3 categories:
    • Question - A question phrase.
      Triggers when a phrase contains the bots nick and a question mark (Or several question marks).
    • Nonquest - An ordinary (non-question) phrase.
      Triggers when a phrase contains the bots nick and NO question marks.
    • React - Any phrase.
      Triggerred when the bot sees a keyword associated with a React type within any phrase disregarding its own nick and question marks.

    • Note: When the bot sees its own nick on a channel it assumes that the message is addressed to it. (Doesn't apply to React types) In private the bots nick is not required to trigger question and nonquest types.
  • Keyword - The differrent ways (words) to trigger the same type.
    Now in case you have no idea what the hell I'm talking about here's an example:
      Typename: whatsup

      Note the ! as the first character of the how_are_you keyword. This indicates a priority keyword. Priority in keywords will be discussed later. Also note that the spaces are replaced by "_" characters. This also will be discussed later.
      In this case the type should be a question type because such phrases are usually followed by a question mark.

      Each type has its own replies database. When the bot sees a keyword it picks a random reply from the database of the type that this keyword belongs to, and uses it as an answer.

  • Here are examples of our 3 kinds of types:
      The question type:

        Typename: whatsup
        Category: question
        Keywords: "!how_are_you", "what's_up", "wazzup"
        Replies: "Ok", "Me? I'm fine", "None of your business"

      *Note* You may name your type any name you like. The type names appearing in this manual are just names I made up.

      In this case what will happen on IRC is the following:
      Let's assume that our bot's nickname is UncleSam.

        <SomeDude> UncleSam: what's up?
        <UncleSam> SomeDude: None of your business

      Remember that the bot picks a random answer from the reply database.

      The following will work the same way:
        <SomeDude> how are you UncleSam?
        <UncleSam> SomeDude: Me? I'm fine

      But if SomeDude would say:
        <SomeDude> how are you UncleSam

      UncleSam would not match the keyword because the corresponding type is a question type.
      In this case you might want to add a nonquest type:

        Typename: whatsup_nonquest
        Category: nonquest
        Keywords: "how_are_you", "what's_up", "wazzup"
        Replies: "Is that a question?"

      And here's what will happen on IRC:
        <SomeDude> UncleSam: wazzup my man
        <UncleSam> SomeDude: Is that a question?

      And here is an example of a react type:

        Typename: time
        Category: react
        Keywords: "what's_the_time_now"
        Replies: "Late. Really late."

      And what will happen on IRC is this:
        <SomeDude> anyone knows what's the time now?
        <UncleSam> SomeDude: Late. Really late.

      In this case the bot disregards its own nick and question marks.

  • Predefined types:
      In case there is a message addressed to the bot that contains no keywords the replies will be taken from the question and nonquest predefined types.

      Note: Do not confuse the question and nonquest types with the question and nonquest type categories.
      In this case "question" and "nonquest" are type names.
      These two types are predefined and cannot be deleted.

      Here goes another example:
        Typename: question <-- These two are fixed and cannot be
        Category: question <-- modified. They're predefined.
        Keywords: None
        Replies: "Yes", "No", "None of your business", "What makes you ask that?"

      Note: Here you should put replies that can answer all questions in general.

      And on IRC:
        <SomeDude> UncleSam, are you cornholio?
        <UncleSam> Somedude: Yes

      This will happen assuming that "are", "you", and "cornholio" are not keywords of an existing question category type.
      The nonquest predefined type works the same way but only on phrases without question marks.
    Doing it
    (Command reference)

    In order to enable a user/yourself to use the AI commands you must set his/your global W flag on.

    If you execute a command without arguments or with invalid arguments the bot will supply you with the correct syntax and list of all existing types.

    Here goes the command list:

      Command: Addtype
      Adds a new type to the AI database.
      Syntax: addtype <newtype> <category> <initial keyword>
      Example: !addtype hi nonquest hello

      Command: Deltype
      Delets an existing type
      Syntax: deltype <type>
      Remarks: The question and nonquest predefined types cannot be deleted.

      Command: Addkeyword
      Adds a keyword to a specific type
      Syntax: addkeyword <type> <keyword(s)>
      Remarks: See "Special characters in keywords" below
      Example: !addkeyword hi hello hi whazzap

      Command: Delkeyword
      Deletes a keyword
      Syntax: delkeyword <type> <keyword>
      Example: !delkeyword hi hello

      Command: Showkeywords
      Lists all keywords of a specific type
      Syntax: showkeywords <type>

      Command: Learn
      Adds a reply phrase to a specific type
      Syntax: learn <type> <phrase>
      Example: !learn hi H.D.S sir. And how are you this afternoon? Alrighty then.

      Command: Forget
      The opposite of learn (duh).
      Syntax: forget <type> <phrase>
      Example: !forget hi H.D.S sir. And how are you this afternoon? Alrighty then.

      Command: DeleteDB
      Deletes the reply database of a type
      Syntax: deletedb <type>
      Remarks: The type itself and the keywords are not deleted

      Command: Listall
      Lists all reply phrases of a specific type
      Syntax: listall <type> [starting line number]

      Command: SearchDB
      Searches for the given substring in all database files, and displays a list of matched strings and their corresponding types in private message.
      Syntax: searchdb <substring>

    Keyword priority

      When a bot recieves a phrase with multiple keywords that belong to different types, it chooses the type to answer on randomally.
        The following command set is executed:

          !addtype hello nonquest hello
          !learn hello Hi :)
          !learn hello Good evening. Would you like some tea?

          !addtype lovelyday nonquest lovely_day
          !learn lovelyday Yes, it sure is, Charles.
          !learn lovelyday No, today is a bad day!

        Then, if on IRC somedude will say:

          <SomeDude> UncleSam: hello, lovely day isn't it.

        Bot's reply to that will be one of the following, chosen randomally:

          <UncleSam> Somedude: Hi :)
          <UncleSam> Somedude: Good evening. Would you like some tea?
          <UncleSam> Somedude: Yes, it sure is, Charles.
          <UncleSam> Somedude: No, today is a bad day!

      If you wish to make a keyword that will override all the other keywords, you need a priority keyword. A priority keyword is a keyword that starts with "!".
        In addition to commands executed in the previous example, the following commands are executed:

          !addtype moron nonquest !moron
          !learn moron Yes, I sure am a moron.

        Then, if on IRC somedude will say:

          <SomeDude> UncleSam: hello, lovely day isn't it, you moron.

        Bot's reply will always be:

          <UncleSam> Somedude: Yes, I sure am a moron.

    Special characters in keywords

      When you want to set a multi-word keyword you should separate the words with "_". Otherwise each of the words will be considered a keyword.

      Note that this does not apply to the Learn command.
      Unlike the Addkeyword command Learn adds only one reply phrase at a time. Therefore the underscores are not required.

      When you want the bot to react to two keywords in one phrase you should separate the keywords with "&&".
      Only one "&&" per keyword allowed.


      !addkeyword asltype i_am&&years_old

      The bot will react to the following phrases:
        "i am 23 years old"
        "i am years old"
        "years old i am"

      Note that the phrase "am i 23 years old" will not trigger because the words separated by underscores are treated as single keywords.

    Variables in phrases

      Teached phrases can now contain variables.
      For a start, only one possible variable was added:
        %r - Replaced with a random nick from the channel.
          You execute the following command set:

            !addtype here react anyone_here
            !learn here Yes, %r is here.

          Now, let's assume that your bot is on a channel with the following people:
          L3ECH, Muhammed, Somedude and UncleSam (which is the bot).
          And then, somedude will say:

            <SomeDude> is anyone here?

          Bot's reply will be one of the following, randomally:

            <UncleSam> Yes, L3ECH is here.
            <UncleSam> Yes, Muhammed is here.

        NoteThe bot's nick will never be used to substitute a %r, the nick of the person saying the triggered keyword (in our case - SomeDude) will never be used and a nick of a person who has a local or global +I flag on the bot, will also never be used (More detailed description of the flag in the next section).

      If you have suggestions for more USEFUL variables, please email the author with the description of the requested variable, examples of usage (and possibly a patch :)).

    How is it done?
    (Some technical information)

      The types and keywords are stored in a file named AI-type.dat in the following format:
        Question types:
          typename => keyword1 keyword2 keyword3 etc
        Nonquest types:
          typename -> keyword1 keyword2 keyword3 etc
        React types:
          typename _> keyword1 keyword2 keyword3 etc

      The reply databases are stored in files which are named in the following manner:

      That includes the question and nonquest predefined types.

    (Not teaching related stuff)

    • Random Talk feature

      This feature makes the bot spontaneously react to phrases that are not addressed to it. The default chance of Random Talk is 1:160 and it is configured in the script itself (also can be disabled). The processing of a Random Talk phrase is the same as any ordinary phrase that is addressed to the bot.

    • Random referring to others

      There was a 1:15 chance the bot will answer something like "I don't know, ask [random nick from the channel]" to a direct question addressed to it. This feature had no actual purpose, and it was kinda cool at first, but now when there are variables in phrases it became completely useless, so the author decided to remove it to make the code free of useless bloat. If you still want this feature, take it from release version 0.04 or earlier.

    • Fixed replies

      The bot has 3 fixed replies.
      • Age/Sex/Location reply
        Triggered by bot's nick and "asl" or "a/s/l". The reply to this will be:
        "I am [random "male" or "female"], [random number] years old from [random country]"
      • Male/Female reply
        Triggered by bot's nick and "m/f" or "m or f". The reply to this will be either "m" or "f".
      • Age reply
        Triggered by bot's nick and " old" or " age". The reply to this will be: "[random number] years.".

    • Answer delay

      (As you probably noticed) There's a 3-7 seconds delay before the bot answers. This is done on purpose, to make the bot act more "human" and think before it answers :)

    • The Ignore flag (+I)

      The bot will never say anything to a user that has a local or a global +I flag on. Even if the user with the +I flag addresses a phrase directly to a bot (says the bot's nick) - the bot will just ignore it, same as it will do for any "React" type triggered phrases. Other public commands are not affected by this flag.

    • The Spying flag (+S)

      If you want to be able to see the private conversations of people with the bot, set your global +S flag on. Then you'll see everything people say to the bot in private messages along with the bot's answers.

    • Shudup/Unshudup public commands

      If the bot gets too annoying - you can shut it up by using the !shudup [#channel] public command. This will stop all bot talk on requested channel (if #channel parameter is not specified - assumes current channel). If you want the bot to start talking again - use the !unshudup [#channel] command.

  • This manual was originally written by Weedsmoka. Fixes, additions and HTML version by me.
    (C) 2002, L3ECH