This repository has been archived by the owner on Jun 8, 2023. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Help text + more idiomatic coffeescript
- Loading branch information
Kevin Qiu
committed
May 14, 2012
1 parent
69f1ce3
commit b0dfc0b
Showing
1 changed file
with
7 additions
and
11 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |