This repository has been archived by the owner. It is now read-only.
Permalink
Browse files

Merge pull request #421 from kevinjqiu/master

Add "whatis" command
  • Loading branch information...
2 parents 20b1293 + b047909 commit d8774995a79083066fef7a63af36f63929f62081 @tombell tombell committed May 15, 2012
Showing with 26 additions and 0 deletions.
  1. +26 −0 src/scripts/whatis.coffee
View
@@ -0,0 +1,26 @@
+#
+# 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=' + (encodeURIComponent msg.match[1]))
+ .get() (err, res, body) ->
+ window = (jsdom body, null,
+ features :
+ FetchExternalResources : false
+ ProcessExternalResources : false
+ MutationEvents : false
+ QuerySelector : false
+ ).createWindow()
+
+ $ = require('jquery').create(window)
+
+ definitions = []
+ $(".definition").each (idx, item) ->
+ definitions.push $(item).text()
+
+ msgText = if definitions.length==0 then "No definition found." else (msg.random definitions)
+ msg.send msgText

0 comments on commit d877499

Please sign in to comment.