Skip to content

Instantly share code, notes, and snippets.

@donpdonp
Last active September 30, 2022 10:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save donpdonp/df36c86a223c749b15d83dcca1181008 to your computer and use it in GitHub Desktop.
Save donpdonp/df36c86a223c749b15d83dcca1181008 to your computer and use it in GitHub Desktop.
gluon urban dictionary
(function() {
// descriptor
return {name:"urbandictionary"}
})
function go(msg) {
if (msg.method == "irc.privmsg") {
var cmd_match = /^!urbandictionary(\s+(\w+))?/.exec(msg.params.message)
if(cmd_match) {
var url = 'http://api.urbandictionary.com/v0/define?term='+encodeURIComponent(cmd_match[2])
bot.say(bot.admin_channel, url)
var data = JSON.parse(http.get(url))
var list = data.list.sort(function(a,b){return b.thumbs_up - a.thumbs_up})
var entry = list[0]
var short_match = /(.+)/.exec(entry.definition)
var say = cmd_match[2]+' '+short_match[1]+' ('+entry.thumbs_up+' thumbs up)'
bot.say(msg.params.channel, say)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment