为此,我一直在使用 Github 的hubot。当被要求讲笑话时,我的机器人会讲笑话。(当然我也有一个我可以问我应该做什么,它会查找我的工作清单。)
GoGoBot> tell a joke about me
GoGoBot> a joke about Shell... Let me think about it...
GoGoBot>
I heard a funny one the other day:
Chuck Norris doesn't look both ways before he crosses the street...
he just roundhouses any cars that get too close.
该机器人在 NodeJS 上运行。该 api 需要一个正则表达式和一个回调,如
robot.hear /tell a joke/i, (msg) -> msg.send 'I heard a funny joke...'
module.exports = (robot) ->
robot.hear /tell (?:a|something) (?:joke|funny)(?: about ([a-z.]+))?/i, (msg) ->
subject = getSubject msg.match[1], msg.message.user.name
msg.send 'a joke about ' + subject + '... Let me think about it...' if subject.length
tellJoke = ->
getJoke subject, (err, text) ->
msg.send "Cannot compute. #{robot.name} is about to die.\r\n#{err}".replace(/e/ig, '3') if err?
msg.send "I heard a funny one the other day:\r\n#{text}" unless err?
setTimeout tellJoke, 5000 * Math.random()
因为我已经熟悉 NodeJS 和咖啡脚本,所以它很容易学习。我写了我今天在几个小时内提到的两个机器人。