Skip to content
This repository has been archived by the owner. It is now read-only.
Branch: master
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
59 lines (49 sloc) 1.72 KB
# Description:
# Allows Hubot to translate text into various dialects
# Dependencies:
# "htmlparser": "1.7.6"
# "soupselect: "0.2.0"
# Configuration:
# None
# Commands:
# hubot dialectize|dialect|dia <dialect>|help <text> - Translates the given text into the given dialect
# Author:
# facto
Select = require("soupselect").select
HtmlParser = require "htmlparser"
#TODO: get this dynamically?
dialects = ["redneck", "jive", "cockney", "fudd", "bork", "moron", "piglatin", "hckr", "censor"]
module.exports = (robot) ->
robot.respond /(?:dialectize|dialect|dia) (\w+)(.*)/i, (msg) ->
[dialect, text] = msg.match[1..2]
if dialect in ["help", "h"]
return unless text
trim text
return unless text.length > 0
if dialect in ["all", "a"]
showDialectizedText(msg, dialect, text, true) for dialect in dialects
else if dialect is "hacker"
dialect = "hckr"
showDialectizedText(msg, dialect, text, false)
showDialectizedText = (msg, dialect, text, showPrefix) ->
msg.http("" + encodeURIComponent(dialect) + "&text=" + encodeURIComponent(text))
.get() (err, res, body) ->
handler = new HtmlParser.DefaultHandler()
parser = new HtmlParser.Parser handler
parser.parseComplete body
result = Select handler.dom, ".dialectized_text p"
return unless result
dialectizedText = trim result[0].children[0].raw
dialectizedText = "#{dialect}: " + dialectizedText if showPrefix
msg.send dialectizedText
showHelp = (msg) ->
msg.send "Dialects: " + dialects.join(", ")
trim = (string) ->
return string.replace(/^\s*|\s*$/g, '')
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.