Search code examples
batch-filechatbots

How To Make Chat Bot In Batch


I want create a chat bot progrom in batch.

The chat bot responds to different keywords.

For example: If you said Hi, bot. Then it takes the keyword "Hi" and then responds with something like: Hello, What Is Your Name?

Here is my code:

@echo off 
color 0a
title Chat Bot
:chatloop
set /p n=Name:
set /p c=Chat:

If "%c%" Contains "Hi" (   <-- What would be this line of code?        

echo Hi, how are you?
pause
goto chatloop


)

Solution

  • search for keywords instead of full phrases:

    @echo off
    :loop
    set /p input="> "
    echo %input%|find /i "hi" >nul && echo Hello.
    echo %input%|find /i "your name" >nul && echo My name is Rob. What's yours?
    echo %input%|find /i "my name is" >nul && echo That's a nice name.
    echo %input%|find /i "wheather" >nul && echo Wonderful. Sun is shining.
    echo %input%|find /i "bye" >nul && (echo what a pity. See you! & goto :eof)
    REM choose your keywords wisely...
    goto :loop
    

    Note: this is a very basic "show how". No errorhandling at all.