在聊天机器人中,机器人有一个函数可以用短语回答确定的命令,例如
match /^Loggy, te amo/, :use_prefix => false
def execute(user)
if user.name.eql? 'Cquintero6'
@client.send_msg '/me besa a Carlos'
@client.send_msg 'Io también te jamón <3'
else
@client.send_msg "#{user.name}, ¿En serio crees que amaria a una basurilla como tú? Sáquese. "
end
end
当我写“Loggy,te amo”时,机器人会在聊天中回答,具体取决于用户。问题是,如何制作答案列表,以便机器人选择一个随机答案?谢谢! (随机字符串“@ Client.send_msg”)
答案 0 :(得分:0)
构造数组很简单:
new DateTimeFormatterBuilder()
.parseCaseInsensitive()
.appendValue(IsoFields.WEEK_BASED_YEAR, 4, 10, SignStyle.EXCEEDS_PAD)
.appendLiteral("-")
.appendValue(IsoFields.WEEK_OF_WEEK_BASED_YEAR, 2)
.toFormatter();
您还可以使用faker gem。有关选项,请参阅其自述文件,但这是一个示例:
phrases = [
"a phrase",
"another phrase"
]
此时您只需选择一个随机条目,这很简单:
phrases = 10.times.map { Faker::Company.catch_phrase }
假设您还想获得一个随机短语,但根据运行时变量更改文本。这是一种方法:
random_phrase = phrases.sample
@client.send_msg random_phrase
这会在运行时编译ERB字符串