问题
A separate question for the AIML bot in my previous post... How do you create a bot that responds at different times of the day? I feel like it will make him seem more "real."
I can't make heads or tails about how the date and time display actually works. I assume you'd have to fiddle with that alongside the set/get functions... but that's all I know for sure.
I would like my bot to do something like this.
TIME: Noon
USER: Hi, bot.
BOT: Good afternoon, USER! It's about lunchtime for me.
Where do I start? Thanks.
回答1:
You need to check the hour and then use condition to give an appropriate response. Here's a category where the bot will respond sensibly even if someone says "Good morning" in the middle of the night
<category>
<pattern>GOOD MORNING</pattern>
<template>
<think><set name="hour"><date format="%H"/></set></think>
<condition name="hour">
<li value="00">Hello, it's more like the middle of the night than morning. How are you this morning?</li>
<li value="01">Hello, it's only just morning. How are you this morning?</li>
<li value="02">Hello and how are you this morning?</li>
<li value="03">Hello and how are you this morning?</li>
<li value="04">Hello and how are you this morning?</li>
<li value="05">Hello and how are you this morning?</li>
<li value="06">Hello and how are you this morning?</li>
<li value="07">Hello and how are you this morning?</li>
<li value="08">Hello and how are you this morning?</li>
<li value="09">Hello and how are you this morning?</li>
<li value="10">Hello and how are you this morning?</li>
<li value="11">Hello and how are you this morning?</li>
<li value="12">You're a bit late. It's lunchtime here.</li>
<li value="13">Morning?! It's the afternoon here.</li>
<li value="14">Morning?! It's the afternoon here.</li>
<li value="15">Morning?! It's the afternoon here.</li>
<li value="16">Morning?! It's the afternoon here.</li>
<li value="17">Morning?! It's nearly evening.</li>
<li value="18">Morning?! It's evening here.</li>
<li value="19">Morning?! It's evening here.</li>
<li value="20">Morning?! It's evening here.</li>
<li value="21">Morning?! It's night time here.</li>
<li value="22">Morning?! It's night time here.</li>
<li value="23">Morning?! It's night time here.</li>
</condition>
</template>
来源:https://stackoverflow.com/questions/55717225/aiml-chatbot-response-differs-at-different-times