Created
May 15, 2012 19:17
-
-
Save eykd/2704330 to your computer and use it in GitHub Desktop.
Markov plugin for Hubot
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
base_url = 'http://nymkit.com/generators/chatterbots/gort/' | |
module.exports = (robot) -> | |
robot.catchAll (msg) -> | |
if msg.message.text.match(/\bgort\b/i) or msg.message.text.match(/\n/) | |
# When addressed, I'll pull something out of my... sock | |
# drawer. Or, if it's a multi-line message, I'll add my | |
# two cents. | |
json_params = | |
name: 'gort' | |
message: msg.message.text | |
# POST signifies a response is desired. | |
msg.http(base_url) | |
.header('Content-Type', 'application/json') | |
.post(JSON.stringify json_params) (err, res, body) -> | |
# http errors | |
if err | |
msg.reply("I'm sorry, what?") | |
return | |
# response json parse errors | |
try | |
decodedResponse = JSON.parse body | |
catch decodeError | |
msg.reply("I'm sorry, what?") | |
return | |
# Reply with witty repartee | |
msg.reply decodedResponse.message | |
if msg.message.text.match(/^([^\n]+)$/) and msg.user.name != 'Sentry' | |
# Listen to, and learn from, from the chatroom chatter. | |
# Every comment in the room is sent to the chatterbot's learner, | |
# except multi-line comments and Sentry notifications. | |
json_params = | |
name: 'gort' | |
message: msg.match[1] | |
# PUT signifies learning mode. | |
msg.http(base_url) | |
.header('Content-Type', 'application/json') | |
.put(JSON.stringify json_params) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment