Sha256: c70fc7ccaac9c7b1b7df6b19bb30d8c5b2b43dc34f056cbf0f061a4f23cc3f82
Contents?: true
Size: 955 Bytes
Versions: 3
Compression:
Stored size: 955 Bytes
Contents
# -*- coding: utf-8 -*- require 'cinch-cooldown' require 'cinch-toolbox' module Cinch::Plugins class UrbanDict include Cinch::Plugin enforce_cooldown self.help = "Use .ud <term> to see the Urban Dictionary definition for that term." match /ud (.*)/ def execute(m, term) m.reply get_def(term) end private def get_def(term) # URI Encode term = URI.escape(term, Regexp.new("[^#{URI::PATTERN::UNRESERVED}]")) url = "http://www.urbandictionary.com/define.php?term=#{term}" # Grab the element result = Cinch::Toolbox.get_html_element(url, '.definition') #Make sure it's not terribly long result = Cinch::Toolbox.truncate(result, 250) return "Urban Dictionary ∴ #{term}: #{result} [#{Cinch::Toolbox.shorten(url)}]" rescue NoMethodError debug "Caught a NoMethodError looking up #{term}" return "Sorry I couldn't find that term." end end end
Version data entries
3 entries across 3 versions & 1 rubygems