Skip to content
Newer
Older
100644 41 lines (35 sloc) 1.02 KB
3406d66 @technicalpickles Update "w" help comments
technicalpickles authored Jun 8, 2012
1 # Description:
2 # None
3 #
4 # Dependencies:
5 # "jsdom": "0.2.14"
6 #
7 # Configuration:
8 # None
9 #
10 # Commands:
11 # hubot whatis <term> - search the term on urbandictionary.com and get a random popular definition for the term.
12 #
13 # Author:
14 # Kevin Qiu
372727e @technicalpickles Update "u" help comments
technicalpickles authored Jun 8, 2012
15 #
16 # FIXME merge with urban.coffee
69f1ce3 @kevinjqiu added urbandictionary script
kevinjqiu authored May 9, 2012
17
18 jsdom = require('jsdom').jsdom
19
20 module.exports = (robot) ->
21 robot.respond /whatis (.+)$/i, (msg) ->
22 msg
b0dfc0b @kevinjqiu Help text + more idiomatic coffeescript
kevinjqiu authored May 14, 2012
23 .http('http://www.urbandictionary.com/define.php?term=' + (encodeURIComponent msg.match[1]))
69f1ce3 @kevinjqiu added urbandictionary script
kevinjqiu authored May 10, 2012
24 .get() (err, res, body) ->
b0dfc0b @kevinjqiu Help text + more idiomatic coffeescript
kevinjqiu authored May 14, 2012
25 window = (jsdom body, null,
26 features :
69f1ce3 @kevinjqiu added urbandictionary script
kevinjqiu authored May 10, 2012
27 FetchExternalResources : false
28 ProcessExternalResources : false
29 MutationEvents : false
30 QuerySelector : false
b0dfc0b @kevinjqiu Help text + more idiomatic coffeescript
kevinjqiu authored May 14, 2012
31 ).createWindow()
69f1ce3 @kevinjqiu added urbandictionary script
kevinjqiu authored May 10, 2012
32
33 $ = require('jquery').create(window)
34
35 definitions = []
18ca775 @cheeaun s/definition/meaning
cheeaun authored Jan 28, 2014
36 $(".meaning").each (idx, item) ->
69f1ce3 @kevinjqiu added urbandictionary script
kevinjqiu authored May 10, 2012
37 definitions.push $(item).text()
38
b0dfc0b @kevinjqiu Help text + more idiomatic coffeescript
kevinjqiu authored May 14, 2012
39 msgText = if definitions.length==0 then "No definition found." else (msg.random definitions)
40 msg.send msgText
Something went wrong with that request. Please try again.