Skip to content
This repository has been archived by the owner on Jun 8, 2023. It is now read-only.

Commit

Permalink
Help text + more idiomatic coffeescript
Browse files Browse the repository at this point in the history
  • Loading branch information
Kevin Qiu committed May 14, 2012
1 parent 69f1ce3 commit b0dfc0b
Showing 1 changed file with 7 additions and 11 deletions.
18 changes: 7 additions & 11 deletions src/scripts/whatis.coffee
@@ -1,30 +1,26 @@
#
# whatis <term> - search the term on urbandictionary.com, return the
# whatis <term> - search the term on urbandictionary.com and get a random popular definition for the term.

jsdom = require('jsdom').jsdom

module.exports = (robot) ->
robot.respond /whatis (.+)$/i, (msg) ->
msg
.http('http://www.urbandictionary.com/define.php?term=' + msg.match[1])
.http('http://www.urbandictionary.com/define.php?term=' + (encodeURIComponent msg.match[1]))
.get() (err, res, body) ->
window = (jsdom body, null, {
features : {
window = (jsdom body, null,
features :
FetchExternalResources : false
ProcessExternalResources : false
MutationEvents : false
QuerySelector : false
}
}).createWindow()
).createWindow()

$ = require('jquery').create(window)

definitions = []
$(".definition").each (idx, item) ->
definitions.push $(item).text()

if definitions.length == 0
msg.send "No definition found."
else
msg.send (msg.random definitions)

msgText = if definitions.length==0 then "No definition found." else (msg.random definitions)
msg.send msgText

0 comments on commit b0dfc0b

Please sign in to comment.