Sha256: 2d230327de962f9c67b9c726c93a5123aed2d461977da53c25c1881d71dd3668

Contents?: true

Size: 764 Bytes

Versions: 14

Compression:

Stored size: 764 Bytes

Contents

require 'open-uri'
require 'nokogiri'
require 'cgi'

module Cinch
  module Plugins
    class Urban
      include Cinch::Plugin

      match /u (.*)$/

      set :plugin_name, 'urban'
      set :help, <<EOT
Urban connects to urban dictionary and returns the first result for a given query, replying with the result directly to the sender
EOT

      def query(query)
        url = "http://www.urbandictionary.com/define.php?term=#{CGI.escape(query)}"
        begin
          CGI.unescape_html Nokogiri::HTML(open(url)).at("div.meaning").text.gsub(/\s+/, ' ')
        rescue
          "no result found"
        end
      end

      def new(bot)
        @bot = bot
      end

      def execute(m,words)
        m.reply(query(words.strip))
      end

    end
  end
end

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
cogbot-0.1.14 plugins/urban.rb
cogbot-0.1.13 plugins/urban.rb
cogbot-0.1.12 plugins/urban.rb
cogbot-0.1.11 plugins/urban.rb
cogbot-0.1.10 plugins/urban.rb
cogbot-0.1.9 plugins/urban.rb
cogbot-0.1.7 plugins/urban.rb
cogbot-0.1.6 plugins/urban.rb
cogbot-0.1.5 plugins/urban.rb
cogbot-0.1.4 plugins/urban.rb
cogbot-0.1.3 plugins/urban.rb
cogbot-0.1.2 plugins/urban.rb
cogbot-0.1.1 plugins/urban.rb
cogbot-0.1.0 plugins/urban.rb