如何将此功能添加到我的bat聊天机器人?

时间:2018-01-06 19:08:42

标签: batch-file chat chatbot

这是我的聊天机器人。我想补充一点,如果输入的内容不同于"是"和"不"然后它应该回应"错误答案"。

@ECHO OFF
title Bane
:CHAT
SET /P input=Oh You think darkness is your ally? (yes or no) Your message:

IF %input%==yes ECHO That's were you're wrong!
IF %input%==no ECHO Admirable, but mistaken.
GOTO CHAT
:END
PAUSE

1 个答案:

答案 0 :(得分:1)

@ECHO OFF
title Bane
:CHAT
SET /P "input=Oh You think darkness is your ally? (yes or no) Your message: "
IF /i "%input%"=="yes" ECHO That's were you're wrong! & goto :end
IF /i "%input%"=="no" ECHO Admirable, but mistaken. & goto :end
echo wrong answer & goto :chat

:END
PAUSE

您可能对choice命令感兴趣,该命令具有自己的输入验证功能:

@ECHO OFF
title Bane
:CHAT
choice /C YN /M "Oh You think darkness is your ally? Your message: "
if errorlevel 2 ECHO That's were you're wrong! & goto :end
if errorlevel 1 ECHO Admirable, but mistaken. & goto :end
echo wrong answer ; this line is never reached

:END
PAUSE

在第二个代码示例中,我删除了(yes or no),因为choice已经打印出所有有效选项。但是当然你可以保留它并使用/n(感谢,Compo,有效参数)来压制默认选择:

`choice /C YN /N /M "Oh You think darkness is your ally? (yes or no) Your message: "`